]> Creatis software - clitk.git/blob - registration/clitkGenericAffineTransform.txx
Debug RTStruct conversion with empty struc
[clitk.git] / registration / clitkGenericAffineTransform.txx
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 #ifndef __clitkGenericAffineTransform_txx
20 #define __clitkGenericAffineTransform_txx
21
22 #include "clitkTransformUtilities.h"
23
24 namespace clitk
25 {
26
27 //=========================================================================================================================
28 //constructor
29 template<class args_info_type, class TCoordRep, unsigned int Dimension>
30 GenericAffineTransform<args_info_type, TCoordRep, Dimension>::GenericAffineTransform()
31 {
32   m_Transform=NULL;
33   m_Verbose=false;
34 }
35
36 //=========================================================================================================================
37 //Get the pointer
38 template<class args_info_type, class TCoordRep, unsigned int Dimension>
39 typename GenericAffineTransform<args_info_type, TCoordRep, Dimension>::TransformPointer
40 GenericAffineTransform<args_info_type, TCoordRep, Dimension>::GetTransform()
41 {
42   //============================================================================
43   // We retrieve the type of transform from the command line
44   //============================================================================
45   typedef itk::MatrixOffsetTransformBase<TCoordRep, Dimension, Dimension> MatrixXType;
46   typename MatrixXType::Pointer tMatrix;
47   typedef itk::TranslationTransform< TCoordRep, Dimension> TranslationXType;
48   typename TranslationXType::Pointer tTranslation;
49
50   switch ( m_ArgsInfo.transform_arg ) {
51   case 0:
52     m_Transform= itk::IdentityTransform< TCoordRep, Dimension>::New();
53     if (m_Verbose) std::cout<<"Using identity transform..."<<std::endl;
54     break;
55   case 1:
56     tTranslation = TranslationXType::New();
57     if (m_Verbose) std::cout<<"Using translation transform..."<<std::endl;
58     break;
59   case 2:
60     tMatrix = GetNewEulerTransform();
61     if (m_Verbose) std::cout<<"Using euler transform..."<<std::endl;
62     break;
63   case 3:
64     tMatrix = itk::AffineTransform< TCoordRep, Dimension >::New();
65     if (m_Verbose) std::cout<<"Using affine transform..."<<std::endl;
66     break;
67   }//end of switch
68
69
70   typename MatrixXType::OutputVectorType offset;
71   if(m_ArgsInfo.transform_arg>0) {
72     //Initialize translations
73     offset[0] = m_ArgsInfo.transX_arg;
74     offset[1] = m_ArgsInfo.transY_arg;
75     if(Dimension>2) offset[2] = m_ArgsInfo.transZ_arg;
76     if(m_ArgsInfo.initMatrix_given) {
77       itk::Matrix<double, Dimension+1 , Dimension+1> matHom = ReadMatrix<Dimension>(m_ArgsInfo.initMatrix_arg);
78       offset = GetTranslationPartMatrix(matHom);
79     }
80   }
81   switch(m_ArgsInfo.transform_arg) {
82   case 1:
83     tTranslation->SetOffset(offset);
84     m_Transform=tTranslation;
85     break;
86   case 2:
87   case 3:
88     //Init rigid and affine transform center
89     itk::Point<TCoordRep, Dimension> center;
90     for (unsigned int i=0; i<Dimension; i++)
91       center[i] = 0;
92     tMatrix->SetCenter(center);
93
94     //Initialize transform
95     tMatrix->SetOffset(offset);
96     if(m_ArgsInfo.initMatrix_given) {
97       itk::Matrix<double, Dimension+1 , Dimension+1> matHom = ReadMatrix<Dimension>(m_ArgsInfo.initMatrix_arg);
98       typename MatrixXType::MatrixType matrix = GetRotationalPartMatrix(matHom);
99       tMatrix->SetMatrix(matrix);
100     }
101     m_Transform=tMatrix;
102     break;
103   }
104
105   return m_Transform;
106 }
107 }
108
109 #endif