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 clitkMatrixTransformToVFGenericFilter_txx
19 #define clitkMatrixTransformToVFGenericFilter_txx
21 /* =================================================
22 * @file clitkMatrixTransformToVFGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 MatrixTransformToVFGenericFilter::UpdateWithDim()
41 // if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
43 // if(PixelType == "short"){
44 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
45 // UpdateWithDimAndPixelType<Dimension, signed short>();
47 // // else if(PixelType == "unsigned_short"){
48 // // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
49 // // UpdateWithDimAndPixelType<Dimension, unsigned short>();
52 // else if (PixelType == "unsigned_char"){
53 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
54 // UpdateWithDimAndPixelType<Dimension, unsigned char>();
57 // // else if (PixelType == "char"){
58 // // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
59 // // UpdateWithDimAndPixelType<Dimension, signed char>();
62 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
63 // UpdateWithDimAndPixelType<Dimension, float>();
68 // //-------------------------------------------------------------------
69 // // Update with the number of dimensions and the pixeltype
70 // //-------------------------------------------------------------------
71 // template <unsigned int Dimension, class PixelType>
73 // MatrixTransformToVFGenericFilter::UpdateWithDimAndPixelType()
77 typedef itk::Vector<float,Dimension> Displacement;
78 typedef itk::Image<Displacement, Dimension> OutputImageType;
81 #if ITK_VERSION_MAJOR >= 4
82 typedef itk::TransformToDisplacementFieldSource<OutputImageType, double> ConvertorType;
84 typedef itk::TransformToDeformationFieldSource<OutputImageType, double> ConvertorType;
86 typename ConvertorType::Pointer filter= ConvertorType::New();
89 if (m_ArgsInfo.like_given)
91 typedef itk::ImageFileReader<OutputImageType> ReaderType;
92 typename ReaderType::Pointer reader2=ReaderType::New();
93 reader2->SetFileName(m_ArgsInfo.like_arg);
96 typename OutputImageType::Pointer image=reader2->GetOutput();
97 filter->SetOutputParametersFromImage(image);
102 if(m_ArgsInfo.origin_given)
104 typename OutputImageType::PointType origin;
105 for(i=0;i<Dimension;i++)
106 origin[i]=m_ArgsInfo.origin_arg[i];
107 filter->SetOutputOrigin(origin);
109 if (m_ArgsInfo.spacing_given)
111 typename OutputImageType::SpacingType spacing;
112 for(i=0;i<Dimension;i++)
113 spacing[i]=m_ArgsInfo.spacing_arg[i];
114 filter->SetOutputSpacing(spacing);
116 if (m_ArgsInfo.size_given)
118 typename OutputImageType::SizeType size;
119 for(i=0;i<Dimension;i++)
120 size[i]=m_ArgsInfo.size_arg[i];
121 filter->SetOutputSize(size);
126 typedef itk::AffineTransform<double, Dimension> TransformType;
127 typename TransformType::Pointer transform =TransformType::New();
128 itk::Matrix<double, Dimension+1, Dimension+1> homMatrix= ReadMatrix<Dimension>( m_ArgsInfo.matrix_arg);
129 itk::Matrix<double, Dimension, Dimension> matrix =GetRotationalPartMatrix( homMatrix);
130 itk::Vector<double, Dimension> offset= GetTranslationPartMatrix( homMatrix);
131 transform->SetMatrix(matrix);
132 transform->SetOffset(offset);
133 filter->SetTransform(transform);
135 typename OutputImageType::Pointer output=filter->GetOutput();
138 typedef itk::ImageFileWriter<OutputImageType> WriterType;
139 typename WriterType::Pointer writer = WriterType::New();
140 writer->SetFileName(m_ArgsInfo.output_arg);
141 writer->SetInput(output);
149 #endif //#define clitkMatrixTransformToVFGenericFilter_txx