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"
28 //--------------------------------------------------------------------
29 template<class args_info_type>
30 ResampleImageGenericFilter<args_info_type>::ResampleImageGenericFilter():
31 ImageToImageGenericFilter<Self>("Resample")
33 InitializeImageType<2>();
34 InitializeImageType<3>();
35 InitializeImageType<4>();
37 //--------------------------------------------------------------------
40 //--------------------------------------------------------------------
41 template<class args_info_type>
42 template<unsigned int Dim>
43 void ResampleImageGenericFilter<args_info_type>::InitializeImageType()
45 ADD_DEFAULT_IMAGE_TYPES(Dim);
46 //ADD_IMAGE_TYPE(Dim, short);
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 void ResampleImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
56 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
57 SetIOVerbose(mArgsInfo.verbose_flag);
58 if (mArgsInfo.input_given) {
59 SetInputFilename(mArgsInfo.input_arg);
61 if (mArgsInfo.output_given) {
62 SetOutputFilename(mArgsInfo.output_arg);
65 //--------------------------------------------------------------------
68 //--------------------------------------------------------------------
69 // Update with the number of dimensions and the pixeltype
70 //--------------------------------------------------------------------
71 template<class args_info_type>
72 template<class InputImageType>
74 ResampleImageGenericFilter<args_info_type>::UpdateWithInputImageType()
78 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
81 typedef typename InputImageType::PixelType PixelType;
82 typedef InputImageType OutputImageType; // to change to float is user ask it (?)
85 typedef clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType> ResampleImageFilterType;
86 typename ResampleImageFilterType::Pointer filter = ResampleImageFilterType::New();
87 filter->SetInput(input);
90 filter->SetVerboseOptions(mArgsInfo.verbose_flag);
93 static const unsigned int dim = OutputImageType::ImageDimension;
94 typename OutputImageType::SpacingType spacing;
95 typename OutputImageType::SizeType size;
96 if (mArgsInfo.spacing_given == 1) {
97 filter->SetOutputIsoSpacing(mArgsInfo.spacing_arg[0]);
99 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.size_given != 0)) {
100 std::cerr << "Error: use spacing or size, not both." << std::endl;
104 if (!((mArgsInfo.spacing_given == 0) && (mArgsInfo.size_given == 0))) {
106 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.spacing_given != dim)) {
107 std::cerr << "Error: spacing should have one or " << dim << " values." << std::endl;
110 if ((mArgsInfo.size_given != 0) && (mArgsInfo.size_given != dim)) {
111 std::cerr << "Error: size should have " << dim << " values." << std::endl;
114 if (mArgsInfo.spacing_given)
115 for(unsigned int i=0; i<dim; i++)
116 spacing[i] = mArgsInfo.spacing_arg[i];
117 if (mArgsInfo.size_given)
118 for(unsigned int i=0; i<dim; i++)
119 size[i] = mArgsInfo.size_arg[i];
120 filter->SetOutputSpacing(spacing);
121 filter->SetOutputSize(size);
125 // Set temporal dimension
126 filter->SetLastDimensionIsTime(mArgsInfo.time_flag);
129 filter->SetGaussianFilteringEnabled(mArgsInfo.autogauss_flag);
130 if (mArgsInfo.gauss_given != 0) {
131 typename ResampleImageFilterType::GaussianSigmaType g;
132 for(unsigned int i=0; i<dim; i++) {
133 g[i] = mArgsInfo.gauss_arg[i];
135 filter->SetGaussianSigma(g);
139 std::string interp = std::string(mArgsInfo.interp_arg);
140 if (interp == "nn") {
141 filter->SetInterpolationType(ResampleImageFilterType::NearestNeighbor);
143 if (interp == "linear") {
144 filter->SetInterpolationType(ResampleImageFilterType::Linear);
146 if (interp == "bspline") {
147 filter->SetInterpolationType(ResampleImageFilterType::BSpline);
149 if (interp == "blut") {
150 filter->SetInterpolationType(ResampleImageFilterType::B_LUT);
152 std::cerr << "Error. I do not know interpolation '" << mArgsInfo.interp_arg
153 << "'. Choose among: nn, linear, bspline, blut" << std::endl;
160 // Set default pixel value
161 filter->SetDefaultPixelValue(mArgsInfo.default_arg);
164 if (mArgsInfo.thread_given) {
165 filter->SetNumberOfThreads(mArgsInfo.thread_arg);
170 typename OutputImageType::Pointer outputImage = filter->GetOutput();
171 this->template SetNextOutput<OutputImageType>(outputImage);
173 //--------------------------------------------------------------------
177 #endif /* end #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX */