Medical Imaging Interaction Toolkit  2024.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 
74  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
75  void ToArray(ArrayType &array, const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
76  {
77  for (unsigned short int var = 0; var < NVectorDimension; ++var)
78  {
79  array[var] = vectorOrPoint[var];
80  }
81  }
82 
92  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
93  ArrayType ToArray(const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
94  {
95  ArrayType result;
96 
97  mitk::ToArray(result, vectorOrPoint);
98 
99  return result;
100  }
101 
102  // The FillVector3D and FillVector4D methods are implemented for all common array types here
103 
104  template <class Tout>
106  {
107  out[0] = x;
108  out[1] = y;
109  out[2] = z;
110  }
111 
112  template <class Tout>
114  {
115  out[0] = x;
116  out[1] = y;
117  out[2] = z;
118  out[3] = t;
119  }
120 
126  template <typename TArrayType1, typename TArrayType2>
127  inline bool EqualArray(
128  TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps = mitk::eps, bool verbose = false)
129  {
130  bool isEqual = true;
131  for (int var = 0; var < size; ++var)
132  {
133  isEqual = isEqual && Equal(arrayType1[var], arrayType2[var], eps);
134  }
135 
136  ConditionalOutputOfDifference(arrayType1, arrayType2, eps, verbose, isEqual);
137 
138  return isEqual;
139  }
140 }
141 
142 #endif
mitk::eps
const MITKCORE_EXPORT ScalarType eps
mitk::FillVector4D
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Definition: mitkArray.h:113
mitk::ToArray
void ToArray(ArrayType &array, const itk::FixedArray< TCoordRep, NVectorDimension > &vectorOrPoint)
Copies the elements of this into an array.
Definition: mitkArray.h:75
mitk::Equal
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.
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::FillVector3D
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:105
mitkNumericConstants.h
mitkEqual.h
mitk::ConditionalOutputOfDifference
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:48
mitk::FillArray
void FillArray(itk::FixedArray< TCoordRep, NVectorDimension > &toArray, const ArrayType &array)
Copies elements of an array to this Vector.
Definition: mitkArray.h:39
mitk::EqualArray
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:127
mitk::ScalarType
double ScalarType
Definition: mitkNumericConstants.h:20