]> Creatis software - clitk.git/blob - segmentation/clitkExtractPatientGenericFilter.txx
The lower and upper options can be tuned for all type of region growing algorithm
[clitk.git] / segmentation / clitkExtractPatientGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 #include "clitkImageCommon.h"
20
21 //--------------------------------------------------------------------
22 template<class ArgsInfoType>
23 clitk::ExtractPatientGenericFilter<ArgsInfoType>::ExtractPatientGenericFilter():
24   ImageToImageGenericFilter<Self>("ExtractPatient") 
25 {
26   // Default values
27   cmdline_parser_clitkExtractPatient_init(&mArgsInfo);
28   InitializeImageType<3>();
29 }
30 //--------------------------------------------------------------------
31
32
33 //--------------------------------------------------------------------
34 template<class ArgsInfoType>
35 template<unsigned int Dim>
36 void clitk::ExtractPatientGenericFilter<ArgsInfoType>::InitializeImageType() 
37 {  
38   ADD_IMAGE_TYPE(Dim, short);
39   ADD_IMAGE_TYPE(Dim, unsigned short);
40   ADD_IMAGE_TYPE(Dim, float);
41   // ADD_IMAGE_TYPE(Dim, int);
42   // ADD_IMAGE_TYPE(Dim, float);
43 }
44 //--------------------------------------------------------------------
45   
46
47 //--------------------------------------------------------------------
48 template<class ArgsInfoType>
49 void clitk::ExtractPatientGenericFilter<ArgsInfoType>::SetArgsInfo(const ArgsInfoType & a) 
50 {
51   mArgsInfo=a;
52   this->SetIOVerbose(mArgsInfo.verbose_flag);
53   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
54   if (mArgsInfo.input_given)  this->SetInputFilename(mArgsInfo.input_arg);
55   if (mArgsInfo.output_given)  this->AddOutputFilename(mArgsInfo.output_arg);
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 template<class ArgsInfoType>
62 template<class FilterType>
63 void 
64 clitk::ExtractPatientGenericFilter<ArgsInfoType>::
65 SetOptionsFromArgsInfoToFilter(FilterType * f)
66 {
67   f->SetVerboseOptionFlag(mArgsInfo.verbose_flag);
68   f->SetVerboseStepFlag(mArgsInfo.verboseStep_flag);
69   f->SetWriteStepFlag(mArgsInfo.writeStep_flag);
70   f->SetVerboseWarningFlag(!mArgsInfo.verboseWarningOff_flag);
71   f->SetVerboseMemoryFlag(mArgsInfo.verboseMemory_flag);
72
73   if (mArgsInfo.afdb_given)
74     f->SetAFDBFilename(mArgsInfo.afdb_arg);  
75   
76   f->SetOutputPatientFilename(mArgsInfo.output_arg);
77
78   f->SetUpperThreshold(mArgsInfo.upper_arg);
79   f->SetLowerThreshold(mArgsInfo.lower_arg);
80   f->SetPrimaryOpeningRadius(mArgsInfo.openingRadius_arg);
81
82   f->SetDecomposeAndReconstructDuringFirstStep(mArgsInfo.erode1_flag);
83
84   // Convert to SizeType
85   typename FilterType::InputImageSizeType s;
86   if (mArgsInfo.radius1_given) {
87     ConvertOptionMacro(mArgsInfo.radius1, s, 3, false);
88     f->SetRadius1(s);
89   }
90
91   f->SetMaximumNumberOfLabels1(mArgsInfo.max1_arg);
92   f->SetNumberOfNewLabels1(mArgsInfo.new1_arg);
93
94   f->SetDecomposeAndReconstructDuringSecondStep(mArgsInfo.erode2_flag);
95
96   // Convert to SizeType
97   if (mArgsInfo.radius2_given) {
98     ConvertOptionMacro(mArgsInfo.radius2, s, 3, false);
99     f->SetRadius2(s);
100   }
101
102   f->SetMaximumNumberOfLabels2(mArgsInfo.max2_arg);
103   f->SetNumberOfNewLabels2(mArgsInfo.new2_arg);
104   
105   f->SetFirstKeep(mArgsInfo.firstKeep_arg);
106   f->SetLastKeep(mArgsInfo.lastKeep_arg);
107
108   f->SetFinalOpenClose(mArgsInfo.openClose_flag);
109   f->SetAutoCrop(!mArgsInfo.noAutoCrop_flag);
110 }
111 //--------------------------------------------------------------------
112
113
114 //--------------------------------------------------------------------
115 // Update with the number of dimensions and the pixeltype
116 //--------------------------------------------------------------------
117 template<class ArgsInfoType>
118 template<class ImageType>
119 void clitk::ExtractPatientGenericFilter<ArgsInfoType>::UpdateWithInputImageType() 
120
121   // Output image type
122   typedef itk::Image<uchar, ImageType::ImageDimension> OutputImageType;
123
124   // Reading input
125   typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
126
127   // Create filter
128   typedef clitk::ExtractPatientFilter<ImageType> FilterType;
129   typename FilterType::Pointer filter = FilterType::New();
130     
131   // Set the filter (needed for example for threaded monitoring)
132   this->SetFilterBase(filter);
133     
134   // Set global Options 
135   filter->SetInput(input);
136   SetOptionsFromArgsInfoToFilter<FilterType>(filter);
137
138   // Go !
139   filter->Update();
140
141   // Write/Save results
142   typename OutputImageType::Pointer output = filter->GetOutput();
143   this->template SetNextOutput<OutputImageType>(output); 
144 }
145 //--------------------------------------------------------------------
146
147