]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer3D.cxx
#2810 crea RigidRegistration Bug New Normal - update Transform3D3PointsBox
[creaRigidRegistration.git] / lib / Transformer3D.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 "Transformer3D.h"
29 #include "vtkMatrix4x4.h"
30
31 /*
32         CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
33 */
34 Transformer3D::Transformer3D() 
35 {
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         vtkMatrix4x4 *_matrix = vtkMatrix4x4::New();
40         _matrix->Identity();
41         _transform->SetMatrix(_matrix);
42         _firstPoint[0] = 0;
43         _firstPoint[1] = 0;
44         _firstPoint[2] = 0;
45         _secondPoint[0] = 0;
46         _secondPoint[1] = 0;
47         _secondPoint[2] = 0;
48 }
49
50 /*
51         DESTRUCTOR
52 */
53 Transformer3D::~Transformer3D()
54 {
55         //We delete the existing transform
56         if (_transform != NULL ) { _transform->Delete(); }
57 }
58
59 /*
60         SETS A NEW TRANSFORM
61 */
62 void Transformer3D::SetTransform(vtkTransform *transform)
63 {
64         _transform=transform;
65 }
66
67 /*
68         SETS FIRST POINT
69 */
70 void Transformer3D::SetFirstTranslation(double* first)
71 {
72     _firstPoint[0]=first[0];
73         _firstPoint[1]=first[1];
74         _firstPoint[2]=first[2];
75 }
76
77 /*
78         SETS SECOND POINT
79 */
80 void Transformer3D::SetSecondTranslation(double* second)
81 {
82     _secondPoint[0]=second[0];
83         _secondPoint[1]=second[1];
84         _secondPoint[2]=second[2];
85 }
86
87 /*
88         SETS ROTATION AXIS
89 */
90 void Transformer3D::SetRotationAxis(double* axis)
91 {
92     _rotationAxis[0]=axis[0];
93         _rotationAxis[1]=axis[1];
94         _rotationAxis[2]=axis[2];
95 }
96
97 /*
98         SETS ROTATION AXIS
99 */
100 void Transformer3D::SetSecondRotationAxis(double axis[3])
101 {
102     _secondRotationAxis[0]=axis[0];
103         _secondRotationAxis[1]=axis[1];
104         _secondRotationAxis[2]=axis[2];
105 }
106
107 /*
108         SETS ROTATION ANGLE
109 */
110 void Transformer3D::SetAngle(double angle)
111 {
112     _angle=angle;
113 }
114
115 /*
116         SETS SECOND ROTATION ANGLE
117 */
118 void Transformer3D::SetSecondAngle(double angle)
119 {
120     _secondAngle=angle;
121 }
122
123
124 void Transformer3D::SetScale(double scale)
125 {
126     _scale=scale;
127 }
128
129
130
131
132 /*
133         GETS THE RESULTANT TRANSFORM
134 */
135 vtkTransform *Transformer3D::GetResult()
136 {
137         return _transform;
138 }
139
140 /*
141         GETS THE FIRST RESULTANT TRANSFORM (NTU: Useful for calculating the new position of the points before applying the second rotation)
142 */
143 vtkTransform *Transformer3D::GetFirstResult()
144 {
145         _transform->Identity();
146         _transform->Translate(-_firstPoint[0], -_firstPoint[1], -_firstPoint[2]);
147         _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
148         _transform->Translate(_secondPoint[0], _secondPoint[1], _secondPoint[2]);
149         _transform->Update();   
150         return _transform;
151 }
152
153 /*
154         MAKES THE TRANSFORMATIONS
155 */
156 void Transformer3D::Run()
157 {       
158         //Cleans the transformation matrix
159         _transform->Identity();
160         //Make all transformations in postmultiply mode
161         _transform->PostMultiply();
162         //Acomodate in 0,0,0 according to the first point of the second vector
163         _transform->Translate(-_secondPoint[0], -_secondPoint[1], -_secondPoint[2]);
164         _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
165         _transform->RotateWXYZ(_secondAngle, _secondRotationAxis[0], _secondRotationAxis[1], _secondRotationAxis[2]);
166 printf("EED Transformer3D::Run %f %f\n", _angle, _secondAngle);
167         _transform->Scale(_scale,_scale,_scale);
168         //Acommodate according to the first point of the first vector
169         _transform->Translate(_firstPoint[0], _firstPoint[1], _firstPoint[2]);  
170         _transform->Inverse();
171         _transform->Update();
172 }
173