4 #include <vtkAppendPolyData.h>
5 #include <vtkPolyDataWriter.h>
6 #include <vtkCellArray.h>
9 #include "clitkMeshToBinaryImageFilter.h"
12 #include <itkImageDuplicator.h>
14 //--------------------------------------------------------------------
15 template <class ImageType>
17 clitk::ExtractLymphStationsFilter<ImageType>::
18 ExtractStation_2RL_SetDefaultValues()
21 //--------------------------------------------------------------------
24 //--------------------------------------------------------------------
25 template <class TImageType>
27 clitk::ExtractLymphStationsFilter<TImageType>::
30 if ((!CheckForStation("2R")) && (!CheckForStation("2L"))) return;
32 StartNewStep("Stations 2RL");
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"]);
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;
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;
52 // Remove superior part to BrachioCephalicVein (used then by RelPos)
53 ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split();
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"]);
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");
67 //--------------------------------------------------------------------
70 //--------------------------------------------------------------------
71 template <class ImageType>
73 clitk::ExtractLymphStationsFilter<ImageType>::
74 ExtractStation_2RL_Ant_Limits(std::string s)
76 // -----------------------------------------------------
77 StartNewStep("[Station "+s+"] Ant limits with vessels centroids");
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
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,
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);
100 m_Working_Support = boolFilter->GetOutput();
103 StopCurrentStep<MaskImageType>(m_Working_Support);
105 //--------------------------------------------------------------------
108 //--------------------------------------------------------------------
109 template <class ImageType>
111 clitk::ExtractLymphStationsFilter<ImageType>::
112 ExtractStation_2RL_Cut_BrachioCephalicVein_superiorly_when_it_split()
114 // -----------------------------------------------------
115 StartNewStep("[Station 2RL] Cut BrachioCephalicVein superiorly (when it split)");
117 // Get BrachioCephalicVein
118 MaskImagePointer BrachioCephalicVein = GetAFDB()->template GetImage<MaskImageType>("BrachioCephalicVein");
120 // Remove the part superior to the slice where BrachioCephalicVein
122 std::vector<MaskSlicePointer> BCV_slices;
123 clitk::ExtractSlices<MaskImageType>(BrachioCephalicVein, 2, BCV_slices);
127 // Count the number of CCL
129 clitk::LabelizeAndCountNumberOfObjects<MaskSliceType>(BCV_slices[i], GetBackgroundValue(), true, 1, nb);
130 if (nb>1) stop = true;
133 // Convert slice into coordinate
134 MaskImagePointType p;
135 MaskImageIndexType index;
136 index[0] = index[1] = 0;
138 BrachioCephalicVein->TransformIndexToPhysicalPoint(index, p);
139 BrachioCephalicVein =
140 clitk::CropImageRemoveGreaterThan<MaskImageType>(BrachioCephalicVein, 2,
142 GetBackgroundValue());
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);
148 StopCurrentStep<MaskImageType>(BrachioCephalicVein);
150 //--------------------------------------------------------------------
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)
160 // create a contour, polydata.
161 vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New();
162 mesh->Allocate(); //for cell structures
163 mesh->SetPoints(vtkPoints::New());
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]);
169 ids[1]=(ids[0]+1)%point_number; //0-1,1-2,...,n-1-0
170 mesh->GetLines()->InsertNextCell(2,ids);
175 //--------------------------------------------------------------------
178 //--------------------------------------------------------------------
179 template <class ImageType>
181 clitk::ExtractLymphStationsFilter<ImageType>::
182 ExtractStation_2RL_Remove_Structures(std::string s)
184 // m_Working_Support must be set
185 Remove_Structures(s, "BrachioCephalicVein");
186 Remove_Structures(s, "BrachioCephalicArtery");
187 Remove_Structures(s, "CommonCarotidArteryLeft");
188 Remove_Structures(s, "CommonCarotidArteryRight");
189 Remove_Structures(s, "SubclavianArteryLeft");
190 Remove_Structures(s, "SubclavianArteryRight");
191 Remove_Structures(s, "Thyroid");
192 Remove_Structures(s, "Aorta");
194 //--------------------------------------------------------------------