]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer.cxx
ed1b25ba8021c4495a356b11295f03c941ccff9a
[creaRigidRegistration.git] / lib / Transformer.cxx
1
2 #include "Transformer.h"
3 #include "vtkMatrix4x4.h"
4
5 /*
6         CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
7 */
8 Transformer::Transformer() 
9 {
10         std::vector<int> empty (3,0); 
11         _angle= 0;
12         _centerPoint=empty;
13         _scaleX=1;
14         _scaleY=1;
15         //If the transform already exists, we delete it before we create a new transform 
16         //and set the matrix with the identity matrix
17         _transform= vtkTransform::New();
18         vtkMatrix4x4 *_matrix = vtkMatrix4x4::New();
19         _matrix->Identity();
20         _transform->SetMatrix(_matrix);
21         
22 }
23
24 /*
25         DESTRUCTOR
26 */
27 Transformer::~Transformer()
28 {
29         //We delete the existing transform
30         if (_transform != NULL ) { _transform->Delete(); }
31 }
32
33 /*
34         SETS A NEW TRANSFORM
35 */
36 void Transformer::SetTransform(vtkTransform *transform)
37 {
38         _transform=transform;
39 }
40
41 /*
42         SETS CENTER POINT
43 */
44 void Transformer::SetCenterPoint(std::vector<int> point)
45 {
46     _centerPoint=point;
47 }
48
49 /*
50         SETS AXIS POINT
51 */
52 void Transformer::SetAxis(std::vector<double> axis)
53 {
54     _transformAxis=axis;
55 }
56
57 /*
58         SETS THE ANGLE
59 */
60 void Transformer::SetAngle(double angle)
61 {
62         _angle=angle;
63 }
64
65 /*
66         SETS THE X SCALE
67 */
68 void Transformer::SetScaleX(double scaleX)
69 {
70         _scaleX=scaleX/100.0;
71 }
72
73 /*
74         SETS THE Y SCALE
75 */
76 void Transformer::SetScaleY(double scaleY)
77 {
78         _scaleY=scaleY/100.0;
79 }
80
81 /*
82  SETS THE Y SCALE
83  */
84 void Transformer::SetScaleZ(double scaleZ)
85 {
86         _scaleZ=scaleZ/100.0;
87 }
88
89
90
91 /*
92         GETS THE RESULTANT TRANSFORM
93 */
94 vtkTransform *Transformer::GetResult()
95 {
96         return _transform;
97 }
98
99 /*
100         MAKES THE TRANSFORMATIONS
101 */
102 void Transformer::Run(bool _3D)
103 {       
104         _transform->Identity();
105         _transform->Translate(_centerPoint[0], _centerPoint[1], _centerPoint[2]);
106         _transform->Scale(_scaleX, _scaleY,_scaleZ);
107         if(_3D)
108         {
109                 _transform->RotateWXYZ(_angle, _transformAxis[0], _transformAxis[1], _transformAxis[2]);                
110         }
111         else
112         {
113                 _transform->RotateWXYZ(_angle, 0, 0, 1);
114         }
115         
116         _transform->Update();
117 }