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