Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkArray.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkArray_h
14 #define mitkArray_h
15 
16 #include <itkFixedArray.h>
17 
18 #include <mitkEqual.h>
19 #include <mitkNumericConstants.h>
20 
21 namespace mitk
22 {
38  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
39  void FillArray(itk::FixedArray<TCoordRep, NVectorDimension> &toArray, const ArrayType &array)
40  {
41  for (unsigned short int var = 0; var < NVectorDimension; ++var)
42  {
43  toArray[var] = array[var];
44  }
45  }
46 
55  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
56  itk::FixedArray<TCoordRep, NVectorDimension> FillArray(const ArrayType &array)
57  {
58  itk::FixedArray<TCoordRep, NVectorDimension> vectorOrPoint;
59 
60  mitk::FillArray(vectorOrPoint, array);
61 
62  return vectorOrPoint;
63  }
64 
73  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
74  void ToArray(ArrayType &array, const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
75  {
76  for (unsigned short int var = 0; var < NVectorDimension; ++var)
77  {
78  array[var] = vectorOrPoint[var];
79  }
80  }
81 
90  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
91  ArrayType ToArray(const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
92  {
93  ArrayType result;
94 
95  mitk::ToArray(result, vectorOrPoint);
96 
97  return result;
98  }
99 
101  template <class Tout>
103  {
104  out[0] = x;
105  out[1] = y;
106  out[2] = z;
107  }
108 
110  template <class Tout>
112  {
113  out[0] = x;
114  out[1] = y;
115  out[2] = z;
116  out[3] = t;
117  }
118 
132  template <typename TArrayType1, typename TArrayType2>
133  inline bool EqualArray(
134  TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps = mitk::eps, bool verbose = false)
135  {
136  bool isEqual = true;
137  for (int var = 0; var < size; ++var)
138  {
139  isEqual = isEqual && Equal(arrayType1[var], arrayType2[var], eps);
140  }
141 
142  ConditionalOutputOfDifference(arrayType1, arrayType2, eps, verbose, isEqual);
143 
144  return isEqual;
145  }
146 }
147 
148 #endif
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
void FillArray(itk::FixedArray< TCoordRep, NVectorDimension > &toArray, const ArrayType &array)
Methods to copy between itk::FixedArray types (like mitk::Vector and mitk::Point) and ArrayTypes.
Definition: mitkArray.h:39
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Conditionally output the difference between two elements to the log.
Definition: mitkEqual.h:50
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Compare two array-like objects element-wise for equality within a tolerance.
Definition: mitkArray.h:133
void ToArray(ArrayType &array, const itk::FixedArray< TCoordRep, NVectorDimension > &vectorOrPoint)
Copy elements from an itk::FixedArray into an array.
Definition: mitkArray.h:74
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Fill a 3D array/vector with the given x, y, z values.
Definition: mitkArray.h:102
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Fill a 4D array/vector with the given x, y, z, t values.
Definition: mitkArray.h:111
double ScalarType
Scalar type used throughout MITK for geometric computations.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.