Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSliceNavigationControllerTest.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 <mitkPlaneGeometry.h>
19 #include <mitkSlicedGeometry3D.h>
21 
22 #include <mitkTestFixture.h>
23 #include <mitkTestingMacros.h>
24 
25 // T22254
26 
27 class mitkSliceNavigationControllerTestSuite : public mitk::TestFixture
28 {
29  CPPUNIT_TEST_SUITE(mitkSliceNavigationControllerTestSuite);
30  CPPUNIT_TEST(validateAxialViewDirection);
31  CPPUNIT_TEST(validateCoronalViewDirection);
32  CPPUNIT_TEST(validateSagittalViewDirection);
33  CPPUNIT_TEST_SUITE_END();
34 
35 public:
36  void setUp() override
37  {
38  mitk::Point3D origin;
39  mitk::FillVector3D(origin, 10.0, 20.0, 30.0);
40 
41  mitk::Vector3D firstAxisVector;
42  mitk::FillVector3D(firstAxisVector, 100.0, 0.0, 0.0);
43 
44  mitk::Vector3D secondAxisVector;
45  mitk::FillVector3D(secondAxisVector, 0.0, 50.0, 0.0);
46 
47  mitk::Vector3D spacing;
48  mitk::FillVector3D(spacing, 1.0, 1.0, 2.0);
49 
50  auto planeGeometry = mitk::PlaneGeometry::New();
51  planeGeometry->InitializeStandardPlane(firstAxisVector, secondAxisVector, &spacing);
52  planeGeometry->SetOrigin(origin);
53 
54  unsigned int numberOfSlices = 100U;
55 
56  auto slicedGeometry3D = mitk::SlicedGeometry3D::New();
57  slicedGeometry3D->InitializeEvenlySpaced(planeGeometry, numberOfSlices);
58 
59  m_Geometry3D = mitk::Geometry3D::New();
60  m_Geometry3D->SetBounds(slicedGeometry3D->GetBounds());
61  m_Geometry3D->SetIndexToWorldTransform(slicedGeometry3D->GetIndexToWorldTransform());
62  }
63 
64  void tearDown() override
65  {
66  }
67 
68  void validateAxialViewDirection()
69  {
70  auto sliceNavigationController = mitk::SliceNavigationController::New();
71 
72  sliceNavigationController->SetInputWorldGeometry3D(m_Geometry3D);
73  sliceNavigationController->SetViewDirection(mitk::SliceNavigationController::Axial);
74  sliceNavigationController->Update();
75 
76  mitk::Point3D origin;
77  mitk::FillVector3D(origin, 10.0, 70.0, 229.0);
78 
79  mitk::Vector3D firstAxisVector;
80  mitk::FillVector3D(firstAxisVector, 100.0, 0.0, 0.0);
81 
82  mitk::Vector3D secondAxisVector;
83  mitk::FillVector3D(secondAxisVector, 0.0, -50.0, 0.0);
84 
85  mitk::Vector3D thirdAxisVector;
86  mitk::FillVector3D(thirdAxisVector, 0.0, 0.0, -200.0);
87 
88  std::cout << "Axial view direction" << std::endl;
89  CPPUNIT_ASSERT(this->validateGeometry(sliceNavigationController->GetCurrentGeometry3D(), origin, firstAxisVector, secondAxisVector, thirdAxisVector));
90  }
91 
92  void validateCoronalViewDirection()
93  {
94  auto sliceNavigationController = mitk::SliceNavigationController::New();
95 
96  sliceNavigationController->SetInputWorldGeometry3D(m_Geometry3D);
97  sliceNavigationController->SetViewDirection(mitk::SliceNavigationController::Frontal);
98  sliceNavigationController->Update();
99 
100  mitk::Point3D origin;
101  mitk::FillVector3D(origin, 10.0, 69.5, 30.0);
102 
103  mitk::Vector3D firstAxisVector;
104  mitk::FillVector3D(firstAxisVector, 100.0, 0.0, 0.0);
105 
106  mitk::Vector3D secondAxisVector;
107  mitk::FillVector3D(secondAxisVector, 0.0, 0.0, 200.0);
108 
109  mitk::Vector3D thirdAxisVector;
110  mitk::FillVector3D(thirdAxisVector, 0.0, -50.0, 0.0);
111 
112  std::cout << "Coronal view direction" << std::endl;
113  CPPUNIT_ASSERT(this->validateGeometry(sliceNavigationController->GetCurrentGeometry3D(), origin, firstAxisVector, secondAxisVector, thirdAxisVector));
114  }
115 
116  void validateSagittalViewDirection()
117  {
118  auto sliceNavigationController = mitk::SliceNavigationController::New();
119 
120  sliceNavigationController->SetInputWorldGeometry3D(m_Geometry3D);
121  sliceNavigationController->SetViewDirection(mitk::SliceNavigationController::Sagittal);
122  sliceNavigationController->Update();
123 
124  mitk::Point3D origin;
125  mitk::FillVector3D(origin, 10.5, 20.0, 30.0);
126 
127  mitk::Vector3D firstAxisVector;
128  mitk::FillVector3D(firstAxisVector, 0.0, 50.0, 0.0);
129 
130  mitk::Vector3D secondAxisVector;
131  mitk::FillVector3D(secondAxisVector, 0.0, 0.0, 200.0);
132 
133  mitk::Vector3D thirdAxisVector;
134  mitk::FillVector3D(thirdAxisVector, 100.0, 0.0, 0.0);
135 
136  std::cout << "Sagittal view direction" << std::endl;
137  CPPUNIT_ASSERT(this->validateGeometry(sliceNavigationController->GetCurrentGeometry3D(), origin, firstAxisVector, secondAxisVector, thirdAxisVector));
138  }
139 
140 private:
141  bool validateGeometry(mitk::BaseGeometry::ConstPointer geometry, const mitk::Point3D &origin, const mitk::Vector3D &firstAxisVector, const mitk::Vector3D &secondAxisVector, const mitk::Vector3D &thirdAxisVector)
142  {
143  bool result = true;
144 
145  std::cout << " Origin" << std::endl;
146 
147  if (!mitk::Equal(geometry->GetOrigin(), origin, mitk::eps, true))
148  result = false;
149 
150  std::cout << " First axis vector" << std::endl;
151 
152  if (!mitk::Equal(geometry->GetAxisVector(0), firstAxisVector, mitk::eps, true))
153  result = false;
154 
155  std::cout << " Second axis vector" << std::endl;
156 
157  if (!mitk::Equal(geometry->GetAxisVector(1), secondAxisVector, mitk::eps, true))
158  result = false;
159 
160  std::cout << " Third axis vector" << std::endl;
161 
162  if (!mitk::Equal(geometry->GetAxisVector(2), thirdAxisVector, mitk::eps, true))
163  result = false;
164 
165  return result;
166  }
167 
168  mitk::Geometry3D::Pointer m_Geometry3D;
169 };
170 
171 MITK_TEST_SUITE_REGISTRATION(mitkSliceNavigationController)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static Pointer New()
static Pointer New()
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
static Pointer New()
MITKCORE_EXPORT const ScalarType eps