13 #ifndef mitkMatrixConvert_h
14 #define mitkMatrixConvert_h
18 #include <vtkMatrix4x4.h>
37 template <
class TTransformType>
40 if (itkTransform ==
nullptr)
43 typename TTransformType::MatrixType::InternalMatrixType &vnlMatrix =
44 const_cast<typename TTransformType::MatrixType::InternalMatrixType &
>(itkTransform->GetMatrix().GetVnlMatrix());
46 for (
int i = 0; i < 3; ++i)
47 for (
int j = 0; j < 3; ++j)
48 vnlMatrix[i][j] = vtkmatrix->GetElement(i, j);
54 typename TTransformType::OffsetType offset;
55 offset[0] = vtkmatrix->GetElement(0, 3);
56 offset[1] = vtkmatrix->GetElement(1, 3);
57 offset[2] = vtkmatrix->GetElement(2, 3);
58 itkTransform->SetOffset(offset);
74 template <
class TTransformType>
78 for (i = 0; i < 3; ++i)
79 for (j = 0; j < 3; ++j)
80 vtkmatrix->SetElement(i, j, itkTransform->GetMatrix().GetVnlMatrix().get(i, j));
81 for (i = 0; i < 3; ++i)
82 vtkmatrix->SetElement(i, 3, itkTransform->GetOffset()[i]);
83 for (i = 0; i < 3; ++i)
84 vtkmatrix->SetElement(3, i, 0.0);
85 vtkmatrix->SetElement(3, 3, 1);
99 template <
class TTransformType1,
class TTransformType2>
102 if ((sourceTransform ==
nullptr) || (destTransform ==
nullptr))
105 destTransform->SetMatrix(sourceTransform->GetMatrix());
106 destTransform->SetOffset(sourceTransform->GetOffset());
121 template <
class TMatrixType>
127 typename TMatrixType::InternalMatrixType &outputVnlMatrix =
128 itkmatrix.GetVnlMatrix();
130 for (
int i = 0; i < 3; ++i)
131 for (
int j = 0; j < 3; ++j)
132 outputVnlMatrix[i][j] = geometryVnlMatrix[i][j] / spacing[j];
149 template <
class TTransformType>
152 if (itkTransform ==
nullptr)
156 typename TTransformType::MatrixType rotationMatrix;
159 const typename mitk::BaseGeometry::TransformType::OffsetType &geometryOffset =
162 vnl_vector<typename TTransformType::MatrixType::ValueType> vnlOffset(3);
163 vnlOffset[0] = geometryOffset[0];
164 vnlOffset[1] = geometryOffset[1];
165 vnlOffset[2] = geometryOffset[2];
168 typename TTransformType::MatrixType::InternalMatrixType inverseRotationVnlMatrix = rotationMatrix.GetTranspose();
170 vnlOffset -= inverseRotationVnlMatrix * vnlOffset;
172 typename TTransformType::OutputVectorType offset;
173 offset[0] = vnlOffset[0];
174 offset[1] = vnlOffset[1];
175 offset[2] = vnlOffset[2];
176 itkTransform->SetOffset(offset);
179 typename TTransformType::MatrixType::InternalMatrixType &destVnlMatrix =
180 itkTransform->GetMatrix().GetVnlMatrix();
182 for (
int i = 0; i < 3; ++i)
183 for (
int j = 0; j < 3; ++j)
184 destVnlMatrix[i][j] = inverseRotationVnlMatrix[i][j];
Abstract base class describing the geometry of a data object.
mitk::Vector3D GetSpacing() const
Get the spacing (voxel size) in mm per unit for each axis.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the affine transform that maps index coordinates to world coordinates.
Internal hack to set m_MatrixMTime of itk::MatrixOffsetTransformBase correctly after changing the mat...
Find image slices visible on a given plane.
void ConvertItkTransform(const TTransformType1 *sourceTransform, TTransformType2 *destTransform)
Convert between two ITK transform types by copying matrix and offset.
void TransferItkTransformToVtkMatrix(const TTransformType *itkTransform, vtkMatrix4x4 *vtkmatrix)
Transfer an ITK transform into a VTK 4x4 matrix.
void GetRotation(const mitk::BaseGeometry *geometry, TMatrixType &itkmatrix)
Extract the rotation matrix from a geometry, removing spacing.
void TransferVtkMatrixToItkTransform(const vtkMatrix4x4 *vtkmatrix, TTransformType *itkTransform)
Transfer a VTK 4x4 matrix into an ITK transform.
void GetWorldToItkPhysicalTransform(const mitk::BaseGeometry *geometry, TTransformType *itkTransform)
Compute the world-to-ITK-physical-space transform from a geometry.