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
mitkSurfaceTest.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 "mitkCommon.h"
18 #include "mitkNumericTypes.h"
19 #include "mitkSurface.h"
20 #include "mitkTestingMacros.h"
21 
22 #include "vtkPolyData.h"
23 #include "vtkSphereSource.h"
24 
25 #include <fstream>
26 
27 int mitkSurfaceTest(int /*argc*/, char * /*argv*/ [])
28 {
29  MITK_TEST_BEGIN("Surface");
30 
32  MITK_TEST_CONDITION_REQUIRED(surface.GetPointer(), "Testing initialization!");
33 
34  mitk::Surface::Pointer cloneSurface = surface->Clone();
35  MITK_TEST_CONDITION_REQUIRED(cloneSurface.GetPointer(), "Testing clone surface initialization!");
36 
37  vtkSphereSource *sphereSource = vtkSphereSource::New();
38  sphereSource->SetCenter(0, 0, 0);
39  sphereSource->SetRadius(5.0);
40  sphereSource->SetThetaResolution(10);
41  sphereSource->SetPhiResolution(10);
42  sphereSource->Update();
43 
44  vtkPolyData *polys = sphereSource->GetOutput();
45  MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData() == nullptr, "Testing initial state of vtkPolyData");
46  surface->SetVtkPolyData(polys);
47  sphereSource->Delete();
48  MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData() != nullptr, "Testing set vtkPolyData");
49 
50  cloneSurface = surface->Clone();
51  MITK_TEST_CONDITION_REQUIRED(cloneSurface->GetVtkPolyData() != nullptr, "Testing set vtkPolyData of cloned surface!");
52  cloneSurface = nullptr;
53 
54  double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
55  polys->ComputeBounds();
56  polys->GetBounds(bounds);
57 
58  surface->UpdateOutputInformation();
59  surface->SetRequestedRegionToLargestPossibleRegion();
60  mitk::BoundingBox *bb = const_cast<mitk::BoundingBox *>(surface->GetGeometry()->GetBoundingBox());
61  mitk::BoundingBox::BoundsArrayType surfBounds = bb->GetBounds();
62 
63  bool passed = false;
64  if (bounds[0] == surfBounds[0] && bounds[1] == surfBounds[1] && bounds[2] == surfBounds[2] &&
65  bounds[3] == surfBounds[3] && bounds[4] == surfBounds[4] && bounds[5] == surfBounds[5])
66  {
67  passed = true;
68  }
69  MITK_TEST_CONDITION_REQUIRED(passed, "Testing GetBoundingBox()!");
70 
71  surface->Expand(5);
72  surface->Update();
73  surface->SetRequestedRegionToLargestPossibleRegion();
74  mitk::Surface::RegionType requestedRegion = surface->GetRequestedRegion();
75  MITK_TEST_CONDITION_REQUIRED(requestedRegion.GetSize(3) == 5, "Testing mitk::Surface::Expand( timesteps ): ");
76 
77  double boundsMat[5][6];
78 
79  for (int i = 0; i < 5; i++)
80  {
81  vtkSphereSource *sphereSource = vtkSphereSource::New();
82  sphereSource->SetCenter(0, 0, 0);
83  sphereSource->SetRadius(1.0 * (i + 1.0));
84  sphereSource->SetThetaResolution(10);
85  sphereSource->SetPhiResolution(10);
86  sphereSource->Update();
87  sphereSource->GetOutput()->ComputeBounds();
88  sphereSource->GetOutput()->GetBounds(boundsMat[i]);
89  surface->SetVtkPolyData(sphereSource->GetOutput(), i);
90  sphereSource->Delete();
91  }
92 
93  surface->UpdateOutputInformation();
94  surface->SetRequestedRegionToLargestPossibleRegion();
95 
96  passed = true;
97  for (int i = 0; i < 5; i++)
98  {
100  (const_cast<mitk::BoundingBox *>(surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox()))
101  ->GetBounds();
102 
103  if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] ||
104  boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5])
105  {
106  passed = false;
107  break;
108  }
109  }
110  MITK_TEST_CONDITION_REQUIRED(passed, "Testing mitk::Surface::Testing 4D surface data creation!");
111 
112  const mitk::TimeGeometry *inputTimeGeometry = surface->GetUpdatedTimeGeometry();
113 
114  int time = 3;
115  int timestep = 0;
116  timestep = inputTimeGeometry->TimePointToTimeStep(time);
117  MITK_TEST_CONDITION_REQUIRED(time == timestep,
118  "Testing correctness of geometry for surface->GetUpdatedTimeGeometry()!");
119 
120  sphereSource = vtkSphereSource::New();
121  sphereSource->SetCenter(0, 0, 0);
122  sphereSource->SetRadius(100.0);
123  sphereSource->SetThetaResolution(10);
124  sphereSource->SetPhiResolution(10);
125  sphereSource->Update();
126  surface->SetVtkPolyData(sphereSource->GetOutput(), 3);
127  sphereSource->Delete();
128 
129  inputTimeGeometry = surface->GetUpdatedTimeGeometry();
130  time = 3;
131 
132  timestep = inputTimeGeometry->TimePointToTimeStep(time);
134  time == timestep,
135  "Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again!");
136 
137  unsigned int numberoftimesteps = surface->GetTimeSteps();
139  dummy->Graft(surface);
140  MITK_TEST_CONDITION_REQUIRED(dummy->GetVtkPolyData() != nullptr, "Testing copying a Surface with Graft()!");
142  dummy->GetTimeSteps() == numberoftimesteps,
143  "orig-numberofTimeSteps:" << numberoftimesteps << " copy-numberofTimeSteps:" << dummy->GetTimeSteps());
144 
145  surface = nullptr;
146  MITK_TEST_CONDITION_REQUIRED(surface.IsNull(), "Testing destruction of surface!");
147 
148  MITK_TEST_END();
149 }
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
and MITK_TEST_END()
itk::ImageRegion< 5 > RegionType
Definition: mitkSurface.h:35
static Pointer New()
BoundingBoxType::BoundsArrayType BoundsArrayType
int mitkSurfaceTest(int, char *[])
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.