]> Creatis software - clitk.git/blob - common/clitkTransformUtilities.cxx
cosmetic for .ggo
[clitk.git] / common / clitkTransformUtilities.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 #include "clitkTransformUtilities.h"
20
21 namespace clitk
22 {
23
24 //--------------------------------------------------------------------
25 template < >
26 itk::Matrix<double, 3, 3>
27 GetForwardAffineMatrix<2>(itk::Array<double> transformParameters)
28 {
29   return GetForwardAffineMatrix2D(transformParameters);
30 }
31
32 //--------------------------------------------------------------------
33 template < >
34 itk::Matrix<double, 4, 4>
35 GetForwardAffineMatrix<3>(itk::Array<double> transformParameters)
36 {
37   return GetForwardAffineMatrix3D(transformParameters);
38 }
39
40 //--------------------------------------------------------------------
41 template < >
42 itk::Matrix<double, 3, 3>
43 GetBackwardAffineMatrix<2>(itk::Array<double> transformParameters)
44 {
45   return GetBackwardAffineMatrix2D(transformParameters);
46 }
47
48 //--------------------------------------------------------------------
49 template < >
50 itk::Matrix<double, 4, 4>
51 GetBackwardAffineMatrix<3>(itk::Array<double> transformParameters)
52 {
53   return GetBackwardAffineMatrix3D(transformParameters);
54 }
55
56 //--------------------------------------------------------------------
57 template <>
58 itk::Matrix<double, 2, 2> GetRotationMatrix<2>(itk::Array<double> rotationParameters)
59 {
60   return GetRotationMatrix2D(rotationParameters);
61 }
62
63 //--------------------------------------------------------------------
64 template <>
65 itk::Matrix<double, 3, 3> GetRotationMatrix<3>(itk::Array<double> rotationParameters)
66 {
67   return GetRotationMatrix3D(rotationParameters);
68 }
69
70 //--------------------------------------------------------------------
71 itk::Matrix<double, 4, 4> ReadMatrix3D(std::string fileName)
72 {
73   // read input matrix
74   std::ifstream is;
75   openFileForReading(is, fileName);
76   std::vector<double> nb;
77   double x;
78   skipComment(is);
79   is >> x;
80   while (is && !is.eof()) {
81     nb.push_back(x);
82     skipComment(is);
83     is >> x;
84   }
85
86   if(nb.size() != 16)
87     itkGenericExceptionMacro(<< "Could not read 4x4 matrix in " << fileName);
88
89   //copy it to the matrix
90   itk::Matrix<double, 4, 4> matrix;
91   unsigned int index=0;
92   for (unsigned int i=0;i<4;i++)
93     for (unsigned int j=0;j<4;j++)
94       matrix[i][j]=nb[index++];
95   return matrix;
96 }
97
98 }