17 #ifndef MITKMATRIXCONVERT_H_HEADER_INCLUDED_C1EBD0AD
18 #define MITKMATRIXCONVERT_H_HEADER_INCLUDED_C1EBD0AD
22 #include <vtkMatrix4x4.h>
26 template <
class TTransformType>
29 if (itkTransform ==
nullptr)
32 typename TTransformType::MatrixType::InternalMatrixType &vnlMatrix =
33 const_cast<typename TTransformType::MatrixType::InternalMatrixType &
>(itkTransform->GetMatrix().GetVnlMatrix());
35 for (
int i = 0; i < 3; ++i)
36 for (
int j = 0; j < 3; ++j)
37 vnlMatrix[i][j] = vtkmatrix->GetElement(i, j);
43 typename TTransformType::OffsetType
offset;
44 offset[0] = vtkmatrix->GetElement(0, 3);
45 offset[1] = vtkmatrix->GetElement(1, 3);
46 offset[2] = vtkmatrix->GetElement(2, 3);
47 itkTransform->SetOffset(offset);
50 template <
class TTransformType>
54 for (i = 0; i < 3; ++i)
55 for (j = 0; j < 3; ++j)
56 vtkmatrix->SetElement(i, j, itkTransform->GetMatrix().GetVnlMatrix().get(i, j));
57 for (i = 0; i < 3; ++i)
58 vtkmatrix->SetElement(i, 3, itkTransform->GetOffset()[i]);
59 for (i = 0; i < 3; ++i)
60 vtkmatrix->SetElement(3, i, 0.0);
61 vtkmatrix->SetElement(3, 3, 1);
64 template <
class TTransformType1,
class TTransformType2>
67 if ((sourceTransform == NULL) || (destTransform == NULL))
71 const typename TTransformType1::OutputVectorType &sourceOffset = sourceTransform->GetOffset();
73 typename TTransformType2::OutputVectorType
offset;
74 offset[0] = sourceOffset[0];
75 offset[1] = sourceOffset[1];
76 offset[2] = sourceOffset[2];
77 destTransform->SetOffset(offset);
79 typename TTransformType1::MatrixType::InternalMatrixType &sourceVnlMatrix =
80 const_cast<typename TTransformType1::MatrixType::InternalMatrixType &
>(
81 sourceTransform->GetMatrix().GetVnlMatrix());
84 typename TTransformType2::MatrixType::InternalMatrixType &destVnlMatrix =
85 const_cast<typename TTransformType2::MatrixType::InternalMatrixType &
>(destTransform->GetMatrix().GetVnlMatrix());
87 for (
int i = 0; i < 3; ++i)
88 for (
int j = 0; j < 3; ++j)
89 destVnlMatrix[i][j] = sourceVnlMatrix[i][j];
97 template <
class TMatrixType>
101 typename mitk::BaseGeometry::TransformType::MatrixType::InternalMatrixType &geometryVnlMatrix =
102 const_cast<typename mitk::BaseGeometry::TransformType::MatrixType::InternalMatrixType &
>(
105 typename TMatrixType::InternalMatrixType &outputVnlMatrix =
106 const_cast<typename TMatrixType::InternalMatrixType &
>(itkmatrix.GetVnlMatrix());
108 for (
int i = 0; i < 3; ++i)
109 for (
int j = 0; j < 3; ++j)
110 outputVnlMatrix[i][j] = geometryVnlMatrix[i][j] / spacing[j];
113 template <
class TTransformType>
116 if (itkTransform ==
nullptr)
120 typename TTransformType::MatrixType rotationMatrix;
123 const typename mitk::BaseGeometry::TransformType::OffsetType &geometryOffset =
126 vnl_vector<typename TTransformType::MatrixType::ValueType> vnlOffset(3);
127 vnlOffset[0] = geometryOffset[0];
128 vnlOffset[1] = geometryOffset[1];
129 vnlOffset[2] = geometryOffset[2];
132 typename TTransformType::MatrixType::InternalMatrixType inverseRotationVnlMatrix = rotationMatrix.GetTranspose();
134 vnlOffset -= inverseRotationVnlMatrix * vnlOffset;
136 typename TTransformType::OutputVectorType
offset;
137 offset[0] = vnlOffset[0];
138 offset[1] = vnlOffset[1];
139 offset[2] = vnlOffset[2];
140 itkTransform->SetOffset(offset);
143 typename TTransformType::MatrixType::InternalMatrixType &destVnlMatrix =
144 const_cast<typename TTransformType::MatrixType::InternalMatrixType &
>(itkTransform->GetMatrix().GetVnlMatrix());
146 for (
int i = 0; i < 3; ++i)
147 for (
int j = 0; j < 3; ++j)
148 destVnlMatrix[i][j] = inverseRotationVnlMatrix[i][j];
void TransferVtkMatrixToItkTransform(const vtkMatrix4x4 *vtkmatrix, TTransformType *itkTransform)
Internal hack to set m_MatrixMTime of itk::MatrixOffsetTransformBase correctly after changing the mat...
void GetRotation(const mitk::BaseGeometry *geometry, TMatrixType &itkmatrix)
void GetWorldToItkPhysicalTransform(const mitk::BaseGeometry *geometry, TTransformType *itkTransform)
DataCollection - Class to facilitate loading/accessing structured data.
void ConvertItkTransform(const TTransformType1 *sourceTransform, TTransformType2 *destTransform)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
void TransferItkTransformToVtkMatrix(const TTransformType *itkTransform, vtkMatrix4x4 *vtkmatrix)
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.