]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer.cxx
Feature #1766 Add licence terms for all files.
[creaRigidRegistration.git] / lib / Transformer.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------      */                                                                    
26
27
28 #include "Transformer.h"
29 #include "vtkMatrix4x4.h"
30
31 /*
32         CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
33 */
34 Transformer::Transformer() 
35 {
36         std::vector<int> empty (3,0); 
37         _angle= 0;
38         _centerPoint=empty;
39         _scaleX=1;
40         _scaleY=1;
41         //If the transform already exists, we delete it before we create a new transform 
42         //and set the matrix with the identity matrix
43         _transform= vtkTransform::New();
44         _matrix = vtkMatrix4x4::New();
45         _matrix->Identity();
46         _transform->SetMatrix(_matrix); 
47 }
48
49 /*
50         DESTRUCTOR
51 */
52 Transformer::~Transformer()
53 {
54         //We delete the existing transform
55         if (_transform != NULL ) { _transform->Delete(); }
56         if (_matrix != NULL ) { _matrix->Delete(); }
57 }
58
59 /*
60         SETS A NEW TRANSFORM
61 */
62 void Transformer::SetTransform(vtkTransform *transform)
63 {
64         _transform=transform;
65 }
66
67 /*
68         SETS CENTER POINT
69 */
70 void Transformer::SetCenterPoint(std::vector<int> point)
71 {
72     _centerPoint=point;
73 }
74
75 /*
76         SETS THE ANGLE
77 */
78 void Transformer::SetAngle(double angle)
79 {
80         _angle=angle;
81 }
82
83 /*
84         SETS THE X SCALE
85 */
86 void Transformer::SetScaleX(double scaleX)
87 {
88         _scaleX=scaleX/100.0;
89 }
90
91 /*
92         SETS THE Y SCALE
93 */
94 void Transformer::SetScaleY(double scaleY)
95 {
96         _scaleY=scaleY/100.0;
97 }
98
99 /*
100  SETS THE Y SCALE
101  */
102 void Transformer::SetScaleZ(double scaleZ)
103 {
104         _scaleZ=scaleZ/100.0;
105 }
106
107
108
109 /*
110         GETS THE RESULTANT TRANSFORM
111 */
112 vtkTransform *Transformer::GetResult()
113 {
114         return _transform;
115 }
116
117 /*
118         MAKES THE TRANSFORMATIONS
119 */
120 void Transformer::Run()
121 {
122         _transform->Identity();
123         _transform->PostMultiply();
124         if(_centerPoint.size() < 3)
125         {
126                 _transform->Translate(-_centerPoint[0], -_centerPoint[1], 0);
127                 std::cout << "NTU Transformer2D Center Points: " << _centerPoint[0] << " " << _centerPoint[1] << std::endl;
128         }
129         else
130         {
131                 _transform->Translate(-_centerPoint[0], -_centerPoint[1], -_centerPoint[2]);
132                 std::cout << "NTU Transformer2D Center Points: " << _centerPoint[0] << " " << _centerPoint[1] << " " << _centerPoint[2] << std::endl;
133         }
134
135         _transform->RotateWXYZ(_angle, 0, 0, 1);
136         //std::cout << "NTU Transformer2D Angle: " << _angle << std::endl;
137
138         if(_scaleX < 0 || _scaleY < 0 || _scaleZ < 0)
139         {
140                 _transform->Scale(100, 100, 100);
141                 //std::cout << "NTU Transformer2D Scale: " << _scaleX << " " << _scaleY << " " << _scaleZ << std::endl;
142         }
143         else
144         {
145                 _transform->Scale(_scaleX, _scaleY,_scaleZ);
146                 //std::cout << "NTU Transformer2D Scale: " << _scaleX << " " << _scaleY << " " << _scaleZ << std::endl;
147         }               
148         _transform->Inverse();
149         _transform->Update();
150 }