19 #include "itkVector.h"
24 #include "vnl/vnl_math.h"
25 #include <vnl/vnl_vector_fixed_ref.h>
36 CPPUNIT_TEST_SUITE(mitkVectorTypeConversionTestSuite);
58 CPPUNIT_TEST_SUITE_END();
74 float epsDouble2Float;
87 template <
typename T1,
typename T2>
88 void TestForEquality(
const T1 &v1,
90 const std::string &v1Name,
91 const std::string &v2Name,
94 CPPUNIT_ASSERT_EQUAL_MESSAGE(
95 "\nAssigning " + v2Name +
" to " + v1Name +
":\n both are equal",
true,
EqualArray(v1, v2, 3,
eps));
99 void setUp(
void)
override
101 FillVector3D(originalValues, 1.123456789987, 2.789456321456, 3.123654789987456);
102 FillVector3D(valuesToCopy, 4.654789123321, 5.987456789321, 6.321654987789546);
104 epsDouble2Float = vnl_math::float_eps * 10.0;
107 void tearDown(
void)
override {}
112 TestForEquality(vector3D, valuesToCopy,
"mitk::Vector3D",
"double POD");
122 TestForEquality(podArray, vector3D,
"double POD",
"mitk::Vector3D");
125 void OneElement2Mitk(
void)
127 double twos[] = {2.0, 2.0, 2.0};
130 CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE(
"\n one values initializes all elements to this value",
136 itk::Vector<ScalarType, 3> itkVector = valuesToCopy;
140 TestForEquality(vector3D, itkVector,
"mitk::Vector3D",
"itk::Vector");
147 itk::Vector<ScalarType, 3> itkVector = vector3D;
149 TestForEquality(itkVector, vector3D,
"itk::Vector",
"mitk::Vector3D");
152 void Vnlfixed2Mitk(
void)
154 vnl_vector_fixed<ScalarType, 3> vnlVectorFixed(valuesToCopy);
158 TestForEquality(vector3D, vnlVectorFixed,
"mitk::Vector3D",
"vnl_vector_fixed<ScalarType>");
161 void Mitk2Vnlfixed(
void)
163 vnl_vector_fixed<ScalarType, 3> vnlVectorFixed(originalValues);
166 vnlVectorFixed = vector3D;
168 TestForEquality(vnlVectorFixed, vector3D,
"vnl_vector_fixed<ScalarType>",
"mitk::Vector3D");
173 vnl_vector<ScalarType> vnlVector(3);
174 vnlVector.set(valuesToCopy);
178 TestForEquality(vector3D, vnlVector,
"mitk::Vector3D",
"vnl_vector<ScalarType>");
183 vnl_vector<ScalarType> vnlVector(3);
184 vnlVector.set(originalValues);
187 vnlVector = vector3D;
189 TestForEquality(vnlVector, vector3D,
"vnl_vector<ScalarType>",
"mitk::Vector3D");
195 void Vnl2Mitk_WrongVnlVectorSize()
197 ScalarType largerValuesToCopy[] = {4.12345678910, 5.10987654321, 6.123456789132456, 7.123456987789456};
199 vnl_vector<ScalarType> vnlVector(4);
200 vnlVector.set(largerValuesToCopy);
205 void ToArray_DifferentType(
void)
208 for (
int var = 0; var < 3; ++var)
210 podArray[var] = originalValues[var];
216 TestForEquality(podArray, vector3D,
"float POD",
"mitk::Vector3D", epsDouble2Float);
219 void Fill_DifferentType(
void)
223 for (
int var = 0; var < 3; ++var)
225 podArray[var] = valuesToCopy[var];
230 TestForEquality(vector3D, podArray,
"mitk::Vector3D",
"float POD", epsDouble2Float);
239 TestForEquality(point3D, vector3D,
"mitk::Point3D",
"mitk::Vector3D");
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void ToArray(ArrayType array) const
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
DataCollection - Class to facilitate loading/accessing structured data.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
void FillVector(const ArrayType &array)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Test fixture for parameterized tests.
MITKCORE_EXPORT const ScalarType eps