]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStationsFilter.h
Attempt to manually adjust the layout of the overlay panel for fusion to minimize...
[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     typedef typename MaskSliceType::RegionType   MaskSliceRegionType; 
80     typedef typename MaskSliceType::SizeType     MaskSliceSizeType; 
81     typedef typename MaskSliceType::IndexType    MaskSliceIndexType; 
82
83     /** ImageDimension constants */
84     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
85     FILTERBASE_INIT;
86    
87     itkGetConstMacro(BackgroundValue, MaskImagePixelType);
88     itkGetConstMacro(ForegroundValue, MaskImagePixelType);
89     itkSetMacro(BackgroundValue, MaskImagePixelType);
90     itkSetMacro(ForegroundValue, MaskImagePixelType);
91
92     // Station 8
93     // itkSetMacro(DistanceMaxToAnteriorPartOfTheSpine, double);
94     //itkGetConstMacro(DistanceMaxToAnteriorPartOfTheSpine, double);
95     itkSetMacro(EsophagusDiltationForAnt, MaskImagePointType);
96     itkGetConstMacro(EsophagusDiltationForAnt, MaskImagePointType);
97     itkSetMacro(EsophagusDiltationForRight, MaskImagePointType);
98     itkGetConstMacro(EsophagusDiltationForRight, MaskImagePointType);
99     itkSetMacro(InjectedThresholdForS8, double);
100     itkGetConstMacro(InjectedThresholdForS8, double);
101
102     // Station 7
103     itkGetConstMacro(S7_UseMostInferiorPartOnlyFlag, bool);
104     itkSetMacro(S7_UseMostInferiorPartOnlyFlag, bool);
105     itkBooleanMacro(S7_UseMostInferiorPartOnlyFlag);
106
107     // All stations
108     bool GetComputeStation(std::string s);
109     void AddComputeStation(std::string station) ;
110     void SetFuzzyThreshold(std::string station, std::string tag, double value);
111     double GetFuzzyThreshold(std::string station, std::string tag);
112
113   protected:
114     ExtractLymphStationsFilter();
115     virtual ~ExtractLymphStationsFilter() {}
116     
117     virtual void GenerateOutputInformation();
118     virtual void GenerateInputRequestedRegion();
119     virtual void GenerateData();
120     
121     ImageConstPointer  m_Input;
122     MaskImagePointer   m_Mediastinum;
123     MaskImagePointer   m_Working_Support;
124     std::map<std::string, MaskImagePointer> m_ListOfStations;
125     std::map<std::string, MaskImagePointer> m_ListOfSupports;
126     MaskImagePixelType m_BackgroundValue;
127     MaskImagePixelType m_ForegroundValue;
128     std::map<std::string, bool> m_ComputeStationMap;
129
130     bool CheckForStation(std::string station);
131     void Remove_Structures(std::string station, std::string s);
132
133     // Functions common to several stations
134     void FindLineForS7S8Separation(MaskImagePointType & A, MaskImagePointType & B);
135     double FindCarinaSlicePosition();
136     void FindLeftAndRightBronchi();
137
138     // Global parameters
139     typedef std::map<std::string, double> FuzzyThresholdByStructureType;
140     std::map<std::string, FuzzyThresholdByStructureType> m_FuzzyThreshold;    
141
142     // Station's supports
143     void ExtractStationSupports();
144
145     // Station 8
146     // double m_DistanceMaxToAnteriorPartOfTheSpine;
147     double m_DiaphragmInferiorLimit;
148     double m_CarinaZ;
149     double m_OriginOfRightMiddleLobeBronchusZ;
150     double m_InjectedThresholdForS8;
151     MaskImagePointer m_Esophagus;
152     MaskImagePointType m_EsophagusDiltationForAnt;
153     MaskImagePointType m_EsophagusDiltationForRight;
154
155     void ExtractStation_8();
156     void ExtractStation_8_SetDefaultValues();
157     void ExtractStation_8_SI_Limits();
158     void ExtractStation_8_Ant_Limits();
159     void ExtractStation_8_Left_Sup_Limits();
160     void ExtractStation_8_Left_Inf_Limits();
161     void ExtractStation_8_Single_CCL_Limits();
162     void ExtractStation_8_Remove_Structures();
163
164     // Station 3P
165     void ExtractStation_3P();
166     void ExtractStation_3P_SetDefaultValues();
167     void ExtractStation_3P_SI_Limits();
168     void ExtractStation_3P_Remove_Structures();
169     void ExtractStation_3P_Ant_Limits();
170     void ExtractStation_3P_Post_Limits();
171     void ExtractStation_3P_LR_sup_Limits();
172     void ExtractStation_3P_LR_sup_Limits_2();
173     void ExtractStation_3P_LR_inf_Limits();
174
175     // Station 2RL
176     void ExtractStation_2RL();
177     void ExtractStation_2RL_SetDefaultValues();
178     void ExtractStation_2RL_SI_Limits();
179     void ExtractStation_2RL_Ant_Limits();
180     void ExtractStation_2RL_Ant_Limits2();
181     void ExtractStation_2RL_Post_Limits();
182     void ExtractStation_2RL_LR_Limits();
183     void ExtractStation_2RL_Remove_Structures();
184     void ExtractStation_2RL_SeparateRL();
185     vtkSmartPointer<vtkPolyData> Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points);
186
187     // Station 3A
188     void ExtractStation_3A();
189     void ExtractStation_3A_SetDefaultValues();
190     void ExtractStation_3A_SI_Limits();
191     void ExtractStation_3A_Ant_Limits();
192     void ExtractStation_3A_Post_Limits();
193
194     // Station 7
195     void ExtractStation_7();
196     void ExtractStation_7_SetDefaultValues();
197     void ExtractStation_7_SI_Limits();
198     void ExtractStation_7_RL_Interior_Limits();
199
200
201     void ExtractStation_7_RL_Limits_OLD();
202     void ExtractStation_7_Posterior_Limits();   
203     void ExtractStation_7_Remove_Structures();
204     bool m_S7_UseMostInferiorPartOnlyFlag;
205     MaskImagePointer m_Working_Trachea;
206     MaskImagePointer m_LeftBronchus;
207     MaskImagePointer m_RightBronchus;
208     typedef std::vector<MaskImageType::PointType> ListOfPointsType;
209     ListOfPointsType  m_RightMostInLeftBronchus;
210     ListOfPointsType  m_AntMostInLeftBronchus;
211     ListOfPointsType  m_PostMostInLeftBronchus;
212     ListOfPointsType  m_LeftMostInRightBronchus;
213     ListOfPointsType  m_AntMostInRightBronchus;
214     ListOfPointsType  m_PostMostInRightBronchus;
215
216     void FindExtremaPointsInBronchus(MaskImagePointer input, 
217                                      int direction,
218                                      double distance_max_from_center_point, 
219                                      ListOfPointsType & LR, 
220                                      ListOfPointsType & Ant, 
221                                      ListOfPointsType & Post);
222     // Station 4RL
223     void ExtractStation_4RL();
224     void ExtractStation_4RL_SI_Limits();
225     void ExtractStation_4RL_LR_Limits();
226     void ExtractStation_4RL_AP_Limits();
227     MaskImagePointer m_RightSupport;
228     MaskImagePointer m_LeftSupport;
229
230   private:
231     ExtractLymphStationsFilter(const Self&); //purposely not implemented
232     void operator=(const Self&); //purposely not implemented
233     
234   }; // end class
235   //--------------------------------------------------------------------
236
237 } // end namespace clitk
238 //--------------------------------------------------------------------
239
240 #ifndef ITK_MANUAL_INSTANTIATION
241 #include "clitkExtractLymphStationsFilter.txx"
242 #include "clitkExtractLymphStation_Supports.txx"
243 #include "clitkExtractLymphStation_8.txx"
244 #include "clitkExtractLymphStation_3P.txx"
245 #include "clitkExtractLymphStation_2RL.txx"
246 #include "clitkExtractLymphStation_3A.txx"
247 #include "clitkExtractLymphStation_7.txx"
248 #include "clitkExtractLymphStation_4RL.txx"
249 #endif
250
251 #endif