Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPointTypeConversionTest.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 "mitkTestFixture.h"
18 
19 #include "itkPoint.h"
20 #include "mitkNumericConstants.h"
21 #include "mitkNumericTypes.h" // for Equal method
22 #include "mitkPoint.h"
23 #include "mitkTestingMacros.h"
24 #include "vtkPoints.h"
25 #include "vtkSmartPointer.h"
26 
27 #include <iostream>
28 
29 using namespace mitk;
30 
31 class mitkPointTypeConversionTestSuite : public mitk::TestFixture
32 {
33  CPPUNIT_TEST_SUITE(mitkPointTypeConversionTestSuite);
34 
35  MITK_TEST(Vector2Point);
36 
37  MITK_TEST(Mitk2Itk_PointCompatibility);
38  MITK_TEST(Itk2Mitk_PointCompatibility);
39 
40  MITK_TEST(Vtk2Mitk_PointCompatibility);
41 
42  MITK_TEST(Mitk2Pod_PointCompatibility);
43  MITK_TEST(Pod2Mitk_PointCompatibility);
44 
45  CPPUNIT_TEST_SUITE_END();
46 
47 private:
48  vtkSmartPointer<vtkPoints> a_vtkPoints;
49  ScalarType originalValues[3];
50  ScalarType valuesToCopy[3];
51 
63  template <typename T1, typename T2>
64  void TestForEquality(T1 v1, T2 v2, std::string v1Name, std::string v2Name, ScalarType eps = mitk::eps)
65  {
66  CPPUNIT_ASSERT_EQUAL_MESSAGE(
67  "\nAssigning " + v2Name + " to " + v1Name + ":\n both are equal", true, EqualArray(v1, v2, 3, eps));
68  }
69 
70 public:
71  void setUp(void) override
72  {
73  FillVector3D(originalValues, 1.0, 2.0, 3.0);
74  FillVector3D(valuesToCopy, 4.0, 5.0, 6.0);
75 
76  a_vtkPoints = vtkSmartPointer<vtkPoints>::New();
77  a_vtkPoints->Initialize();
78  }
79 
80  void tearDown(void) override
81  {
82  // a_vtkPoints = NULL;
83  }
84 
85  void Mitk2Itk_PointCompatibility()
86  {
87  mitk::Point3D point3D = valuesToCopy;
88 
89  itk::Point<ScalarType, 3> itkPoint3D = point3D;
90 
91  TestForEquality(itkPoint3D, point3D, "itk::Point", "mitk:Point");
92  }
93 
94  void Itk2Mitk_PointCompatibility()
95  {
96  itk::Point<ScalarType, 3> itkPoint3D = valuesToCopy;
97 
98  mitk::Point3D point3D = itkPoint3D;
99 
100  TestForEquality(point3D, itkPoint3D, "mitk:Point", "itk::Point");
101  }
102 
103  void Vtk2Mitk_PointCompatibility()
104  {
105  a_vtkPoints->InsertNextPoint(valuesToCopy);
106  double vtkPoint[3];
107  a_vtkPoints->GetPoint(0, vtkPoint);
108 
109  mitk::Point3D point3D = vtkPoint;
110 
111  TestForEquality(point3D, vtkPoint, "mitk:Point", "vtkPoint");
112  }
113 
114  void Mitk2Pod_PointCompatibility()
115  {
116  ScalarType podPoint[] = {1.0, 2.0, 3.0};
117  mitk::Point3D point3D = valuesToCopy;
118 
119  point3D.ToArray(podPoint);
120 
121  TestForEquality(podPoint, point3D, "POD point", "mitk::Point");
122  }
123 
124  void Pod2Mitk_PointCompatibility()
125  {
126  ScalarType podPoint[] = {4.0, 5.0, 6.0};
127 
128  itk::Point<double, 3> point3D = podPoint;
129 
130  TestForEquality(point3D, podPoint, "mitk::Point3D", "POD point");
131  }
132 
133  void Vector2Point()
134  {
135  itk::Vector<double, 3> vector3D = originalValues;
136 
137  itk::Point<double, 3> point3D = vector3D;
138 
139  TestForEquality(point3D, vector3D, "mitk::Point", "mitk::Vector");
140  }
141 };
142 
143 MITK_TEST_SUITE_REGISTRATION(mitkPointTypeConversion)
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:132
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
DataCollection - Class to facilitate loading/accessing structured data.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
Test fixture for parameterized tests.
MITKCORE_EXPORT const ScalarType eps
void ToArray(ArrayType array) const
Definition: mitkPoint.h:92
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.