]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer3D.cxx
Black box that generates a grid over an image in order to visualize the deformation...
[creaRigidRegistration.git] / lib / Transformer3D.cxx
1
2 #include "Transformer3D.h"
3 #include "vtkMatrix4x4.h"
4
5 /*
6         CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
7 */
8 Transformer3D::Transformer3D() 
9 {
10         //If the transform already exists, we delete it before we create a new transform 
11         //and set the matrix with the identity matrix
12         _transform= vtkTransform::New();
13         vtkMatrix4x4 *_matrix = vtkMatrix4x4::New();
14         _matrix->Identity();
15         _transform->SetMatrix(_matrix);
16         _firstPoint[0] = 0;
17         _firstPoint[1] = 0;
18         _firstPoint[2] = 0;
19         _secondPoint[0] = 0;
20         _secondPoint[1] = 0;
21         _secondPoint[2] = 0;
22 }
23
24 /*
25         DESTRUCTOR
26 */
27 Transformer3D::~Transformer3D()
28 {
29         //We delete the existing transform
30         if (_transform != NULL ) { _transform->Delete(); }
31 }
32
33 /*
34         SETS A NEW TRANSFORM
35 */
36 void Transformer3D::SetTransform(vtkTransform *transform)
37 {
38         _transform=transform;
39 }
40
41 /*
42         SETS FIRST POINT
43 */
44 void Transformer3D::SetFirstTranslation(double* first)
45 {
46     _firstPoint[0]=first[0];
47         _firstPoint[1]=first[1];
48         _firstPoint[2]=first[2];
49 }
50
51 /*
52         SETS SECOND POINT
53 */
54 void Transformer3D::SetSecondTranslation(double* second)
55 {
56     _secondPoint[0]=second[0];
57         _secondPoint[1]=second[1];
58         _secondPoint[2]=second[2];
59 }
60
61 /*
62         SETS ROTATION AXIS
63 */
64 void Transformer3D::SetRotationAxis(double* axis)
65 {
66     _rotationAxis[0]=axis[0];
67         _rotationAxis[1]=axis[1];
68         _rotationAxis[2]=axis[2];
69 }
70
71 /*
72         SETS ROTATION AXIS
73 */
74 void Transformer3D::SetSecondRotationAxis(double axis[3])
75 {
76     _secondRotationAxis[0]=axis[0];
77         _secondRotationAxis[1]=axis[1];
78         _secondRotationAxis[2]=axis[2];
79 }
80
81 /*
82         SETS ROTATION ANGLE
83 */
84 void Transformer3D::SetAngle(double angle)
85 {
86     _angle=angle;
87 }
88
89 /*
90         SETS SECOND ROTATION ANGLE
91 */
92 void Transformer3D::SetSecondAngle(double angle)
93 {
94     _secondAngle=angle;
95 }
96
97
98 /*
99         GETS THE RESULTANT TRANSFORM
100 */
101 vtkTransform *Transformer3D::GetResult()
102 {
103         return _transform;
104 }
105
106 /*
107         GETS THE FIRST RESULTANT TRANSFORM (NTU: Useful for calculating the new position of the points before applying the second rotation)
108 */
109 vtkTransform *Transformer3D::GetFirstResult()
110 {
111         _transform->Identity();
112
113         _transform->Translate(-_firstPoint[0], -_firstPoint[1], -_firstPoint[2]);
114
115         _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
116
117         _transform->Translate(_secondPoint[0], _secondPoint[1], _secondPoint[2]);
118
119         
120         _transform->Update();   
121         return _transform;
122 }
123
124 /*
125         MAKES THE TRANSFORMATIONS
126 */
127 void Transformer3D::Run()
128 {       
129         //Cleans the transformation matrix
130         _transform->Identity();
131
132         //Make all transformations in postmultiply mode
133         _transform->PostMultiply();
134
135         //Acomodate in 0,0,0 according to the first point of the second vector
136         _transform->Translate(-_secondPoint[0], -_secondPoint[1], -_secondPoint[2]);
137
138         _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
139
140         _transform->RotateWXYZ(_secondAngle, _secondRotationAxis[0], _secondRotationAxis[1], _secondRotationAxis[2]);
141
142         //Acommodate according to the first point of the first vector
143         _transform->Translate(_firstPoint[0], _firstPoint[1], _firstPoint[2]);  
144         
145         _transform->Inverse();
146         _transform->Update();
147 }