From: trillos Date: Wed, 2 Dec 2009 13:14:16 +0000 (+0000) Subject: Added transformer changes X-Git-Tag: CREATOOLS.2-0-3~14 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaRigidRegistration.git;a=commitdiff_plain;h=74f4f8e7e7e9a04fd303a14c0135d98bd3017af1 Added transformer changes --- diff --git a/lib/Transformer.cxx b/lib/Transformer.cxx index e6e6c8b..47b3980 100644 --- a/lib/Transformer.cxx +++ b/lib/Transformer.cxx @@ -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(); } diff --git a/lib/Transformer3D.cxx b/lib/Transformer3D.cxx index 2cdbabb..36cb6a9 100644 --- a/lib/Transformer3D.cxx +++ b/lib/Transformer3D.cxx @@ -7,15 +7,18 @@ */ Transformer3D::Transformer3D() { - std::vector 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 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(); } diff --git a/lib/Transformer3D.h b/lib/Transformer3D.h index 7f84d53..cd25fd4 100644 --- a/lib/Transformer3D.h +++ b/lib/Transformer3D.h @@ -10,12 +10,23 @@ public: Transformer3D(); ~Transformer3D(); void SetTransform(vtkTransform *transform); - void SetCenterPoint(std::vector 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 _centerPoint; + double _rotationAxis[3]; + double _secondRotationAxis[3]; + double _firstPoint[3]; + double _secondPoint[3]; + double _angle; + double _secondAngle; vtkTransform *_transform; };