1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #ifndef CLITKEXTRACTLYMPHSTATIONSFILTER_TXX
20 #define CLITKEXTRACTLYMPHSTATIONSFILTER_TXX
23 #include "clitkCommon.h"
24 #include "clitkExtractLymphStationsFilter.h"
25 #include "clitkAddRelativePositionConstraintToLabelImageFilter.h"
26 #include "clitkSegmentationUtils.h"
27 #include "clitkAutoCropFilter.h"
28 #include "clitkSegmentationUtils.h"
29 #include "clitkSliceBySliceRelativePositionFilter.h"
32 #include <itkStatisticsLabelMapFilter.h>
33 #include <itkLabelImageToStatisticsLabelMapFilter.h>
34 #include <itkRegionOfInterestImageFilter.h>
35 #include <itkBinaryThresholdImageFilter.h>
36 #include <itkImageSliceConstIteratorWithIndex.h>
37 #include <itkImageSliceIteratorWithIndex.h>
38 #include <itkBinaryThinningImageFilter.h>
41 #include "RelativePositionPropImageFilter.h"
43 //--------------------------------------------------------------------
44 template <class TImageType>
45 clitk::ExtractLymphStationsFilter<TImageType>::
46 ExtractLymphStationsFilter():
48 clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
49 itk::ImageToImageFilter<TImageType, MaskImageType>()
51 this->SetNumberOfRequiredInputs(1);
52 SetBackgroundValue(0);
53 SetForegroundValue(1);
56 ExtractStation_8_SetDefaultValues();
57 ExtractStation_3P_SetDefaultValues();
60 SetFuzzyThreshold(0.5);
61 SetStation7Filename("station7.mhd");
63 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 template <class TImageType>
69 clitk::ExtractLymphStationsFilter<TImageType>::
70 GenerateOutputInformation() {
73 m_Input = dynamic_cast<const ImageType*>(itk::ProcessObject::GetInput(0));
74 m_Mediastinum = GetAFDB()->template GetImage <MaskImageType>("Mediastinum");
77 StartNewStep("Station 8");
82 DD(GetCurrentStepNumber());
85 StartNewStep("Station 3P");
90 if (0) { // temporary suppress
92 StartNewStep("Station 7");
98 StartNewStep("Station 4RL");
100 //ExtractStation_4RL();
106 // typedef clitk::BooleanOperatorLabelImageFilter<MaskImageType> BFilter;
107 //BFilter::Pointer merge = BFilter::New();
108 // writeImage<MaskImageType>(m_Output, "ouput.mhd");
109 //writeImage<MaskImageType>(m_Working_Support, "ws.mhd");
110 /*merge->SetInput1(m_Station7);
111 merge->SetInput2(m_Station4RL); // support
112 merge->SetOperationType(BFilter::AndNot); CHANGE OPERATOR
113 merge->SetForegroundValue(4);
115 m_Output = merge->GetOutput();
118 //--------------------------------------------------------------------
121 //--------------------------------------------------------------------
122 template <class TImageType>
124 clitk::ExtractLymphStationsFilter<TImageType>::
125 GenerateInputRequestedRegion() {
126 DD("GenerateInputRequestedRegion (nothing?)");
128 //--------------------------------------------------------------------
131 //--------------------------------------------------------------------
132 template <class TImageType>
134 clitk::ExtractLymphStationsFilter<TImageType>::
136 DD("GenerateData, graft output");
138 // Final Step -> graft output (if SetNthOutput => redo)
139 this->GraftOutput(m_ListOfStations["8"]);
141 //--------------------------------------------------------------------
144 //--------------------------------------------------------------------
145 template <class TImageType>
147 clitk::ExtractLymphStationsFilter<TImageType>::
148 CheckForStation(std::string station)
150 // Compute Station name
151 std::string s = "Station"+station;
154 // Check if station already exist in DB
156 if (GetAFDB()->TagExist(s)) {
157 m_ListOfStations[station] = GetAFDB()->template GetImage<MaskImageType>(s);
161 // Define the starting support
162 if (found && GetComputeStation("8")) {
163 std::cout << "Station " << station << " already exists, but re-computation forced." << std::endl;
165 if (!found || GetComputeStation("8")) {
166 m_Working_Support = m_Mediastinum = GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true);
170 std::cout << "Station " << station << " found. I used it" << std::endl;
174 //--------------------------------------------------------------------
177 //--------------------------------------------------------------------
178 template <class TImageType>
180 clitk::ExtractLymphStationsFilter<TImageType>::
181 GetComputeStation(std::string station)
183 return (m_ComputeStationMap.find(station) != m_ComputeStationMap.end());
185 //--------------------------------------------------------------------
188 //--------------------------------------------------------------------
189 template <class TImageType>
191 clitk::ExtractLymphStationsFilter<TImageType>::
192 AddComputeStation(std::string station)
194 m_ComputeStationMap[station] = true;
196 //--------------------------------------------------------------------
199 //--------------------------------------------------------------------
200 template <class TImageType>
202 clitk::ExtractLymphStationsFilter<TImageType>::
205 if (CheckForStation("8")) {
206 ExtractStation_8_SI_Limits();
207 ExtractStation_8_Post_Limits();
208 ExtractStation_8_Ant_Limits();
209 ExtractStation_8_LR_Limits();
210 // Store image filenames into AFDB
211 writeImage<MaskImageType>(m_ListOfStations["8"], "seg/Station8.mhd");
212 GetAFDB()->SetImageFilename("Station8", "seg/Station8.mhd");
216 //--------------------------------------------------------------------
219 //--------------------------------------------------------------------
220 template <class TImageType>
222 clitk::ExtractLymphStationsFilter<TImageType>::
225 if (CheckForStation("3P")) {
226 ExtractStation_3P_SI_Limits();
227 // Store image filenames into AFDB
228 writeImage<MaskImageType>(m_ListOfStations["3P"], "seg/Station3P.mhd");
229 GetAFDB()->SetImageFilename("Station3P", "seg/Station3P.mhd");
232 //--------------------------------------------------------------------
235 //--------------------------------------------------------------------
236 template <class TImageType>
238 clitk::ExtractLymphStationsFilter<TImageType>::
240 if (m_ListOfStations["7"]) {
241 DD("Station 7 support already exist -> use it");
242 m_Working_Support = m_ListOfStations["7"];
244 else m_Working_Support = m_Mediastinum;
245 ExtractStation_7_SI_Limits();
246 ExtractStation_7_RL_Limits();
247 ExtractStation_7_Posterior_Limits();
249 //--------------------------------------------------------------------
252 //--------------------------------------------------------------------
253 template <class TImageType>
255 clitk::ExtractLymphStationsFilter<TImageType>::
256 ExtractStation_4RL() {
258 WARNING ONLY 4R FIRST !!! (not same inf limits)
260 ExtractStation_4RL_SI_Limits();
261 ExtractStation_4RL_LR_Limits();
262 ExtractStation_4RL_AP_Limits();
264 //--------------------------------------------------------------------
267 //--------------------------------------------------------------------
270 //--------------------------------------------------------------------
271 template <class TImageType>
273 clitk::ExtractLymphStationsFilter<TImageType>::
274 FindExtremaPointsInBronchus(MaskImagePointer input,
276 double distance_max_from_center_point,
277 ListOfPointsType & LR,
278 ListOfPointsType & Ant,
279 ListOfPointsType & Post)
282 // Other solution ==> with auto bounding box ! (but pb to prevent to
283 // be too distant from the center point
286 std::vector<typename MaskSliceType::Pointer> slices;
287 clitk::ExtractSlices<MaskImageType>(input, 2, slices);
291 for(uint i=0; i<slices.size(); i++) {
294 slices[i] = Labelize<MaskSliceType>(slices[i], 0, true, 10);
295 slices[i] = KeepLabels<MaskSliceType>(slices[i],
296 GetBackgroundValue(),
297 GetForegroundValue(), 1, 1, true);
300 // ------- Find rightmost or leftmost point -------
301 MaskSliceType::PointType LRMost;
303 clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i],
304 GetBackgroundValue(),
306 (direction==0?false:true), // right or left according to direction
308 // ------- Find postmost point -------
309 MaskSliceType::PointType postMost;
311 clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i],
312 GetBackgroundValue(),
314 distance_max_from_center_point,
316 // ------- Find antmost point -------
317 MaskSliceType::PointType antMost;
319 clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i],
320 GetBackgroundValue(),
322 distance_max_from_center_point,
324 // Only add point if found
326 // ------- Convert 2D to 3D points --------
327 MaskImageType::PointType p;
328 clitk::PointsUtils<MaskImageType>::Convert2DTo3D(LRMost, input, i, p);
330 clitk::PointsUtils<MaskImageType>::Convert2DTo3D(antMost, input, i, p);
332 clitk::PointsUtils<MaskImageType>::Convert2DTo3D(postMost, input, i, p);
337 //--------------------------------------------------------------------
339 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX