]> Creatis software - clitk.git/blob - filters/clitkFooImageGenericFilter.txx
- forget a typename
[clitk.git] / filters / clitkFooImageGenericFilter.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 #ifndef clitkFooImageGenericFilter_txx
19 #define clitkFooImageGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkFooImageGenericFilter.txx
23  * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24  * @date   29 june 2009
25  *
26  * @brief
27  *
28  ===================================================*/
29
30 // itk include
31 #include "itkBinaryThresholdImageFilter.h"
32 #include "itkMaskImageFilter.h"
33 #include "itkMaskNegatedImageFilter.h"
34 #include <clitkCommon.h>
35
36 namespace clitk
37 {
38
39 //--------------------------------------------------------------------
40 template<class args_info_type>
41 FooImageGenericFilter<args_info_type>::FooImageGenericFilter():
42         ImageToImageGenericFilter<Self>("FooImage") {
43     InitializeImageType<2>();
44     InitializeImageType<3>();
45     InitializeImageType<4>();
46 }
47 //--------------------------------------------------------------------
48
49
50 //--------------------------------------------------------------------
51 template<class args_info_type>
52 template<unsigned int Dim>
53 void FooImageGenericFilter<args_info_type>::InitializeImageType() {
54     ADD_IMAGE_TYPE(Dim, char);
55     ADD_IMAGE_TYPE(Dim, uchar);
56     ADD_IMAGE_TYPE(Dim, short);
57     ADD_IMAGE_TYPE(Dim, ushort);
58     ADD_IMAGE_TYPE(Dim, int);
59     ADD_IMAGE_TYPE(Dim, float);
60     ADD_IMAGE_TYPE(Dim, double);
61 }
62 //--------------------------------------------------------------------
63
64
65 //--------------------------------------------------------------------
66 template<class args_info_type>
67 void FooImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
68     mArgsInfo=a;
69     SetIOVerbose(mArgsInfo.verbose_flag);
70     if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
71
72     if (mArgsInfo.input_given) {
73         SetInputFilename(mArgsInfo.input_arg);
74     }
75     if (mArgsInfo.output_given) {
76         SetOutputFilename(mArgsInfo.output_arg);
77     }
78 }
79 //--------------------------------------------------------------------
80
81 //--------------------------------------------------------------------
82 // Update with the number of dimensions and the pixeltype
83 //--------------------------------------------------------------------
84 template<class args_info_type>
85 template<class InputImageType>
86 void
87 FooImageGenericFilter<args_info_type>::UpdateWithInputImageType()
88 {
89
90     // Reading input
91     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
92
93     // Main filter
94     typedef typename InputImageType::PixelType PixelType;
95     typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
96
97     // Filter
98     typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
99     typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
100     thresholdFilter->SetInput(input);
101     thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
102
103     if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
104     if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
105
106     if (mArgsInfo.mode_arg == std::string("both")) {
107         thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
108         thresholdFilter->Update();
109
110         typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
111         this->template SetNextOutput<OutputImageType>(outputImage);
112     }
113     else {
114         typename InputImageType::Pointer outputImage;
115         thresholdFilter->SetOutsideValue(0);
116         if (mArgsInfo.mode_arg == std::string("BG")) {
117             typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
118             typename maskFilterType::Pointer maskFilter = maskFilterType::New();
119             maskFilter->SetInput1(input);
120             maskFilter->SetInput2(thresholdFilter->GetOutput());
121             maskFilter->SetOutsideValue(mArgsInfo.bg_arg);
122             maskFilter->Update();
123             outputImage = maskFilter->GetOutput();
124         }
125         else {
126             typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
127             typename maskFilterType::Pointer maskFilter = maskFilterType::New();
128             maskFilter->SetInput1(input);
129             maskFilter->SetInput2(thresholdFilter->GetOutput());
130             maskFilter->SetOutsideValue(mArgsInfo.fg_arg);
131             maskFilter->Update();
132             outputImage = maskFilter->GetOutput();
133         }
134         // Write/Save results
135         this->template SetNextOutput<InputImageType>(outputImage);
136     }
137 }
138 //--------------------------------------------------------------------
139
140
141 }//end clitk
142
143 #endif //#define clitkFooImageGenericFilter_txx