Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGeometryDataToSurfaceFilterTest.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 
18 
19 #include "mitkPlaneGeometry.h"
20 #include "mitkPlaneGeometryData.h"
21 #include "mitkSurface.h"
22 
23 #include "vtkPolyData.h"
24 
25 #include <fstream>
26 
27 template <typename TScalarType>
28 int testExpectedIndexBoundingBox(mitk::BaseGeometry *geometry, TScalarType expectedIndexBounds[6])
29 {
30  mitk::BoundingBox *bb = const_cast<mitk::BoundingBox *>(geometry->GetBoundingBox());
31  mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
32 
33  int i;
34  for (i = 0; i < 6; ++i)
35  {
36  if (mitk::Equal(bounds[i], expectedIndexBounds[i]) == false)
37  {
38  std::cout << "[FAILED]" << std::endl;
39  return EXIT_FAILURE;
40  }
41  }
42  std::cout << "[PASSED]" << std::endl;
43  return EXIT_SUCCESS;
44 }
45 
46 template <typename TScalarType>
47 int testExpectedAxisParallelBoundingBox(mitk::BaseGeometry *geometry, TScalarType expectedAxisParallelBounds[6])
48 {
50  mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
51 
52  int i;
53  for (i = 0; i < 6; ++i)
54  {
55  if (mitk::Equal(bounds[i], expectedAxisParallelBounds[i]) == false)
56  {
57  std::cout << "[FAILED]" << std::endl;
58  return EXIT_FAILURE;
59  }
60  }
61  std::cout << "[PASSED]" << std::endl;
62  return EXIT_SUCCESS;
63 }
64 
65 int testSurfaceBoundingBoxConsistency(mitk::Surface *surface, bool expectIdentityTransform)
66 {
67  int result;
68  std::cout << " Testing surface contents: ";
69  if ((surface == nullptr) || (surface->GetVtkPolyData() == nullptr) ||
70  (surface->GetVtkPolyData()->GetNumberOfPoints() == 0))
71  {
72  std::cout << "[FAILED]" << std::endl;
73  return EXIT_FAILURE;
74  }
75  else
76  {
77  std::cout << "[PASSED]" << std::endl;
78  }
79 
80  double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
81 
82  vtkPolyData *polys = surface->GetVtkPolyData();
83  polys->ComputeBounds();
84  polys->GetBounds(bounds);
85 
86  if (expectIdentityTransform == false)
87  {
89  geometry->SetFloatBounds(bounds);
90  geometry->SetIndexToWorldTransform(surface->GetGeometry()->GetIndexToWorldTransform());
91  mitk::BoundingBox::BoundsArrayType bb = const_cast<mitk::BoundingBox *>(geometry->GetBoundingBox())->GetBounds();
92  for (int i = 0; i < 6; ++i)
93  bounds[i] = bb[i];
94  }
95 
96  std::cout << " Testing GetBoundingBox() ";
97  if ((testExpectedIndexBoundingBox(surface->GetGeometry(), bounds)) != EXIT_SUCCESS)
98  {
99  std::cout << "[FAILED]" << std::endl;
100  return EXIT_FAILURE;
101  }
102  std::cout << "[PASSED]" << std::endl;
103 
104  return EXIT_SUCCESS;
105 }
106 
108  mitk::ScalarType expectedIndexBounds[6],
109  mitk::ScalarType expectedAxisParallelBounds[6],
110  bool expectIdentityTransform)
111 {
112  int result;
113 
114  std::cout << "Testing SetRequestedRegionToLargestPossibleRegion(): ";
115  geometryToSurfaceFilter->GetOutput()->SetRequestedRegionToLargestPossibleRegion();
116  std::cout << "[PASSED]" << std::endl;
117 
118  std::cout << "Testing UpdateOutputInformation(): ";
119  geometryToSurfaceFilter->UpdateOutputInformation();
120  std::cout << "[PASSED]" << std::endl;
121 
122  std::cout << "Testing correctness of bounding-box after UpdateOutputInformation(): ";
123  if ((result = testExpectedIndexBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(),
124  expectedIndexBounds)) != EXIT_SUCCESS)
125  {
126  return result;
127  }
128 
129  std::cout << "Testing correctness of axis-parallel bounding-box after UpdateOutputInformation(): ";
130  if ((result = testExpectedAxisParallelBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(),
131  expectedAxisParallelBounds)) != EXIT_SUCCESS)
132  {
133  return result;
134  }
135 
136  std::cout << "Testing Update(): ";
137  geometryToSurfaceFilter->Update();
138  std::cout << "[PASSED]" << std::endl;
139 
140  std::cout << "Testing correctness of bounding-box after Update(): ";
141  if ((result = testExpectedIndexBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(),
142  expectedIndexBounds)) != EXIT_SUCCESS)
143  {
144  return result;
145  }
146 
147  std::cout << "Testing correctness of axis-parallel bounding-box after UpdateOutputInformation(): ";
148  if ((result = testExpectedAxisParallelBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(),
149  expectedAxisParallelBounds)) != EXIT_SUCCESS)
150  {
151  return result;
152  }
153 
154  std::cout << "Testing bounding-box consistency: " << std::endl;
155  if ((result = testSurfaceBoundingBoxConsistency(geometryToSurfaceFilter->GetOutput(), expectIdentityTransform)) !=
156  EXIT_SUCCESS)
157  {
158  std::cout << "[FAILED]" << std::endl;
159  return result;
160  }
161  else
162  {
163  std::cout << "[PASSED]" << std::endl;
164  }
165  return EXIT_SUCCESS;
166 }
167 
168 int mitkGeometryDataToSurfaceFilterTest(int /*argc*/, char * /*argv*/ [])
169 {
170  int result;
171 
172  std::cout << "Testing mitk::PlaneGeometryDataToSurfaceFilter: " << std::endl;
173 
174  mitk::PlaneGeometryDataToSurfaceFilter::Pointer geometryToSurfaceFilter;
175  std::cout << "Testing PlaneGeometryDataToSurfaceFilter::New(): ";
176  geometryToSurfaceFilter = mitk::PlaneGeometryDataToSurfaceFilter::New();
177  if (geometryToSurfaceFilter.IsNull())
178  {
179  std::cout << "[FAILED]" << std::endl;
180  return EXIT_FAILURE;
181  }
182  else
183  {
184  std::cout << "[PASSED]" << std::endl;
185  }
186 
187  mitk::Point3D origin;
189  plane->InitializeStandardPlane(50, 100);
190  mitk::FillVector3D(origin, 1.0, 2.0, 3.0);
191  plane->SetOrigin(origin);
192 
194  geometryData->SetPlaneGeometry(plane);
195 
196  std::cout << "Testing SetInput(): ";
197  geometryToSurfaceFilter->SetInput(geometryData);
198  std::cout << "[PASSED]" << std::endl;
199 
200  std::cout << "Testing GetInput(): ";
201  if (geometryToSurfaceFilter->GetInput() != geometryData)
202  {
203  std::cout << "[FAILED]" << std::endl;
204  return EXIT_FAILURE;
205  }
206  else
207  {
208  std::cout << "[PASSED]" << std::endl;
209  }
210 
211  std::cout << "Testing default of PlaneGeometryDataToSurfaceFilter::m_PlaceByGeometry (expected is false): ";
212  if (geometryToSurfaceFilter->GetPlaceByGeometry() != false)
213  {
214  std::cout << "[FAILED]" << std::endl;
215  return EXIT_FAILURE;
216  }
217  else
218  {
219  std::cout << "[PASSED]" << std::endl;
220  }
221 
222  // test with m_PlaceByGeometry==false
223  mitk::ScalarType expectedBoundsFinal[6] = {1.0, 51.0, 2.0, 102.0, 3.0, 3.0};
224  if ((result = testGeometryDataToSurfaceFilter(
225  geometryToSurfaceFilter, expectedBoundsFinal, expectedBoundsFinal, true)) != EXIT_SUCCESS)
226  {
227  return result;
228  }
229 
230  std::cout << "Testing PlaneGeometryDataToSurfaceFilter::SetPlaceByGeometry(true): ";
231  geometryToSurfaceFilter->SetPlaceByGeometry(true);
232  if (geometryToSurfaceFilter->GetPlaceByGeometry() != true)
233  {
234  std::cout << "[FAILED]" << std::endl;
235  return EXIT_FAILURE;
236  }
237  else
238  {
239  std::cout << "[PASSED]" << std::endl;
240  }
241 
242  // test with m_PlaceByGeometry==true
243  mitk::ScalarType expectedIndexBounds[6] = {0.0, 50.0, 0.0, 100.0, 0.0, 0.0};
244  mitk::ScalarType expectedAxisParallelBounds[6] = {1.0, 51.0, 2.0, 102.0, 3.0, 3.0};
245  if ((result = testGeometryDataToSurfaceFilter(
246  geometryToSurfaceFilter, expectedIndexBounds, expectedAxisParallelBounds, true)) != EXIT_SUCCESS)
247  {
248  return result;
249  }
250 
251  // test with specified BoundingBox (m_PlaceByGeometry is irrelevant for this test)
253  mitk::Point3D bbMin, bbMax;
254  mitk::FillVector3D(bbMin, 10.0, 10.0, -6.0);
255  mitk::FillVector3D(bbMax, 40.0, 90.0, 6.0);
256 
258  pointsContainer->InsertElement(0, bbMin);
259  pointsContainer->InsertElement(1, bbMax);
260  boundingBox->SetPoints(pointsContainer);
261  boundingBox->ComputeBoundingBox();
262 
263  geometryToSurfaceFilter->SetPlaceByGeometry(true);
264  geometryToSurfaceFilter->SetBoundingBox(boundingBox);
265  mitk::ScalarType expectedIndexBoundsWithBB[6] = {9.0, 39.0, 8.0, 88.0, 0.0, 0.0};
266  mitk::ScalarType expectedAxisParallelBoundsWithBB[6] = {10.0, 40.0, 10.0, 90.0, 3.0, 3.0};
267  if ((result = testGeometryDataToSurfaceFilter(
268  geometryToSurfaceFilter, expectedIndexBoundsWithBB, expectedAxisParallelBoundsWithBB, true)) != EXIT_SUCCESS)
269  {
270  return result;
271  }
272 
273  std::cout << "[TEST DONE]" << std::endl;
274  return EXIT_SUCCESS;
275 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
itk::SmartPointer< Self > Pointer
double ScalarType
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
Superclass of all classes having a PlaneGeometryData as input and generating Images as output...
OutputType * GetOutput()
int testSurfaceBoundingBoxConsistency(mitk::Surface *surface, bool expectIdentityTransform)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
int mitkGeometryDataToSurfaceFilterTest(int, char *[])
int testExpectedAxisParallelBoundingBox(mitk::BaseGeometry *geometry, TScalarType expectedAxisParallelBounds[6])
static Pointer New()
mitk::BoundingBox::Pointer CalculateBoundingBoxRelativeToTransform(const mitk::AffineTransform3D *transform) const
Calculates a bounding-box around the geometry relative to a coordinate system defined by a transform...
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.
int testExpectedIndexBoundingBox(mitk::BaseGeometry *geometry, TScalarType expectedIndexBounds[6])
virtual void SetRequestedRegionToLargestPossibleRegion() override=0
Set the RequestedRegion to the LargestPossibleRegion.
static Pointer New()
int testGeometryDataToSurfaceFilter(mitk::PlaneGeometryDataToSurfaceFilter *geometryToSurfaceFilter, mitk::ScalarType expectedIndexBounds[6], mitk::ScalarType expectedAxisParallelBounds[6], bool expectIdentityTransform)
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType
virtual const BoundingBoxType * GetBoundingBox()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.