Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
SFLSSegmentor3D.h
Go to the documentation of this file.
1 #ifndef SFLSSegmentor3D_h_
2 #define SFLSSegmentor3D_h_
3 
4 #include "SFLS.h"
5 
6 #include <list>
7 #include <vector>
8 
9 // douher
10 // #include "cArray3D.h"
11 
12 // itk
13 #include "itkImage.h"
14 
15 template <typename TPixel>
16 class CSFLSSegmentor3D : public CSFLS
17 {
18 public:
20 
22 
25  // typedef boost::shared_ptr< Self > Pointer;
26 
27  typedef itk::Image<TPixel, 3> TImage;
28  typedef itk::Image<float, 3> TFloatImage;
29  typedef itk::Image<double, 3> TDoubleImage;
30  typedef itk::Image<char, 3> TCharImage;
31  typedef itk::Image<unsigned char, 3> TUCharImage;
32  typedef itk::Image<short, 3> TShortImage;
33 
34  typedef TImage ImageType;
39 
40  typedef typename TImage::IndexType TIndex;
41  typedef typename TImage::SizeType TSize;
42  typedef typename TImage::RegionType TRegion;
43 
45  virtual ~CSFLSSegmentor3D() = default;
46 
47  /* New */
48  // static Pointer New() { return Pointer(new Self); }
49 
50  /* ============================================================
51  * functions */
52  void basicInit();
53 
54  void setNumIter(unsigned long n);
55 
56  void setImage(typename ImageType::Pointer img);
57  void setMask(typename MaskImageType::Pointer mask);
58 
59  virtual void computeForce() = 0;
60 
61  void normalizeForce();
62 
63  // double maxPhi(long ix, long iy, long iz, double level);
64  // double minPhi(long ix, long iy, long iz, double level);
65  bool getPhiOfTheNbhdWhoIsClosestToZeroLevelInLayerCloserToZeroLevel(long ix, long iy, long iz, double& thePhi);
66 
68 
69  // void getSFLSFromPhi();
70 
72  {
74  }
75  void initializeSFLSFromMask(); // m_insideVoxelCount is first computed here
76 
77  void initializeLabel();
78 
79  void initializePhi();
80 
81  virtual void doSegmenation() = 0;
82 
83  // geometry
84  double computeKappa(long ix, long iy, long iz);
85 
86  void setMaxVolume(double v); // v is in mL
87 
88  void setMaxRunningTime(double t); // t in min
89 
90  // about evolution history
91  void keepZeroLayerHistory(bool b)
92  {
94  }
95  CSFLSLayer getZeroLayerAtIteration(unsigned long i);
96 
97  void writeZeroLayerAtIterationToFile(unsigned long i, const char* name);
98 
99  void writeZeroLayerToFile(const char* namePrefix);
100 
101  void setCurvatureWeight(double a);
102 
103  LSImageType::Pointer getLevelSetFunction();
104 
105  /* ============================================================
106  * data */
107  // CSFLS::Pointer mp_sfls;
108 
109  typename ImageType::Pointer mp_img;
110  typename LabelImageType::Pointer mp_label;
111  typename MaskImageType::Pointer mp_mask; // 0, non-0 mask for object
112  typename LSImageType::Pointer mp_phi;
113 
114  // std::list< double > m_force;
115  std::vector<double> m_force;
116 
117  double m_timeStep;
118 
119  unsigned long m_numIter;
120 protected:
122 
123  bool m_done;
124 
125  long m_nx;
126  long m_ny;
127  long m_nz;
128 
129  double m_dx; // in mm
130  double m_dy; // in mm
131  double m_dz; // in mm
132 
135 
136  double m_maxVolume; // max physical volume, in mm^3
137  double m_maxRunningTime; // in sec
138 
139  /*----------------------------------------------------------------------
140  These two record the pts which change status
141 
142  Because they are created and visited sequentially, and when not
143  needed, are clear-ed as a whole. No random insertion or removal is
144  needed. So use vector is faster than list. */
147 
148  void updateInsideVoxelCount();
149 
150  inline bool doubleEqual(double a, double b, double eps = 1e-10)
151  {
152  return a - b < eps && b - a < eps;
153  }
154 
156  std::vector<CSFLSLayer> m_zeroLayerHistory;
157 
158 };
159 
160 #include "SFLSSegmentor3D.txx"
161 
162 #endif
Definition: SFLS.h:10
vnl_vector_fixed< int, 3 > NodeType
Definition: SFLS.h:15
virtual void doSegmenation()=0
std::vector< CSFLSLayer > m_zeroLayerHistory
void writeZeroLayerToFile(const char *namePrefix)
double computeKappa(long ix, long iy, long iz)
TImage::SizeType TSize
TUCharImage MaskImageType
std::list< NodeType > CSFLSLayer
Definition: SFLS.h:16
TShortImage ShortImageType
TImage::IndexType TIndex
void setMaxVolume(double v)
SuperClassType::CSFLSLayer CSFLSLayer
bool getPhiOfTheNbhdWhoIsClosestToZeroLevelInLayerCloserToZeroLevel(long ix, long iy, long iz, double &thePhi)
itk::Image< double, 3 > TDoubleImage
unsigned long m_numIter
CSFLSLayer m_lOut2in
void writeZeroLayerAtIterationToFile(unsigned long i, const char *name)
MaskImageType::Pointer mp_mask
LabelImageType::Pointer mp_label
void setMaxRunningTime(double t)
TFloatImage LSImageType
TCharImage LabelImageType
void setCurvatureWeight(double a)
virtual ~CSFLSSegmentor3D()=default
ImageType::Pointer mp_img
virtual void computeForce()=0
void initializeSFLSFromMask()
itk::Image< char, 3 > TCharImage
itk::Image< short, 3 > TShortImage
void setMask(typename MaskImageType::Pointer mask)
CSFLSSegmentor3D< TPixel > Self
LSImageType::Pointer getLevelSetFunction()
SuperClassType::NodeType NodeType
itk::Image< unsigned char, 3 > TUCharImage
void initializeLabel()
itk::Image< float, 3 > TFloatImage
std::vector< double > m_force
LSImageType::Pointer mp_phi
CSFLSLayer getZeroLayerAtIteration(unsigned long i)
bool doubleEqual(double a, double b, double eps=1e-10)
CSFLSLayer m_lIn2out
void keepZeroLayerHistory(bool b)
void oneStepLevelSetEvolution()
TImage::RegionType TRegion
void setNumIter(unsigned long n)
void setImage(typename ImageType::Pointer img)
void updateInsideVoxelCount()
itk::Image< TPixel, 3 > TImage