Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
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  itk::FixedArray<TCoordRep, NVectorDimension> vectorOrPoint;
42  for (unsigned short int var = 0; var < NVectorDimension; ++var)
43  {
44  toArray[var] = array[var];
45  }
46  }
47 
56  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
57  itk::FixedArray<TCoordRep, NVectorDimension> FillArray(const ArrayType &array)
58  {
59  itk::FixedArray<TCoordRep, NVectorDimension> vectorOrPoint;
60 
61  mitk::FillArray(vectorOrPoint, array);
62 
63  return vectorOrPoint;
64  }
65 
75  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
76  void ToArray(ArrayType &array, const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
77  {
78  for (unsigned short int var = 0; var < NVectorDimension; ++var)
79  {
80  array[var] = vectorOrPoint[var];
81  }
82  }
83 
93  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
94  ArrayType ToArray(const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
95  {
96  ArrayType result;
97 
98  mitk::ToArray(result, vectorOrPoint);
99 
100  return result;
101  }
102 
103  // The FillVector3D and FillVector4D methods are implemented for all common array types here
104 
105  template <class Tout>
107  {
108  out[0] = x;
109  out[1] = y;
110  out[2] = z;
111  }
112 
113  template <class Tout>
115  {
116  out[0] = x;
117  out[1] = y;
118  out[2] = z;
119  out[3] = t;
120  }
121 
127  template <typename TArrayType1, typename TArrayType2>
128  inline bool EqualArray(
129  TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps = mitk::eps, bool verbose = false)
130  {
131  bool isEqual = true;
132  for (int var = 0; var < size; ++var)
133  {
134  isEqual = isEqual && Equal(arrayType1[var], arrayType2[var], eps);
135  }
136 
137  ConditionalOutputOfDifference(arrayType1, arrayType2, eps, verbose, isEqual);
138 
139  return isEqual;
140  }
141 }
142 
143 #endif /* MITKARRAY_H_ */
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:128
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:54
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:106
void FillArray(itk::FixedArray< TCoordRep, NVectorDimension > &toArray, const ArrayType &array)
Copies elements of an array to this Vector.
Definition: mitkArray.h:39
bool verbose(false)
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Definition: mitkArray.h:114
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 ToArray(ArrayType &array, const itk::FixedArray< TCoordRep, NVectorDimension > &vectorOrPoint)
Copies the elements of this into an array.
Definition: mitkArray.h:76
MITKCORE_EXPORT const ScalarType eps