Medical Imaging Interaction Toolkit  2018.4.99-67d34b5d
Medical Imaging Interaction Toolkit
mitkAbstractTransformGeometryTest.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 "mitkExternAbstractTransformGeometry.h"
14 #include "mitkImage.h"
15 #include "mitkPlaneGeometry.h"
16 #include "mitkSlicedGeometry3D.h"
17 
18 #include <vtkSphericalTransform.h>
19 
20 #include <fstream>
21 
22 int mitkAbstractTransformGeometryTest(int /*argc*/, char * /*argv*/ [])
23 {
24  mitk::Point3D origin;
25  mitk::Vector3D right, bottom;
26  mitk::ScalarType width, height;
27  mitk::ScalarType widthInMM, heightInMM;
28 
29  std::cout << "Initializing an x-/y-plane (xyPlane) as parameter plane by InitializeStandardPlane(rightVector, "
30  "downVector, spacing = nullptr): "
31  << std::endl;
33  width = 100;
34  widthInMM = width;
35  height = 200;
36  heightInMM = height;
37  mitk::ScalarType bounds[6] = {0, width, 0, height, 0, 1};
38  mitk::FillVector3D(origin, 4.5, 7.3, 11.2);
39  mitk::FillVector3D(right, widthInMM, 0, 0);
40  mitk::FillVector3D(bottom, 0, heightInMM, 0);
41  xyPlane->InitializeStandardPlane(right, bottom);
42  xyPlane->SetOrigin(origin);
43  xyPlane->SetSizeInUnits(width, height);
44 
45  std::cout << "Creating AbstractTransformGeometry: " << std::endl;
46  mitk::ExternAbstractTransformGeometry::Pointer abstractgeometry = mitk::ExternAbstractTransformGeometry::New();
47 
48  std::cout << "Setting xyPlane as parameter plane of AbstractTransformGeometry: " << std::endl;
49  abstractgeometry->SetPlane(xyPlane);
50 
51  std::cout
52  << "Testing whether the bounds of xyPlane and the parametric bounds of AbstractTransformGeometry are equal: ";
53  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
54  const_cast<mitk::BoundingBox *>(xyPlane->GetBoundingBox())->GetMinimum()) == false) ||
55  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
56  const_cast<mitk::BoundingBox *>(xyPlane->GetBoundingBox())->GetMaximum()) == false))
57  {
58  std::cout << "[FAILED]" << std::endl;
59  return EXIT_FAILURE;
60  }
61  std::cout << "[PASSED]" << std::endl;
62 
63  std::cout << "Testing whether the parametic bounds of AbstractTransformGeometry and the bounds of the plane accessed "
64  "from there are equal: ";
65  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
66  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum()) ==
67  false) ||
68  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
69  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum()) ==
70  false))
71  {
72  std::cout << "[FAILED]" << std::endl;
73  return EXIT_FAILURE;
74  }
75  std::cout << "[PASSED]" << std::endl;
76 
77  std::cout << "Change parametic bounds of AbstractTransformGeometry and test whether they are equal to the bounds of "
78  "the plane accessed from there: "
79  << std::endl;
80  height = 300;
81  bounds[3] = height;
82  abstractgeometry->SetParametricBounds(bounds);
83  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
84  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum()) ==
85  false) ||
86  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
87  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum()) ==
88  false))
89  {
90  std::cout << "[FAILED]" << std::endl;
91  return EXIT_FAILURE;
92  }
93  std::cout << "[PASSED]" << std::endl;
94 
95  std::cout << "Initializing an phi-/theta-plane (sphereParameterPlane) as parameter plane by "
96  "InitializeStandardPlane(rightVector, downVector, spacing = nullptr): "
97  << std::endl;
99  width = 100;
100  widthInMM = 2 * vnl_math::pi;
101  height = 200;
102  heightInMM = vnl_math::pi;
103  mitk::ScalarType radiusInMM = 2.5;
104 
105  mitk::FillVector3D(origin, radiusInMM, 0, widthInMM);
106  mitk::FillVector3D(right, 0, 0, -widthInMM);
107  mitk::FillVector3D(bottom, 0, heightInMM, 0);
108  sphereParameterPlane->InitializeStandardPlane(right, bottom);
109  sphereParameterPlane->SetOrigin(origin);
110  sphereParameterPlane->SetSizeInUnits(width, height);
111 
112  std::cout << "Creating an vtkSphericalTransform (sphericalTransform) to use with sphereParameterPlane: " << std::endl;
113  vtkSphericalTransform *sphericalTransform = vtkSphericalTransform::New();
114 
115  std::cout << "Setting sphereParameterPlane as parameter plane and sphericalTransform as transform of "
116  "AbstractTransformGeometry: "
117  << std::endl;
118  abstractgeometry->SetPlane(sphereParameterPlane);
119  abstractgeometry->SetVtkAbstractTransform(sphericalTransform);
120 
121  std::cout << "Testing whether the bounds of sphereParameterPlane and the parametric bounds of "
122  "AbstractTransformGeometry are equal: ";
123  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
124  const_cast<mitk::BoundingBox *>(sphereParameterPlane->GetBoundingBox())->GetMinimum()) == false) ||
125  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
126  const_cast<mitk::BoundingBox *>(sphereParameterPlane->GetBoundingBox())->GetMaximum()) == false))
127  {
128  std::cout << "[FAILED]" << std::endl;
129  return EXIT_FAILURE;
130  }
131  std::cout << "[PASSED]" << std::endl;
132 
133  std::cout << "Testing whether the parametic bounds of AbstractTransformGeometry and the bounds of the plane accessed "
134  "from there are equal: ";
135  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
136  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum()) ==
137  false) ||
138  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
139  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum()) ==
140  false))
141  {
142  std::cout << "[FAILED]" << std::endl;
143  return EXIT_FAILURE;
144  }
145  std::cout << "[PASSED]" << std::endl;
146 
147  std::cout << "Testing mapping Map(pt2d_mm(phi=Pi,theta=Pi/2.0), pt3d_mm) and compare with expected (-radius, 0, 0): ";
148  mitk::Point2D pt2d_mm;
149  mitk::Point3D pt3d_mm, expected_pt3d_mm;
150  pt2d_mm[0] = vnl_math::pi;
151  pt2d_mm[1] = vnl_math::pi_over_2;
152  mitk::FillVector3D(expected_pt3d_mm, -radiusInMM, 0, 0);
153  abstractgeometry->Map(pt2d_mm, pt3d_mm);
154  if (mitk::Equal(pt3d_mm, expected_pt3d_mm) == false)
155  {
156  std::cout << "[FAILED]" << std::endl;
157  return EXIT_FAILURE;
158  }
159  std::cout << "[PASSED]" << std::endl;
160 
161  std::cout << "Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected: ";
162  mitk::Point2D testpt2d_mm;
163  abstractgeometry->Map(pt3d_mm, testpt2d_mm);
164  if (mitk::Equal(pt2d_mm, testpt2d_mm) == false)
165  {
166  std::cout << "[FAILED]" << std::endl;
167  return EXIT_FAILURE;
168  }
169  std::cout << "[PASSED]" << std::endl;
170 
171  std::cout << "Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
172  mitk::Point2D pt2d_units;
173  pt2d_units[0] = width / 2.0;
174  pt2d_units[1] = height / 2.0;
175  pt2d_mm[0] = widthInMM / 2.0;
176  pt2d_mm[1] = heightInMM / 2.0;
177  abstractgeometry->IndexToWorld(pt2d_units, testpt2d_mm);
178  if (mitk::Equal(pt2d_mm, testpt2d_mm) == false)
179  {
180  std::cout << "[FAILED]" << std::endl;
181  return EXIT_FAILURE;
182  }
183  std::cout << "[PASSED]" << std::endl;
184 
185  std::cout << "Change parametic bounds of AbstractTransformGeometry and test whether they are equal to the bounds of "
186  "the plane accessed from there: "
187  << std::endl;
188  height = 300;
189  bounds[3] = height;
190  abstractgeometry->SetParametricBounds(bounds);
191  if ((mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(),
192  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum()) ==
193  false) ||
194  (mitk::Equal(const_cast<mitk::BoundingBox *>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(),
195  const_cast<mitk::BoundingBox *>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum()) ==
196  false))
197  {
198  std::cout << "[FAILED]" << std::endl;
199  return EXIT_FAILURE;
200  }
201  std::cout << "[PASSED]" << std::endl;
202 
203  std::cout << "Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
204  pt2d_units[0] = width / 2.0;
205  pt2d_units[1] = height / 2.0;
206  pt2d_mm[0] = widthInMM / 2.0;
207  pt2d_mm[1] = heightInMM / 2.0;
208  abstractgeometry->IndexToWorld(pt2d_units, testpt2d_mm);
209  if (mitk::Equal(pt2d_mm, testpt2d_mm) == false)
210  {
211  std::cout << "[FAILED]" << std::endl;
212  return EXIT_FAILURE;
213  }
214  std::cout << "[PASSED]" << std::endl;
215 
216  // std::cout << "Testing availability and type (PlaneGeometry) of first geometry in the SlicedGeometry3D: ";
217  // mitk::PlaneGeometry* accessedplanegeometry3 =
218  // dynamic_cast<mitk::PlaneGeometry*>(slicedWorldGeometry->GetGeometry2D(0));
219  // if(accessedplanegeometry3==nullptr)
220  //{
221  // std::cout<<"[FAILED]"<<std::endl;
222  // return EXIT_FAILURE;
223  //}
224  // std::cout<<"[PASSED]"<<std::endl;
225 
226  // std::cout << "Testing whether the first geometry in the SlicedGeometry3D is identical to planegeometry3 by axis
227  // comparison: "<<std::endl;
228  // if((mitk::Equal(accessedplanegeometry3->GetAxisVector(0), planegeometry3->GetAxisVector(0))==false) ||
229  // (mitk::Equal(accessedplanegeometry3->GetAxisVector(1), planegeometry3->GetAxisVector(1))==false) ||
230  // (mitk::Equal(accessedplanegeometry3->GetAxisVector(2), planegeometry3->GetAxisVector(2))==false))
231  //{
232  // std::cout<<"[FAILED]"<<std::endl;
233  // return EXIT_FAILURE;
234  //}
235  // std::cout<<"[PASSED]"<<std::endl;
236 
237  sphericalTransform->Delete();
238 
239  std::cout << "[TEST DONE]" << std::endl;
240  return EXIT_SUCCESS;
241 }
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
int mitkAbstractTransformGeometryTest(int, char *[])
void GetMinimum(itk::Image< TPixel, VImageDimension > *itkImage, double &minimum)
double ScalarType
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:106
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()