2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 #include "Transformer3D.h"
29 #include "vtkMatrix4x4.h"
32 CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
34 Transformer3D::Transformer3D()
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();
41 _transform->SetMatrix(_matrix);
53 Transformer3D::~Transformer3D()
55 //We delete the existing transform
56 if (_transform != NULL ) { _transform->Delete(); }
62 void Transformer3D::SetTransform(vtkTransform *transform)
70 void Transformer3D::SetFirstTranslation(double* first)
72 _firstPoint[0]=first[0];
73 _firstPoint[1]=first[1];
74 _firstPoint[2]=first[2];
80 void Transformer3D::SetSecondTranslation(double* second)
82 _secondPoint[0]=second[0];
83 _secondPoint[1]=second[1];
84 _secondPoint[2]=second[2];
90 void Transformer3D::SetRotationAxis(double* axis)
92 _rotationAxis[0]=axis[0];
93 _rotationAxis[1]=axis[1];
94 _rotationAxis[2]=axis[2];
100 void Transformer3D::SetSecondRotationAxis(double axis[3])
102 _secondRotationAxis[0]=axis[0];
103 _secondRotationAxis[1]=axis[1];
104 _secondRotationAxis[2]=axis[2];
110 void Transformer3D::SetAngle(double angle)
116 SETS SECOND ROTATION ANGLE
118 void Transformer3D::SetSecondAngle(double angle)
125 GETS THE RESULTANT TRANSFORM
127 vtkTransform *Transformer3D::GetResult()
133 GETS THE FIRST RESULTANT TRANSFORM (NTU: Useful for calculating the new position of the points before applying the second rotation)
135 vtkTransform *Transformer3D::GetFirstResult()
137 _transform->Identity();
139 _transform->Translate(-_firstPoint[0], -_firstPoint[1], -_firstPoint[2]);
141 _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
143 _transform->Translate(_secondPoint[0], _secondPoint[1], _secondPoint[2]);
146 _transform->Update();
151 MAKES THE TRANSFORMATIONS
153 void Transformer3D::Run()
155 //Cleans the transformation matrix
156 _transform->Identity();
158 //Make all transformations in postmultiply mode
159 _transform->PostMultiply();
161 //Acomodate in 0,0,0 according to the first point of the second vector
162 _transform->Translate(-_secondPoint[0], -_secondPoint[1], -_secondPoint[2]);
164 _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
166 _transform->RotateWXYZ(_secondAngle, _secondRotationAxis[0], _secondRotationAxis[1], _secondRotationAxis[2]);
168 //Acommodate according to the first point of the first vector
169 _transform->Translate(_firstPoint[0], _firstPoint[1], _firstPoint[2]);
171 _transform->Inverse();
172 _transform->Update();