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