1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #ifndef CLITKEXTRACTLYMPHSTATIONSFILTER_H
20 #define CLITKEXTRACTLYMPHSTATIONSFILTER_H
23 #include "clitkFilterBase.h"
24 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
27 #include <vtkPolyData.h>
31 //--------------------------------------------------------------------
33 Try to extract the LymphStations part of a thorax CT.
34 Need a set of Anatomical Features (AFDB)
36 //--------------------------------------------------------------------
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> >
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;
52 /** Method for creation through the object factory. */
55 /** Run-time type information (and related methods). */
56 itkTypeMacro(ExtractLymphStationsFilter, ImageToImageFilter);
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;
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;
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;
83 /** ImageDimension constants */
84 itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
87 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
88 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
89 itkSetMacro(BackgroundValue, MaskImagePixelType);
90 itkSetMacro(ForegroundValue, MaskImagePixelType);
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);
103 itkGetConstMacro(S7_UseMostInferiorPartOnlyFlag, bool);
104 itkSetMacro(S7_UseMostInferiorPartOnlyFlag, bool);
105 itkBooleanMacro(S7_UseMostInferiorPartOnlyFlag);
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 itkGetConstMacro(ComputeStationsSupportsFlag, bool);
113 itkSetMacro(ComputeStationsSupportsFlag, bool);
114 itkBooleanMacro(ComputeStationsSupportsFlag);
117 ExtractLymphStationsFilter();
118 virtual ~ExtractLymphStationsFilter() {}
120 virtual void GenerateOutputInformation();
121 virtual void GenerateInputRequestedRegion();
122 virtual void GenerateData();
124 ImageConstPointer m_Input;
125 MaskImagePointer m_Mediastinum;
126 MaskImagePointer m_Working_Support;
127 std::map<std::string, MaskImagePointer> m_ListOfStations;
128 std::map<std::string, MaskImagePointer> m_ListOfSupports;
129 MaskImagePixelType m_BackgroundValue;
130 MaskImagePixelType m_ForegroundValue;
131 std::map<std::string, bool> m_ComputeStationMap;
133 bool CheckForStation(std::string station);
134 void Remove_Structures(std::string station, std::string s);
136 // Functions common to several stations
138 double FindApexOfTheChest();
139 double FindSuperiorBorderOfAorticArch();
140 double FindInferiorBorderOfAorticArch();
141 void FindLeftAndRightBronchi();
142 void FindLineForS7S8Separation(MaskImagePointType & A, MaskImagePointType & B);
143 MaskImagePointer FindAntPostVessels();
144 MaskImagePointer FindAntPostVessels2();
147 typedef std::map<std::string, double> FuzzyThresholdByStructureType;
148 std::map<std::string, FuzzyThresholdByStructureType> m_FuzzyThreshold;
150 // Station's supports
151 void ExtractStationSupports();
152 void Support_SupInf_S1RL();
153 void Support_LeftRight_S1R_S1L();
154 void Support_SupInf_S2R_S2L();
155 void Support_LeftRight_S2R_S2L();
156 void Support_SupInf_S4R_S4L();
157 void Support_LeftRight_S4R_S4L();
158 void Support_Post_S1S2S4();
164 MaskImagePointer LimitsWithTrachea(MaskImageType * input,
165 int extremaDirection, int lineDirection,
166 double offset, double maxSupPosition);
167 MaskImagePointer LimitsWithTrachea(MaskImageType * input,
168 int extremaDirection, int lineDirection,
172 // double m_DistanceMaxToAnteriorPartOfTheSpine;
173 double m_DiaphragmInferiorLimit;
174 double m_OriginOfRightMiddleLobeBronchusZ;
175 double m_InjectedThresholdForS8;
176 MaskImagePointer m_Esophagus;
177 MaskImagePointType m_EsophagusDiltationForAnt;
178 MaskImagePointType m_EsophagusDiltationForRight;
180 void ExtractStation_8();
181 void ExtractStation_8_SetDefaultValues();
182 void ExtractStation_8_SI_Limits();
183 void ExtractStation_8_Ant_Limits();
184 void ExtractStation_8_Left_Sup_Limits();
185 void ExtractStation_8_Left_Inf_Limits();
186 void ExtractStation_8_Single_CCL_Limits();
187 void ExtractStation_8_Remove_Structures();
190 void ExtractStation_3P();
191 void ExtractStation_3P_SetDefaultValues();
192 void ExtractStation_3P_LR_inf_Limits();
193 void ExtractStation_3P_LR_sup_Limits_2();
194 void ExtractStation_3P_Remove_Structures();
195 void ExtractStation_3P_LR_sup_Limits();
198 void ExtractStation_3A();
199 void ExtractStation_3A_SetDefaultValues();
200 void ExtractStation_3A_AntPost_S5();
201 void ExtractStation_3A_AntPost_S6();
202 void ExtractStation_3A_AntPost_Superiorly();
203 void ExtractStation_3A_SI_Limits();
204 void ExtractStation_3A_Ant_Limits();
205 void ExtractStation_3A_Post_Limits();
208 void ExtractStation_2RL();
209 void ExtractStation_2RL_SetDefaultValues();
210 void ExtractStation_2RL_SI_Limits();
211 void ExtractStation_2RL_Ant_Limits();
212 void ExtractStation_2RL_Ant_Limits2();
213 void ExtractStation_2RL_Post_Limits();
214 void ExtractStation_2RL_LR_Limits();
215 void ExtractStation_2RL_Remove_Structures();
216 void ExtractStation_2RL_SeparateRL();
217 vtkSmartPointer<vtkPolyData> Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points);
220 void ExtractStation_7();
221 void ExtractStation_7_SetDefaultValues();
222 void ExtractStation_7_SI_Limits();
223 void ExtractStation_7_RL_Interior_Limits();
226 void ExtractStation_7_RL_Limits_OLD();
227 void ExtractStation_7_Posterior_Limits();
228 void ExtractStation_7_Remove_Structures();
229 bool m_S7_UseMostInferiorPartOnlyFlag;
230 bool m_ComputeStationsSupportsFlag;
231 MaskImagePointer m_Working_Trachea;
232 MaskImagePointer m_LeftBronchus;
233 MaskImagePointer m_RightBronchus;
234 typedef std::vector<MaskImageType::PointType> ListOfPointsType;
235 ListOfPointsType m_RightMostInLeftBronchus;
236 ListOfPointsType m_AntMostInLeftBronchus;
237 ListOfPointsType m_PostMostInLeftBronchus;
238 ListOfPointsType m_LeftMostInRightBronchus;
239 ListOfPointsType m_AntMostInRightBronchus;
240 ListOfPointsType m_PostMostInRightBronchus;
242 void FindExtremaPointsInBronchus(MaskImagePointer input,
244 double distance_max_from_center_point,
245 ListOfPointsType & LR,
246 ListOfPointsType & Ant,
247 ListOfPointsType & Post);
249 void ExtractStation_4RL();
250 void ExtractStation_4RL_SI_Limits();
251 void ExtractStation_4RL_LR_Limits();
252 void ExtractStation_4RL_AP_Limits();
253 MaskImagePointer m_RightSupport;
254 MaskImagePointer m_LeftSupport;
257 ExtractLymphStationsFilter(const Self&); //purposely not implemented
258 void operator=(const Self&); //purposely not implemented
261 //--------------------------------------------------------------------
263 } // end namespace clitk
264 //--------------------------------------------------------------------
266 #ifndef ITK_MANUAL_INSTANTIATION
267 #include "clitkExtractLymphStationsFilter.txx"
268 #include "clitkExtractLymphStation_Supports.txx"
269 #include "clitkExtractLymphStation_8.txx"
270 #include "clitkExtractLymphStation_3P.txx"
271 #include "clitkExtractLymphStation_2RL.txx"
272 #include "clitkExtractLymphStation_3A.txx"
273 #include "clitkExtractLymphStation_7.txx"
274 #include "clitkExtractLymphStation_4RL.txx"