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 CLITKRESAMPLEIMAGEGENERICFILTER_TXX
20 #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX
23 #include "clitkResampleImageWithOptionsFilter.h"
25 //--------------------------------------------------------------------
26 template<class args_info_type>
27 clitk::ResampleImageGenericFilter<args_info_type>::ResampleImageGenericFilter():
28 ImageToImageGenericFilter<Self>("Resample")
30 // InitializeImageType<2>();
31 InitializeImageType<3>();
32 InitializeImageType<4>();
34 //--------------------------------------------------------------------
37 //--------------------------------------------------------------------
38 template<class args_info_type>
39 template<unsigned int Dim>
40 void clitk::ResampleImageGenericFilter<args_info_type>::InitializeImageType()
42 //ADD_DEFAULT_IMAGE_TYPES(Dim);
43 ADD_IMAGE_TYPE(Dim, short);
45 //--------------------------------------------------------------------
48 //--------------------------------------------------------------------
49 template<class args_info_type>
50 void clitk::ResampleImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
53 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
54 SetIOVerbose(mArgsInfo.verbose_flag);
55 if (mArgsInfo.input_given) {
56 SetInputFilename(mArgsInfo.input_arg);
58 if (mArgsInfo.output_given) {
59 SetOutputFilename(mArgsInfo.output_arg);
62 //--------------------------------------------------------------------
65 //--------------------------------------------------------------------
66 // Update with the number of dimensions and the pixeltype
67 //--------------------------------------------------------------------
68 template<class args_info_type>
69 template<class InputImageType>
71 clitk::ResampleImageGenericFilter<args_info_type>::UpdateWithInputImageType()
75 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
78 typedef typename InputImageType::PixelType PixelType;
79 typedef InputImageType OutputImageType; // to change to float is user ask it (?)
82 typedef clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType> ResampleImageFilterType;
83 typename ResampleImageFilterType::Pointer filter = ResampleImageFilterType::New();
84 filter->SetInput(input);
87 filter->SetVerboseOptions(mArgsInfo.verbose_flag);
90 static const unsigned int dim = OutputImageType::ImageDimension;
91 typename OutputImageType::SpacingType spacing;
92 typename OutputImageType::SizeType size;
93 if (mArgsInfo.spacing_given == 1) {
94 filter->SetOutputIsoSpacing(mArgsInfo.spacing_arg[0]);
96 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.size_given != 0)) {
97 std::cerr << "Error: use spacing or size, not both." << std::endl;
101 if (!((mArgsInfo.spacing_given == 0) && (mArgsInfo.size_given == 0))) {
103 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.spacing_given != dim)) {
104 std::cerr << "Error: spacing should have one or " << dim << " values." << std::endl;
107 if ((mArgsInfo.size_given != 0) && (mArgsInfo.size_given != dim)) {
108 std::cerr << "Error: size should have " << dim << " values." << std::endl;
111 if (mArgsInfo.spacing_given)
112 for(unsigned int i=0; i<dim; i++)
113 spacing[i] = mArgsInfo.spacing_arg[i];
114 if (mArgsInfo.size_given)
115 for(unsigned int i=0; i<dim; i++)
116 size[i] = mArgsInfo.size_arg[i];
117 filter->SetOutputSpacing(spacing);
118 filter->SetOutputSize(size);
122 // Set temporal dimension
123 filter->SetLastDimensionIsTime(mArgsInfo.time_flag);
126 filter->SetGaussianFilteringEnabled(mArgsInfo.autogauss_flag);
127 if (mArgsInfo.gauss_given != 0) {
128 typename ResampleImageFilterType::GaussianSigmaType g;
129 for(unsigned int i=0; i<dim; i++) {
130 g[i] = mArgsInfo.gauss_arg[i];
132 filter->SetGaussianSigma(g);
136 std::string interp = std::string(mArgsInfo.interp_arg);
137 if (interp == "nn") {
138 filter->SetInterpolationType(ResampleImageFilterType::NearestNeighbor);
140 if (interp == "linear") {
141 filter->SetInterpolationType(ResampleImageFilterType::Linear);
143 if (interp == "bspline") {
144 filter->SetInterpolationType(ResampleImageFilterType::BSpline);
146 if (interp == "blut") {
147 filter->SetInterpolationType(ResampleImageFilterType::B_LUT);
149 std::cerr << "Error. I do not know interpolation '" << mArgsInfo.interp_arg
150 << "'. Choose among: nn, linear, bspline, blut" << std::endl;
157 // Set default pixel value
158 filter->SetDefaultPixelValue(mArgsInfo.default_arg);
161 if (mArgsInfo.thread_given) {
162 filter->SetNumberOfThreads(mArgsInfo.thread_arg);
167 typename OutputImageType::Pointer outputImage = filter->GetOutput();
168 this->template SetNextOutput<OutputImageType>(outputImage);
170 //--------------------------------------------------------------------
173 #endif /* end #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX */