13 #ifndef mitkMatrixConvert_h
14 #define mitkMatrixConvert_h
18 #include <vtkMatrix4x4.h>
22 template <
class TTransformType>
25 if (itkTransform ==
nullptr)
28 typename TTransformType::MatrixType::InternalMatrixType &vnlMatrix =
29 const_cast<typename TTransformType::MatrixType::InternalMatrixType &
>(itkTransform->GetMatrix().GetVnlMatrix());
31 for (
int i = 0; i < 3; ++i)
32 for (
int j = 0; j < 3; ++j)
33 vnlMatrix[i][j] = vtkmatrix->GetElement(i, j);
39 typename TTransformType::OffsetType offset;
40 offset[0] = vtkmatrix->GetElement(0, 3);
41 offset[1] = vtkmatrix->GetElement(1, 3);
42 offset[2] = vtkmatrix->GetElement(2, 3);
43 itkTransform->SetOffset(offset);
46 template <
class TTransformType>
50 for (i = 0; i < 3; ++i)
51 for (j = 0; j < 3; ++j)
52 vtkmatrix->SetElement(i, j, itkTransform->GetMatrix().GetVnlMatrix().get(i, j));
53 for (i = 0; i < 3; ++i)
54 vtkmatrix->SetElement(i, 3, itkTransform->GetOffset()[i]);
55 for (i = 0; i < 3; ++i)
56 vtkmatrix->SetElement(3, i, 0.0);
57 vtkmatrix->SetElement(3, 3, 1);
60 template <
class TTransformType1,
class TTransformType2>
63 if ((sourceTransform ==
nullptr) || (destTransform ==
nullptr))
66 destTransform->SetMatrix(sourceTransform->GetMatrix());
67 destTransform->SetOffset(sourceTransform->GetOffset());
70 template <
class TMatrixType>
76 typename TMatrixType::InternalMatrixType &outputVnlMatrix =
77 itkmatrix.GetVnlMatrix();
79 for (
int i = 0; i < 3; ++i)
80 for (
int j = 0; j < 3; ++j)
81 outputVnlMatrix[i][j] = geometryVnlMatrix[i][j] / spacing[j];
84 template <
class TTransformType>
87 if (itkTransform ==
nullptr)
91 typename TTransformType::MatrixType rotationMatrix;
94 const typename mitk::BaseGeometry::TransformType::OffsetType &geometryOffset =
97 vnl_vector<typename TTransformType::MatrixType::ValueType> vnlOffset(3);
98 vnlOffset[0] = geometryOffset[0];
99 vnlOffset[1] = geometryOffset[1];
100 vnlOffset[2] = geometryOffset[2];
103 typename TTransformType::MatrixType::InternalMatrixType inverseRotationVnlMatrix = rotationMatrix.GetTranspose();
105 vnlOffset -= inverseRotationVnlMatrix * vnlOffset;
107 typename TTransformType::OutputVectorType offset;
108 offset[0] = vnlOffset[0];
109 offset[1] = vnlOffset[1];
110 offset[2] = vnlOffset[2];
111 itkTransform->SetOffset(offset);
114 typename TTransformType::MatrixType::InternalMatrixType &destVnlMatrix =
115 itkTransform->GetMatrix().GetVnlMatrix();
117 for (
int i = 0; i < 3; ++i)
118 for (
int j = 0; j < 3; ++j)
119 destVnlMatrix[i][j] = inverseRotationVnlMatrix[i][j];