lsgrmBaatzSegmenter.txx 1.76 KB
Newer Older
1 2 3
#ifndef __LSGRM_BAATZ_SEGMENTER_TXX
#define __LSGRM_BAATZ_SEGMENTER_TXX
#include "lsgrmBaatzSegmenter.h"
remicres's avatar
remicres committed
4
namespace lsgrm
5 6
{

remicres's avatar
remicres committed
7 8 9 10 11 12 13 14
template<class TImage>
void
BaatzSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
  std::size_t bands = node->m_Means.size();
  fwrite(&(bands), sizeof(bands), 1, nodeStream);

  for(unsigned int b = 0; b < node->m_Means.size(); b++)
15
    {
remicres's avatar
remicres committed
16 17 18 19
    fwrite(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
    fwrite(&(node->m_SquareMeans[b]), sizeof(node->m_SquareMeans[b]), 1, nodeStream);
    fwrite(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
    fwrite(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
20
    }
remicres's avatar
remicres committed
21
}
22

remicres's avatar
remicres committed
23 24 25 26 27 28 29 30 31 32 33 34
template<class TImage>
void
BaatzSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
  std::size_t bands;
  fread(&(bands), sizeof(bands), 1, nodeStream);
  node->m_Means.assign(bands, 0);
  node->m_SquareMeans.assign(bands, 0);
  node->m_SpectralSum.assign(bands, 0);
  node->m_Std.assign(bands, 0);

  for(unsigned int b = 0; b < bands; b++)
35
    {
remicres's avatar
remicres committed
36 37 38 39 40 41
    fread(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
    fread(&(node->m_SquareMeans[b]), sizeof(node->m_SquareMeans[b]), 1, nodeStream);
    fread(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
    fread(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
    }
}
42

remicres's avatar
remicres committed
43 44
template<class TImage>
long long unsigned int
45
BaatzSegmenter<TImage>::GetSpecificAttributesMemory(NodePointerType &node)
remicres's avatar
remicres committed
46
{
47
  long long unsigned int memory = 0;
48

49 50
  memory += 4 * node->m_Means.size() * sizeof(float); // 4 vectors values
  memory += 4 * sizeof(std::vector<float>);           // 4 vector containers
remicres's avatar
remicres committed
51 52 53

  return memory;
}
54 55 56 57 58 59 60 61 62 63
} // end of namespace lsrm

#endif