]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStationsFilter.h
b7b8c3b939bf0039542db04cb0a6e1411c688820
[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 "clitkStructuresExtractionFilter.h"
24
25 // vtk
26 #include <vtkPolyData.h>
27
28 namespace clitk {
29   
30   //--------------------------------------------------------------------
31   /*
32     Try to extract the LymphStations part of a thorax CT.
33     Need a set of Anatomical Features (AFDB)
34   */
35   //--------------------------------------------------------------------
36   
37   template <class TImageType>
38   class ITK_EXPORT ExtractLymphStationsFilter: 
39     public clitk::StructuresExtractionFilter<TImageType>
40   {
41
42   public:
43     /** Standard class typedefs. */
44     typedef clitk::StructuresExtractionFilter<TImageType> Superclass;
45     typedef ExtractLymphStationsFilter          Self;
46     typedef itk::SmartPointer<Self>             Pointer;
47     typedef itk::SmartPointer<const Self>       ConstPointer;
48     
49     /** Method for creation through the object factory. */
50     itkNewMacro(Self);
51     
52     /** Run-time type information (and related methods). */
53     itkTypeMacro(ExtractLymphStationsFilter, ImageToImageFilter);
54
55     /** Some convenient typedefs. */
56     typedef TImageType                       ImageType;
57     typedef typename ImageType::ConstPointer ImageConstPointer;
58     typedef typename ImageType::Pointer      ImagePointer;
59     typedef typename ImageType::RegionType   ImageRegionType; 
60     typedef typename ImageType::PixelType    ImagePixelType; 
61     typedef typename ImageType::SizeType     ImageSizeType; 
62     typedef typename ImageType::IndexType    ImageIndexType; 
63     typedef typename ImageType::PointType    ImagePointType; 
64         
65     typedef uchar MaskImagePixelType;
66     typedef itk::Image<MaskImagePixelType, 3>    MaskImageType;  
67     typedef typename MaskImageType::Pointer      MaskImagePointer;
68     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
69     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
70     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
71     typedef typename MaskImageType::PointType    MaskImagePointType; 
72
73     typedef itk::Image<MaskImagePixelType, 2>    MaskSliceType;
74     typedef typename MaskSliceType::Pointer      MaskSlicePointer;
75     typedef typename MaskSliceType::PointType    MaskSlicePointType;
76     typedef typename MaskSliceType::RegionType   MaskSliceRegionType; 
77     typedef typename MaskSliceType::SizeType     MaskSliceSizeType; 
78     typedef typename MaskSliceType::IndexType    MaskSliceIndexType; 
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(EsophagusDiltationForAnt, MaskImagePointType);
91     itkGetConstMacro(EsophagusDiltationForAnt, MaskImagePointType);
92     itkSetMacro(EsophagusDiltationForRight, MaskImagePointType);
93     itkGetConstMacro(EsophagusDiltationForRight, MaskImagePointType);
94     itkSetMacro(InjectedThresholdForS8, double);
95     itkGetConstMacro(InjectedThresholdForS8, double);
96
97     // Station 7
98     itkGetConstMacro(S7_UseMostInferiorPartOnlyFlag, bool);
99     itkSetMacro(S7_UseMostInferiorPartOnlyFlag, bool);
100     itkBooleanMacro(S7_UseMostInferiorPartOnlyFlag);
101
102     // All stations
103     bool GetComputeStation(std::string s);
104     void AddComputeStation(std::string station) ;
105     void SetFuzzyThreshold(std::string station, std::string tag, double value);
106     double GetFuzzyThreshold(std::string station, std::string tag);
107     void SetThreshold(std::string station, std::string tag, double value);
108     double GetThreshold(std::string station, std::string tag);
109     itkGetConstMacro(ComputeStationsSupportsFlag, bool);
110     itkSetMacro(ComputeStationsSupportsFlag, bool);
111     itkBooleanMacro(ComputeStationsSupportsFlag);
112
113   protected:
114     ExtractLymphStationsFilter();
115     virtual ~ExtractLymphStationsFilter() {}
116     
117     virtual void GenerateOutputInformation();
118     virtual void GenerateInputRequestedRegion();
119     virtual void GenerateData();
120     
121     // To avoid repeat "this->"
122     AnatomicalFeatureDatabase * GetAFDB() { return clitk::FilterWithAnatomicalFeatureDatabaseManagement::GetAFDB(); }
123     void WriteAFDB() { clitk::FilterWithAnatomicalFeatureDatabaseManagement::WriteAFDB(); }
124     void LoadAFDB() {  clitk::FilterWithAnatomicalFeatureDatabaseManagement::LoadAFDB(); }  
125     void StartNewStep(std::string s) { clitk::FilterBase::StartNewStep(s); }
126     void StartSubStep() { clitk::FilterBase::StartSubStep(); }
127     template<class TInternalImageType>
128       void StopCurrentStep(typename TInternalImageType::Pointer p, std::string txt="") { clitk::FilterBase::StopCurrentStep<TInternalImageType>(p, txt); }
129     void StopCurrentStep() {clitk::FilterBase::StopCurrentStep(); }
130     void StopSubStep() {clitk::FilterBase::StopSubStep(); }
131
132     ImageConstPointer  m_Input;
133     MaskImagePointer   m_Mediastinum;
134     MaskImagePointer   m_Working_Support;
135     std::map<std::string, MaskImagePointer> m_ListOfStations;
136     std::map<std::string, MaskImagePointer> m_ListOfSupports;
137     MaskImagePixelType m_BackgroundValue;
138     MaskImagePixelType m_ForegroundValue;
139     std::map<std::string, bool> m_ComputeStationMap;
140
141     bool CheckForStation(std::string station);
142     void Remove_Structures(std::string station, std::string s);
143
144     // Functions common to several stations
145     double FindCarina();
146     double FindApexOfTheChest();
147     double FindSuperiorBorderOfAorticArch();
148     double FindInferiorBorderOfAorticArch();
149     void FindLeftAndRightBronchi();
150     void FindLineForS7S8Separation(MaskImagePointType & A, MaskImagePointType & B);
151     MaskImagePointer FindAntPostVesselsOLD();
152     MaskImagePointer FindAntPostVessels2();
153
154     // Global parameters
155     typedef std::map<std::string, double> FuzzyThresholdByStructureType;
156     std::map<std::string, FuzzyThresholdByStructureType> m_FuzzyThreshold;    
157     typedef std::map<std::string, double> ThresholdByStructureType;
158     std::map<std::string, ThresholdByStructureType> m_Threshold;    
159
160     // Station's supports
161     void ExtractStationSupports();
162     void Support_SupInf_S1RL();
163     void Support_LeftRight_S1R_S1L();
164     void Support_SupInf_S2R_S2L();
165     void Support_LeftRight_S2R_S2L();
166     void Support_SupInf_S4R_S4L();
167     void Support_LeftRight_S4R_S4L();
168     void Support_Post_S1S2S4();
169     void Support_S3P();
170     void Support_S3A();
171     void Support_S5();
172     void Support_S6();
173
174     MaskImagePointer LimitsWithTrachea(MaskImageType * input, 
175                                        int extremaDirection, int lineDirection, 
176                                        double offset, double maxSupPosition);
177     MaskImagePointer LimitsWithTrachea(MaskImageType * input, 
178                                        int extremaDirection, int lineDirection, 
179                                        double offset);
180     // Station 8
181     double m_DiaphragmInferiorLimit;
182     double m_OriginOfRightMiddleLobeBronchusZ;
183     double m_InjectedThresholdForS8;
184     MaskImagePointer m_Esophagus;
185     MaskImagePointType m_EsophagusDiltationForAnt;
186     MaskImagePointType m_EsophagusDiltationForRight;
187
188     void ExtractStation_8();
189     void ExtractStation_8_SetDefaultValues();
190     void ExtractStation_8_SI_Limits();
191     void ExtractStation_8_Ant_Limits();
192     void ExtractStation_8_Left_Sup_Limits();
193     void ExtractStation_8_Left_Inf_Limits();
194     void ExtractStation_8_Single_CCL_Limits();
195     void ExtractStation_8_Remove_Structures();
196
197     // Station 3P
198     void ExtractStation_3P();
199     void ExtractStation_3P_SetDefaultValues();
200     void ExtractStation_3P_LR_inf_Limits();
201     void ExtractStation_3P_LR_sup_Limits_2();
202     void ExtractStation_3P_Remove_Structures();
203     void ExtractStation_3P_LR_sup_Limits();
204
205     // Station 3A
206     void ExtractStation_3A();
207     void ExtractStation_3A_SetDefaultValues();
208     void ExtractStation_3A_Post_Left_Limits_With_Aorta_S5_Support();
209     void ExtractStation_3A_Post_Limits_With_Dilated_Aorta_S6_Support();
210     void ExtractStation_3A_AntPost_Superiorly();
211     void ExtractStation_3A_Remove_Structures();
212
213     // Station 2RL
214     void ExtractStation_2RL();
215     void ExtractStation_2RL_SetDefaultValues();
216     void ExtractStation_2RL_Ant_Limits(std::string s);
217     void ExtractStation_2RL_Remove_Structures(std::string s);
218     void ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split();
219     vtkSmartPointer<vtkPolyData> Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points);
220
221     // Station 1RL
222     void ExtractStation_1RL();
223     void ExtractStation_1RL_SetDefaultValues();
224     void ExtractStation_1RL_Ant_Limits();
225     void ExtractStation_1RL_Post_Limits();
226
227     // Station 4RL
228     void ExtractStation_4RL_SetDefaultValues();
229     void ExtractStation_4RL();
230     void ExtractStation_S4L_S5_Limits_Aorta_LeftPulmonaryArtery(int KeepPoint);
231
232     // Station 5
233     void ExtractStation_5_SetDefaultValues();
234     void ExtractStation_5();
235     void ExtractStation_5_Limits_AscendingAorta_Ant();
236
237     // Station 6
238     void ExtractStation_6_SetDefaultValues();
239     void ExtractStation_6();
240
241
242     // Station 7
243     void ExtractStation_7();
244     void ExtractStation_7_SetDefaultValues();
245     void ExtractStation_7_SI_Limits();
246     void ExtractStation_7_RL_Interior_Limits();
247
248     void ExtractStation_7_RL_Limits_OLD();
249     void ExtractStation_7_Posterior_Limits();   
250     void ExtractStation_7_Remove_Structures();
251     bool m_S7_UseMostInferiorPartOnlyFlag;
252     bool m_ComputeStationsSupportsFlag;
253     MaskImagePointer m_Working_Trachea;
254     MaskImagePointer m_LeftBronchus;
255     MaskImagePointer m_RightBronchus;
256     typedef std::vector<MaskImageType::PointType> ListOfPointsType;
257     ListOfPointsType  m_RightMostInLeftBronchus;
258     ListOfPointsType  m_AntMostInLeftBronchus;
259     ListOfPointsType  m_PostMostInLeftBronchus;
260     ListOfPointsType  m_LeftMostInRightBronchus;
261     ListOfPointsType  m_AntMostInRightBronchus;
262     ListOfPointsType  m_PostMostInRightBronchus;
263
264     void FindExtremaPointsInBronchus(MaskImagePointer input, 
265                                      int direction,
266                                      double distance_max_from_center_point, 
267                                      ListOfPointsType & LR, 
268                                      ListOfPointsType & Ant, 
269                                      ListOfPointsType & Post);
270   private:
271     ExtractLymphStationsFilter(const Self&); //purposely not implemented
272     void operator=(const Self&); //purposely not implemented
273     
274   }; // end class
275   //--------------------------------------------------------------------
276
277 } // end namespace clitk
278 //--------------------------------------------------------------------
279
280 #ifndef ITK_MANUAL_INSTANTIATION
281 #include "clitkExtractLymphStationsFilter.txx"
282 #include "clitkExtractLymphStation_Supports.txx"
283 #include "clitkExtractLymphStation_3P.txx"
284 #include "clitkExtractLymphStation_2RL.txx"
285 #include "clitkExtractLymphStation_3A.txx"
286 #include "clitkExtractLymphStation_4RL.txx"
287 #include "clitkExtractLymphStation_1RL.txx"
288 #include "clitkExtractLymphStation_5.txx"
289 #include "clitkExtractLymphStation_6.txx"
290
291 #include "clitkExtractLymphStation_8.txx"
292 #include "clitkExtractLymphStation_7.txx"
293 #endif
294
295 #endif