Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 "mitkGeometry3D.h"
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 class mitkGeometry3DEqualTestSuite : public mitk::TestFixture
22 {
23  CPPUNIT_TEST_SUITE(mitkGeometry3DEqualTestSuite);
24  MITK_TEST(Equal_CloneAndOriginal_ReturnsTrue);
25  MITK_TEST(Equal_DifferentOrigin_ReturnsFalse);
26  MITK_TEST(Equal_DifferentIndexToWorldTransform_ReturnsFalse);
27  MITK_TEST(Equal_DifferentSpacing_ReturnsFalse);
28  MITK_TEST(Equal_DifferentImageGeometry_ReturnsFalse);
29  MITK_TEST(Equal_DifferentBoundingBox_ReturnsFalse);
30  CPPUNIT_TEST_SUITE_END();
31 
32 private:
34  mitk::Geometry3D::Pointer m_Geometry3D;
35  mitk::Geometry3D::Pointer m_AnotherGeometry3D;
36 
37 public:
42  void setUp() override
43  {
44  m_Geometry3D = mitk::Geometry3D::New();
45  m_Geometry3D->Initialize();
46  m_AnotherGeometry3D = m_Geometry3D->Clone();
47  }
48 
49  void tearDown() override
50  {
51  m_Geometry3D = nullptr;
52  m_AnotherGeometry3D = nullptr;
53  }
54 
55  void Equal_CloneAndOriginal_ReturnsTrue()
56  {
57  MITK_ASSERT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "A clone should be equal to its original.");
58  }
59 
60  void Equal_DifferentOrigin_ReturnsFalse()
61  {
62  mitk::Point3D origin;
63  origin[0] = 0.0;
64  origin[1] = 0.0;
65  origin[2] = 1.0 + 2 * mitk::eps;
66  m_AnotherGeometry3D->SetOrigin(origin);
67 
68  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Origin was modified. Result should be false.");
69  }
70 
71  void Equal_DifferentIndexToWorldTransform_ReturnsFalse()
72  {
73  // Create another index to world transform and make it different somehow
74  mitk::AffineTransform3D::Pointer differentIndexToWorldTransform = mitk::AffineTransform3D::New();
75 
76  mitk::AffineTransform3D::MatrixType differentMatrix;
77  differentMatrix.SetIdentity();
78  differentMatrix(1, 1) = 2;
79 
80  differentIndexToWorldTransform->SetMatrix(differentMatrix);
81  m_AnotherGeometry3D->SetIndexToWorldTransform(differentIndexToWorldTransform);
82 
84  m_Geometry3D, m_AnotherGeometry3D, "IndexToWorldTransform was modified. Result should be false.");
85  }
86 
87  void Equal_DifferentSpacing_ReturnsFalse()
88  {
89  mitk::Vector3D differentSpacing;
90  differentSpacing[0] = 1.0;
91  differentSpacing[1] = 1.0 + 2 * mitk::eps;
92  differentSpacing[2] = 1.0;
93 
94  m_AnotherGeometry3D->SetSpacing(differentSpacing);
95 
96  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Spacing was modified. Result should be false.");
97  }
98 
99  void Equal_DifferentImageGeometry_ReturnsFalse()
100  {
101  m_AnotherGeometry3D->SetImageGeometry(true);
102 
104  m_Geometry3D, m_AnotherGeometry3D, "One Geometry is image, the other is not. Result should be false.");
105  }
106 
107  void Equal_DifferentBoundingBox_ReturnsFalse()
108  {
109  // create different bounds to make the comparison false
110  mitk::ScalarType bounds[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
111  m_AnotherGeometry3D->SetBounds(bounds);
112 
113  MITK_ASSERT_NOT_EQUAL(m_Geometry3D, m_AnotherGeometry3D, "Bounds are different. Result should be false.");
114  }
115 };
116 
117 MITK_TEST_SUITE_REGISTRATION(mitkGeometry3DEqual)
itk::SmartPointer< Self > Pointer
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
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.