Medical Imaging Interaction Toolkit  2022.04.99-8b707dbd
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 /* MITKARRAY_H_ */
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:127
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:55
MITKCORE_EXPORT const ScalarType eps
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:105
void FillArray(itk::FixedArray< TCoordRep, NVectorDimension > &toArray, const ArrayType &array)
Copies elements of an array to this Vector.
Definition: mitkArray.h:39
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.
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Definition: mitkArray.h:113
void ToArray(ArrayType &array, const itk::FixedArray< TCoordRep, NVectorDimension > &vectorOrPoint)
Copies the elements of this into an array.
Definition: mitkArray.h:75