+ // ImageTypes
+ typedef itk::Image<PixelType, Dimension> InputImageType;
+ typedef itk::Image<PixelType, Dimension> OutputImageType;
+
+ // Read the input
+ typedef itk::ImageFileReader<InputImageType> InputReaderType;
+ typename InputReaderType::Pointer reader = InputReaderType::New();
+ reader->SetFileName( m_InputFileName);
+ reader->Update();
+ typename InputImageType::Pointer input= reader->GetOutput();
+
+ //Filter
+ typedef itk::ResampleImageFilter< InputImageType,OutputImageType > ResampleFilterType;
+ typename ResampleFilterType::Pointer resampler = ResampleFilterType::New();
+
+ // Matrix
+ typename itk::Matrix<double, Dimension+1, Dimension+1> matrix;
+ if (m_ArgsInfo.matrix_given) {
+ matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
+ if (m_Verbose) std::cout<<"Reading the matrix..."<<std::endl;
+ } else {
+ matrix.SetIdentity();
+ }
+ if (m_Verbose) std::cout<<"Using the following matrix:"<<std::endl;
+ if (m_Verbose) std::cout<<matrix<<std::endl;
+ typename itk::Matrix<double, Dimension, Dimension> rotationMatrix=clitk::GetRotationalPartMatrix(matrix);
+ typename itk::Vector<double,Dimension> translationPart= clitk::GetTranslationPartMatrix(matrix);
+
+ // Transform
+ typedef itk::AffineTransform<double, Dimension> AffineTransformType;
+ typename AffineTransformType::Pointer affineTransform=AffineTransformType::New();
+ affineTransform->SetMatrix(rotationMatrix);
+ affineTransform->SetTranslation(translationPart);
+
+ // Interp
+ typedef clitk::GenericInterpolator<args_info_type, InputImageType, double> GenericInterpolatorType;
+ typename GenericInterpolatorType::Pointer genericInterpolator=GenericInterpolatorType::New();
+ genericInterpolator->SetArgsInfo(m_ArgsInfo);
+
+ // Properties
+ if (m_ArgsInfo.like_given) {
+ typename InputReaderType::Pointer likeReader=InputReaderType::New();
+ likeReader->SetFileName(m_ArgsInfo.like_arg);
+ likeReader->Update();
+ resampler->SetOutputParametersFromImage(likeReader->GetOutput());
+ } else if(m_ArgsInfo.transform_grid_flag) {
+ typename itk::Matrix<double, Dimension+1, Dimension+1> invMatrix( matrix.GetInverse() );
+ typename itk::Matrix<double, Dimension, Dimension> invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) );
+ typename itk::Vector<double,Dimension> invTrans = clitk::GetTranslationPartMatrix(invMatrix);
+
+ // Spacing is influenced by affine transform matrix and input direction
+ typename InputImageType::SpacingType outputSpacing;
+ outputSpacing = invRotMatrix *
+ input->GetDirection() *
+ input->GetSpacing();
+
+ // Origin is influenced by translation but not by input direction
+ typename InputImageType::PointType outputOrigin;
+ outputOrigin = invRotMatrix *
+ input->GetOrigin() +
+ invTrans;
+
+ // Size is influenced by affine transform matrix and input direction
+ // Size is converted to double, transformed and converted back to size type.
+ vnl_vector<double> vnlOutputSize(Dimension);
+ for(unsigned int i=0; i< Dimension; i++) {
+ vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i];
+ }
+ vnlOutputSize = invRotMatrix *
+ input->GetDirection().GetVnlMatrix() *
+ vnlOutputSize;
+ typename OutputImageType::SizeType outputSize;
+ for(unsigned int i=0; i< Dimension; i++) {
+ // If the size is negative, we have a flip and we must modify
+ // the origin and the spacing accordingly.
+ if(vnlOutputSize[i]<0.) {
+ vnlOutputSize[i] *= -1.;
+ outputOrigin[i] = outputOrigin[i] + outputSpacing[i] * (vnlOutputSize[i]-1);
+ outputSpacing[i] *= -1.;