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://www.centreleonberard.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 ===========================================================================**/
18 #ifndef clitkResampleBSplineDeformableTransformGenericFilter_txx
19 #define clitkResampleBSplineDeformableTransformGenericFilter_txx
21 /* =================================================
22 * @file clitkResampleBSplineDeformableTransformGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 ResampleBSplineDeformableTransformGenericFilter::UpdateWithDim(std::string PixelType, int Components)
41 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<< PixelType<<"..."<<std::endl;
45 if(PixelType == "double"){
46 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 2D double..." << std::endl;
47 UpdateWithDimAndPixelType<Dimension, itk::Vector<double,2 > >();
50 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 2D float..." << std::endl;
51 UpdateWithDimAndPixelType<Dimension, itk::Vector<float,2 > >();
54 else if (Components==3)
56 if(PixelType == "double"){
57 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D double..." << std::endl;
58 UpdateWithDimAndPixelType<Dimension, itk::Vector<double,3 > >();
61 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float..." << std::endl;
62 UpdateWithDimAndPixelType<Dimension, itk::Vector<float,3 > >();
65 else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
69 //-------------------------------------------------------------------
70 // Update with the number of dimensions and the pixeltype
71 //-------------------------------------------------------------------
72 template <unsigned int Dimension, class PixelType>
74 ResampleBSplineDeformableTransformGenericFilter::UpdateWithDimAndPixelType()
78 typedef itk::Image<PixelType, Dimension> InputImageType;
79 typedef itk::Image<PixelType, Dimension> OutputImageType;
82 typedef itk::ImageFileReader<InputImageType> InputReaderType;
83 typename InputReaderType::Pointer reader = InputReaderType::New();
84 reader->SetFileName( m_InputFileName);
86 typename InputImageType::Pointer input= reader->GetOutput();
89 typedef clitk::ResampleBSplineDeformableTransformImageFilter<InputImageType,OutputImageType> ResampleFilterType;
90 typename ResampleFilterType::Pointer filter=ResampleFilterType::New();
91 filter->SetInput(input);
94 if (m_ArgsInfo.like_given)
96 typename InputReaderType::Pointer likeReader=InputReaderType::New();
97 likeReader->SetFileName(m_ArgsInfo.like_arg);
99 filter->SetOutputParametersFromImage(likeReader->GetOutput());
104 typename OutputImageType::SizeType outputSize;
105 if (m_ArgsInfo.size_given)
107 for(unsigned int i=0; i< Dimension; i++)
108 outputSize[i]=m_ArgsInfo.size_arg[i];
110 else outputSize=input->GetLargestPossibleRegion().GetSize();
111 if (m_Verbose) std::cout<<"Setting the size to "<<outputSize<<"..."<<std::endl;
114 typename OutputImageType::SpacingType outputSpacing;
115 if (m_ArgsInfo.spacing_given)
117 for(unsigned int i=0; i< Dimension; i++)
118 outputSpacing[i]=m_ArgsInfo.spacing_arg[i];
120 else outputSpacing=input->GetSpacing();
121 if (m_Verbose) std::cout<<"Setting the spacing to "<<outputSpacing<<"..."<<std::endl;
124 typename OutputImageType::PointType outputOrigin;
125 if (m_ArgsInfo.origin_given)
127 for(unsigned int i=0; i< Dimension; i++)
128 outputOrigin[i]=m_ArgsInfo.origin_arg[i];
130 else outputOrigin=input->GetOrigin();
131 if (m_Verbose) std::cout<<"Setting the origin to "<<outputOrigin<<"..."<<std::endl;
134 filter->SetSize( outputSize );
135 filter->SetOutputSpacing( outputSpacing );
136 filter->SetOutputOrigin( outputOrigin );
144 typename OutputImageType::Pointer output=filter->GetOutput();
147 typedef itk::ImageFileWriter<OutputImageType> WriterType;
148 typename WriterType::Pointer writer = WriterType::New();
149 writer->SetFileName(m_ArgsInfo.output_arg);
150 writer->SetInput(output);
158 #endif //#define clitkResampleBSplineDeformableTransformGenericFilter_txx