Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkProportionalTimeGeometryTest.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"
19 #include "mitkSlicedGeometry3D.h"
21 
22 #include <mitkTestFixture.h>
23 #include <mitkTestingMacros.h>
24 
25 class mitkProportionalTimeGeometryTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkProportionalTimeGeometryTestSuite);
28  MITK_TEST(TestInheritance);
29  MITK_TEST(TestProportionalTimeGeometryCloning);
30  CPPUNIT_TEST_SUITE_END();
31 
32 public:
33  void setUp() override {}
34  void tearDown() override {}
35  // This test is supposed to verify inheritance behaviour, this test will fail if the behaviour changes in the future
36  void TestInheritance()
37  {
39  mitk::Geometry3D::Pointer g3d = dynamic_cast<mitk::Geometry3D *>(ptGeom.GetPointer());
40  CPPUNIT_ASSERT_MESSAGE("ProportionalTimeGeometry should not be castable to Geometry3D", g3d.IsNull());
41 
42  mitk::TimeGeometry::Pointer base = dynamic_cast<mitk::TimeGeometry *>(ptGeom.GetPointer());
43  CPPUNIT_ASSERT_MESSAGE("ProportionalTimeGeometry should be castable to TimeGeometry", base.IsNotNull());
44  }
45 
46  void TestProportionalTimeGeometryCloning()
47  {
48  mitk::ProportionalTimeGeometry::Pointer geom = CreateProportionalTimeGeometry();
49 
51  CPPUNIT_ASSERT_MESSAGE("First time point of clone matches original", clone->GetFirstTimePoint() == 1.1);
52  CPPUNIT_ASSERT_MESSAGE("Step duration of clone matches original", clone->GetStepDuration() == 2.2);
53 
54  mitk::PlaneGeometry *planeGeom = dynamic_cast<mitk::PlaneGeometry *>(clone->GetGeometryForTimeStep(0).GetPointer());
55  itk::Matrix<mitk::ScalarType, 3, 3> matrix = planeGeom->GetIndexToWorldTransform()->GetMatrix();
56  CPPUNIT_ASSERT_MESSAGE("Matrix element [0][0] of clone matches original", matrix[0][0] == 31);
57 
58  double origin = planeGeom->GetOrigin()[0];
59  CPPUNIT_ASSERT_MESSAGE("First Point of origin of clone matches original", mitk::Equal(origin, 8));
60 
61  double spacing = planeGeom->GetSpacing()[0];
62  CPPUNIT_ASSERT_MESSAGE("First Point of spacing of clone matches original", mitk::Equal(spacing, 31));
63  }
64 
65 private:
66  // helper Methods for the Tests
67 
68  mitk::ProportionalTimeGeometry::Pointer CreateProportionalTimeGeometry()
69  {
70  mitk::Vector3D mySpacing;
71  mySpacing[0] = 31;
72  mySpacing[1] = 0.1;
73  mySpacing[2] = 5.4;
74  mitk::Point3D myOrigin;
75  myOrigin[0] = 8;
76  myOrigin[1] = 9;
77  myOrigin[2] = 10;
79  itk::Matrix<mitk::ScalarType, 3, 3> transMatrix;
80  transMatrix.Fill(0);
81  transMatrix[0][0] = 1;
82  transMatrix[1][1] = 2;
83  transMatrix[2][2] = 4;
84 
85  myTransform->SetMatrix(transMatrix);
86 
88  geom2D->SetIndexToWorldTransform(myTransform);
89  geom2D->SetSpacing(mySpacing);
90  geom2D->SetOrigin(myOrigin);
91 
93  geom->SetFirstTimePoint(1.1);
94  geom->SetStepDuration(2.2);
95  geom->SetTimeStepGeometry(geom2D, 0);
96 
97  return geom;
98  }
99 };
100 MITK_TEST_SUITE_REGISTRATION(mitkProportionalTimeGeometry)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
itk::SmartPointer< Self > Pointer
Standard implementation of BaseGeometry.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
static void clone(T *&dst, S *src, int n)
Definition: svm.cpp:73
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()
Describes a two-dimensional, rectangular plane.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.