2 #include "Transformer3D.h"
3 #include "vtkMatrix4x4.h"
6 CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
8 Transformer3D::Transformer3D()
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();
15 _transform->SetMatrix(_matrix);
27 Transformer3D::~Transformer3D()
29 //We delete the existing transform
30 if (_transform != NULL ) { _transform->Delete(); }
36 void Transformer3D::SetTransform(vtkTransform *transform)
44 void Transformer3D::SetFirstTranslation(double* first)
46 _firstPoint[0]=first[0];
47 _firstPoint[1]=first[1];
48 _firstPoint[2]=first[2];
54 void Transformer3D::SetSecondTranslation(double* second)
56 _secondPoint[0]=second[0];
57 _secondPoint[1]=second[1];
58 _secondPoint[2]=second[2];
64 void Transformer3D::SetRotationAxis(double* axis)
66 _rotationAxis[0]=axis[0];
67 _rotationAxis[1]=axis[1];
68 _rotationAxis[2]=axis[2];
74 void Transformer3D::SetSecondRotationAxis(double axis[3])
76 _secondRotationAxis[0]=axis[0];
77 _secondRotationAxis[1]=axis[1];
78 _secondRotationAxis[2]=axis[2];
84 void Transformer3D::SetAngle(double angle)
90 SETS SECOND ROTATION ANGLE
92 void Transformer3D::SetSecondAngle(double angle)
99 GETS THE RESULTANT TRANSFORM
101 vtkTransform *Transformer3D::GetResult()
107 GETS THE FIRST RESULTANT TRANSFORM (NTU: Useful for calculating the new position of the points before applying the second rotation)
109 vtkTransform *Transformer3D::GetFirstResult()
111 _transform->Identity();
113 _transform->Translate(-_firstPoint[0], -_firstPoint[1], -_firstPoint[2]);
115 _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
117 _transform->Translate(_secondPoint[0], _secondPoint[1], _secondPoint[2]);
120 _transform->Update();
125 MAKES THE TRANSFORMATIONS
127 void Transformer3D::Run()
129 //Cleans the transformation matrix
130 _transform->Identity();
132 //Make all transformations in postmultiply mode
133 _transform->PostMultiply();
135 //Acomodate in 0,0,0 according to the first point of the second vector
136 _transform->Translate(-_secondPoint[0], -_secondPoint[1], -_secondPoint[2]);
138 _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
140 _transform->RotateWXYZ(_secondAngle, _secondRotationAxis[0], _secondRotationAxis[1], _secondRotationAxis[2]);
142 //Acommodate according to the first point of the first vector
143 _transform->Translate(_firstPoint[0], _firstPoint[1], _firstPoint[2]);
145 _transform->Inverse();
146 _transform->Update();