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();
58 ExtractStation_2RL_SetDefaultValues();
59 ExtractStation_3A_SetDefaultValues();
60 ExtractStation_7_SetDefaultValues();
62 //--------------------------------------------------------------------
65 //--------------------------------------------------------------------
66 template <class TImageType>
68 clitk::ExtractLymphStationsFilter<TImageType>::
69 GenerateOutputInformation() {
72 m_Input = dynamic_cast<const ImageType*>(itk::ProcessObject::GetInput(0));
73 m_Mediastinum = GetAFDB()->template GetImage <MaskImageType>("Mediastinum");
76 StartNewStep("Station 8");
82 StartNewStep("Station 3P");
88 StartNewStep("Station 2RL");
94 StartNewStep("Station 3A");
100 StartNewStep("Station 7");
105 if (0) { // temporary suppress
106 // Extract Station4RL
107 StartNewStep("Station 4RL");
109 //ExtractStation_4RL();
113 //--------------------------------------------------------------------
116 //--------------------------------------------------------------------
117 template <class TImageType>
119 clitk::ExtractLymphStationsFilter<TImageType>::
120 GenerateInputRequestedRegion() {
121 //DD("GenerateInputRequestedRegion (nothing?)");
123 //--------------------------------------------------------------------
126 //--------------------------------------------------------------------
127 template <class TImageType>
129 clitk::ExtractLymphStationsFilter<TImageType>::
131 // Final Step -> graft output (if SetNthOutput => redo)
132 this->GraftOutput(m_ListOfStations["8"]);
134 //--------------------------------------------------------------------
137 //--------------------------------------------------------------------
138 template <class TImageType>
140 clitk::ExtractLymphStationsFilter<TImageType>::
141 CheckForStation(std::string station)
143 // Compute Station name
144 std::string s = "Station"+station;
147 // Check if station already exist in DB
149 if (GetAFDB()->TagExist(s)) {
150 m_ListOfStations[station] = GetAFDB()->template GetImage<MaskImageType>(s);
154 // Define the starting support
155 if (found && GetComputeStation(station)) {
156 std::cout << "Station " << station << " already exists, but re-computation forced." << std::endl;
158 if (!found || GetComputeStation(station)) {
159 m_Working_Support = m_Mediastinum = GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true);
163 std::cout << "Station " << station << " found. I used it" << std::endl;
167 //--------------------------------------------------------------------
170 //--------------------------------------------------------------------
171 template <class TImageType>
173 clitk::ExtractLymphStationsFilter<TImageType>::
174 GetComputeStation(std::string station)
176 return (m_ComputeStationMap.find(station) != m_ComputeStationMap.end());
178 //--------------------------------------------------------------------
181 //--------------------------------------------------------------------
182 template <class TImageType>
184 clitk::ExtractLymphStationsFilter<TImageType>::
185 AddComputeStation(std::string station)
187 m_ComputeStationMap[station] = true;
189 //--------------------------------------------------------------------
192 //--------------------------------------------------------------------
193 template <class TImageType>
195 clitk::ExtractLymphStationsFilter<TImageType>::
198 if (CheckForStation("8")) {
199 ExtractStation_8_SI_Limits();
200 ExtractStation_8_Post_Limits();
201 ExtractStation_8_Ant_Sup_Limits();
202 ExtractStation_8_Ant_Inf_Limits();
203 ExtractStation_8_LR_1_Limits();
204 ExtractStation_8_LR_2_Limits();
205 ExtractStation_8_LR_Limits();
206 ExtractStation_8_Ant_Injected_Limits();
207 ExtractStation_8_Single_CCL_Limits();
208 ExtractStation_8_Remove_Structures();
209 // Store image filenames into AFDB
210 writeImage<MaskImageType>(m_ListOfStations["8"], "seg/Station8.mhd");
211 GetAFDB()->SetImageFilename("Station8", "seg/Station8.mhd");
215 //--------------------------------------------------------------------
218 //--------------------------------------------------------------------
219 template <class TImageType>
221 clitk::ExtractLymphStationsFilter<TImageType>::
224 if (CheckForStation("3P")) {
225 ExtractStation_3P_SI_Limits();
226 ExtractStation_3P_Ant_Limits();
227 ExtractStation_3P_Post_Limits();
228 ExtractStation_3P_LR_sup_Limits();
229 // ExtractStation_3P_LR_sup_Limits_2();
230 ExtractStation_3P_LR_inf_Limits();
231 ExtractStation_8_Single_CCL_Limits(); // YES 8 !
232 ExtractStation_3P_Remove_Structures(); // after CCL
233 // Store image filenames into AFDB
234 writeImage<MaskImageType>(m_ListOfStations["3P"], "seg/Station3P.mhd");
235 GetAFDB()->SetImageFilename("Station3P", "seg/Station3P.mhd");
239 //--------------------------------------------------------------------
242 //--------------------------------------------------------------------
243 template <class TImageType>
245 clitk::ExtractLymphStationsFilter<TImageType>::
247 if (CheckForStation("7")) {
248 ExtractStation_7_SI_Limits();
249 ExtractStation_7_RL_Limits();
250 ExtractStation_7_Posterior_Limits();
251 // ExtractStation_8_Single_CCL_Limits(); // Yes the same than 8
252 ExtractStation_7_Remove_Structures();
253 // Store image filenames into AFDB
254 writeImage<MaskImageType>(m_ListOfStations["7"], "seg/Station7.mhd");
255 GetAFDB()->SetImageFilename("Station7", "seg/Station7.mhd");
259 //--------------------------------------------------------------------
262 //--------------------------------------------------------------------
263 template <class TImageType>
265 clitk::ExtractLymphStationsFilter<TImageType>::
268 if (CheckForStation("3A")) {
269 ExtractStation_3A_SI_Limits();
270 ExtractStation_3A_Ant_Limits();
271 ExtractStation_3A_Post_Limits();
272 // Store image filenames into AFDB
273 writeImage<MaskImageType>(m_ListOfStations["3A"], "seg/Station3A.mhd");
274 GetAFDB()->SetImageFilename("Station3A", "seg/Station3A.mhd");
278 //--------------------------------------------------------------------
281 //--------------------------------------------------------------------
282 template <class TImageType>
284 clitk::ExtractLymphStationsFilter<TImageType>::
287 if (CheckForStation("2RL")) {
288 ExtractStation_2RL_SI_Limits();
289 ExtractStation_2RL_Post_Limits();
290 ExtractStation_2RL_Ant_Limits2();
291 ExtractStation_2RL_Ant_Limits();
292 ExtractStation_2RL_LR_Limits();
293 ExtractStation_2RL_Remove_Structures();
294 ExtractStation_2RL_SeparateRL();
296 // Store image filenames into AFDB
297 writeImage<MaskImageType>(m_ListOfStations["2R"], "seg/Station2R.mhd");
298 writeImage<MaskImageType>(m_ListOfStations["2L"], "seg/Station2L.mhd");
299 GetAFDB()->SetImageFilename("Station2R", "seg/Station2R.mhd");
300 GetAFDB()->SetImageFilename("Station2L", "seg/Station2L.mhd");
304 //--------------------------------------------------------------------
307 //--------------------------------------------------------------------
308 template <class TImageType>
310 clitk::ExtractLymphStationsFilter<TImageType>::
311 ExtractStation_4RL() {
315 WARNING ONLY 4R FIRST !!! (not same inf limits)
317 ExtractStation_4RL_SI_Limits();
318 ExtractStation_4RL_LR_Limits();
319 ExtractStation_4RL_AP_Limits();
321 //--------------------------------------------------------------------
324 //--------------------------------------------------------------------
325 template <class ImageType>
327 clitk::ExtractLymphStationsFilter<ImageType>::
328 Remove_Structures(std::string station, std::string s)
331 StartNewStep("[Station"+station+"] Remove "+s);
332 MaskImagePointer Structure = GetAFDB()->template GetImage<MaskImageType>(s);
333 clitk::AndNot<MaskImageType>(m_Working_Support, Structure, GetBackgroundValue());
335 catch(clitk::ExceptionObject e) {
336 std::cout << s << " not found, skip." << std::endl;
339 //--------------------------------------------------------------------
342 //--------------------------------------------------------------------
343 template <class TImageType>
345 clitk::ExtractLymphStationsFilter<TImageType>::
346 SetFuzzyThreshold(std::string station, std::string tag, double value)
348 m_FuzzyThreshold[station][tag] = value;
350 //--------------------------------------------------------------------
353 //--------------------------------------------------------------------
354 template <class TImageType>
356 clitk::ExtractLymphStationsFilter<TImageType>::
357 GetFuzzyThreshold(std::string station, std::string tag)
359 if (m_FuzzyThreshold.find(station) == m_FuzzyThreshold.end()) {
360 clitkExceptionMacro("Could not find options for station "+station+" in the list (while searching for tag "+tag+").");
364 if (m_FuzzyThreshold[station].find(tag) == m_FuzzyThreshold[station].end()) {
365 clitkExceptionMacro("Could not find options "+tag+" in the list of FuzzyThreshold for station "+station+".");
369 return m_FuzzyThreshold[station][tag];
371 //--------------------------------------------------------------------
376 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX