]> 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 = 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   GetAFDB()->SetImageFilename("Support_Inf_Carina", "seg/Support_Inf_Carina.mhd");
28   writeImage<MaskImageType>(m_Support_Superior_to_Carina, "seg/Support_Sup_Carina.mhd");
29   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   GetAFDB()->SetImageFilename("Support_S1R", "seg/Support_S1R.mhd");
64   writeImage<MaskImageType>(m_ListOfSupports["S1L"], "seg/Support_S1L.mhd");
65   GetAFDB()->SetImageFilename("Support_S1L", "seg/Support_S1L.mhd");
66
67   writeImage<MaskImageType>(m_ListOfSupports["S2L"], "seg/Support_S2L.mhd");
68   GetAFDB()->SetImageFilename("Support_S2L", "seg/Support_S2L.mhd");
69   writeImage<MaskImageType>(m_ListOfSupports["S2R"], "seg/Support_S2R.mhd");
70   GetAFDB()->SetImageFilename("Support_S2R", "seg/Support_S2R.mhd");
71
72   writeImage<MaskImageType>(m_ListOfSupports["S3P"], "seg/Support_S3P.mhd");
73   GetAFDB()->SetImageFilename("Support_S3P", "seg/Support_S3P.mhd");
74   writeImage<MaskImageType>(m_ListOfSupports["S3A"], "seg/Support_S3A.mhd");
75   GetAFDB()->SetImageFilename("Support_S3A", "seg/Support_S3A.mhd");
76
77   writeImage<MaskImageType>(m_ListOfSupports["S4L"], "seg/Support_S4L.mhd");
78   GetAFDB()->SetImageFilename("Support_S4L", "seg/Support_S4L.mhd");
79   writeImage<MaskImageType>(m_ListOfSupports["S4R"], "seg/Support_S4R.mhd");
80   GetAFDB()->SetImageFilename("Support_S4R", "seg/Support_S4R.mhd");
81
82   writeImage<MaskImageType>(m_ListOfSupports["S5"], "seg/Support_S5.mhd");
83   GetAFDB()->SetImageFilename("Support_S5", "seg/Support_S5.mhd");
84   writeImage<MaskImageType>(m_ListOfSupports["S6"], "seg/Support_S6.mhd");
85   GetAFDB()->SetImageFilename("Support_S6", "seg/Support_S6.mhd");
86
87   writeImage<MaskImageType>(m_ListOfSupports["S7"], "seg/Support_S7.mhd");
88   GetAFDB()->SetImageFilename("Support_S7", "seg/Support_S7.mhd");
89
90   writeImage<MaskImageType>(m_ListOfSupports["S8"], "seg/Support_S8.mhd");
91   GetAFDB()->SetImageFilename("Support_S8", "seg/Support_S8.mhd");
92
93   writeImage<MaskImageType>(m_ListOfSupports["S9"], "seg/Support_S9.mhd");
94   GetAFDB()->SetImageFilename("Support_S9", "seg/Support_S9.mhd");
95
96   writeImage<MaskImageType>(m_ListOfSupports["S10"], "seg/Support_S10.mhd");
97   GetAFDB()->SetImageFilename("Support_S10", "seg/Support_S10.mhd");  
98
99   writeImage<MaskImageType>(m_ListOfSupports["S11"], "seg/Support_S11.mhd");
100   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 = 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 = 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 = 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   GetAFDB()->SetDouble("CaudalMarginOfLeftBrachiocephalicVeinZ", CaudalMarginOfLeftBrachiocephalicVeinZ);
210   MaskImagePointer S2R = 
211     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
212                                                    CaudalMarginOfLeftBrachiocephalicVeinZ, true,
213                                                    GetBackgroundValue());
214   m_ListOfSupports["S2R"] = S2R;
215
216   // S2L : Top Of Aortic Arch
217   MaskImagePointer Aorta = GetAFDB()->template GetImage<MaskImageType>("Aorta");
218   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Aorta, GetBackgroundValue(), 2, false, p);
219   // I add slightly more than a slice
220   double TopOfAorticArchZ=p[2]+ 1.1*m_Working_Support->GetSpacing()[2];
221   GetAFDB()->SetDouble("TopOfAorticArchZ", TopOfAorticArchZ);
222
223   MaskImagePointer S2L = 
224     clitk::CropImageRemoveLowerThan<MaskImageType>(m_Working_Support, 2, 
225                                                    TopOfAorticArchZ, true,
226                                                    GetBackgroundValue());
227   m_ListOfSupports["S2L"] = S2L;
228 }
229 //--------------------------------------------------------------------
230
231
232
233
234 //--------------------------------------------------------------------
235 template <class ImageType>
236 void 
237 clitk::ExtractLymphStationsFilter<ImageType>::
238 Support_LeftRight_S2R_S2L()
239 {
240   // ---------------------------------------------------------------------------
241   /* Step : S2RL LeftRight
242      As for lymph node station 4R, 2R includes nodes extending to the
243      left lateral border of the trachea
244      Rod says:  "For station 2 there is a shift, dividing 2R from 2L, from midline
245      to the left paratracheal border."
246   */
247   StartNewStep("[Support] Separate 2R/2L according to Trachea");
248   MaskImagePointer S2R = m_ListOfSupports["S2R"];
249   MaskImagePointer S2L = m_ListOfSupports["S2L"];
250   S2R = LimitsWithTrachea(S2R, 0, 1, -10);
251   S2L = LimitsWithTrachea(S2L, 0, 1, 10);
252   m_ListOfSupports["S2R"] = S2R;
253   m_ListOfSupports["S2L"] = S2L;  
254   GetAFDB()->template ReleaseImage<MaskImageType>("Trachea");
255 }
256 //--------------------------------------------------------------------
257
258
259 //--------------------------------------------------------------------
260 template <class ImageType>
261 void 
262 clitk::ExtractLymphStationsFilter<ImageType>::
263 Support_SupInf_S4R_S4L()
264 {
265   // ---------------------------------------------------------------------------
266   /* Step : S4RL Sup-Inf
267      - start at the end of 2R and 2L
268      - stop ?
269      - 4R
270      Rod says : "The inferior border is at the lower border of the azygous vein."
271      Rod says : difficulties
272      (was : "ends at the upper lobe bronchus or where the right pulmonary artery
273      crosses the midline of the mediastinum ")
274      - 4L
275      Rod says : "The lower border is to upper margin of the left main pulmonary artery."
276      (was LLL bronchus)
277   */
278   StartNewStep("[Support] Sup-Inf limits of 4R/4L");
279
280   // Start from the support, remove 2R and 2L
281   MaskImagePointer S4RL = clitk::Clone<MaskImageType>(m_Working_Support);
282   MaskImagePointer S2R = m_ListOfSupports["S2R"];
283   MaskImagePointer S2L = m_ListOfSupports["S2L"];
284   clitk::AndNot<MaskImageType>(S4RL, S2R, GetBackgroundValue());
285   clitk::AndNot<MaskImageType>(S4RL, S2L, GetBackgroundValue());
286   S4RL = clitk::AutoCrop<MaskImageType>(S4RL, GetBackgroundValue());
287
288   // Copy, stop 4R at AzygousVein and 4L at LeftPulmonaryArtery
289   MaskImagePointer S4R = clitk::Clone<MaskImageType>(S4RL);
290   MaskImagePointer S4L = clitk::Clone<MaskImageType>(S4RL);
291   
292   // Get AzygousVein and limit according to LowerBorderAzygousVein
293   MaskImagePointer LowerBorderAzygousVein 
294     = GetAFDB()->template GetImage<MaskImageType>("LowerBorderAzygousVein");
295   std::vector<MaskImagePointType> c;
296   clitk::ComputeCentroids<MaskImageType>(LowerBorderAzygousVein, GetBackgroundValue(), c);
297   S4R = clitk::CropImageRemoveLowerThan<MaskImageType>(S4RL, 2, 
298                                                        c[1][2], true, GetBackgroundValue());
299   S4R = clitk::AutoCrop<MaskImageType>(S4R, GetBackgroundValue());
300   m_ListOfSupports["S4R"] = S4R;
301
302
303   // Limit according to LeftPulmonaryArtery
304   MaskImagePointer LeftPulmonaryArtery 
305     = GetAFDB()->template GetImage<MaskImageType>("LeftPulmonaryArtery");
306   MaskImagePointType p;
307   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(LeftPulmonaryArtery, GetBackgroundValue(), 
308                                                           2, false, p);
309   S4L = clitk::CropImageRemoveLowerThan<MaskImageType>(S4RL, 2, 
310                                                        p[2], true, GetBackgroundValue());
311   S4L = clitk::AutoCrop<MaskImageType>(S4L, GetBackgroundValue());
312   m_ListOfSupports["S4L"] = S4L;
313 }
314 //--------------------------------------------------------------------
315
316
317 //--------------------------------------------------------------------
318 template <class ImageType>
319 void 
320 clitk::ExtractLymphStationsFilter<ImageType>::
321 Support_LeftRight_S4R_S4L()
322 {
323   // ---------------------------------------------------------------------------
324   /* Step : S4RL LeftRight 
325      
326      - 4R: includes right paratracheal nodes, and pretracheal nodes
327      extending to the left lateral border of trachea
328      
329      - 4L: includes nodes to the left of the left lateral border of
330      the trachea, medial to the ligamentum arteriosum
331      
332      => same than 2RL
333   */
334   StartNewStep("[Support] Left Right separation of 4R/4L");
335
336   MaskImagePointer S4R = m_ListOfSupports["S4R"];
337   MaskImagePointer S4L = m_ListOfSupports["S4L"];
338   S4R = LimitsWithTrachea(S4R, 0, 1, -10);
339   S4L = LimitsWithTrachea(S4L, 0, 1, 10);
340   m_ListOfSupports["S4R"] = S4R;
341   m_ListOfSupports["S4L"] = S4L;
342 }
343 //--------------------------------------------------------------------
344
345
346 //--------------------------------------------------------------------
347 template <class ImageType>
348 typename clitk::ExtractLymphStationsFilter<ImageType>::MaskImagePointer
349 clitk::ExtractLymphStationsFilter<ImageType>::
350 LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection, 
351                   double offset) 
352 {
353   MaskImagePointType min, max;
354   GetMinMaxBoundary<MaskImageType>(input, min, max);
355   return LimitsWithTrachea(input, extremaDirection, lineDirection, offset, max[2]);
356 }
357 template <class ImageType>
358 typename clitk::ExtractLymphStationsFilter<ImageType>::MaskImagePointer
359 clitk::ExtractLymphStationsFilter<ImageType>::
360 LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection, 
361                   double offset, double maxSupPosition)
362 {
363   /*
364     Take the input mask, consider the trachea and limit according to
365     Left border of the trachea. Keep at Left or at Right according to
366     the offset
367   */
368   // Read the trachea
369   MaskImagePointer Trachea = GetAFDB()->template GetImage<MaskImageType>("Trachea");
370
371   // Find extrema post positions
372   std::vector<MaskImagePointType> tracheaLeftPositionsA;
373   std::vector<MaskImagePointType> tracheaLeftPositionsB;
374
375   // Crop Trachea only on the Sup-Inf axes, without autocrop
376   //  Trachea = clitk::ResizeImageLike<MaskImageType>(Trachea, input, GetBackgroundValue());
377   MaskImagePointType min, max;
378   GetMinMaxBoundary<MaskImageType>(input, min, max);
379   Trachea = clitk::CropImageAlongOneAxis<MaskImageType>(Trachea, 2, min[2], max[2], 
380                                                         false, GetBackgroundValue()); 
381   
382   // Select the main CCL (because of bronchus)
383   Trachea = SliceBySliceKeepMainCCL<MaskImageType>(Trachea, GetBackgroundValue(), GetForegroundValue());
384
385   // Slice by slice, build the separation line 
386   clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(Trachea, 
387                                                                                GetBackgroundValue(), 2, 
388                                                                                extremaDirection, false, // Left
389                                                                                lineDirection, // Vertical line 
390                                                                                1, // margins 
391                                                                                tracheaLeftPositionsA, 
392                                                                                tracheaLeftPositionsB);
393   // Do not consider trachea above the limit
394   int indexMax=tracheaLeftPositionsA.size();
395   for(uint i=0; i<tracheaLeftPositionsA.size(); i++) {
396     if (tracheaLeftPositionsA[i][2] > maxSupPosition) {
397       indexMax = i;
398       i = tracheaLeftPositionsA.size(); // stop loop
399     }
400   }  
401   tracheaLeftPositionsA.erase(tracheaLeftPositionsA.begin()+indexMax, tracheaLeftPositionsA.end());
402   tracheaLeftPositionsB.erase(tracheaLeftPositionsB.begin()+indexMax, tracheaLeftPositionsB.end());
403
404   // Cut post to this line 
405   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(input, 
406                                                                     tracheaLeftPositionsA,
407                                                                     tracheaLeftPositionsB,
408                                                                     GetBackgroundValue(), 
409                                                                     extremaDirection, offset); 
410   MaskImagePointer output = clitk::AutoCrop<MaskImageType>(input, GetBackgroundValue());
411   return output;
412 }
413 //--------------------------------------------------------------------
414
415
416 //--------------------------------------------------------------------
417 template <class ImageType>
418 void
419 clitk::ExtractLymphStationsFilter<ImageType>::
420 Support_Post_S1S2S4()
421 {
422   StartNewStep("[Support] Post limits of S1RL, S2RL, S4RL");
423   
424   double m_ApexOfTheChest = FindApexOfTheChest();
425   
426   // Post limits with Trachea 
427   MaskImagePointer S1R = m_ListOfSupports["S1R"];
428   MaskImagePointer S1L = m_ListOfSupports["S1L"];
429   MaskImagePointer S2R = m_ListOfSupports["S2R"];
430   MaskImagePointer S2L = m_ListOfSupports["S2L"];
431   MaskImagePointer S4R = m_ListOfSupports["S4R"];
432   MaskImagePointer S4L = m_ListOfSupports["S4L"];
433   S1L = LimitsWithTrachea(S1L, 1, 0, -10, m_ApexOfTheChest);
434   S1R = LimitsWithTrachea(S1R, 1, 0, -10, m_ApexOfTheChest);
435   S2R = LimitsWithTrachea(S2R, 1, 0, -10, m_ApexOfTheChest);
436   S2L = LimitsWithTrachea(S2L, 1, 0, -10, m_ApexOfTheChest);
437   S4R = LimitsWithTrachea(S4R, 1, 0, -10, m_ApexOfTheChest);
438   S4L = LimitsWithTrachea(S4L, 1, 0, -10, m_ApexOfTheChest);
439 }
440 //--------------------------------------------------------------------
441
442
443 //--------------------------------------------------------------------
444 template <class ImageType>
445 void
446 clitk::ExtractLymphStationsFilter<ImageType>::
447 Support_S3P()
448 {
449   StartNewStep("[Support] Ant limits of S3P and Post limits of S1RL, S2RL, S4RL");
450   
451   // Initial S3P support
452   MaskImagePointer S3P = clitk::Clone<MaskImageType>(m_ListOfSupports["Support_Superior_to_Carina"]);
453
454   // Stop at Lung Apex
455   double m_ApexOfTheChest = FindApexOfTheChest();
456   S3P = 
457     clitk::CropImageRemoveGreaterThan<MaskImageType>(S3P, 2, 
458                                                      m_ApexOfTheChest, true,
459                                                      GetBackgroundValue());
460   // Ant limits with Trachea
461   S3P = LimitsWithTrachea(S3P, 1, 0, 10);
462   m_ListOfSupports["S3P"] = S3P;
463 }
464 //--------------------------------------------------------------------
465
466
467 //--------------------------------------------------------------------
468 template <class ImageType>
469 void
470 clitk::ExtractLymphStationsFilter<ImageType>::
471 Support_S3A()
472 {
473   StartNewStep("[Support] Sup-Inf and Post limits for S3A");
474
475   // Initial S3A support
476   MaskImagePointer S3A = clitk::Clone<MaskImageType>(m_ListOfSupports["Support_Superior_to_Carina"]);
477
478   // Stop at Lung Apex or like S2/S1 (upper border Sternum - manubrium) ?
479
480   //double m_ApexOfTheChest = FindApexOfTheChest();
481
482   MaskImagePointer Sternum = GetAFDB()->template GetImage <MaskImageType>("Sternum");
483   MaskImagePointType p;
484   p[0] = p[1] = p[2] =  0.0; // to avoid warning
485   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(Sternum, GetBackgroundValue(), 2, false, p);
486
487   S3A = 
488     clitk::CropImageRemoveGreaterThan<MaskImageType>(S3A, 2, 
489                                                      //m_ApexOfTheChest
490                                                      p[2], true,
491                                                      GetBackgroundValue());
492   // Ant limits with Trachea
493   S3A = LimitsWithTrachea(S3A, 1, 0, -10);
494   m_ListOfSupports["S3A"] = S3A;  
495 }
496 //--------------------------------------------------------------------
497
498
499 //--------------------------------------------------------------------
500 template <class ImageType>
501 void
502 clitk::ExtractLymphStationsFilter<ImageType>::
503 Support_S5()
504 {
505   StartNewStep("[Support] Sup-Inf limits S5 with aorta");
506
507   // Initial S5 support
508   MaskImagePointer S5 = clitk::Clone<MaskImageType>(GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true));
509
510   // Sup limits with Aorta
511   double sup = FindInferiorBorderOfAorticArch();
512   
513   // Inf limits with "upper rim of the left main pulmonary artery"
514   // For the moment only, it will change.
515   MaskImagePointer PulmonaryTrunk = GetAFDB()->template GetImage<MaskImageType>("PulmonaryTrunk");
516   MaskImagePointType p;
517   p[0] = p[1] = p[2] =  0.0; // to avoid warning
518   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(PulmonaryTrunk, GetBackgroundValue(), 2, false, p);
519   
520   // Cut Sup/Inf
521   S5 = clitk::CropImageAlongOneAxis<MaskImageType>(S5, 2, p[2], sup, true, GetBackgroundValue());
522
523   m_ListOfSupports["S5"] = S5; 
524 }
525 //--------------------------------------------------------------------
526
527 //--------------------------------------------------------------------
528 template <class ImageType>
529 void
530 clitk::ExtractLymphStationsFilter<ImageType>::
531 Support_S6()
532 {
533   StartNewStep("[Support] Sup-Inf limits S6 with aorta");
534
535   // Initial S6 support like S3A
536   MaskImagePointer S6 = clitk::Clone<MaskImageType>(m_ListOfSupports["S3A"]);
537
538   // Inf Sup limits with Aorta
539   double sup = FindSuperiorBorderOfAorticArch();
540   double inf = FindInferiorBorderOfAorticArch();
541   
542   // Cut Sup/Inf
543   S6 = clitk::CropImageAlongOneAxis<MaskImageType>(S6, 2, inf, sup, true, GetBackgroundValue());
544
545   m_ListOfSupports["S6"] = S6;  
546 }
547 //--------------------------------------------------------------------
548