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 "clitkStructuresExtractionFilter.h"
24 #include "clitkLabelImageOverlapMeasureFilter.h"
27 #include <vtkPolyData.h>
31 class SupportLimitsType {
33 std::string station_limit;
35 std::string structure_limit;
36 std::string structure;
38 void Read(istream & is) {
41 is >> structure_limit;
45 offset = atof(s.c_str());
49 //--------------------------------------------------------------------
51 Try to extract the LymphStations part of a thorax CT.
52 Need a set of Anatomical Features (AFDB)
54 //--------------------------------------------------------------------
56 template <class TImageType>
57 class ITK_EXPORT ExtractLymphStationsFilter:
58 public clitk::StructuresExtractionFilter<TImageType>
62 /** Standard class typedefs. */
63 typedef clitk::StructuresExtractionFilter<TImageType> Superclass;
64 typedef ExtractLymphStationsFilter Self;
65 typedef itk::SmartPointer<Self> Pointer;
66 typedef itk::SmartPointer<const Self> ConstPointer;
68 /** Method for creation through the object factory. */
71 /** Run-time type information (and related methods). */
72 itkTypeMacro(ExtractLymphStationsFilter, ImageToImageFilter);
74 /** Some convenient typedefs. */
75 typedef TImageType ImageType;
76 typedef typename ImageType::ConstPointer ImageConstPointer;
77 typedef typename ImageType::Pointer ImagePointer;
78 typedef typename ImageType::RegionType ImageRegionType;
79 typedef typename ImageType::PixelType ImagePixelType;
80 typedef typename ImageType::SizeType ImageSizeType;
81 typedef typename ImageType::IndexType ImageIndexType;
82 typedef typename ImageType::PointType ImagePointType;
84 typedef uchar MaskImagePixelType;
85 typedef itk::Image<MaskImagePixelType, 3> MaskImageType;
86 typedef typename MaskImageType::Pointer MaskImagePointer;
87 typedef typename MaskImageType::RegionType MaskImageRegionType;
88 typedef typename MaskImageType::SizeType MaskImageSizeType;
89 typedef typename MaskImageType::IndexType MaskImageIndexType;
90 typedef typename MaskImageType::PointType MaskImagePointType;
92 typedef itk::Image<MaskImagePixelType, 2> MaskSliceType;
93 typedef typename MaskSliceType::Pointer MaskSlicePointer;
94 typedef typename MaskSliceType::PointType MaskSlicePointType;
95 typedef typename MaskSliceType::RegionType MaskSliceRegionType;
96 typedef typename MaskSliceType::SizeType MaskSliceSizeType;
97 typedef typename MaskSliceType::IndexType MaskSliceIndexType;
99 /** ImageDimension constants */
100 itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
103 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
104 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
105 itkSetMacro(BackgroundValue, MaskImagePixelType);
106 itkSetMacro(ForegroundValue, MaskImagePixelType);
109 itkSetMacro(EsophagusDiltationForAnt, MaskImagePointType);
110 itkGetConstMacro(EsophagusDiltationForAnt, MaskImagePointType);
111 itkSetMacro(EsophagusDiltationForRight, MaskImagePointType);
112 itkGetConstMacro(EsophagusDiltationForRight, MaskImagePointType);
113 itkSetMacro(InjectedThresholdForS8, double);
114 itkGetConstMacro(InjectedThresholdForS8, double);
117 itkGetConstMacro(S7_UseMostInferiorPartOnlyFlag, bool);
118 itkSetMacro(S7_UseMostInferiorPartOnlyFlag, bool);
119 itkBooleanMacro(S7_UseMostInferiorPartOnlyFlag);
122 bool GetComputeStation(std::string s);
123 void AddComputeStation(std::string station) ;
124 void SetFuzzyThreshold(std::string station, std::string tag, double value);
125 double GetFuzzyThreshold(std::string station, std::string tag);
126 void SetThreshold(std::string station, std::string tag, double value);
127 double GetThreshold(std::string station, std::string tag);
128 itkGetConstMacro(ForceSupportsFlag, bool);
129 itkSetMacro(ForceSupportsFlag, bool);
130 itkBooleanMacro(ForceSupportsFlag);
132 itkGetConstMacro(CheckSupportFlag, bool);
133 itkSetMacro(CheckSupportFlag, bool);
134 itkBooleanMacro(CheckSupportFlag);
136 itkGetConstMacro(SupportLimitsFilename, std::string);
137 itkSetMacro(SupportLimitsFilename, std::string);
140 ExtractLymphStationsFilter();
141 virtual ~ExtractLymphStationsFilter() {}
143 virtual void GenerateOutputInformation();
144 virtual void GenerateInputRequestedRegion();
145 virtual void GenerateData();
147 // To avoid repeat "this->"
148 AnatomicalFeatureDatabase * GetAFDB() { return clitk::FilterWithAnatomicalFeatureDatabaseManagement::GetAFDB(); }
149 void WriteAFDB() { clitk::FilterWithAnatomicalFeatureDatabaseManagement::WriteAFDB(); }
150 void LoadAFDB() { clitk::FilterWithAnatomicalFeatureDatabaseManagement::LoadAFDB(); }
151 void StartNewStep(std::string s) { clitk::FilterBase::StartNewStep(s); }
152 void StartSubStep() { clitk::FilterBase::StartSubStep(); }
153 template<class TInternalImageType>
154 void StopCurrentStep(typename TInternalImageType::Pointer p, std::string txt="") { clitk::FilterBase::StopCurrentStep<TInternalImageType>(p, txt); }
155 void StopCurrentStep() {clitk::FilterBase::StopCurrentStep(); }
156 void StopSubStep() {clitk::FilterBase::StopSubStep(); }
158 ImageConstPointer m_Input;
159 MaskImagePointer m_Mediastinum;
160 MaskImagePointer m_Working_Support;
161 std::map<std::string, MaskImagePointer> m_ListOfStations;
162 std::map<std::string, MaskImagePointer> m_ListOfSupports;
163 MaskImagePixelType m_BackgroundValue;
164 MaskImagePixelType m_ForegroundValue;
165 std::map<std::string, bool> m_ComputeStationMap;
166 std::string m_SupportLimitsFilename;
167 std::vector<SupportLimitsType> m_ListOfSupportLimits;
169 bool CheckForStation(std::string station);
170 void Remove_Structures(std::string station, std::string s);
171 void WriteImageSupport(std::string support);
172 void WriteImageStation(std::string station);
173 void ComputeOverlapWithRef(std::string station);
174 void Support_SI_Limit(const std::string station_limit, const std::string station,
175 const std::string structure_limit, const std::string structure,
176 const double offset);
177 void ReadSupportLimits(std::string filename);
179 // Functions common to several stations
181 double FindApexOfTheChest();
182 double FindSuperiorBorderOfAorticArch();
183 double FindInferiorBorderOfAorticArch();
184 void FindLeftAndRightBronchi();
185 void FindLineForS7S8Separation(MaskImagePointType & A, MaskImagePointType & B);
186 MaskImagePointer FindAntPostVesselsOLD();
187 MaskImagePointer FindAntPostVessels2();
190 typedef std::map<std::string, double> FuzzyThresholdByStructureType;
191 std::map<std::string, FuzzyThresholdByStructureType> m_FuzzyThreshold;
192 typedef std::map<std::string, double> ThresholdByStructureType;
193 std::map<std::string, ThresholdByStructureType> m_Threshold;
195 // Station's supports
196 void ExtractStationSupports();
197 void Support_LeftRight_S1R_S1L();
198 void Support_LeftRight_S2R_S2L();
199 void Support_LeftRight_S4R_S4L();
200 void Support_Post_S1S2S4();
202 MaskImagePointer LimitsWithTrachea(MaskImageType * input,
203 int extremaDirection, int lineDirection,
204 double offset, double maxSupPosition);
205 MaskImagePointer LimitsWithTrachea(MaskImageType * input,
206 int extremaDirection, int lineDirection,
209 double m_DiaphragmInferiorLimit;
210 double m_OriginOfRightMiddleLobeBronchusZ;
211 double m_InjectedThresholdForS8;
212 MaskImagePointer m_Esophagus;
213 MaskImagePointType m_EsophagusDiltationForAnt;
214 MaskImagePointType m_EsophagusDiltationForRight;
216 void ExtractStation_8();
217 void ExtractStation_8_SetDefaultValues();
218 void ExtractStation_8_SI_Limits();
219 void ExtractStation_8_Ant_Limits();
220 void ExtractStation_8_Left_Sup_Limits();
221 void ExtractStation_8_Left_Inf_Limits();
222 void ExtractStation_8_Single_CCL_Limits();
223 void ExtractStation_8_Remove_Structures();
226 void ExtractStation_3P();
227 void ExtractStation_3P_SetDefaultValues();
228 void ExtractStation_3P_LR_inf_Limits();
229 void ExtractStation_3P_LR_sup_Limits_2();
230 void ExtractStation_3P_Remove_Structures();
231 void ExtractStation_3P_LR_sup_Limits();
234 void ExtractStation_3A();
235 void ExtractStation_3A_SetDefaultValues();
236 void ExtractStation_3A_Post_Left_Limits_With_Aorta_S5_Support();
237 void ExtractStation_3A_Post_Limits_With_Dilated_Aorta_S6_Support();
238 void ExtractStation_3A_AntPost_Superiorly();
239 void ExtractStation_3A_Remove_Structures();
242 void ExtractStation_2RL();
243 void ExtractStation_2RL_SetDefaultValues();
244 void ExtractStation_2RL_Ant_Limits(std::string s);
245 void ExtractStation_2RL_Remove_Structures(std::string s);
246 void ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split();
247 vtkSmartPointer<vtkPolyData> Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points);
250 void ExtractStation_1RL();
251 void ExtractStation_1RL_SetDefaultValues();
252 void ExtractStation_1RL_Ant_Limits();
253 void ExtractStation_1RL_Post_Limits();
256 void ExtractStation_4RL_SetDefaultValues();
257 void ExtractStation_4L();
258 void ExtractStation_4R();
259 void ExtractStation_S4L_S5_Limits_Aorta_LeftPulmonaryArtery(int KeepPoint);
262 void ExtractStation_5_SetDefaultValues();
263 void ExtractStation_5();
264 void ExtractStation_5_Limits_AscendingAorta_Ant();
267 void ExtractStation_6_SetDefaultValues();
268 void ExtractStation_6();
272 void ExtractStation_7();
273 void ExtractStation_7_SetDefaultValues();
274 void ExtractStation_7_SI_Limits();
275 void ExtractStation_7_RL_Interior_Limits();
277 void ExtractStation_7_RL_Limits_OLD();
278 void ExtractStation_7_Posterior_Limits();
279 void ExtractStation_7_Remove_Structures();
280 bool m_S7_UseMostInferiorPartOnlyFlag;
281 bool m_ForceSupportsFlag;
282 bool m_CheckSupportFlag;
283 MaskImagePointer m_Working_Trachea;
284 MaskImagePointer m_LeftBronchus;
285 MaskImagePointer m_RightBronchus;
286 typedef std::vector<MaskImageType::PointType> ListOfPointsType;
287 ListOfPointsType m_RightMostInLeftBronchus;
288 ListOfPointsType m_AntMostInLeftBronchus;
289 ListOfPointsType m_PostMostInLeftBronchus;
290 ListOfPointsType m_LeftMostInRightBronchus;
291 ListOfPointsType m_AntMostInRightBronchus;
292 ListOfPointsType m_PostMostInRightBronchus;
294 void FindExtremaPointsInBronchus(MaskImagePointer input,
296 double distance_max_from_center_point,
297 ListOfPointsType & LR,
298 ListOfPointsType & Ant,
299 ListOfPointsType & Post);
301 ExtractLymphStationsFilter(const Self&); //purposely not implemented
302 void operator=(const Self&); //purposely not implemented
305 //--------------------------------------------------------------------
307 } // end namespace clitk
308 //--------------------------------------------------------------------
310 #ifndef ITK_MANUAL_INSTANTIATION
311 #include "clitkExtractLymphStationsFilter.txx"
312 #include "clitkExtractLymphStation_Supports.txx"
313 #include "clitkExtractLymphStation_3P.txx"
314 #include "clitkExtractLymphStation_2RL.txx"
315 #include "clitkExtractLymphStation_3A.txx"
316 #include "clitkExtractLymphStation_4RL.txx"
317 #include "clitkExtractLymphStation_1RL.txx"
318 #include "clitkExtractLymphStation_5.txx"
319 #include "clitkExtractLymphStation_6.txx"
321 #include "clitkExtractLymphStation_8.txx"
322 #include "clitkExtractLymphStation_7.txx"