Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKARRAY_H_
18 #define MITKARRAY_H_
19 
20 #include <itkFixedArray.h>
21 
22 #include "mitkEqual.h"
23 #include "mitkNumericConstants.h"
24 
25 namespace mitk
26 {
42  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
43  void FillArray(itk::FixedArray<TCoordRep, NVectorDimension> &toArray, const ArrayType &array)
44  {
45  itk::FixedArray<TCoordRep, NVectorDimension> vectorOrPoint;
46  for (unsigned short int var = 0; var < NVectorDimension; ++var)
47  {
48  toArray[var] = array[var];
49  }
50  }
51 
60  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
61  itk::FixedArray<TCoordRep, NVectorDimension> FillArray(const ArrayType &array)
62  {
63  itk::FixedArray<TCoordRep, NVectorDimension> vectorOrPoint;
64 
65  mitk::FillArray(vectorOrPoint, array);
66 
67  return vectorOrPoint;
68  }
69 
79  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
80  void ToArray(ArrayType &array, const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
81  {
82  for (unsigned short int var = 0; var < NVectorDimension; ++var)
83  {
84  array[var] = vectorOrPoint[var];
85  }
86  }
87 
97  template <typename ArrayType, typename TCoordRep, unsigned int NVectorDimension>
98  ArrayType ToArray(const itk::FixedArray<TCoordRep, NVectorDimension> &vectorOrPoint)
99  {
100  ArrayType result;
101 
102  mitk::ToArray(result, vectorOrPoint);
103 
104  return result;
105  }
106 
107  // The FillVector3D and FillVector4D methods are implemented for all common array types here
108 
109  template <class Tout>
111  {
112  out[0] = x;
113  out[1] = y;
114  out[2] = z;
115  }
116 
117  template <class Tout>
119  {
120  out[0] = x;
121  out[1] = y;
122  out[2] = z;
123  out[3] = t;
124  }
125 
131  template <typename TArrayType1, typename TArrayType2>
132  inline bool EqualArray(
133  TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps = mitk::eps, bool verbose = false)
134  {
135  bool isEqual = true;
136  for (int var = 0; var < size; ++var)
137  {
138  isEqual = isEqual && Equal(arrayType1[var], arrayType2[var], eps);
139  }
140 
141  ConditionalOutputOfDifference(arrayType1, arrayType2, eps, verbose, isEqual);
142 
143  return isEqual;
144  }
145 }
146 
147 #endif /* MITKARRAY_H_ */
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:132
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:42
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:110
void FillArray(itk::FixedArray< TCoordRep, NVectorDimension > &toArray, const ArrayType &array)
Copies elements of an array to this Vector.
Definition: mitkArray.h:43
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Definition: mitkArray.h:118
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:80
MITKCORE_EXPORT const ScalarType eps