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