]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStationsFilter.h
merge cvs -> git
[clitk.git] / segmentation / clitkExtractLymphStationsFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 #ifndef CLITKEXTRACTLYMPHSTATIONSFILTER_H
20 #define CLITKEXTRACTLYMPHSTATIONSFILTER_H
21
22 // clitk
23 #include "clitkFilterBase.h"
24 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
25
26 // vtk
27 #include <vtkPolyData.h>
28
29 namespace clitk {
30   
31   //--------------------------------------------------------------------
32   /*
33     Try to extract the LymphStations part of a thorax CT.
34     Need a set of Anatomical Features (AFDB)
35   */
36   //--------------------------------------------------------------------
37   
38   template <class TImageType>
39   class ITK_EXPORT ExtractLymphStationsFilter: 
40     public virtual clitk::FilterBase, 
41     public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
42     public itk::ImageToImageFilter<TImageType, itk::Image<uchar, 3> >
43   {
44
45   public:
46     /** Standard class typedefs. */
47     typedef itk::ImageToImageFilter<TImageType, itk::Image<uchar, 3> > Superclass;
48     typedef ExtractLymphStationsFilter          Self;
49     typedef itk::SmartPointer<Self>             Pointer;
50     typedef itk::SmartPointer<const Self>       ConstPointer;
51     
52     /** Method for creation through the object factory. */
53     itkNewMacro(Self);
54     
55     /** Run-time type information (and related methods). */
56     itkTypeMacro(ExtractLymphStationsFilter, ImageToImageFilter);
57
58     /** Some convenient typedefs. */
59     typedef TImageType                       ImageType;
60     typedef typename ImageType::ConstPointer ImageConstPointer;
61     typedef typename ImageType::Pointer      ImagePointer;
62     typedef typename ImageType::RegionType   ImageRegionType; 
63     typedef typename ImageType::PixelType    ImagePixelType; 
64     typedef typename ImageType::SizeType     ImageSizeType; 
65     typedef typename ImageType::IndexType    ImageIndexType; 
66     typedef typename ImageType::PointType    ImagePointType; 
67         
68     typedef uchar MaskImagePixelType;
69     typedef itk::Image<MaskImagePixelType, 3>    MaskImageType;  
70     typedef typename MaskImageType::Pointer      MaskImagePointer;
71     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
72     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
73     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
74     typedef typename MaskImageType::PointType    MaskImagePointType; 
75
76     typedef itk::Image<MaskImagePixelType, 2>    MaskSliceType;
77     typedef typename MaskSliceType::Pointer      MaskSlicePointer;
78     typedef typename MaskSliceType::PointType    MaskSlicePointType;
79
80     /** ImageDimension constants */
81     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
82     FILTERBASE_INIT;
83    
84     itkGetConstMacro(BackgroundValue, MaskImagePixelType);
85     itkGetConstMacro(ForegroundValue, MaskImagePixelType);
86     itkSetMacro(BackgroundValue, MaskImagePixelType);
87     itkSetMacro(ForegroundValue, MaskImagePixelType);
88
89     // Station 8
90     itkSetMacro(DistanceMaxToAnteriorPartOfTheSpine, double);
91     itkGetConstMacro(DistanceMaxToAnteriorPartOfTheSpine, double);
92     itkSetMacro(EsophagusDiltationForAnt, MaskImagePointType);
93     itkGetConstMacro(EsophagusDiltationForAnt, MaskImagePointType);
94     itkSetMacro(EsophagusDiltationForRight, MaskImagePointType);
95     itkGetConstMacro(EsophagusDiltationForRight, MaskImagePointType);
96     itkSetMacro(InjectedThresholdForS8, double);
97     itkGetConstMacro(InjectedThresholdForS8, double);
98
99     // Station 7
100
101     // All stations
102     bool GetComputeStation(std::string s);
103     void AddComputeStation(std::string station) ;
104     void SetFuzzyThreshold(std::string station, std::string tag, double value);
105     double GetFuzzyThreshold(std::string station, std::string tag);
106
107   protected:
108     ExtractLymphStationsFilter();
109     virtual ~ExtractLymphStationsFilter() {}
110     
111     virtual void GenerateOutputInformation();
112     virtual void GenerateInputRequestedRegion();
113     virtual void GenerateData();
114     
115     ImageConstPointer  m_Input;
116     MaskImagePointer   m_Mediastinum;
117     MaskImagePointer   m_Working_Support;
118     std::map<std::string, MaskImagePointer> m_ListOfStations;
119     MaskImagePixelType m_BackgroundValue;
120     MaskImagePixelType m_ForegroundValue;
121     std::map<std::string, bool> m_ComputeStationMap;
122
123     bool CheckForStation(std::string station);
124     void Remove_Structures(std::string station, std::string s);
125
126     // Global parameters
127     typedef std::map<std::string, double> FuzzyThresholdByStructureType;
128     std::map<std::string, FuzzyThresholdByStructureType> m_FuzzyThreshold;    
129
130     // Station 8
131     double m_DistanceMaxToAnteriorPartOfTheSpine;
132     double m_DiaphragmInferiorLimit;
133     double m_CarinaZ;
134     double m_OriginOfRightMiddleLobeBronchusZ;
135     double m_InjectedThresholdForS8;
136     MaskImagePointer m_Esophagus;
137     MaskImagePointType m_EsophagusDiltationForAnt;
138     MaskImagePointType m_EsophagusDiltationForRight;
139     MaskImagePointer EnlargeEsophagusDilatationRadiusInferiorly(MaskImagePointer & eso);
140     void ExtractStation_8();
141     void ExtractStation_8_SetDefaultValues();
142     void ExtractStation_8_SI_Limits();
143     void ExtractStation_8_Post_Limits();
144     void ExtractStation_8_Ant_Sup_Limits();
145     void ExtractStation_8_Ant_Inf_Limits();
146     void ExtractStation_8_Ant_Injected_Limits();
147     void ExtractStation_8_LR_1_Limits();
148     void ExtractStation_8_LR_2_Limits();
149     void ExtractStation_8_Single_CCL_Limits();
150     void ExtractStation_8_LR_Limits();
151     void ExtractStation_8_Remove_Structures();
152     void ExtractStation_8_LR_Limits_old();
153     void ExtractStation_8_LR_Limits_old2();
154     
155     // Station 3P
156     void ExtractStation_3P();
157     void ExtractStation_3P_SetDefaultValues();
158     void ExtractStation_3P_SI_Limits();
159     void ExtractStation_3P_Remove_Structures();
160     void ExtractStation_3P_Ant_Limits();
161     void ExtractStation_3P_Post_Limits();
162     void ExtractStation_3P_LR_sup_Limits();
163     void ExtractStation_3P_LR_sup_Limits_2();
164     void ExtractStation_3P_LR_inf_Limits();
165
166     // Station 2RL
167     void ExtractStation_2RL();
168     void ExtractStation_2RL_SetDefaultValues();
169     void ExtractStation_2RL_SI_Limits();
170     void ExtractStation_2RL_Ant_Limits();
171     void ExtractStation_2RL_Ant_Limits2();
172     void ExtractStation_2RL_Post_Limits();
173     void ExtractStation_2RL_LR_Limits();
174     void ExtractStation_2RL_Remove_Structures();
175     void ExtractStation_2RL_SeparateRL();
176     vtkSmartPointer<vtkPolyData> Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points);
177
178     // Station 3A
179     void ExtractStation_3A();
180     void ExtractStation_3A_SetDefaultValues();
181     void ExtractStation_3A_SI_Limits();
182     void ExtractStation_3A_Ant_Limits();
183     void ExtractStation_3A_Post_Limits();
184
185     // Station 7
186     void ExtractStation_7();
187     void ExtractStation_7_SetDefaultValues();
188     void ExtractStation_7_SI_Limits();
189     void ExtractStation_7_RL_Limits();
190     void ExtractStation_7_Posterior_Limits();   
191     void ExtractStation_7_Remove_Structures();
192     MaskImagePointer m_Working_Trachea;
193     MaskImagePointer m_LeftBronchus;
194     MaskImagePointer m_RightBronchus;
195     typedef std::vector<MaskImageType::PointType> ListOfPointsType;
196     ListOfPointsType  m_RightMostInLeftBronchus;
197     ListOfPointsType  m_AntMostInLeftBronchus;
198     ListOfPointsType  m_PostMostInLeftBronchus;
199     ListOfPointsType  m_LeftMostInRightBronchus;
200     ListOfPointsType  m_AntMostInRightBronchus;
201     ListOfPointsType  m_PostMostInRightBronchus;
202
203     void FindExtremaPointsInBronchus(MaskImagePointer input, 
204                                      int direction,
205                                      double distance_max_from_center_point, 
206                                      ListOfPointsType & LR, 
207                                      ListOfPointsType & Ant, 
208                                      ListOfPointsType & Post);
209     // Station 4RL
210     void ExtractStation_4RL();
211     void ExtractStation_4RL_SI_Limits();
212     void ExtractStation_4RL_LR_Limits();
213     void ExtractStation_4RL_AP_Limits();
214     MaskImagePointer m_RightSupport;
215     MaskImagePointer m_LeftSupport;
216
217   private:
218     ExtractLymphStationsFilter(const Self&); //purposely not implemented
219     void operator=(const Self&); //purposely not implemented
220     
221   }; // end class
222   //--------------------------------------------------------------------
223
224 } // end namespace clitk
225 //--------------------------------------------------------------------
226
227 #ifndef ITK_MANUAL_INSTANTIATION
228 #include "clitkExtractLymphStationsFilter.txx"
229 #include "clitkExtractLymphStation_8.txx"
230 #include "clitkExtractLymphStation_3P.txx"
231 #include "clitkExtractLymphStation_2RL.txx"
232 #include "clitkExtractLymphStation_3A.txx"
233 #include "clitkExtractLymphStation_7.txx"
234 #include "clitkExtractLymphStation_4RL.txx"
235 #endif
236
237 #endif