]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_2RL.txx
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[clitk.git] / segmentation / clitkExtractLymphStation_2RL.txx
1
2
3 // vtk
4 #include <vtkAppendPolyData.h>
5 #include <vtkPolyDataWriter.h>
6 #include <vtkCellArray.h>
7
8 // clitk
9 #include "clitkMeshToBinaryImageFilter.h"
10
11 // itk
12 #include <itkImageDuplicator.h>
13
14 //--------------------------------------------------------------------
15 template <class ImageType>
16 void 
17 clitk::ExtractLymphStationsFilter<ImageType>::
18 ExtractStation_2RL_SetDefaultValues()
19 {
20 }
21 //--------------------------------------------------------------------
22
23
24 //--------------------------------------------------------------------
25 template <class TImageType>
26 void 
27 clitk::ExtractLymphStationsFilter<TImageType>::
28 ExtractStation_2RL()
29 {
30   if ((!CheckForStation("2R")) && (!CheckForStation("2L"))) return;
31
32   StartNewStep("Stations 2RL");
33   StartSubStep(); 
34
35   // Get the current support 
36   StartNewStep("[Station 2RL] Get the current 2RL suppport");
37   m_ListOfStations["2R"] = m_ListOfSupports["S2R"];
38   m_ListOfStations["2L"] = m_ListOfSupports["S2L"];
39   StopCurrentStep<MaskImageType>(m_ListOfStations["2R"]);
40     
41   // Do the same limits for R & L
42   m_Working_Support = m_ListOfStations["2R"];
43   ExtractStation_2RL_Ant_Limits("2R"); 
44   ExtractStation_2RL_Remove_Structures(" 2R");
45   m_ListOfStations["2R"] = m_Working_Support;
46
47   m_Working_Support = m_ListOfStations["2L"];
48   ExtractStation_2RL_Ant_Limits("2L");
49   ExtractStation_2RL_Remove_Structures(" 2L");
50   m_ListOfStations["2L"] = m_Working_Support;
51
52   // Remove superior part to BrachioCephalicVein (used then by RelPos)
53   ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split();
54
55   // Generic RelativePosition processes
56   m_ListOfStations["2R"] = this->ApplyRelativePositionList("Station_2R", m_ListOfStations["2R"]);
57   m_ListOfStations["2L"] = this->ApplyRelativePositionList("Station_2L", m_ListOfStations["2L"]);
58   
59   // Store image filenames into AFDB 
60   writeImage<MaskImageType>(m_ListOfStations["2R"], "seg/Station2R.mhd");
61   writeImage<MaskImageType>(m_ListOfStations["2L"], "seg/Station2L.mhd");
62   GetAFDB()->SetImageFilename("Station2R", "seg/Station2R.mhd"); 
63   GetAFDB()->SetImageFilename("Station2L", "seg/Station2L.mhd"); 
64   WriteAFDB(); 
65   StopSubStep();
66 }
67 //--------------------------------------------------------------------
68
69
70 //--------------------------------------------------------------------
71 template <class ImageType>
72 void 
73 clitk::ExtractLymphStationsFilter<ImageType>::
74 ExtractStation_2RL_Ant_Limits(std::string s)
75 {
76   // -----------------------------------------------------
77   StartNewStep("[Station "+s+"] Ant limits with vessels centroids");
78   
79   // WARNING, as I used "And" after, empty slice in binarizedContour
80   // lead to remove part of the support, although we want to keep
81   // unchanged. So we decide to ResizeImageLike but pad with
82   // ForegroundValue instead of BG
83
84   // Get or compute the binary mask that separate Ant/Post part
85   // according to vessels
86   MaskImagePointer binarizedContour = FindAntPostVessels2();
87   binarizedContour = clitk::ResizeImageLike<MaskImageType>(binarizedContour, 
88                                                            m_Working_Support, 
89                                                            GetForegroundValue());
90   // remove from support
91   typedef clitk::BooleanOperatorLabelImageFilter<MaskImageType> BoolFilterType;
92   typename BoolFilterType::Pointer boolFilter = BoolFilterType::New(); 
93   boolFilter->InPlaceOn();
94   boolFilter->SetInput1(m_Working_Support);
95   boolFilter->SetInput2(binarizedContour);
96   boolFilter->SetBackgroundValue1(GetBackgroundValue());
97   boolFilter->SetBackgroundValue2(GetBackgroundValue());
98   boolFilter->SetOperationType(BoolFilterType::And);
99   boolFilter->Update();
100   m_Working_Support = boolFilter->GetOutput();
101   
102   // End
103   StopCurrentStep<MaskImageType>(m_Working_Support);
104 }
105 //--------------------------------------------------------------------
106
107
108 //--------------------------------------------------------------------
109 template <class ImageType>
110 void 
111 clitk::ExtractLymphStationsFilter<ImageType>::
112 ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split() 
113 {
114   // -----------------------------------------------------
115   StartNewStep("[Station 2RL] Cut BrachioCephalicVein superiorly (when it split)");
116   
117   // Get BrachioCephalicVein
118   MaskImagePointer BrachioCephalicVein = GetAFDB()->template GetImage<MaskImageType>("BrachioCephalicVein");
119   
120   // Remove the part superior to the slice where BrachioCephalicVein
121   // divide in two CCL
122   std::vector<MaskSlicePointer> BCV_slices;
123   clitk::ExtractSlices<MaskImageType>(BrachioCephalicVein, 2, BCV_slices);
124   bool stop = false;
125   uint i=0;
126   while (!stop) {
127     // Count the number of CCL
128     int nb;
129     clitk::LabelizeAndCountNumberOfObjects<MaskSliceType>(BCV_slices[i], GetBackgroundValue(), true, 1, nb);
130     if (nb>1) stop = true;
131     i++; 
132   }
133   // Convert slice into coordinate
134   MaskImagePointType p;
135   MaskImageIndexType index;
136   index[0] = index[1] = 0;
137   index[2] = i;
138   BrachioCephalicVein->TransformIndexToPhysicalPoint(index, p);
139   BrachioCephalicVein = 
140     clitk::CropImageRemoveGreaterThan<MaskImageType>(BrachioCephalicVein, 2, 
141                                                      p[2], true,
142                                                      GetBackgroundValue());
143
144   // Now, insert this image in the AFDB (but do not store on disk)
145   GetAFDB()->template SetImage<MaskImageType>("BrachioCephalicVein_ForS2RL", "bidon", 
146                                               BrachioCephalicVein, false);
147   // End
148   StopCurrentStep<MaskImageType>(BrachioCephalicVein);
149 }
150 //--------------------------------------------------------------------
151
152
153 //--------------------------------------------------------------------
154 // Build a vtk mesh from a list of slice number/closed-contours
155 template <class ImageType>
156 vtkSmartPointer<vtkPolyData> 
157 clitk::ExtractLymphStationsFilter<ImageType>::
158 Build3DMeshFrom2DContour(const std::vector<ImagePointType> & points)
159 {
160   // create a contour, polydata. 
161   vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New();
162   mesh->Allocate(); //for cell structures
163   mesh->SetPoints(vtkPoints::New());
164   vtkIdType ids[2];
165   int point_number = points.size();
166   for (unsigned int i=0; i<points.size(); i++) {
167     mesh->GetPoints()->InsertNextPoint(points[i][0],points[i][1],points[i][2]);
168     ids[0]=i;
169     ids[1]=(ids[0]+1)%point_number; //0-1,1-2,...,n-1-0
170     mesh->GetLines()->InsertNextCell(2,ids);
171   }
172   // Return
173   return mesh;
174 }
175 //--------------------------------------------------------------------
176
177
178 //--------------------------------------------------------------------
179 template <class ImageType>
180 void
181 clitk::ExtractLymphStationsFilter<ImageType>::
182 ExtractStation_2RL_Remove_Structures(std::string s)
183 {
184   // m_Working_Support must be set
185   Remove_Structures(s, "BrachioCephalicVein");
186   Remove_Structures(s, "BrachioCephalicArtery");
187   Remove_Structures(s, "LeftCommonCarotidArtery");
188   Remove_Structures(s, "RightCommonCarotidArtery");
189   Remove_Structures(s, "LeftSubclavianArtery");
190   Remove_Structures(s, "RightSubclavianArtery");
191   Remove_Structures(s, "Thyroid");
192   Remove_Structures(s, "Aorta");
193 }
194 //--------------------------------------------------------------------
195
196