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"
27 //--------------------------------------------------------------------
28 template<class args_info_type>
29 ResampleImageGenericFilter<args_info_type>::ResampleImageGenericFilter():
30 ImageToImageGenericFilter<Self>("Resample") {
31 InitializeImageType<2>();
32 InitializeImageType<3>();
33 InitializeImageType<4>();
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 template<class args_info_type>
40 template<unsigned int Dim>
41 void 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 ResampleImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
52 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
53 SetIOVerbose(mArgsInfo.verbose_flag);
54 if (mArgsInfo.input_given) {
55 SetInputFilename(mArgsInfo.input_arg);
57 if (mArgsInfo.output_given) {
58 SetOutputFilename(mArgsInfo.output_arg);
61 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 // Update with the number of dimensions and the pixeltype
66 //--------------------------------------------------------------------
67 template<class args_info_type>
68 template<class InputImageType>
70 ResampleImageGenericFilter<args_info_type>::UpdateWithInputImageType() {
73 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
76 typedef typename InputImageType::PixelType PixelType;
77 typedef InputImageType OutputImageType; // to change to float is user ask it (?)
80 typedef clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType> ResampleImageFilterType;
81 typename ResampleImageFilterType::Pointer filter = ResampleImageFilterType::New();
82 filter->SetInput(input);
85 filter->SetVerboseOptions(mArgsInfo.verbose_flag);
88 static const unsigned int dim = OutputImageType::ImageDimension;
89 typename OutputImageType::SpacingType spacing;
90 typename OutputImageType::SizeType size;
91 if (mArgsInfo.spacing_given == 1) {
92 filter->SetOutputIsoSpacing(mArgsInfo.spacing_arg[0]);
95 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.size_given != 0)) {
96 std::cerr << "Error: use spacing or size, not both." << std::endl;
100 if (!((mArgsInfo.spacing_given == 0) && (mArgsInfo.size_given == 0))) {
102 if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.spacing_given != dim)) {
103 std::cerr << "Error: spacing should have one or " << dim << " values." << std::endl;
106 if ((mArgsInfo.size_given != 0) && (mArgsInfo.size_given != dim)) {
107 std::cerr << "Error: size should have " << dim << " values." << std::endl;
110 if (mArgsInfo.spacing_given)
111 for(unsigned int i=0; i<dim; i++)
112 spacing[i] = mArgsInfo.spacing_arg[i];
113 if (mArgsInfo.size_given)
114 for(unsigned int i=0; i<dim; i++)
115 size[i] = mArgsInfo.size_arg[i];
116 filter->SetOutputSpacing(spacing);
117 filter->SetOutputSize(size);
121 // Set temporal dimension
122 filter->SetLastDimensionIsTime(mArgsInfo.time_flag);
125 filter->SetGaussianFilteringEnabled(mArgsInfo.autogauss_flag);
126 if (mArgsInfo.gauss_given != 0) {
127 typename ResampleImageFilterType::GaussianSigmaType g;
128 for(unsigned int i=0; i<dim; i++) {
129 g[i] = mArgsInfo.gauss_arg[i];
131 filter->SetGaussianSigma(g);
135 std::string interp = std::string(mArgsInfo.interp_arg);
136 if (interp == "nn") {
137 filter->SetInterpolationType(ResampleImageFilterType::NearestNeighbor);
140 if (interp == "linear") {
141 filter->SetInterpolationType(ResampleImageFilterType::Linear);
144 if (interp == "bspline") {
145 filter->SetInterpolationType(ResampleImageFilterType::BSpline);
148 if (interp == "blut") {
149 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 */