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