Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
Medical Imaging Interaction Toolkit
mitkNodePredicateGeometryTest.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"
16 #include "mitkDataNode.h"
17 #include "mitkTestFixture.h"
18 #include "mitkTestingMacros.h"
20 
21 
22 class mitkNodePredicateGeometryTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkNodePredicateGeometryTestSuite);
25  MITK_TEST(Check_InvalidConstructor);
26  MITK_TEST(Check_CloneAndOriginal);
27  MITK_TEST(Check_DifferentOrigin);
28  MITK_TEST(Check_DifferentIndexToWorldTransform);
29  MITK_TEST(Check_DifferentSpacing);
30  MITK_TEST(Check_DifferentBoundingBox);
31  CPPUNIT_TEST_SUITE_END();
32 
33 private:
36 
37  mitk::Geometry3D::Pointer m_RefGeometry;
38  mitk::TimeGeometry::Pointer m_RefTimeGeometry;
39 
40  mitk::Geometry3D::Pointer m_AnotherGeometry3D;
41 
42 public:
47  void setUp() override
48  {
49  m_RefGeometry = mitk::Geometry3D::New();
50  m_RefGeometry->Initialize();
51 
53  tgeo->Initialize(m_RefGeometry, 1);
54 
55  m_RefTimeGeometry = tgeo.GetPointer();
56 
58  m_Data->SetClonedGeometry(m_RefGeometry);
59 
60  m_Node = mitk::DataNode::New();
61  m_Node->SetData(m_Data);
62 
63  m_AnotherGeometry3D = m_RefGeometry->Clone();
64  }
65 
66  void tearDown() override
67  {
68  m_RefGeometry = nullptr;
69  m_RefTimeGeometry = nullptr;
70  m_AnotherGeometry3D = nullptr;
71  m_Data = nullptr;
72  }
73 
74  void Check_InvalidConstructor()
75  {
76  m_RefGeometry = nullptr;
77  m_RefTimeGeometry = nullptr;
78  CPPUNIT_ASSERT_THROW(mitk::NodePredicateGeometry::New(m_RefGeometry, 3), mitk::Exception);
79  CPPUNIT_ASSERT_THROW(mitk::NodePredicateGeometry::New(m_RefGeometry), mitk::Exception);
80  CPPUNIT_ASSERT_THROW(mitk::NodePredicateGeometry::New(m_RefTimeGeometry), mitk::Exception);
81  }
82 
83  void Check_CloneAndOriginal()
84  {
87 
88  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
89  CPPUNIT_ASSERT(predicateTime->CheckNode(m_Node));
90  }
91 
92  void Check_DifferentOrigin()
93  {
96 
97  mitk::Point3D origin;
98  origin[0] = 0.0;
99  origin[1] = 0.0;
100  origin[2] = 1.0;
101  m_AnotherGeometry3D->SetOrigin(origin);
102  m_Data->SetClonedGeometry(m_AnotherGeometry3D);
103 
104  CPPUNIT_ASSERT(!predicate->CheckNode(m_Node));
105  CPPUNIT_ASSERT(!predicateTime->CheckNode(m_Node));
106 
107  predicate = mitk::NodePredicateGeometry::New(m_AnotherGeometry3D);
108  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
109  }
110 
111  void Check_DifferentIndexToWorldTransform()
112  {
115 
116  mitk::AffineTransform3D::Pointer differentIndexToWorldTransform = mitk::AffineTransform3D::New();
117 
118  mitk::AffineTransform3D::MatrixType differentMatrix;
119  differentMatrix.SetIdentity();
120  differentMatrix(1, 1) = 2;
121 
122  differentIndexToWorldTransform->SetMatrix(differentMatrix);
123  m_AnotherGeometry3D->SetIndexToWorldTransform(differentIndexToWorldTransform);
124  m_Data->SetClonedGeometry(m_AnotherGeometry3D);
125 
126  CPPUNIT_ASSERT(!predicate->CheckNode(m_Node));
127  CPPUNIT_ASSERT(!predicateTime->CheckNode(m_Node));
128 
129  predicate = mitk::NodePredicateGeometry::New(m_AnotherGeometry3D);
130  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
131  }
132 
133  void Check_DifferentSpacing()
134  {
137 
138  mitk::Vector3D differentSpacing;
139  differentSpacing[0] = 1.0;
140  differentSpacing[1] = 2.0;
141  differentSpacing[2] = 3.0+3* mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_PRECISION;
142 
143  m_AnotherGeometry3D->SetSpacing(differentSpacing);
144  m_Data->SetClonedGeometry(m_AnotherGeometry3D);
145 
146  CPPUNIT_ASSERT(!predicate->CheckNode(m_Node));
147  CPPUNIT_ASSERT(!predicateTime->CheckNode(m_Node));
148 
149  //check with altered geometry as reference (sanity check).
151  CPPUNIT_ASSERT(predicate2->CheckNode(m_Node));
152 
153  //check less strict precission checkings
154  differentSpacing[0] = 1.0;
155  differentSpacing[1] = 1.0;
156  differentSpacing[2] = 1.0 + 3 * mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_PRECISION;
157 
158  m_AnotherGeometry3D->SetSpacing(differentSpacing);
159  m_Data->SetClonedGeometry(m_AnotherGeometry3D);
160 
161  CPPUNIT_ASSERT(!predicate->CheckNode(m_Node));
162  CPPUNIT_ASSERT(!predicateTime->CheckNode(m_Node));
163 
164  predicate->SetCheckPrecision(1e-3);
165  predicateTime->SetCheckPrecision(1e-3);
166 
167  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
168  CPPUNIT_ASSERT(predicateTime->CheckNode(m_Node));
169  }
170 
171  void Check_DifferentBoundingBox()
172  {
175 
176  mitk::ScalarType bounds[] = { 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 };
177  m_AnotherGeometry3D->SetBounds(bounds);
178  m_Data->SetClonedGeometry(m_AnotherGeometry3D);
179 
180  CPPUNIT_ASSERT(!predicate->CheckNode(m_Node));
181  CPPUNIT_ASSERT(!predicateTime->CheckNode(m_Node));
182 
183  predicate = mitk::NodePredicateGeometry::New(m_AnotherGeometry3D);
184  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
185  }
186 };
187 
188 MITK_TEST_SUITE_REGISTRATION(mitkNodePredicateGeometry)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
constexpr double NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_PRECISION
static Pointer New(const TimeGeometry *_arg)
mitk::DataNode::Pointer m_Node
static Pointer New()
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:45
Test fixture for parameterized tests.