lsgrmSpringSegmenter.txx 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifndef __LSRM_Spring_SEGMENTER_TXX
#define __LSRM_Spring_SEGMENTER_TXX
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>

namespace lsgrm
{

	template<class TImage>
	void
	SpringSegmenter<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++)
	    {
	    fwrite(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
	    }
	}

    template<class TImage>
    void
    SpringSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
    {
      std::size_t bands;
      fread(&(bands), sizeof(bands), 1, nodeStream);
      node->m_Means.assign(bands, 0);

      for(unsigned int b = 0; b < bands; b++)
        {
        fread(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
        }
    }

    template<class TImage>
    long long unsigned int
    SpringSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
    {

      unsigned int nBands = node->m_Means.size(); //this->m_InputImage->GetNumberOfComponentsPerPixel();

      long long unsigned int memory = 0;
      memory += sizeof(NodePointerType);    // size of the node pointer
      memory += sizeof(NodeType);           // size of the node (actually, size of the base node)
      memory += 1 * nBands * sizeof(float); // size of the 1 attribute, multiplied by the nb. of bands
      memory += node->m_Edges.size() * sizeof(EdgeType);  // size of the edges
      return memory;
    }
} // end of namespace lsrm

#endif