lsgrmController.h 4.37 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

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

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

  /** 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;
32
  using SegmentationParameterType = typename SegmenterType::ParamType;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

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

  void RunSegmentation();

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

  /* Accessors */
  void SetTilingModeNone(){m_TilingMode = LSGRM_TILING_NONE;};
  void SetTilingModeUser(){m_TilingMode = LSGRM_TILING_USER;};
  void SetTilingModeAuto(){m_TilingMode = LSGRM_TILING_AUTO;};

  typename LabelImageType::Pointer GetLabeledClusteredOutput();
50
  std::vector<std::string> GetTemporaryFilesList();
51
52
53

  itkGetMacro(Margin, unsigned int);

54
55
  itkGetMacro(CleanTemporaryFiles, bool);
  itkSetMacro(CleanTemporaryFiles, bool);
56

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
81
82

  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);

private:

remicres's avatar
remicres committed
83
84
85
86
87
88
89
90
  /** Enum for tiling mode */
  enum LSGRMTilingMode
  {
    LSGRM_TILING_NONE, // No tiling
    LSGRM_TILING_USER, // User tiling
    LSGRM_TILING_AUTO  // Automatic tiling
  };

91
  void GetAutomaticConfiguration();
remicres's avatar
remicres committed
92
  void ComputeMaximumStabilityMargin(unsigned int width, unsigned int height, unsigned int &iter, unsigned int &margin);
93
  unsigned int GetNodeMemory();
94
95
96
  long unsigned int GetMaximumNumberOfNodesInMemory();

  /* Parameters given by the user */
97
98
  std::string m_TemporaryFilesPrefix;    // Path used to store intermediate files during the process.
  bool        m_CleanTemporaryFiles;     // Clean temporary files
99
100
101
102
103
104
105
106
107
108
  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
   */
remicres's avatar
remicres committed
109
110
111
112
113
114
  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)
115
116

  /* read-only variables */
remicres's avatar
remicres committed
117
118
119
120
  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
  typename LabelImageType::Pointer   m_LabelImage;         // output label image
121
};
122
123
124
125
} // end of namespace lsgrm

#include "lsgrmController.txx"
#endif