]> Creatis software - creaRigidRegistration.git/commitdiff
Added transformer changes
authortrillos <trillos>
Wed, 2 Dec 2009 13:14:16 +0000 (13:14 +0000)
committertrillos <trillos>
Wed, 2 Dec 2009 13:14:16 +0000 (13:14 +0000)
lib/Transformer.cxx
lib/Transformer3D.cxx
lib/Transformer3D.h

index e6e6c8b5ce8091c40d034173498d26ec8165a762..47b3980c78a4d022630da00be691fd8d5edd9b0b 100644 (file)
@@ -93,11 +93,15 @@ vtkTransform *Transformer::GetResult()
 */
 void Transformer::Run()
 {      
+       
        _transform->Identity();
-       _transform->Translate(_centerPoint[0], _centerPoint[1], _centerPoint[2]);
+       _transform->PostMultiply();
+       _transform->Translate(-_centerPoint[0], -_centerPoint[1], -_centerPoint[2]);
 
        _transform->RotateWXYZ(_angle, 0, 0, 1);
        _transform->Scale(_scaleX, _scaleY,_scaleZ);
+       
                
+       _transform->Inverse();
        _transform->Update();
 }
index 2cdbabbc5c137a472b752a6ab033e6e0a2ee0402..36cb6a9c0b1ba09282c43f66171f5058f62876f1 100644 (file)
@@ -7,15 +7,18 @@
 */
 Transformer3D::Transformer3D() 
 {
-       std::vector<int> empty (3,0); 
-       _centerPoint=empty;     
        //If the transform already exists, we delete it before we create a new transform 
        //and set the matrix with the identity matrix
        _transform= vtkTransform::New();
        vtkMatrix4x4 *_matrix = vtkMatrix4x4::New();
        _matrix->Identity();
        _transform->SetMatrix(_matrix);
-       
+       _firstPoint[0] = 0;
+       _firstPoint[1] = 0;
+       _firstPoint[2] = 0;
+       _secondPoint[0] = 0;
+       _secondPoint[1] = 0;
+       _secondPoint[2] = 0;
 }
 
 /*
@@ -36,11 +39,59 @@ void Transformer3D::SetTransform(vtkTransform *transform)
 }
 
 /*
-       SETS CENTER POINT
+       SETS FIRST POINT
+*/
+void Transformer3D::SetFirstTranslation(double* first)
+{
+    _firstPoint[0]=first[0];
+       _firstPoint[1]=first[1];
+       _firstPoint[2]=first[2];
+}
+
+/*
+       SETS SECOND POINT
+*/
+void Transformer3D::SetSecondTranslation(double* second)
+{
+    _secondPoint[0]=second[0];
+       _secondPoint[1]=second[1];
+       _secondPoint[2]=second[2];
+}
+
+/*
+       SETS ROTATION AXIS
+*/
+void Transformer3D::SetRotationAxis(double* axis)
+{
+    _rotationAxis[0]=axis[0];
+       _rotationAxis[1]=axis[1];
+       _rotationAxis[2]=axis[2];
+}
+
+/*
+       SETS ROTATION AXIS
+*/
+void Transformer3D::SetSecondRotationAxis(double axis[3])
+{
+    _secondRotationAxis[0]=axis[0];
+       _secondRotationAxis[1]=axis[1];
+       _secondRotationAxis[2]=axis[2];
+}
+
+/*
+       SETS ROTATION ANGLE
 */
-void Transformer3D::SetCenterPoint(std::vector<int> point)
+void Transformer3D::SetAngle(double angle)
 {
-    _centerPoint=point;
+    _angle=angle;
+}
+
+/*
+       SETS SECOND ROTATION ANGLE
+*/
+void Transformer3D::SetSecondAngle(double angle)
+{
+    _secondAngle=angle;
 }
 
 
@@ -52,17 +103,45 @@ vtkTransform *Transformer3D::GetResult()
        return _transform;
 }
 
+/*
+       GETS THE FIRST RESULTANT TRANSFORM (NTU: Useful for calculating the new position of the points before applying the second rotation)
+*/
+vtkTransform *Transformer3D::GetFirstResult()
+{
+       _transform->Identity();
+
+       _transform->Translate(-_firstPoint[0], -_firstPoint[1], -_firstPoint[2]);
+
+       _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
+
+       _transform->Translate(_secondPoint[0], _secondPoint[1], _secondPoint[2]);
+
+       
+       _transform->Update();   
+       return _transform;
+}
+
 /*
        MAKES THE TRANSFORMATIONS
 */
 void Transformer3D::Run()
 {      
+       //Cleans the transformation matrix
        _transform->Identity();
-       std::cout << "Center points transform 3D: " << "X: " << _centerPoint[0] << "Y: " << _centerPoint[1] << "Z: " << _centerPoint[2] << std::endl;
-       _transform->Translate(_centerPoint[0], _centerPoint[1], _centerPoint[2]);
 
-       //_transform->Scale(_scaleX, _scaleY,_scaleZ);
-       //_transform->RotateWXYZ(_angle, 0, 0, 1);
+       //Make all transformations in postmultiply mode
+       _transform->PostMultiply();
+
+       //Acomodate in 0,0,0 according to the first point of the second vector
+       _transform->Translate(-_secondPoint[0], -_secondPoint[1], -_secondPoint[2]);
+
+       _transform->RotateWXYZ(_angle, _rotationAxis[0], _rotationAxis[1], _rotationAxis[2]);
+
+       _transform->RotateWXYZ(_secondAngle, _secondRotationAxis[0], _secondRotationAxis[1], _secondRotationAxis[2]);
+
+       //Acommodate according to the first point of the first vector
+       _transform->Translate(_firstPoint[0], _firstPoint[1], _firstPoint[2]);  
        
+       _transform->Inverse();
        _transform->Update();
 }
index 7f84d53594e6fd50b15aad3fc648dc71d850b8dc..cd25fd429abee3eb1211e070755cefd5c78cf684 100644 (file)
@@ -10,12 +10,23 @@ public:
        Transformer3D();
     ~Transformer3D();
        void SetTransform(vtkTransform *transform);
-       void SetCenterPoint(std::vector<int> point);    
+       void SetRotationAxis(double* axis);
+       void SetFirstTranslation(double* first);
+       void SetSecondTranslation(double* second);
+       void SetSecondRotationAxis(double* axis);
+       void SetAngle(double angle);
+       void SetSecondAngle(double angle);
        void Run();
        
     vtkTransform *GetResult();
+       vtkTransform *GetFirstResult();
 private:
-       std::vector<int> _centerPoint;
+       double _rotationAxis[3];
+       double _secondRotationAxis[3];
+       double _firstPoint[3];
+       double _secondPoint[3];
+       double _angle;
+       double _secondAngle;
        
        vtkTransform *_transform;
 };