Slicer  4.8
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;
35  typedef TFloatImage LSImageType;
36  typedef TCharImage LabelImageType;
37  typedef TUCharImage MaskImageType;
38  typedef TShortImage ShortImageType;
39 
40  typedef typename TImage::IndexType TIndex;
41  typedef typename TImage::SizeType TSize;
42  typedef typename TImage::RegionType TRegion;
43 
46  {
47  }
48 
49  /* New */
50  // static Pointer New() { return Pointer(new Self); }
51 
52  /* ============================================================
53  * functions */
54  void basicInit();
55 
56  void setNumIter(unsigned long n);
57 
58  void setImage(typename ImageType::Pointer img);
59  void setMask(typename MaskImageType::Pointer mask);
60 
61  virtual void computeForce() = 0;
62 
63  void normalizeForce();
64 
65  // double maxPhi(long ix, long iy, long iz, double level);
66  // double minPhi(long ix, long iy, long iz, double level);
67  bool getPhiOfTheNbhdWhoIsClosestToZeroLevelInLayerCloserToZeroLevel(long ix, long iy, long iz, double& thePhi);
68 
70 
71  // void getSFLSFromPhi();
72 
74  {
76  }
77  void initializeSFLSFromMask(); // m_insideVoxelCount is first computed here
78 
79  void initializeLabel();
80 
81  void initializePhi();
82 
83  virtual void doSegmenation() = 0;
84 
85  // geometry
86  double computeKappa(long ix, long iy, long iz);
87 
88  void setMaxVolume(double v); // v is in mL
89 
90  void setMaxRunningTime(double t); // t in min
91 
92  // about evolution history
93  void keepZeroLayerHistory(bool b)
94  {
96  }
97  CSFLSLayer getZeroLayerAtIteration(unsigned long i);
98 
99  void writeZeroLayerAtIterationToFile(unsigned long i, const char* name);
100 
101  void writeZeroLayerToFile(const char* namePrefix);
102 
103  void setCurvatureWeight(double a);
104 
105  LSImageType::Pointer getLevelSetFunction();
106 
107  /* ============================================================
108  * data */
109  // CSFLS::Pointer mp_sfls;
110 
111  typename ImageType::Pointer mp_img;
112  typename LabelImageType::Pointer mp_label;
113  typename MaskImageType::Pointer mp_mask; // 0, non-0 mask for object
114  typename LSImageType::Pointer mp_phi;
115 
116  // std::list< double > m_force;
117  std::vector<double> m_force;
118 
119  double m_timeStep;
120 
121  unsigned long m_numIter;
122 protected:
124 
125  bool m_done;
126 
127  long m_nx;
128  long m_ny;
129  long m_nz;
130 
131  double m_dx; // in mm
132  double m_dy; // in mm
133  double m_dz; // in mm
134 
137 
138  double m_maxVolume; // max physical volume, in mm^3
139  double m_maxRunningTime; // in sec
140 
141  /*----------------------------------------------------------------------
142  These two record the pts which change status
143 
144  Because they are created and visited sequentially, and when not
145  needed, are clear-ed as a whole. No random insertion or removal is
146  needed. So use vector is faster than list. */
147  CSFLSLayer m_lIn2out;
148  CSFLSLayer m_lOut2in;
149 
150  void updateInsideVoxelCount();
151 
152  inline bool doubleEqual(double a, double b, double eps = 1e-10)
153  {
154  return a - b < eps && b - a < eps;
155  }
156 
158  std::vector<CSFLSLayer> m_zeroLayerHistory;
159 
160 };
161 
162 #include "SFLSSegmentor3D.txx"
163 
164 #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)
ImageType::Pointer mp_img
virtual ~CSFLSSegmentor3D()
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