]> Creatis software - clitk.git/blob - tools/clitkMatrixToElastixTransform.cxx
Add output dicom filename to clitkImage2Dicom
[clitk.git] / tools / clitkMatrixToElastixTransform.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18
19 // clitk
20 #include "clitkMatrixToElastixTransform_ggo.h"
21 #include "clitkTransformUtilities.h"
22 #include "clitkIO.h"
23
24 // itk
25 #include <itkEuler3DTransform.h>
26
27 //--------------------------------------------------------------------
28 int main(int argc, char * argv[])
29 {
30   // Init command line
31   GGO(clitkMatrixToElastixTransform, args_info);
32   CLITK_INIT;
33
34   // Read matrix
35   itk::Matrix<double, 4, 4> matrix;
36   try {
37     matrix = clitk::ReadMatrix3D(args_info.input_arg);
38   }
39   catch (itk::ExceptionObject & err) {
40     std::cerr << "Error reading " << args_info.input_arg << std::endl;
41     std::cerr << err.GetDescription() << std::endl;
42     exit(-1);
43   }
44
45   // Compute parameters from transfer using itk Euler transform
46   itk::Euler3DTransform<double>::CenterType center;
47   center.Fill(0.);
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];
52   }
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];
59   }
60   itk::Euler3DTransform<double>::Pointer euler;
61   euler = itk::Euler3DTransform<double>::New();
62   euler->SetCenter(center);
63   euler->SetOffset(transVec);
64   euler->SetComputeZYX(false);
65   try {
66     euler->SetMatrix(rotMat);
67   }
68   catch (itk::ExceptionObject & err) {
69     std::cerr << "Error reading " << args_info.input_arg << std::endl;
70     std::cerr << err.GetDescription() << std::endl;
71     exit(-1);
72   }
73
74   // Write result
75   std::ofstream out;
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;
85
86   out << "// EulerTransform specific" << std::endl;
87   out << "(CenterOfRotationPoint "<< center[0] << ' ' << center[1] << ' ' << center[2] << ')' << std::endl;
88   out << "(ComputeZYX \"false\")" << std::endl;
89
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;
102
103   out << "// ResampleInterpolator specific" << std::endl;
104   out << "// (ResampleInterpolator \"FinalBSplineInterpolator\")" << std::endl;
105   out << "// (FinalBSplineInterpolationOrder 3)" << std::endl << std::endl;
106
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;
113   out.close();
114
115   return EXIT_SUCCESS;
116 }// end main
117
118 //--------------------------------------------------------------------