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