]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer3D1Point.cxx
Feature #1766 Add licence terms for all files.
[creaRigidRegistration.git] / lib / Transformer3D1Point.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 "Transformer3D1Point.h"
29 /*
30         CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
31 */
32 Transformer3D1Point::Transformer3D1Point() 
33 {
34         std::vector<int> empty (3,0); 
35         _centerPoint=empty;     
36         //If the transform already exists, we delete it before we create a new transform 
37         //and set the matrix with the identity matrix
38         _transform= vtkTransform::New();
39         _matrix = vtkMatrix4x4::New();
40         _matrix->Identity();
41         _transform->SetMatrix(_matrix); 
42 }
43
44 /*
45         DESTRUCTOR
46 */
47 Transformer3D1Point::~Transformer3D1Point()
48 {
49         //We delete the existing transform
50         if (_transform != NULL ) { _transform->Delete(); }
51         if (_matrix != NULL ) { _matrix->Delete(); }
52 }
53
54 /*
55         SETS A NEW TRANSFORM
56 */
57 void Transformer3D1Point::SetTransform(vtkTransform *transform)
58 {
59         _transform=transform;
60 }
61
62 /*
63         SETS CENTER POINT
64 */
65 void Transformer3D1Point::SetCenterPoint(std::vector<int> point)
66 {
67     _centerPoint=point;
68 }
69
70 /*
71         SETS THE ANGLE IN X
72 */
73 void Transformer3D1Point::SetAngleX(double angle)
74 {
75         _angleX=angle;
76 }
77
78 /*
79         SETS THE ANGLE IN Y
80 */
81 void Transformer3D1Point::SetAngleY(double angle)
82 {
83         _angleY=angle;
84 }
85
86 /*
87         SETS THE ANGLE IN Z
88 */
89 void Transformer3D1Point::SetAngleZ(double angle)
90 {
91         _angleZ=angle;
92 }
93
94 /*
95         SETS THE X SCALE
96 */
97 void Transformer3D1Point::SetScaleX(double scaleX)
98 {
99         _scaleX=scaleX/100.0;
100 }
101
102 /*
103         SETS THE Y SCALE
104 */
105 void Transformer3D1Point::SetScaleY(double scaleY)
106 {
107         _scaleY=scaleY/100.0;
108 }
109
110 /*
111  SETS THE Y SCALE
112  */
113 void Transformer3D1Point::SetScaleZ(double scaleZ)
114 {
115         _scaleZ=scaleZ/100.0;
116 }
117
118 /*
119         GETS THE RESULTANT TRANSFORM
120 */
121 vtkTransform *Transformer3D1Point::GetResult()
122 {
123         return _transform;
124 }
125
126 /*
127         MAKES THE TRANSFORMATIONS
128 */
129 void Transformer3D1Point::Run()
130 {       
131         //Clears any old transformations in the pipeline
132         _transform->Identity();
133
134         //Make all transformations in post multiply mode
135         _transform->PostMultiply();
136
137         //Centers the image before applying the transformation
138         _transform->Translate(-_centerPoint[0], -_centerPoint[1], -_centerPoint[2]);
139
140         
141         _transform->RotateWXYZ(_angleY, 0, 1, 0);
142         _transform->RotateWXYZ(_angleX, 1, 0, 0);
143         _transform->RotateWXYZ(_angleZ, 0, 0, 1);
144         _transform->Scale(_scaleX, _scaleY,_scaleZ);
145
146         //Returns the inverse of the transformation (NTU: Have no idea why we have to do this for the image to appear properly)
147         _transform->Inverse();  
148         _transform->Update();
149 }