*/
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;
}
/*
}
/*
- 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;
}
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();
}
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;
};