]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_3P.txx
Merge branch 'master' of /home/dsarrut/clitk3.server
[clitk.git] / segmentation / clitkExtractLymphStation_3P.txx
1
2 //--------------------------------------------------------------------
3 template <class ImageType>
4 void 
5 clitk::ExtractLymphStationsFilter<ImageType>::
6 ExtractStation_3P_SetDefaultValues()
7 {
8 }
9 //--------------------------------------------------------------------
10
11
12 //--------------------------------------------------------------------
13 template <class TImageType>
14 void 
15 clitk::ExtractLymphStationsFilter<TImageType>::
16 ExtractStation_3P()
17 {
18   if (!CheckForStation("3P")) return;
19
20   StartNewStep("Station 3P");
21   StartSubStep();  
22
23   // Get the current support 
24   StartNewStep("[Station 3P] Get the current 3P suppport");
25   m_Working_Support = m_ListOfSupports["S3P"];
26   m_ListOfStations["3P"] = m_Working_Support;
27   StopCurrentStep<MaskImageType>(m_Working_Support);
28   
29   // LR limits inferiorly
30   ExtractStation_3P_LR_inf_Limits();
31   
32   // LR limits superiorly => not here for the moment because not
33   //  clear in the def
34   // ExtractStation_3P_LR_sup_Limits_2(); //TODO
35   // ExtractStation_3P_LR_sup_Limits();   // old version to change
36   
37   ExtractStation_8_Single_CCL_Limits(); // YES 8 !
38   ExtractStation_3P_Remove_Structures(); // after CCL
39   
40   // Store image filenames into AFDB 
41   writeImage<MaskImageType>(m_ListOfStations["3P"], "seg/Station3P.mhd");
42   GetAFDB()->SetImageFilename("Station3P", "seg/Station3P.mhd"); 
43   WriteAFDB();   
44   StopSubStep();
45 }
46 //--------------------------------------------------------------------
47
48
49 //--------------------------------------------------------------------
50 template <class ImageType>
51 void 
52 clitk::ExtractLymphStationsFilter<ImageType>::
53 ExtractStation_3P_Remove_Structures() 
54 {
55   StartNewStep("[Station 3P] Remove some structures.");
56
57   Remove_Structures("3P", "Aorta");
58   Remove_Structures("3P", "VertebralBody");
59   Remove_Structures("3P", "SubclavianArteryLeft");
60   Remove_Structures("3P", "SubclavianArteryRight");
61   Remove_Structures("3P", "Esophagus");
62   Remove_Structures("3P", "AzygousVein");
63   Remove_Structures("3P", "Thyroid");
64   Remove_Structures("3P", "VertebralArtery");
65
66   StopCurrentStep<MaskImageType>(m_Working_Support);
67   m_ListOfStations["3P"] = m_Working_Support;
68 }
69 //--------------------------------------------------------------------
70
71
72 //--------------------------------------------------------------------
73 template <class ImageType>
74 void 
75 clitk::ExtractLymphStationsFilter<ImageType>::
76 ExtractStation_3P_LR_sup_Limits() 
77 {
78   /*
79     "On the right side, the limit is defined by the air–soft-tissue
80     interface. On the left side, it is defined by the air–tissue
81     interface superiorly (Fig. 2A–C) and the aorta inferiorly
82     (Figs. 2D–I and 3A–C)."
83
84     sup : 
85     Resizelike support : Trachea, SubclavianArtery
86     Trachea, slice by slice, get centroid trachea
87     SubclavianArtery, slice by slice, CCL
88     prendre la 1ère à L et R, not at Left
89     
90   */
91   StartNewStep("[Station 3P] Left/Right limits (superior part) ");
92
93   // Load structures
94   MaskImagePointer Trachea = GetAFDB()->template GetImage<MaskImageType>("Trachea");
95   MaskImagePointer SubclavianArtery = GetAFDB()->template GetImage<MaskImageType>("SubclavianArtery");
96   
97   // Crop like current support
98   Trachea = clitk::ResizeImageLike<MaskImageType>(Trachea, m_Working_Support, GetBackgroundValue());
99   SubclavianArtery = clitk::ResizeImageLike<MaskImageType>(SubclavianArtery, m_Working_Support, GetBackgroundValue());
100   
101   writeImage<MaskImageType>(Trachea, "tr.mhd");
102   writeImage<MaskImageType>(SubclavianArtery, "sca.mhd");
103   
104   // Get list of slices
105   std::vector<MaskSlicePointer> slices_support;
106   std::vector<MaskSlicePointer> slices_trachea;
107   std::vector<MaskSlicePointer> slices_subclavianartery;
108   clitk::ExtractSlices<MaskImageType>(m_Working_Support, 2, slices_support);
109   clitk::ExtractSlices<MaskImageType>(Trachea, 2, slices_trachea);
110   clitk::ExtractSlices<MaskImageType>(SubclavianArtery, 2, slices_subclavianartery);
111
112   // Loop on slices
113   std::vector<MaskImagePointType> points;
114   MaskImagePointType p;
115   for(uint i=0; i<slices_support.size(); i++) {
116     // Get Trachea centroid
117     std::vector<typename MaskSliceType::PointType> centroids;
118     typename MaskSliceType::PointType c;
119     ComputeCentroids<MaskSliceType>(slices_trachea[i], GetBackgroundValue(), centroids);
120     c = centroids[1];
121
122     // [debug] Store point
123     clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[1], Trachea, i, p);
124     points.push_back(p);
125     
126     // Get Right and Left CCL in SubclavianArtery
127     slices_subclavianartery[i] = Labelize<MaskSliceType>(slices_subclavianartery[i], 0, true, 10);
128     ComputeCentroids<MaskSliceType>(slices_subclavianartery[i], GetBackgroundValue(), centroids);
129
130     if (centroids.size() > 1) {
131       // Determine the one at Right/Left -> first after Trachea
132       // centroid 
133       typename MaskSliceType::PointType right;
134       typename MaskSliceType::PointType left;
135       int label_right=-1;
136       int label_left=-1;
137       right[0] = c[0]-100;
138       left[0] = c[0]+100;
139       for(uint j=1; j<centroids.size(); j++) {
140         if (centroids[j][0] < c[0]) { // At Right of Trachea centroid
141           if (centroids[j][0] >= right[0]) {
142             right = centroids[j];
143             label_right = j;
144           }
145         }
146         if (centroids[j][0] > c[0]) { // At Left of Trachea centroid
147           if (centroids[j][0] <= left[0]) {
148             left = centroids[j];
149             label_left = j;
150           }
151         }
152       }
153
154       if (label_right != -1) {
155     
156         // Debug points
157         clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[label_right], SubclavianArtery, i, p);
158         points.push_back(p);
159
160         // Set Background and ForegroundValue according to label_right
161         MaskSlicePointer object = 
162           clitk::Binarize<MaskSliceType>(slices_subclavianartery[i], label_right, label_right, 
163                                          GetBackgroundValue(), GetForegroundValue());
164       
165         // Relative Position : not at Right
166         typedef clitk::AddRelativePositionConstraintToLabelImageFilter<MaskSliceType> RelPosFilterType;
167         typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
168         relPosFilter->VerboseStepFlagOff();
169         relPosFilter->WriteStepFlagOff();
170         relPosFilter->SetBackgroundValue(GetBackgroundValue());
171         relPosFilter->SetInput(slices_support[i]); 
172         relPosFilter->SetInputObject(object); 
173         relPosFilter->AddOrientationTypeString("R");
174         relPosFilter->SetInverseOrientationFlag(true);
175         //      relPosFilter->SetIntermediateSpacing(3);
176         relPosFilter->SetIntermediateSpacingFlag(false);
177         relPosFilter->SetFuzzyThreshold(0.7);
178         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
179         relPosFilter->Update();
180         slices_support[i] = relPosFilter->GetOutput();
181
182         // Relative Position : not Anterior
183         relPosFilter = RelPosFilterType::New();
184         relPosFilter->VerboseStepFlagOff();
185         relPosFilter->WriteStepFlagOff();
186         relPosFilter->SetBackgroundValue(GetBackgroundValue());
187         relPosFilter->SetInput(slices_support[i]); 
188         relPosFilter->SetInputObject(object); 
189         relPosFilter->AddOrientationTypeString("A");
190         relPosFilter->SetInverseOrientationFlag(true);
191         //      relPosFilter->SetIntermediateSpacing(3);
192         relPosFilter->SetIntermediateSpacingFlag(false);
193         relPosFilter->SetFuzzyThreshold(0.7);
194         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
195         relPosFilter->Update();
196         slices_support[i] = relPosFilter->GetOutput();
197
198       } // End RelativePosition for Right
199
200
201       if (label_left != -1) {
202     
203         // Debug points
204         clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[label_left], SubclavianArtery, i, p);
205         points.push_back(p);
206
207         // Set Background and ForegroundValue according to label_right
208         MaskSlicePointer object = 
209           clitk::Binarize<MaskSliceType>(slices_subclavianartery[i], label_left, label_left, 
210                                          GetBackgroundValue(), GetForegroundValue());
211       
212         // Relative Position : not at Right
213         typedef clitk::AddRelativePositionConstraintToLabelImageFilter<MaskSliceType> RelPosFilterType;
214         typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
215         relPosFilter->VerboseStepFlagOff();
216         relPosFilter->WriteStepFlagOff();
217         relPosFilter->SetBackgroundValue(GetBackgroundValue());
218         relPosFilter->SetInput(slices_support[i]); 
219         relPosFilter->SetInputObject(object); 
220         relPosFilter->AddOrientationTypeString("L");
221         relPosFilter->SetInverseOrientationFlag(true);
222         //      relPosFilter->SetIntermediateSpacing(3);
223         relPosFilter->SetIntermediateSpacingFlag(false);
224         relPosFilter->SetFuzzyThreshold(0.7);
225         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
226         relPosFilter->Update();
227         slices_support[i] = relPosFilter->GetOutput();
228
229         // Relative Position : not Anterior
230         relPosFilter = RelPosFilterType::New();
231         relPosFilter->VerboseStepFlagOff();
232         relPosFilter->WriteStepFlagOff();
233         relPosFilter->SetBackgroundValue(GetBackgroundValue());
234         relPosFilter->SetInput(slices_support[i]); 
235         relPosFilter->SetInputObject(object); 
236         relPosFilter->AddOrientationTypeString("A");
237         relPosFilter->SetInverseOrientationFlag(true);
238         //      relPosFilter->SetIntermediateSpacing(3);
239         relPosFilter->SetIntermediateSpacingFlag(false);
240         relPosFilter->SetFuzzyThreshold(0.7);
241         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
242         relPosFilter->Update();
243         slices_support[i] = relPosFilter->GetOutput();
244
245       }
246
247     
248     } // if centroids.size > 1
249   } // End loop slices
250
251   // Joint slices
252   m_Working_Support = clitk::JoinSlices<MaskImageType>(slices_support, m_Working_Support, 2);
253
254   // Save list points
255   clitk::WriteListOfLandmarks<MaskImageType>(points, "subcl-lr.txt");
256
257
258   StopCurrentStep<MaskImageType>(m_Working_Support);
259   m_ListOfStations["3P"] = m_Working_Support;
260 }
261 //--------------------------------------------------------------------
262
263 //--------------------------------------------------------------------
264 template <class ImageType>
265 void 
266 clitk::ExtractLymphStationsFilter<ImageType>::
267 ExtractStation_3P_LR_sup_Limits_2() 
268 {
269   /*
270     "On the right side, the limit is defined by the air–soft-tissue
271     interface. On the left side, it is defined by the air–tissue
272     interface superiorly (Fig. 2A–C) and the aorta inferiorly
273     (Figs. 2D–I and 3A–C)."
274
275     sup : 
276     Resizelike support : Trachea, SubclavianArtery
277     Trachea, slice by slice, get centroid trachea
278     SubclavianArtery, slice by slice, CCL
279     prendre la 1ère à L et R, not at Left
280     
281   */
282   //  StartNewStep("[Station 3P] Left/Right limits (superior part) ");
283   
284
285 }
286 //--------------------------------------------------------------------
287
288 //--------------------------------------------------------------------
289 template <class ImageType>
290 void 
291 clitk::ExtractLymphStationsFilter<ImageType>::
292 ExtractStation_3P_LR_inf_Limits() 
293 {
294   /*
295     "On the right side, the limit is defined by the air–soft-tissue
296     interface. On the left side, it is defined by the air–tissue
297     interface superiorly (Fig. 2A–C) and the aorta inferiorly
298     (Figs. 2D–I and 3A–C)."
299
300     inf : not Right to Azygousvein    
301   */
302   StartNewStep("[Station 3P] Left/Right limits (inferior part) with Azygousvein and Aorta");
303
304   // Load structures
305   MaskImagePointer AzygousVein = GetAFDB()->template GetImage<MaskImageType>("AzygousVein");
306   MaskImagePointer Aorta = GetAFDB()->template GetImage<MaskImageType>("Aorta");
307
308   DD("ici");
309   writeImage<MaskImageType>(m_Working_Support, "ws.mhd");
310
311   typedef clitk::AddRelativePositionConstraintToLabelImageFilter<MaskImageType> RelPosFilterType;
312   typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
313   relPosFilter->VerboseStepFlagOff();
314   relPosFilter->WriteStepFlagOff();
315   relPosFilter->SetBackgroundValue(GetBackgroundValue());
316   relPosFilter->SetInput(m_Working_Support); 
317   relPosFilter->SetInputObject(AzygousVein); 
318   relPosFilter->AddOrientationTypeString("R");
319   relPosFilter->SetInverseOrientationFlag(true);
320   relPosFilter->SetIntermediateSpacing(3);
321   relPosFilter->SetIntermediateSpacingFlag(false);
322   relPosFilter->SetFuzzyThreshold(0.7);
323   relPosFilter->AutoCropFlagOn();
324   relPosFilter->Update();
325   m_Working_Support = relPosFilter->GetOutput();
326
327   DD("la");
328   writeImage<MaskImageType>(m_Working_Support, "before-L-aorta.mhd");
329   relPosFilter->SetInput(m_Working_Support); 
330   relPosFilter->SetInputObject(Aorta); 
331   relPosFilter->AddOrientationTypeString("L");
332   relPosFilter->SetInverseOrientationFlag(true);
333   relPosFilter->SetIntermediateSpacing(3);
334   relPosFilter->SetIntermediateSpacingFlag(false);
335   relPosFilter->SetFuzzyThreshold(0.7);
336   relPosFilter->AutoCropFlagOn();
337   relPosFilter->Update();
338   m_Working_Support = relPosFilter->GetOutput();
339   writeImage<MaskImageType>(m_Working_Support, "after-L-aorta.mhd");
340
341   StopCurrentStep<MaskImageType>(m_Working_Support);
342   m_ListOfStations["3P"] = m_Working_Support;
343 }
344 //--------------------------------------------------------------------