]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_4RL.txx
fixed over_one counter
[clitk.git] / segmentation / clitkExtractLymphStation_4RL.txx
1
2
3 //--------------------------------------------------------------------
4 template <class ImageType>
5 void 
6 clitk::ExtractLymphStationsFilter<ImageType>::
7 ExtractStation_4RL_SetDefaultValues()
8 {
9 }
10 //--------------------------------------------------------------------
11
12
13 //--------------------------------------------------------------------
14 template <class TImageType>
15 void 
16 clitk::ExtractLymphStationsFilter<TImageType>::
17 ExtractStation_4RL() {
18   if ((!CheckForStation("4R")) && (!CheckForStation("4L"))) return;
19
20   StartNewStep("Stations 4RL");
21   StartSubStep(); 
22
23   // Get the current support 
24   StartNewStep("[Station 4RL] Get the current 4RL suppport");
25   m_ListOfStations["4R"] = m_ListOfSupports["S4R"];
26   m_ListOfStations["4L"] = m_ListOfSupports["S4L"];
27   StopCurrentStep<MaskImageType>(m_ListOfStations["4R"]);
28     
29   // Generic RelativePosition processes
30   m_ListOfStations["4R"] = this->ApplyRelativePositionList("Station_4R", m_ListOfStations["4R"]);
31   m_ListOfStations["4L"] = this->ApplyRelativePositionList("Station_4L", m_ListOfStations["4L"]);
32
33   // Separation Ant/Post
34   m_Working_Support = m_ListOfStations["4L"];
35   ExtractStation_S4L_S5_Limits_Aorta_LeftPulmonaryArtery(10);
36   m_ListOfStations["4L"] = m_Working_Support;
37   
38   // Keep only one single CCL by slice
39   StartNewStep("[Station 4L] Keep only one CCL by slice");  
40   m_ListOfStations["4L"] = SliceBySliceKeepMainCCL<MaskImageType>(m_ListOfStations["4L"], 
41                                                                   GetBackgroundValue(), 
42                                                                   GetForegroundValue());
43   StopCurrentStep<MaskImageType>(m_ListOfStations["4L"]);
44
45   // Store image filenames into AFDB 
46   writeImage<MaskImageType>(m_ListOfStations["4R"], "seg/Station4R.mhd");
47   writeImage<MaskImageType>(m_ListOfStations["4L"], "seg/Station4L.mhd");
48   GetAFDB()->SetImageFilename("Station4R", "seg/Station4R.mhd"); 
49   GetAFDB()->SetImageFilename("Station4L", "seg/Station4L.mhd"); 
50   WriteAFDB(); 
51   StopSubStep();
52
53 }
54 //--------------------------------------------------------------------
55
56
57 //--------------------------------------------------------------------
58 template <class TImageType>
59 void 
60 clitk::ExtractLymphStationsFilter<TImageType>::
61 ExtractStation_S4L_S5_Limits_Aorta_LeftPulmonaryArtery(int KeepPoint) 
62 {
63   // ----------------------------------------------------------
64   StartNewStep("[Station 4L] Limits between Asc and Desc Aorta, and with LeftPulmonaryArtery ");
65
66   // Separate Aorta into DescendingAorta AscendingAorta
67   MaskImagePointer AscendingAorta = GetAFDB()->template GetImage<MaskImageType>("AscendingAorta");
68   MaskImagePointer DescendingAorta = GetAFDB()->template GetImage<MaskImageType>("DescendingAorta");  
69
70   // Crop like support (inferiorly)
71   m_Working_Support = clitk::AutoCrop<MaskImageType>(m_Working_Support, GetBackgroundValue());
72   AscendingAorta = 
73     clitk::ResizeImageLike<MaskImageType>(AscendingAorta, m_Working_Support, GetBackgroundValue());
74   DescendingAorta = 
75     clitk::ResizeImageLike<MaskImageType>(DescendingAorta, m_Working_Support, GetBackgroundValue());
76
77   // Crop superior part (when AscendingAorta and DescendingAorta join)
78   MaskImagePointType p;
79   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(AscendingAorta, 
80                                                           GetBackgroundValue(), 2, false, p);
81   double max = p[2]+AscendingAorta->GetSpacing()[2];
82   AscendingAorta = 
83     clitk::CropImageRemoveGreaterThan<MaskImageType>(AscendingAorta, 2, max, false, GetBackgroundValue());
84   DescendingAorta = 
85     clitk::CropImageRemoveGreaterThan<MaskImageType>(DescendingAorta, 2, max, false, GetBackgroundValue());
86
87   // Crop inferior part, where LeftPulmonaryArtery start
88   MaskImagePointer AscendingAortaCopy = clitk::Clone<MaskImageType>(AscendingAorta);
89   MaskImagePointer LeftPulmonaryArtery = GetAFDB()->template GetImage<MaskImageType>("LeftPulmonaryArtery");
90   clitk::FindExtremaPointInAGivenDirection<MaskImageType>(LeftPulmonaryArtery, 
91                                                           GetBackgroundValue(), 2, false, p);
92   max = p[2]+LeftPulmonaryArtery->GetSpacing()[2];
93   AscendingAorta = 
94     clitk::CropImageRemoveLowerThan<MaskImageType>(AscendingAorta, 2, max, false, GetBackgroundValue());
95   DescendingAorta = 
96     clitk::CropImageRemoveLowerThan<MaskImageType>(DescendingAorta, 2, max, false, GetBackgroundValue());
97
98   // Find closest points
99   std::vector<MaskImagePointType> A;
100   std::vector<MaskImagePointType> B;
101   clitk::SliceBySliceBuildLineSegmentAccordingToMinimalDistanceBetweenStructures<MaskImageType>(AscendingAorta, 
102                                                                                                 DescendingAorta, 
103                                                                                                 GetBackgroundValue(), 
104                                                                                                 2, A, B);
105   // Separate according to AB lines
106   // clitk::WriteListOfLandmarks<MaskImageType>(A, "A.txt");
107   // clitk::WriteListOfLandmarks<MaskImageType>(B, "B.txt");
108   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_Working_Support, A, B,
109                                                                     GetBackgroundValue(), 
110                                                                     1, KeepPoint); // Keep point along axis 1
111
112   // Now, same principle between AscendingAorta and LeftPulmonaryArtery
113   AscendingAorta = 
114     clitk::ResizeImageLike<MaskImageType>(AscendingAortaCopy, m_Working_Support, GetBackgroundValue());
115   LeftPulmonaryArtery = 
116     clitk::ResizeImageLike<MaskImageType>(LeftPulmonaryArtery, m_Working_Support, GetBackgroundValue());
117   AscendingAorta = 
118     clitk::CropImageRemoveGreaterThan<MaskImageType>(AscendingAorta, 2, max, false, GetBackgroundValue());
119   LeftPulmonaryArtery = 
120     clitk::CropImageRemoveGreaterThan<MaskImageType>(LeftPulmonaryArtery, 2, max, false, GetBackgroundValue());
121   A.clear();
122   B.clear();
123   clitk::SliceBySliceBuildLineSegmentAccordingToMinimalDistanceBetweenStructures<MaskImageType>(AscendingAorta, 
124                                                                                                 LeftPulmonaryArtery, 
125                                                                                                 GetBackgroundValue(), 
126                                                                                                 2, A, B);
127   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_Working_Support, A, B,
128                                                                     GetBackgroundValue(), 
129                                                                     1, KeepPoint); // Keep point along axis 1
130
131   // AutoCrop
132   m_Working_Support = clitk::AutoCrop<MaskImageType>(m_Working_Support, GetBackgroundValue());
133
134   // End
135   StopCurrentStep<MaskImageType>(m_Working_Support);
136 }
137 //--------------------------------------------------------------------
138
139