Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
mitkMatrixTypeConversionTest.cpp
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 #include <string>
14 
15 #include "mitkTestFixture.h"
16 #include "mitkTestingMacros.h"
17 
18 #include "mitkMatrix.h"
19 
20 class mitkMatrixTypeConversionTestSuite : public mitk::TestFixture
21 
22 {
23  CPPUNIT_TEST_SUITE(mitkMatrixTypeConversionTestSuite);
24 
25  MITK_TEST(Mitk2Pod);
26  MITK_TEST(Pod2Mitk);
27 
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31  mitk::Matrix3D mitkMatrix3D;
32  mitk::ScalarType podMatrix3D[3][3];
33 
42  template <typename T1, typename T2>
43  void TestForEquality(const T1 &m1, const T2 &m2)
44  {
45  for (unsigned i = 0; i < 3; i++)
46  {
47  for (unsigned j = 0; j < 3; j++)
48  {
49  std::stringstream ss;
50  ss << "element [" << i << "][" << j << "] equal for mitkMatrix and podMatrix";
51 
52  CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), true, (m1[i][j] == m2[i][j]));
53  }
54  }
55  }
56 
57 public:
58  void setUp(void) override
59  {
60  for (unsigned i = 0; i < 3; i++)
61  for (unsigned j = 0; j < 3; j++)
62  {
63  mitkMatrix3D[i][j] = i + j;
64  podMatrix3D[i][j] = (mitk::ScalarType)(9 - (i + j));
65  }
66  }
67 
68  void tearDown(void) override {}
69  void Mitk2Pod(void)
70  {
71  mitkMatrix3D.ToArray(podMatrix3D);
72 
73  TestForEquality(mitkMatrix3D, podMatrix3D);
74  }
75 
76  void Pod2Mitk(void)
77  {
78  mitkMatrix3D.FillMatrix(podMatrix3D);
79 
80  TestForEquality(podMatrix3D, mitkMatrix3D);
81  }
82 };
83 
84 MITK_TEST_SUITE_REGISTRATION(mitkMatrixTypeConversion)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void FillMatrix(const ArrayType &array)
Definition: mitkMatrix.h:57
Test fixture for parameterized tests.
void ToArray(MatrixType matrix) const
Definition: mitkMatrix.h:72