]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_Supports.txx
Merge branch 'master' of /home/dsarrut/clitk3.server
[clitk.git] / segmentation / clitkExtractLymphStation_Supports.txx
1
2 #include <itkBinaryDilateImageFilter.h>
3 #include <itkMirrorPadImageFilter.h>
4
5 //--------------------------------------------------------------------
6 template <class ImageType>
7 void 
8 clitk::ExtractLymphStationsFilter<ImageType>::
9 ExtractStationSupports()
10 {
11   DD("ExtractStationSupports");
12
13   // Get initial Mediastinum
14   m_Working_Support = m_Mediastinum = this->GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true);
15
16   // Consider sup/inf to Carina
17   double m_CarinaZ = FindCarina();
18   MaskImagePointer m_Support_Superior_to_Carina = 
19     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
20                                                    m_CarinaZ, true, GetBackgroundValue());
21   MaskImagePointer m_Support_Inferior_to_Carina = 
22     clitk::CropImageRemoveGreaterThan<MaskImageType>(m_Working_Support, 2, 
23                                                      m_CarinaZ, true, GetBackgroundValue());
24   m_ListOfSupports["Support_Superior_to_Carina"] = m_Support_Superior_to_Carina;
25   m_ListOfSupports["Support_Inferior_to_Carina"] = m_Support_Inferior_to_Carina;
26   writeImage<MaskImageType>(m_Support_Inferior_to_Carina, "seg/Support_Inf_Carina.mhd");
27   this->GetAFDB()->SetImageFilename("Support_Inf_Carina", "seg/Support_Inf_Carina.mhd");
28   writeImage<MaskImageType>(m_Support_Superior_to_Carina, "seg/Support_Sup_Carina.mhd");
29   this->GetAFDB()->SetImageFilename("Support_Sup_Carina", "seg/Support_Sup_Carina.mhd");
30
31   // S1RL
32   Support_SupInf_S1RL();
33   Support_LeftRight_S1R_S1L();
34
35   // S2RL
36   Support_SupInf_S2R_S2L();
37   Support_LeftRight_S2R_S2L();
38
39   // S4RL
40   Support_SupInf_S4R_S4L();
41   Support_LeftRight_S4R_S4L();
42   
43   // Post limits of S1,S2,S4
44   Support_Post_S1S2S4();
45
46   // S3AP
47   Support_S3P();
48   Support_S3A();
49   
50   // S5, S6
51   Support_S5();
52   Support_S6();
53   
54   // Below Carina S7,8,9,10
55   m_ListOfSupports["S7"] = clitk::Clone<MaskImageType>(m_Support_Inferior_to_Carina);
56   m_ListOfSupports["S8"] = clitk::Clone<MaskImageType>(m_Support_Inferior_to_Carina);
57   m_ListOfSupports["S9"] = clitk::Clone<MaskImageType>(m_Support_Inferior_to_Carina);
58   m_ListOfSupports["S10"] = clitk::Clone<MaskImageType>(m_Support_Inferior_to_Carina);
59   m_ListOfSupports["S11"] = clitk::Clone<MaskImageType>(m_Support_Inferior_to_Carina);
60
61   // Store image filenames into AFDB 
62   writeImage<MaskImageType>(m_ListOfSupports["S1R"], "seg/Support_S1R.mhd");
63   this->GetAFDB()->SetImageFilename("Support_S1R", "seg/Support_S1R.mhd");
64   writeImage<MaskImageType>(m_ListOfSupports["S1L"], "seg/Support_S1L.mhd");
65   this->GetAFDB()->SetImageFilename("Support_S1L", "seg/Support_S1L.mhd");
66
67   writeImage<MaskImageType>(m_ListOfSupports["S2L"], "seg/Support_S2L.mhd");
68   this->GetAFDB()->SetImageFilename("Support_S2L", "seg/Support_S2L.mhd");
69   writeImage<MaskImageType>(m_ListOfSupports["S2R"], "seg/Support_S2R.mhd");
70   this->GetAFDB()->SetImageFilename("Support_S2R", "seg/Support_S2R.mhd");
71
72   writeImage<MaskImageType>(m_ListOfSupports["S3P"], "seg/Support_S3P.mhd");
73   this->GetAFDB()->SetImageFilename("Support_S3P", "seg/Support_S3P.mhd");
74   writeImage<MaskImageType>(m_ListOfSupports["S3A"], "seg/Support_S3A.mhd");
75   this->GetAFDB()->SetImageFilename("Support_S3A", "seg/Support_S3A.mhd");
76
77   writeImage<MaskImageType>(m_ListOfSupports["S4L"], "seg/Support_S4L.mhd");
78   this->GetAFDB()->SetImageFilename("Support_S4L", "seg/Support_S4L.mhd");
79   writeImage<MaskImageType>(m_ListOfSupports["S4R"], "seg/Support_S4R.mhd");
80   this->GetAFDB()->SetImageFilename("Support_S4R", "seg/Support_S4R.mhd");
81
82   writeImage<MaskImageType>(m_ListOfSupports["S5"], "seg/Support_S5.mhd");
83   this->GetAFDB()->SetImageFilename("Support_S5", "seg/Support_S5.mhd");
84   writeImage<MaskImageType>(m_ListOfSupports["S6"], "seg/Support_S6.mhd");
85   this->GetAFDB()->SetImageFilename("Support_S6", "seg/Support_S6.mhd");
86
87   writeImage<MaskImageType>(m_ListOfSupports["S7"], "seg/Support_S7.mhd");
88   this->GetAFDB()->SetImageFilename("Support_S7", "seg/Support_S7.mhd");
89
90   writeImage<MaskImageType>(m_ListOfSupports["S8"], "seg/Support_S8.mhd");
91   this->GetAFDB()->SetImageFilename("Support_S8", "seg/Support_S8.mhd");
92
93   writeImage<MaskImageType>(m_ListOfSupports["S9"], "seg/Support_S9.mhd");
94   this->GetAFDB()->SetImageFilename("Support_S9", "seg/Support_S9.mhd");
95
96   writeImage<MaskImageType>(m_ListOfSupports["S10"], "seg/Support_S10.mhd");
97   this->GetAFDB()->SetImageFilename("Support_S10", "seg/Support_S10.mhd");  
98
99   writeImage<MaskImageType>(m_ListOfSupports["S11"], "seg/Support_S11.mhd");
100   this->GetAFDB()->SetImageFilename("Support_S11", "seg/Support_S11.mhd");  
101   WriteAFDB();
102 }
103 //--------------------------------------------------------------------
104
105
106 //--------------------------------------------------------------------
107 template <class ImageType>
108 void 
109 clitk::ExtractLymphStationsFilter<ImageType>::
110 Support_SupInf_S1RL()
111 {
112   // Step : S1RL
113   StartNewStep("[Support] Sup-Inf S1RL");
114   /*
115     2R: Upper border: apex of the right lung and pleural space, and in
116     the midline, the upper border of the manubrium
117     
118     2L: Upper border: apex of the left lung and pleural space, and in the
119     midline, the upper border of the manubrium
120
121     => apex / manubrium = up Sternum
122   */
123   m_Working_Support = m_ListOfSupports["Support_Superior_to_Carina"];
124   MaskImagePointer Sternum = this->GetAFDB()->template GetImage <MaskImageType>("Sternum");
125   MaskImagePointType p;
126   p[0] = p[1] = p[2] =  0.0; // to avoid warning
127   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Sternum, GetBackgroundValue(), 2, false, p);
128   MaskImagePointer S1RL = 
129     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
130                                                    p[2], true, GetBackgroundValue());
131   m_Working_Support = 
132     clitk::CropImageRemoveGreaterThan<MaskImageType>(m_Working_Support, 2, 
133                                                      p[2], true, GetBackgroundValue());
134   m_ListOfSupports["S1RL"] = S1RL;
135 }
136 //--------------------------------------------------------------------
137
138
139 //--------------------------------------------------------------------
140 template <class ImageType>
141 void 
142 clitk::ExtractLymphStationsFilter<ImageType>::
143 Support_LeftRight_S1R_S1L()
144 {
145   // Step S1RL : Left-Right
146   StartNewStep("[Support] Left-Right S1R S1L");
147   std::vector<ImagePointType> A;
148   std::vector<ImagePointType> B;
149   // Search for centroid positions of trachea
150   MaskImagePointer Trachea = this->GetAFDB()->template GetImage <MaskImageType>("Trachea");
151   MaskImagePointer S1RL = m_ListOfSupports["S1RL"];
152   Trachea = clitk::ResizeImageLike<MaskImageType>(Trachea, S1RL, GetBackgroundValue());
153   std::vector<MaskSlicePointer> slices;
154   clitk::ExtractSlices<MaskImageType>(Trachea, 2, slices);
155   for(uint i=0; i<slices.size(); i++) {
156     slices[i] = Labelize<MaskSliceType>(slices[i], 0, false, 10);
157     std::vector<typename MaskSliceType::PointType> c;
158     clitk::ComputeCentroids<MaskSliceType>(slices[i], GetBackgroundValue(), c);
159     ImagePointType a,b;
160     clitk::PointsUtils<MaskImageType>::Convert2DTo3D(c[1], Trachea, i, a);
161     A.push_back(a);
162     b = a; 
163     b[1] += 50;
164     B.push_back(b);
165   }
166   clitk::WriteListOfLandmarks<MaskImageType>(A, "S1LR_A.txt");
167   clitk::WriteListOfLandmarks<MaskImageType>(B, "S1LR_B.txt");
168
169   // Clone support
170   MaskImagePointer S1R = clitk::Clone<MaskImageType>(S1RL);
171   MaskImagePointer S1L = clitk::Clone<MaskImageType>(S1RL);
172
173   // Right part
174   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(S1R, A, B, 
175                                                                     GetBackgroundValue(), 0, -10);
176   S1R = clitk::AutoCrop<MaskImageType>(S1R, GetBackgroundValue());
177   m_ListOfSupports["S1R"] = S1R;
178
179   // Left part
180   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(S1L, A, B, 
181                                                                     GetBackgroundValue(), 0, 10);
182   S1L = clitk::AutoCrop<MaskImageType>(S1L, GetBackgroundValue());
183   m_ListOfSupports["S1L"] = S1L;
184 }
185 //--------------------------------------------------------------------
186
187
188 //--------------------------------------------------------------------
189 template <class ImageType>
190 void 
191 clitk::ExtractLymphStationsFilter<ImageType>::
192 Support_SupInf_S2R_S2L()
193 {
194   // Step : S2RL Sup-Inf limits
195   /*
196     2R Lower border: intersection of caudal margin of innominate vein with
197     the trachea
198     2L Lower border: superior border of the aortic arch
199   */
200   StartNewStep("[Support] Sup-Inf S2RL");
201   m_Working_Support = m_ListOfSupports["Support_Superior_to_Carina"];
202   
203   // S2R Caudal Margin Of Left BrachiocephalicVein
204   MaskImagePointer BrachioCephalicVein = this->GetAFDB()->template GetImage<MaskImageType>("BrachioCephalicVein");
205   MaskImagePointType p;
206   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(BrachioCephalicVein, GetBackgroundValue(), 2, true, p);
207   // I add slightly more than a slice
208   double CaudalMarginOfLeftBrachiocephalicVeinZ=p[2]+ 1.1*m_Working_Support->GetSpacing()[2];
209   this->GetAFDB()->SetDouble("CaudalMarginOfLeftBrachiocephalicVeinZ", CaudalMarginOfLeftBrachiocephalicVeinZ);
210   MaskImagePointer S2R = 
211     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
212                                                    CaudalMarginOfLeftBrachiocephalicVeinZ, true,
213                                                    GetBackgroundValue());
214   // S2L : Top Of Aortic Arch
215   MaskImagePointer Aorta = this->GetAFDB()->template GetImage<MaskImageType>("Aorta");
216   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Aorta, GetBackgroundValue(), 2, false, p);
217
218   // Save the TopOfAorticArchZ
219   this->GetAFDB()->SetDouble("TopOfAorticArchZ", p[2]);
220
221   // I substract slightly more than a slice to respect delineation
222   double TopOfAorticArchZ=p[2]- 1.1*m_Working_Support->GetSpacing()[2];
223   //  this->GetAFDB()->SetDouble("TopOfAorticArchZ", TopOfAorticArchZ);
224
225   MaskImagePointer S2L = 
226     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
227                                                    TopOfAorticArchZ, true,
228                                                    GetBackgroundValue());
229
230   /*
231   // S2RL: Superior support, I use inferior part of S1RL
232   MaskImagePointer S1L = m_ListOfSupports["S1L"];
233   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(S1L, GetBackgroundValue(), 2, true, p);
234   DD(p);
235   S2L = 
236     clitk::CropImageRemoveGreaterThan<MaskImageType>(S2L, 2, 
237                                                      p[2], true,
238                                                      GetBackgroundValue());
239
240   MaskImagePointer S1R = m_ListOfSupports["S1R"];
241   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(S1R, GetBackgroundValue(), 2, true, p);
242   DD(p);
243   S2R = 
244     clitk::CropImageRemoveGreaterThan<MaskImageType>(S2R, 2, 
245                                                      p[2], true,
246                                                      GetBackgroundValue());          
247   */
248
249   // Superior limits, use Sternum (but not strictly inf to S1RL
250   MaskImagePointer Sternum = this->GetAFDB()->template GetImage <MaskImageType>("Sternum");
251   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Sternum, GetBackgroundValue(), 2, false, p);
252   // Add one slice
253   p[2] = p[2] +  m_Working_Support->GetSpacing()[2];
254   S2L = 
255     clitk::CropImageRemoveGreaterThan<MaskImageType>(S2L, 2, 
256                                                      p[2], true, GetBackgroundValue());
257   S2R = 
258     clitk::CropImageRemoveGreaterThan<MaskImageType>(S2R, 2, 
259                                                      p[2], true, GetBackgroundValue());
260
261   // The is the end
262   m_ListOfSupports["S2L"] = S2L;
263   m_ListOfSupports["S2R"] = S2R;
264 }
265 //--------------------------------------------------------------------
266
267
268
269 //--------------------------------------------------------------------
270 template <class ImageType>
271 void 
272 clitk::ExtractLymphStationsFilter<ImageType>::
273 Support_LeftRight_S2R_S2L()
274 {
275   // ---------------------------------------------------------------------------
276   /* Step : S2RL LeftRight
277      As for lymph node station 4R, 2R includes nodes extending to the
278      left lateral border of the trachea
279      Rod says:  "For station 2 there is a shift, dividing 2R from 2L, from midline
280      to the left paratracheal border."
281   */
282   StartNewStep("[Support] Separate 2R/2L according to Trachea");
283   MaskImagePointer S2R = m_ListOfSupports["S2R"];
284   MaskImagePointer S2L = m_ListOfSupports["S2L"];
285   S2R = LimitsWithTrachea(S2R, 0, 1, -10);
286   S2L = LimitsWithTrachea(S2L, 0, 1, 10);
287   m_ListOfSupports["S2R"] = S2R;
288   m_ListOfSupports["S2L"] = S2L;  
289   this->GetAFDB()->template ReleaseImage<MaskImageType>("Trachea");
290 }
291 //--------------------------------------------------------------------
292
293
294 //--------------------------------------------------------------------
295 template <class ImageType>
296 void 
297 clitk::ExtractLymphStationsFilter<ImageType>::
298 Support_SupInf_S4R_S4L()
299 {
300   // ---------------------------------------------------------------------------
301   /* Step : S4RL Sup-Inf
302      - start at the end of 2R and 2L
303      - stop ?
304      - 4R
305      Rod says : "The inferior border is at the lower border of the azygous vein."
306      Rod says : difficulties
307      (was : "ends at the upper lobe bronchus or where the right pulmonary artery
308      crosses the midline of the mediastinum ")
309      - 4L
310      Rod says : "The lower border is to upper margin of the left main pulmonary artery."
311      (was LLL bronchus)
312   */
313   StartNewStep("[Support] Sup-Inf limits of 4R/4L");
314
315   // Start from the support
316   MaskImagePointer S4RL = clitk::Clone<MaskImageType>(m_Working_Support);
317   MaskImagePointer S4R = clitk::Clone<MaskImageType>(S4RL);
318   MaskImagePointer S4L = clitk::Clone<MaskImageType>(S4RL);
319
320   // Keep only what is lower than S2
321   MaskImagePointer S2R = m_ListOfSupports["S2R"];
322   MaskImagePointer S2L = m_ListOfSupports["S2L"];
323   MaskImagePointType p;
324   // Right part
325   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(S2R, GetBackgroundValue(), 
326                                                           2, true, p);
327   DD(p);
328   writeImage<MaskImageType>(S4R, "before.mha");
329   S4R = clitk::CropImageRemoveGreaterThan<MaskImageType>(S4R, 2, 
330                                                        p[2], true, GetBackgroundValue());
331   writeImage<MaskImageType>(S4R, "after.mha");
332   
333   // Left part
334   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(S2L, GetBackgroundValue(), 
335                                                           2, true, p);
336   DD(p);
337   S4L = clitk::CropImageRemoveGreaterThan<MaskImageType>(S4L, 2, 
338                                                          p[2], true, GetBackgroundValue());
339   // S4R = clitk::AutoCrop<MaskImageType>(S4R, GetBackgroundValue());
340   // S4L = clitk::AutoCrop<MaskImageType>(S4L, GetBackgroundValue());
341
342   // Get AzygousVein and limit according to LowerBorderAzygousVein
343   MaskImagePointer LowerBorderAzygousVein 
344     = this->GetAFDB()->template GetImage<MaskImageType>("LowerBorderAzygousVein");
345   std::vector<MaskImagePointType> c;
346   clitk::ComputeCentroids<MaskImageType>(LowerBorderAzygousVein, GetBackgroundValue(), c);
347   S4R = clitk::CropImageRemoveLowerThan<MaskImageType>(S4R, 2, 
348                                                        c[1][2], true, GetBackgroundValue());
349   S4R = clitk::AutoCrop<MaskImageType>(S4R, GetBackgroundValue());
350   m_ListOfSupports["S4R"] = S4R;
351
352
353   // Limit according to LeftPulmonaryArtery
354   MaskImagePointer LeftPulmonaryArtery 
355     = this->GetAFDB()->template GetImage<MaskImageType>("LeftPulmonaryArtery");
356   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(LeftPulmonaryArtery, GetBackgroundValue(), 
357                                                           2, false, p);
358   S4L = clitk::CropImageRemoveLowerThan<MaskImageType>(S4L, 2, 
359                                                        p[2], true, GetBackgroundValue());
360   S4L = clitk::AutoCrop<MaskImageType>(S4L, GetBackgroundValue());
361   m_ListOfSupports["S4L"] = S4L;
362 }
363 //--------------------------------------------------------------------
364
365
366 //--------------------------------------------------------------------
367 template <class ImageType>
368 void 
369 clitk::ExtractLymphStationsFilter<ImageType>::
370 Support_LeftRight_S4R_S4L()
371 {
372   // ---------------------------------------------------------------------------
373   /* Step : S4RL LeftRight 
374      
375      - 4R: includes right paratracheal nodes, and pretracheal nodes
376      extending to the left lateral border of trachea
377      
378      - 4L: includes nodes to the left of the left lateral border of
379      the trachea, medial to the ligamentum arteriosum
380      
381      => same than 2RL
382   */
383   StartNewStep("[Support] Left Right separation of 4R/4L");
384
385   MaskImagePointer S4R = m_ListOfSupports["S4R"];
386   MaskImagePointer S4L = m_ListOfSupports["S4L"];
387   S4R = LimitsWithTrachea(S4R, 0, 1, -10);
388   S4L = LimitsWithTrachea(S4L, 0, 1, 10);
389   m_ListOfSupports["S4R"] = S4R;
390   m_ListOfSupports["S4L"] = S4L;
391 }
392 //--------------------------------------------------------------------
393
394
395 //--------------------------------------------------------------------
396 template <class ImageType>
397 typename clitk::ExtractLymphStationsFilter<ImageType>::MaskImagePointer
398 clitk::ExtractLymphStationsFilter<ImageType>::
399 LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection, 
400                   double offset) 
401 {
402   MaskImagePointType min, max;
403   GetMinMaxBoundary<MaskImageType>(input, min, max);
404   return LimitsWithTrachea(input, extremaDirection, lineDirection, offset, max[2]);
405 }
406 template <class ImageType>
407 typename clitk::ExtractLymphStationsFilter<ImageType>::MaskImagePointer
408 clitk::ExtractLymphStationsFilter<ImageType>::
409 LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection, 
410                   double offset, double maxSupPosition)
411 {
412   /*
413     Take the input mask, consider the trachea and limit according to
414     Left border of the trachea. Keep at Left or at Right according to
415     the offset
416   */
417   // Read the trachea
418   MaskImagePointer Trachea = this->GetAFDB()->template GetImage<MaskImageType>("Trachea");
419
420   // Find extrema post positions
421   std::vector<MaskImagePointType> tracheaLeftPositionsA;
422   std::vector<MaskImagePointType> tracheaLeftPositionsB;
423
424   // Crop Trachea only on the Sup-Inf axes, without autocrop
425   //  Trachea = clitk::ResizeImageLike<MaskImageType>(Trachea, input, GetBackgroundValue());
426   MaskImagePointType min, max;
427   GetMinMaxBoundary<MaskImageType>(input, min, max);
428   Trachea = clitk::CropImageAlongOneAxis<MaskImageType>(Trachea, 2, min[2], max[2], 
429                                                         false, GetBackgroundValue()); 
430   
431   // Select the main CCL (because of bronchus)
432   Trachea = SliceBySliceKeepMainCCL<MaskImageType>(Trachea, GetBackgroundValue(), GetForegroundValue());
433
434   // Slice by slice, build the separation line 
435   clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(Trachea, 
436                                                                                GetBackgroundValue(), 2, 
437                                                                                extremaDirection, false, // Left
438                                                                                lineDirection, // Vertical line 
439                                                                                -1, // margins 
440                                                                                tracheaLeftPositionsA, 
441                                                                                tracheaLeftPositionsB);
442   // Do not consider trachea above the limit
443   int indexMax=tracheaLeftPositionsA.size();
444   for(uint i=0; i<tracheaLeftPositionsA.size(); i++) {
445     if (tracheaLeftPositionsA[i][2] > maxSupPosition) {
446       indexMax = i;
447       i = tracheaLeftPositionsA.size(); // stop loop
448     }
449   }  
450   tracheaLeftPositionsA.erase(tracheaLeftPositionsA.begin()+indexMax, tracheaLeftPositionsA.end());
451   tracheaLeftPositionsB.erase(tracheaLeftPositionsB.begin()+indexMax, tracheaLeftPositionsB.end());
452
453   // Cut post to this line 
454   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(input, 
455                                                                     tracheaLeftPositionsA,
456                                                                     tracheaLeftPositionsB,
457                                                                     GetBackgroundValue(), 
458                                                                     extremaDirection, offset); 
459   MaskImagePointer output = clitk::AutoCrop<MaskImageType>(input, GetBackgroundValue());
460   return output;
461 }
462 //--------------------------------------------------------------------
463
464
465 //--------------------------------------------------------------------
466 template <class ImageType>
467 void
468 clitk::ExtractLymphStationsFilter<ImageType>::
469 Support_Post_S1S2S4()
470 {
471   StartNewStep("[Support] Post limits of S1RL, S2RL, S4RL");
472   
473   double m_ApexOfTheChest = FindApexOfTheChest();
474   
475   // Post limits with Trachea 
476   MaskImagePointer S1R = m_ListOfSupports["S1R"];
477   MaskImagePointer S1L = m_ListOfSupports["S1L"];
478   MaskImagePointer S2R = m_ListOfSupports["S2R"];
479   MaskImagePointer S2L = m_ListOfSupports["S2L"];
480   MaskImagePointer S4R = m_ListOfSupports["S4R"];
481   MaskImagePointer S4L = m_ListOfSupports["S4L"];
482   S1L = LimitsWithTrachea(S1L, 1, 0, -10, m_ApexOfTheChest);
483   S1R = LimitsWithTrachea(S1R, 1, 0, -10, m_ApexOfTheChest);
484   S2R = LimitsWithTrachea(S2R, 1, 0, -10, m_ApexOfTheChest);
485   S2L = LimitsWithTrachea(S2L, 1, 0, -10, m_ApexOfTheChest);
486   S4R = LimitsWithTrachea(S4R, 1, 0, -10, m_ApexOfTheChest);
487   S4L = LimitsWithTrachea(S4L, 1, 0, -10, m_ApexOfTheChest);
488 }
489 //--------------------------------------------------------------------
490
491
492 //--------------------------------------------------------------------
493 template <class ImageType>
494 void
495 clitk::ExtractLymphStationsFilter<ImageType>::
496 Support_S3P()
497 {
498   StartNewStep("[Support] Ant limits of S3P and Post limits of S1RL, S2RL, S4RL");
499   
500   // Initial S3P support
501   MaskImagePointer S3P = clitk::Clone<MaskImageType>(m_ListOfSupports["Support_Superior_to_Carina"]);
502
503   // Stop at Lung Apex
504   double m_ApexOfTheChest = FindApexOfTheChest();
505   S3P = 
506     clitk::CropImageRemoveGreaterThan<MaskImageType>(S3P, 2, 
507                                                      m_ApexOfTheChest, true,
508                                                      GetBackgroundValue());
509   // Ant limits with Trachea
510   S3P = LimitsWithTrachea(S3P, 1, 0, 10);
511   m_ListOfSupports["S3P"] = S3P;
512 }
513 //--------------------------------------------------------------------
514
515
516 //--------------------------------------------------------------------
517 template <class ImageType>
518 void
519 clitk::ExtractLymphStationsFilter<ImageType>::
520 Support_S3A()
521 {
522   StartNewStep("[Support] Sup-Inf and Post limits for S3A");
523
524   // Initial S3A support
525   MaskImagePointer S3A = clitk::Clone<MaskImageType>(m_ListOfSupports["Support_Superior_to_Carina"]);
526
527   // Stop at Lung Apex or like S2/S1 (upper border Sternum - manubrium) ?
528
529   //double m_ApexOfTheChest = FindApexOfTheChest();
530
531   MaskImagePointer Sternum = this->GetAFDB()->template GetImage <MaskImageType>("Sternum");
532   MaskImagePointType p;
533   p[0] = p[1] = p[2] =  0.0; // to avoid warning
534   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Sternum, GetBackgroundValue(), 2, false, p);
535
536   S3A = 
537     clitk::CropImageRemoveGreaterThan<MaskImageType>(S3A, 2, 
538                                                      //m_ApexOfTheChest
539                                                      p[2], true,
540                                                      GetBackgroundValue());
541   // Ant limits with Trachea
542   S3A = LimitsWithTrachea(S3A, 1, 0, -10);
543   m_ListOfSupports["S3A"] = S3A;  
544 }
545 //--------------------------------------------------------------------
546
547
548 //--------------------------------------------------------------------
549 template <class ImageType>
550 void
551 clitk::ExtractLymphStationsFilter<ImageType>::
552 Support_S5()
553 {
554   StartNewStep("[Support] Sup-Inf limits S5 with aorta");
555
556   // Initial S5 support
557   MaskImagePointer S5 = 
558     clitk::Clone<MaskImageType>(this->GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true));
559
560   // Sup limits with Aorta
561   double sup = FindInferiorBorderOfAorticArch();
562   
563   // Inf limits with "upper rim of the left main pulmonary artery"
564   // For the moment only, it will change.
565   MaskImagePointer PulmonaryTrunk = this->GetAFDB()->template GetImage<MaskImageType>("PulmonaryTrunk");
566   MaskImagePointType p;
567   p[0] = p[1] = p[2] =  0.0; // to avoid warning
568   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(PulmonaryTrunk, GetBackgroundValue(), 2, false, p);
569   p[2] += PulmonaryTrunk->GetSpacing()[2];
570   DD(p);
571   
572   // Cut Sup/Inf
573   S5 = clitk::CropImageAlongOneAxis<MaskImageType>(S5, 2, p[2], sup, true, GetBackgroundValue());
574
575   m_ListOfSupports["S5"] = S5; 
576 }
577 //--------------------------------------------------------------------
578
579 //--------------------------------------------------------------------
580 template <class ImageType>
581 void
582 clitk::ExtractLymphStationsFilter<ImageType>::
583 Support_S6()
584 {
585   StartNewStep("[Support] Sup-Inf limits S6 with aorta");
586
587   // Initial S6 support like S3A
588   MaskImagePointer S6 = clitk::Clone<MaskImageType>(m_ListOfSupports["S3A"]);
589
590   // Inf Sup limits with Aorta
591   double sup = FindSuperiorBorderOfAorticArch();
592   double inf = FindInferiorBorderOfAorticArch();
593   
594   // Cut Sup/Inf
595   S6 = clitk::CropImageAlongOneAxis<MaskImageType>(S6, 2, inf, sup, true, GetBackgroundValue());
596
597   m_ListOfSupports["S6"] = S6;  
598 }
599 //--------------------------------------------------------------------
600