lsgrmController.h 4.32 KB
Newer Older
1 2
#ifndef __LSGRM_CONTROLLER_H
#define __LSGRM_CONTROLLER_H
remicres's avatar
remicres committed
3
#include "lsgrmGetInternalMemory.h"
4 5
#include "lsgrmSplitter.h"
#include "lsgrmGraphOperations.h"
6
#include "itkObject.h"
7
#include "itkMacro.h"
8

9

10
namespace lsgrm
11 12 13 14 15 16 17 18
{
template<class TSegmenter>
class ITK_EXPORT Controller : public itk::Object
{
public:

  /** Standard class typedef */
  typedef Controller Self;
19 20 21
  typedef itk::Object                   Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;
22 23 24 25 26 27 28 29 30 31 32

  /** Runtime information support. */
  itkTypeMacro(Controller, itk::Object);

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /* Some convenient typedefs */
  using SegmenterType = TSegmenter;
  using ImageType = typename SegmenterType::ImageType;
  using LabelImageType = typename SegmenterType::LabelImageType;
33
  using SegmentationParameterType = typename SegmenterType::ParamType;
34
  using GraphType = typename SegmenterType::GraphType;
35 36 37 38 39

  /* Default constructor and destructor. */
  Controller();
  ~Controller();

40 41
  void Modified();

42 43 44 45 46 47 48
  void RunSegmentation();

  void SetSpecificParameters(const SegmentationParameterType& params);
  void SetInputImage(ImageType * inputImage);
  void SetInternalMemoryAvailable(long long unsigned int v); // expecting a value in Mbytes.

  /* Accessors */
49 50 51
  void SetTilingModeNone(){m_TilingMode = LSGRM_TILING_NONE; Modified();};
  void SetTilingModeUser(){m_TilingMode = LSGRM_TILING_USER; Modified();};
  void SetTilingModeAuto(){m_TilingMode = LSGRM_TILING_AUTO; Modified();};
52

53
  std::vector<std::string> GetTemporaryFilesList();
54 55 56

  itkGetMacro(Margin, unsigned int);

57 58
  itkGetMacro(TemporaryFilesPrefix, std::string);
  itkSetMacro(TemporaryFilesPrefix, std::string);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

  itkGetMacro(Threshold, float);
  itkSetMacro(Threshold, float);

  itkGetMacro(NumberOfIterations, unsigned int);
  itkSetMacro(NumberOfIterations, unsigned int);

  itkGetMacro(NbTilesX, unsigned int);
  itkSetMacro(NbTilesX, unsigned int);

  itkGetMacro(NbTilesY, unsigned int);
  itkSetMacro(NbTilesY, unsigned int);

  itkGetMacro(NumberOfFirstIterations, unsigned int);
  itkSetMacro(NumberOfFirstIterations, unsigned int);

  itkGetMacro(TileWidth, unsigned int);
  itkSetMacro(TileWidth, unsigned int);

  itkGetMacro(TileHeight, unsigned int);
  itkSetMacro(TileHeight, unsigned int);

81 82
  itkGetMacro(OutputGraph, GraphType);

83 84
private:

85 86 87 88 89 90 91 92
  /** Enum for tiling mode */
  enum LSGRMTilingMode
  {
    LSGRM_TILING_NONE, // No tiling
    LSGRM_TILING_USER, // User tiling
    LSGRM_TILING_AUTO  // Automatic tiling
  };

93
  void GetAutomaticConfiguration();
94
  void ComputeMaximumStabilityMargin(unsigned int width, unsigned int height, unsigned int &iter, unsigned int &margin);
95
  void CheckMemorySize();
96
  unsigned int GetNodeMemory();
97
  std::size_t GetMaximumNumberOfNodesInMemory();
98 99

  /* Parameters given by the user */
100
  std::string m_TemporaryFilesPrefix;    // Path used to store intermediate files during the process.
101 102 103 104 105 106 107 108 109 110
  ImageType * m_InputImage;              // Input image

  /* Segmentation parameters */
  SegmentationParameterType m_SpecificParameters; // Specific parameters
  float                     m_Threshold;          // Threshold
  unsigned int              m_NumberOfIterations; // Number of iterations

  /* Parameters given by the user or computed automatically
   * depending of the chosen mode
   */
111 112 113 114 115 116
  long long unsigned int    m_Memory;                  // RAM available for the computation.
  unsigned int              m_NbTilesX;                // number of tiles in x dimension
  unsigned int              m_NbTilesY;                // number of tiles in y dimension
  unsigned int              m_NumberOfFirstIterations; // number of iterations in the first step
  unsigned int              m_TileWidth;               // regular tile width (i.e. not left tiles)
  unsigned int              m_TileHeight;              // regular tile height (i.e. not bottom tiles)
117 118

  /* read-only variables */
119 120 121
  LSGRMTilingMode                    m_TilingMode;         // tiling mode (none/user/auto)
  unsigned int                       m_Margin;             // stability margin related to m_NumberOfFirstIterations
  std::vector<ProcessingTile>        m_Tiles;              // list of tiles
122 123
  GraphType                          m_OutputGraph;        // Output graph

124
};
125 126 127 128
} // end of namespace lsgrm

#include "lsgrmController.txx"
#endif