Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkAffineTransformBaseTest.cpp
Go to the documentation of this file.
1 
2 
3 /*===================================================================
4 
5 The Medical Imaging Interaction Toolkit (MITK)
6 
7 Copyright (c) German Cancer Research Center,
8 Division of Medical and Biological Informatics.
9 All rights reserved.
10 
11 This software is distributed WITHOUT ANY WARRANTY; without
12 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE.
14 
15 See LICENSE.txt or http://www.mitk.org for details.
16 
17 ===================================================================*/
18 
19 #include "itkScalableAffineTransform.h"
20 #include "mitkMatrixConvert.h"
21 #include "mitkNumericTypes.h"
22 
23 #include "mitkTestingMacros.h"
24 
25 using namespace mitk;
26 
30 static double originalPointDouble[4];
31 
32 static vtkMatrix4x4 *homogenMatrix = nullptr;
33 
34 static vtkMatrix4x4 *expectedHomogenousMatrix = nullptr;
35 static const double expectedPointAfterTransformation[] = {2, 4, 4, 1};
36 
37 static void Setup()
38 {
39  originalPoint[0] = 1.0;
40  originalPoint[1] = 0.0;
41  originalPoint[2] = 0.0;
42 
43  for (int i = 0; i < 3; i++)
44  originalPointDouble[i] = originalPoint[i]; // same point as the Point3D version
45  originalPointDouble[3] = 1; // homogenous extension
46 
47  offset[0] = 2.0;
48  offset[1] = 3.0;
49  offset[2] = 4.0;
50 
51  // 90� rotation
52  rotation.Fill(0);
53  rotation[0][1] = -1;
54  rotation[1][0] = 1;
55 
56  // prepare a Matrix which shall be set later to a specific
57  // homogen matrix by TransferItkTransformToVtkMatrix
58  // this makes sure, that the initialization to the identity does not
59  // overshadow any bugs in TransferItkTransformToVtkMatrix
60  // (it actually did that by "helping out" TransferItkTransformToVtkMatrix
61  // by setting the (3,3) element to 1).
63  for (int i = 0; i < 4; i++)
64  for (int j = 0; j < 4; j++)
65  homogenMatrix->SetElement(i, j, i + j * j); // just some not trivial value
66 
67  // set the expected homogenous matrix result
70  expectedHomogenousMatrix->SetElement(0, 1, -1);
71  expectedHomogenousMatrix->SetElement(1, 0, 1);
72  expectedHomogenousMatrix->SetElement(0, 3, 2);
73  expectedHomogenousMatrix->SetElement(1, 3, 3);
74  expectedHomogenousMatrix->SetElement(2, 3, 4);
75  expectedHomogenousMatrix->SetElement(3, 3, 1);
76 }
77 
78 static void TearDown()
79 {
80  if (homogenMatrix)
81  homogenMatrix->Delete();
83  expectedHomogenousMatrix->Delete();
84 }
85 
91 {
92  Setup();
93 
96 
97  transform->SetOffset(offset);
98  transform->SetMatrix(rotation);
99 
100  TransferItkTransformToVtkMatrix(transform.GetPointer(), homogenMatrix);
101 
103  Point3D pointTransformedByAffineTransform3D = transform->TransformPoint(originalPoint);
104 
106  bool pointCorrect = true;
107  for (int i = 0; i < 3; i++) // only first three since no homogenous coordinates
108  pointCorrect &= Equal(pointTransformedByAffineTransform3D[i], expectedPointAfterTransformation[i]);
109 
110  MITK_TEST_CONDITION(pointCorrect, "Point has been correctly transformed by AffineTranform3D")
111 
112  TearDown();
113 }
114 
120 {
121  Setup();
122 
124 
125  transform->SetOffset(offset);
126  transform->SetMatrix(rotation);
127 
128  TransferItkTransformToVtkMatrix(transform.GetPointer(), homogenMatrix);
129 
130  bool allElementsEqual = true;
131  for (int i = 0; i < 4; i++)
132  for (int j = 0; j < 4; j++)
133  allElementsEqual &= Equal(homogenMatrix->GetElement(i, j), expectedHomogenousMatrix->GetElement(i, j));
134 
135  MITK_TEST_CONDITION(allElementsEqual, "Homogenous Matrix is set as expected")
136 
137  TearDown();
138 }
139 
150 {
151  Setup();
152 
159 
160  transform->SetOffset(offset);
161  transform->SetMatrix(rotation);
162 
163  TransferItkTransformToVtkMatrix(transform.GetPointer(), homogenMatrix);
164 
166  Point3D pointTransformedByAffineTransform3D = transform->TransformPoint(originalPoint);
167 
168  double *pointTransformedByHomogenous = homogenMatrix->MultiplyDoublePoint(originalPointDouble);
169 
170  /* check if results match */
171 
172  bool pointsMatch = true;
173  for (int i = 0; i < 3; i++) // only first three since no homogenous coordinates
174  pointsMatch &= Equal(pointTransformedByAffineTransform3D[i], pointTransformedByHomogenous[i]);
175 
176  bool homogenousComponentCorrect = Equal(1, pointTransformedByHomogenous[3]);
177 
178  MITK_TEST_CONDITION(pointsMatch && homogenousComponentCorrect,
179  "Point transformed by AffineTransform and homogenous coordinates match")
180 
181  TearDown();
182 }
183 
188 int mitkAffineTransformBaseTest(int /*argc*/, char * /*argv*/ [])
189 {
190  MITK_TEST_BEGIN("AffineTransformationBaseTest");
191 
193 
195 
197 
198  MITK_TEST_END();
199 }
static vtkMatrix4x4 * homogenMatrix
itk::SmartPointer< Self > Pointer
static void TearDown()
DataCollection - Class to facilitate loading/accessing structured data.
void TransferItkTransformToVtkMatrix(const TTransformType *itkTransform, vtkMatrix4x4 *vtkmatrix)
int mitkAffineTransformBaseTest(int, char *[])
static void testIfPointIsTransformedAsExpected(void)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Matrix3D rotation
static void testIfBothTransformationsProduceSameResults(void)
static Vector3D offset
#define MITK_TEST_CONDITION(COND, MSG)
static double originalPointDouble[4]
static void testTransferItkTransformToVtkMatrix(void)
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 Point3D originalPoint
static const double expectedPointAfterTransformation[]
and MITK_TEST_END()
static void Setup()
static vtkMatrix4x4 * expectedHomogenousMatrix
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.