Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkGeometry3DEqualTest.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 "mitkGeometry3D.h"
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 
17 class mitkGeometry3DEqualTestSuite : public mitk::TestFixture
18 {
19  CPPUNIT_TEST_SUITE(mitkGeometry3DEqualTestSuite);
20  MITK_TEST(Equal_CloneAndOriginal_ReturnsTrue);
21  MITK_TEST(Equal_DifferentOrigin_ReturnsFalse);
22  MITK_TEST(Equal_DifferentIndexToWorldTransform_ReturnsFalse);
23  MITK_TEST(Equal_DifferentSpacing_ReturnsFalse);
24  MITK_TEST(Equal_DifferentImageGeometry_ReturnsFalse);
25  MITK_TEST(Equal_DifferentBoundingBox_ReturnsFalse);
26  CPPUNIT_TEST_SUITE_END();
27 
28 private:
30  mitk::Geometry3D::Pointer m_Geometry3D;
31  mitk::Geometry3D::Pointer m_AnotherGeometry3D;
32 
33 public:
38  void setUp() override
39  {
40  m_Geometry3D = mitk::Geometry3D::New();
41  m_Geometry3D->Initialize();
42  m_AnotherGeometry3D = m_Geometry3D->Clone();
43  }
44 
45  void tearDown() override
46  {
47  m_Geometry3D = nullptr;
48  m_AnotherGeometry3D = nullptr;
49  }
50 
51  void Equal_CloneAndOriginal_ReturnsTrue()
52  {
53  MITK_ASSERT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "A clone should be equal to its original.");
54  }
55 
56  void Equal_DifferentOrigin_ReturnsFalse()
57  {
58  mitk::Point3D origin;
59  origin[0] = 0.0;
60  origin[1] = 0.0;
61  origin[2] = 1.0 + 2 * mitk::eps;
62  m_AnotherGeometry3D->SetOrigin(origin);
63 
64  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Origin was modified. Result should be false.");
65  }
66 
67  void Equal_DifferentIndexToWorldTransform_ReturnsFalse()
68  {
69  // Create another index to world transform and make it different somehow
70  mitk::AffineTransform3D::Pointer differentIndexToWorldTransform = mitk::AffineTransform3D::New();
71 
72  mitk::AffineTransform3D::MatrixType differentMatrix;
73  differentMatrix.SetIdentity();
74  differentMatrix(1, 1) = 2;
75 
76  differentIndexToWorldTransform->SetMatrix(differentMatrix);
77  m_AnotherGeometry3D->SetIndexToWorldTransform(differentIndexToWorldTransform);
78 
80  m_Geometry3D, m_AnotherGeometry3D, "IndexToWorldTransform was modified. Result should be false.");
81  }
82 
83  void Equal_DifferentSpacing_ReturnsFalse()
84  {
85  mitk::Vector3D differentSpacing;
86  differentSpacing[0] = 1.0;
87  differentSpacing[1] = 1.0 + 2 * mitk::eps;
88  differentSpacing[2] = 1.0;
89 
90  m_AnotherGeometry3D->SetSpacing(differentSpacing);
91 
92  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Spacing was modified. Result should be false.");
93  }
94 
95  void Equal_DifferentImageGeometry_ReturnsFalse()
96  {
97  m_AnotherGeometry3D->SetImageGeometry(true);
98 
100  m_Geometry3D, m_AnotherGeometry3D, "One Geometry is image, the other is not. Result should be false.");
101  }
102 
103  void Equal_DifferentBoundingBox_ReturnsFalse()
104  {
105  // create different bounds to make the comparison false
106  mitk::ScalarType bounds[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
107  m_AnotherGeometry3D->SetBounds(bounds);
108 
109  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Bounds are different. Result should be false.");
110  }
111 };
112 
113 MITK_TEST_SUITE_REGISTRATION(mitkGeometry3DEqual)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
#define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG)
Testing macro to test if two objects are not equal.
Test fixture for parameterized tests.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
MITKCORE_EXPORT const ScalarType eps