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