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