]> Creatis software - creaRigidRegistration.git/blob - lib/Transformer.cxx
Added template methods
[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         _matrix = vtkMatrix4x4::New();
19         _matrix->Identity();
20         _transform->SetMatrix(_matrix); 
21 }
22
23 /*
24         DESTRUCTOR
25 */
26 Transformer::~Transformer()
27 {
28         //We delete the existing transform
29         if (_transform != NULL ) { _transform->Delete(); }
30         if (_matrix != NULL ) { _matrix->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 THE ANGLE
51 */
52 void Transformer::SetAngle(double angle)
53 {
54         _angle=angle;
55 }
56
57 /*
58         SETS THE X SCALE
59 */
60 void Transformer::SetScaleX(double scaleX)
61 {
62         _scaleX=scaleX/100.0;
63 }
64
65 /*
66         SETS THE Y SCALE
67 */
68 void Transformer::SetScaleY(double scaleY)
69 {
70         _scaleY=scaleY/100.0;
71 }
72
73 /*
74  SETS THE Y SCALE
75  */
76 void Transformer::SetScaleZ(double scaleZ)
77 {
78         _scaleZ=scaleZ/100.0;
79 }
80
81
82
83 /*
84         GETS THE RESULTANT TRANSFORM
85 */
86 vtkTransform *Transformer::GetResult()
87 {
88         return _transform;
89 }
90
91 /*
92         MAKES THE TRANSFORMATIONS
93 */
94 void Transformer::Run()
95 {       
96         _transform->Identity();
97         _transform->Translate(_centerPoint[0], _centerPoint[1], _centerPoint[2]);
98
99         _transform->RotateWXYZ(_angle, 0, 0, 1);
100         _transform->Scale(_scaleX, _scaleY,_scaleZ);
101                 
102         _transform->Update();
103 }