Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
Numeric MITK data types and their usage.

This page describes how to use very foundational data-tyes in MITK like mitk::Vector, mitk::Point and mitk::Matrix and how they can interact.

Structure

The previously known, monolythic structure of putting every basic type into mitkVector.h has been broken and mitkVector.h has been split up into several, more atomic files, namely:

  1. mitkNumericConstants.h : contains basic constants like mitk::ScalarType or mitk::eps
  2. mitkArray.h : copy itk::FixedArrays (like itk::Point and itk::Vector) from and to types which implement the [] operator (array-types), like e.g. Plain Old Datatypes (POD)
  3. mitkPoint.h : the mitk::Point class. This is basically the itk::Point with the added ToArray and Fill members to conveniently copy from and to array-types. In MITK, a point is considered a fixed geometric location and thus cannot be summed or multiplied.
  4. mitkVector.h : the mitk::Vector class. This is an itk::Vector, but with the possibility to implicitly convert to vnl_vector and vnl_vector_fixed. In MITK, vectors denote directions and can be summed or multiplied with scalars.
  5. mitkMatrix.h : the mitk::Matrix class. This is an itk::Matrix with the added ToArray and Fill members to conveniently copy from and to array-types.
  6. mitkQuaternion.h : a typedef to vnl_quaternion.
  7. mitkAffineTransform3D.h : a typedef to itk::ScalableAffineTransform<ScalarType, 3>
  8. mitkNumericTypes.h : this file includes all of the above as a convenience header

The Equal methods to compare Points, Vectors, Matrices, ... have been moved into the respective files. E.g., if you want to compare two vectors simply use the Equal method provided by mitkVector.h.

Conversion between the data-types

If you want to convert a mitk::Vector from or to a vnl_vector or a vnl_vector_fixed, simply write

mitkVector3D = vnlVector3D;
vnlVector3D_2 = mitkVector3D;

Unfortunately this mechanism couldn't be implemented to every type of conversion. But in any case, the ToArray and FillVector/FillPoint/FillMatrix member functions can be used to convert to array-types. E.g.,

cv::Vec3d cvVec3D;
mitkVector3D.ToArray(cvVec3D);
mitkVector3D_2.FillVector(cvVec3D);

No implicit conversion from mitk::Point to mitk::Vector was implemented as this would break with itk's concept of separating points and vectors. If you want to convert, use:

mitkVector3D = mitkPoint3D.GetVectorFromOrigin();
mitkPoint3D_2 = mitkVector3D;

more examples of how to convert between data types can be found in the tests:

  1. mitkArrayTypeConversionTest.cpp
  2. mitkPointTypeConversionTest.cpp
  3. mitkVectorTypeConversionTest.cpp
  4. mitkMatrixTypeConversionTest.cpp