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 ===========================================================================**/
20 #include "clitkMatrixToElastixTransform_ggo.h"
21 #include "clitkTransformUtilities.h"
25 #include <itkEuler3DTransform.h>
27 //--------------------------------------------------------------------
28 int main(int argc, char * argv[])
31 GGO(clitkMatrixToElastixTransform, args_info);
35 itk::Matrix<double, 4, 4> matrix;
37 matrix = clitk::ReadMatrix3D(args_info.input_arg);
39 catch (itk::ExceptionObject & err) {
40 std::cerr << "Error reading " << args_info.input_arg << std::endl;
41 std::cerr << err.GetDescription() << std::endl;
45 // Compute parameters from transfer using itk Euler transform
46 itk::Euler3DTransform<double>::CenterType center;
48 if(args_info.center_given==3) {
49 center[0] = args_info.center_arg[0];
50 center[1] = args_info.center_arg[1];
51 center[2] = args_info.center_arg[2];
53 itk::Euler3DTransform<double>::MatrixType rotMat;
54 itk::Euler3DTransform<double>::OutputVectorType transVec;
55 for(int i=0; i<3; i++) {
56 transVec[i] = matrix[i][3];
57 for(int j=0; j<3; j++)
58 rotMat[i][j] = matrix[i][j];
60 itk::Euler3DTransform<double>::Pointer euler;
61 euler = itk::Euler3DTransform<double>::New();
62 euler->SetCenter(center);
63 euler->SetOffset(transVec);
64 euler->SetComputeZYX(false);
66 euler->SetMatrix(rotMat);
68 catch (itk::ExceptionObject & err) {
69 std::cerr << "Error reading " << args_info.input_arg << std::endl;
70 std::cerr << err.GetDescription() << std::endl;
76 clitk::openFileForWriting(out, args_info.output_arg);
77 out << "(Transform \"EulerTransform\")" << std::endl;
78 out << "(NumberOfParameters 6)" << std::endl;
79 out << "(TransformParameters ";
80 for(unsigned int i=0; i<6; i++)
81 out << euler->GetParameters()[i] << ' ';
82 out << ')' << std::endl;
83 out << "(InitialTransformParametersFileName \"NoInitialTransform\")" << std::endl;
84 out << "(HowToCombineTransforms \"Compose\")" << std::endl;
86 out << "// EulerTransform specific" << std::endl;
87 out << "(CenterOfRotationPoint "<< center[0] << ' ' << center[1] << ' ' << center[2] << ')' << std::endl;
88 out << "(ComputeZYX \"false\")" << std::endl;
90 // The rest is commented, up to the user to define it manually
91 out << "// Image specific" << std::endl;
92 out << "// (FixedImageDimension 3)" << std::endl;
93 out << "// (MovingImageDimension 3)" << std::endl;
94 out << "// (FixedInternalImagePixelType \"float\")" << std::endl;
95 out << "// (MovingInternalImagePixelType \"float\")" << std::endl;
96 out << "// (Size 1 1 1)" << std::endl;
97 out << "// (Index 0 0 0)" << std::endl;
98 out << "// (Spacing 1 1 1)" << std::endl;
99 out << "// (Origin -0.5 -0.5 -0.5)" << std::endl;
100 out << "// (Direction 1 0 0 0 1 0 0 0 1)" << std::endl;
101 out << "// (UseDirectionCosines \"true\")" << std::endl << std::endl;
103 out << "// ResampleInterpolator specific" << std::endl;
104 out << "// (ResampleInterpolator \"FinalBSplineInterpolator\")" << std::endl;
105 out << "// (FinalBSplineInterpolationOrder 3)" << std::endl << std::endl;
107 out << "// Resampler specific" << std::endl;
108 out << "// (Resampler \"DefaultResampler\")" << std::endl;
109 out << "// (DefaultPixelValue 0.000000)" << std::endl;
110 out << "// (ResultImageFormat \"mhd\")" << std::endl;
111 out << "// (ResultImagePixelType \"short\")" << std::endl;
112 out << "// (CompressResultImage \"false\")" << std::endl;
118 //--------------------------------------------------------------------