]> Creatis software - clitk.git/blob - segmentation/clitkExtractBonesGenericFilter.txx
9c998936519602cdef56ce0a98fbf786a13524e0
[clitk.git] / segmentation / clitkExtractBonesGenericFilter.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://oncora1.lyon.fnclcc.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 #ifndef CLITKEXTRACTBONESSGENERICFILTER_TXX
20 #define CLITKEXTRACTBONESSGENERICFILTER_TXX
21
22 #include "clitkImageCommon.h"
23   
24 //--------------------------------------------------------------------
25 template<class ArgsInfoType>
26 clitk::ExtractBonesGenericFilter<ArgsInfoType>::ExtractBonesGenericFilter():
27   ImageToImageGenericFilter<Self>("ExtractBones") 
28 {
29   // Default values
30   cmdline_parser_clitkExtractBones_init(&mArgsInfo);
31   InitializeImageType<3>();
32 }
33 //--------------------------------------------------------------------
34
35
36 //--------------------------------------------------------------------
37 template<class ArgsInfoType>
38 template<unsigned int Dim>
39 void clitk::ExtractBonesGenericFilter<ArgsInfoType>::InitializeImageType() 
40 {  
41   ADD_IMAGE_TYPE(Dim, short);
42   // ADD_IMAGE_TYPE(Dim, int);
43   ADD_IMAGE_TYPE(Dim, float);
44 }
45 //--------------------------------------------------------------------
46   
47
48 //--------------------------------------------------------------------
49 template<class ArgsInfoType>
50 void clitk::ExtractBonesGenericFilter<ArgsInfoType>::SetArgsInfo(const ArgsInfoType & a) 
51 {
52   mArgsInfo=a;
53   SetIOVerbose(mArgsInfo.verbose_flag);
54   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
55   if (mArgsInfo.input_given)   AddInputFilename(mArgsInfo.input_arg);
56   if (mArgsInfo.output_given)  AddOutputFilename(mArgsInfo.output_arg);
57 }
58 //--------------------------------------------------------------------
59
60
61 //--------------------------------------------------------------------
62 template<class ArgsInfoType>
63 template<class FilterType>
64 void clitk::ExtractBonesGenericFilter<ArgsInfoType>::
65 SetOptionsFromArgsInfoToFilter(FilterType * f) 
66 {
67   f->SetVerboseOptionFlag(mArgsInfo.verboseOption_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->SetOutputBonesFilename(mArgsInfo.output_arg);
77
78   f->SetInitialSmoothing(mArgsInfo.smooth_flag);
79   f->SetSmoothingConductanceParameter(mArgsInfo.cond_arg);
80   f->SetSmoothingNumberOfIterations(mArgsInfo.iter_arg);
81   f->SetSmoothingTimeStep(mArgsInfo.time_arg);
82   f->SetSmoothingUseImageSpacing(mArgsInfo.spacing_flag);
83
84   f->SetMinimalComponentSize(mArgsInfo.minSize_arg);
85   f->SetUpperThreshold1(mArgsInfo.upper1_arg);
86   f->SetLowerThreshold1(mArgsInfo.lower1_arg);
87   f->SetFullConnectivity(mArgsInfo.full_flag);
88
89   f->SetUpperThreshold2(mArgsInfo.upper2_arg);
90   f->SetLowerThreshold2(mArgsInfo.lower2_arg);
91
92   typename FilterType::InputImageSizeType s;
93   if (mArgsInfo.radius2_given) {
94     ConvertOptionMacro(mArgsInfo.radius2, s, 3, false);
95     f->SetRadius2(s);
96   }
97
98   f->SetSampleRate2(mArgsInfo.sampleRate2_arg);
99   f->SetAutoCrop(!mArgsInfo.noAutoCrop_flag);
100   f->SetFillHoles(!mArgsInfo.doNotFillHoles_flag);
101 }
102 //--------------------------------------------------------------------
103
104
105 //--------------------------------------------------------------------
106 // Update with the number of dimensions and the pixeltype
107 //--------------------------------------------------------------------
108 template<class ArgsInfoType>
109 template<class ImageType>
110 void clitk::ExtractBonesGenericFilter<ArgsInfoType>::UpdateWithInputImageType() 
111
112   // Mask & output image type
113   typedef itk::Image<uchar, ImageType::ImageDimension> MaskImageType;
114
115   // Reading input
116   typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
117
118   // Create filter
119   typedef clitk::ExtractBonesFilter<ImageType> FilterType;
120   typename FilterType::Pointer filter = FilterType::New();
121     
122   // Set global Options 
123   filter->SetInput(input);
124   SetOptionsFromArgsInfoToFilter<FilterType>(filter);
125
126   // Go !
127   filter->Update();
128   
129   // Write/Save results
130   typename MaskImageType::Pointer output = filter->GetOutput();
131   this->template SetNextOutput<MaskImageType>(output); 
132 }
133 //--------------------------------------------------------------------
134
135 #endif //#define CLITKEXTRACTBONESSGENERICFILTER_TXX