Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSurfaceEqualTest.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 "mitkSurface.h"
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 #include <vtkCellArray.h>
22 #include <vtkPolyData.h>
23 #include <vtkPolyLine.h>
24 #include <vtkPolygon.h>
25 #include <vtkSmartPointer.h>
26 
31 class mitkSurfaceEqualTestSuite : public mitk::TestFixture
32 {
33  CPPUNIT_TEST_SUITE(mitkSurfaceEqualTestSuite);
34  MITK_TEST(Equal_CloneAndOriginalOneTimestep_ReturnsTrue);
35  MITK_TEST(Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue);
36  MITK_TEST(Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse);
37  MITK_TEST(Equal_TwoTimeStepsDifferentPoints_ReturnsFalse);
38  MITK_TEST(Equal_DifferentPoints_ReturnsFalse);
39  MITK_TEST(Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse);
40  CPPUNIT_TEST_SUITE_END();
41 
42 private:
44  mitk::Surface::Pointer m_Surface3D;
45  mitk::Surface::Pointer m_Surface3DTwoTimeSteps;
46 
47  vtkSmartPointer<vtkPoints> m_PointsOne;
48  vtkSmartPointer<vtkPoints> m_PointsTwo;
49  vtkSmartPointer<vtkCellArray> m_PolygonArrayTwo;
50  vtkSmartPointer<vtkPolyData> m_PolyDataOne;
51 
52 public:
57  void setUp() override
58  {
59  // generate two sets of points
60  m_PointsOne = vtkSmartPointer<vtkPoints>::New();
61  m_PointsOne->InsertNextPoint(0.0, 0.0, 0.0);
62  m_PointsOne->InsertNextPoint(1.0, 0.0, 0.0);
63  m_PointsOne->InsertNextPoint(0.0, 1.0, 0.0);
64  m_PointsOne->InsertNextPoint(1.0, 1.0, 0.0);
65 
66  m_PointsTwo = vtkSmartPointer<vtkPoints>::New();
67  m_PointsTwo->InsertNextPoint(0.0, 0.0, 0.0);
68  m_PointsTwo->InsertNextPoint(0.0, 0.0, 2.0);
69  m_PointsTwo->InsertNextPoint(0.0, 1.0, 0.0);
70  m_PointsTwo->InsertNextPoint(0.0, 1.0, 2.0);
71 
72  // generate two polygons
73  vtkSmartPointer<vtkPolygon> polygonOne = vtkSmartPointer<vtkPolygon>::New();
74  polygonOne->GetPointIds()->SetNumberOfIds(4);
75  polygonOne->GetPointIds()->SetId(0, 0);
76  polygonOne->GetPointIds()->SetId(1, 1);
77  polygonOne->GetPointIds()->SetId(2, 2);
78  polygonOne->GetPointIds()->SetId(3, 3);
79 
80  vtkSmartPointer<vtkPolygon> polygonTwo = vtkSmartPointer<vtkPolygon>::New();
81  polygonTwo->GetPointIds()->SetNumberOfIds(4);
82  polygonTwo->GetPointIds()->SetId(0, 3);
83  polygonTwo->GetPointIds()->SetId(1, 2);
84  polygonTwo->GetPointIds()->SetId(2, 0);
85  polygonTwo->GetPointIds()->SetId(3, 1);
86 
87  // generate polydatas
88  vtkSmartPointer<vtkCellArray> polygonArrayOne = vtkSmartPointer<vtkCellArray>::New();
89  polygonArrayOne->InsertNextCell(polygonOne);
90 
91  m_PolyDataOne = vtkSmartPointer<vtkPolyData>::New();
92  m_PolyDataOne->SetPoints(m_PointsOne);
93  m_PolyDataOne->SetPolys(polygonArrayOne);
94 
95  m_PolygonArrayTwo = vtkSmartPointer<vtkCellArray>::New();
96  m_PolygonArrayTwo->InsertNextCell(polygonTwo);
97 
98  vtkSmartPointer<vtkPolyData> polyDataTwo = vtkSmartPointer<vtkPolyData>::New();
99  polyDataTwo->SetPoints(m_PointsOne);
100  polyDataTwo->SetPolys(m_PolygonArrayTwo);
101 
102  // generate surfaces
103  m_Surface3D = mitk::Surface::New();
104  m_Surface3D->SetVtkPolyData(m_PolyDataOne);
105 
106  m_Surface3DTwoTimeSteps = mitk::Surface::New();
107  m_Surface3DTwoTimeSteps->SetVtkPolyData(m_PolyDataOne, 0);
108  m_Surface3DTwoTimeSteps->SetVtkPolyData(polyDataTwo, 1);
109  }
110 
111  void tearDown() override
112  {
113  m_Surface3D = nullptr;
114  m_Surface3DTwoTimeSteps = nullptr;
115  m_PolyDataOne = nullptr;
116  m_PolygonArrayTwo = nullptr;
117  m_PointsOne = nullptr;
118  m_PointsTwo = nullptr;
119  }
120 
121  void Equal_CloneAndOriginalOneTimestep_ReturnsTrue()
122  {
123  MITK_ASSERT_EQUAL(m_Surface3D, m_Surface3D->Clone(), "A one timestep clone should be equal to its original.");
124  }
125 
126  void Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue()
127  {
128  MITK_ASSERT_EQUAL(m_Surface3DTwoTimeSteps,
129  m_Surface3DTwoTimeSteps->Clone(),
130  "A two timestep clone should be equal to its original.");
131  }
132 
133  void Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse()
134  {
136  m_Surface3D, m_Surface3DTwoTimeSteps, "A one timestep and two timestep surface should not be equal.");
137  }
138 
139  void Equal_TwoTimeStepsDifferentPoints_ReturnsFalse()
140  {
141  vtkSmartPointer<vtkPolyData> polyDataDifferentPoints = vtkSmartPointer<vtkPolyData>::New();
142  polyDataDifferentPoints->SetPoints(m_PointsTwo);
143  polyDataDifferentPoints->SetPolys(m_PolygonArrayTwo);
144 
145  mitk::Surface::Pointer surface3DTwoTimeStepsDifferentPoints = mitk::Surface::New();
146  surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData(m_PolyDataOne, 0);
147  surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData(polyDataDifferentPoints, 1);
148 
149  // The geometry also changes, because the second pointset has a different geometry/extent.
150  MITK_ASSERT_NOT_EQUAL(surface3DTwoTimeStepsDifferentPoints,
151  m_Surface3DTwoTimeSteps,
152  "A surface with the same timesteps and different points should not be equal.");
153  }
154 
155  void Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse()
156  {
157  // generate a line
158  vtkSmartPointer<vtkPolyLine> polyLineOne = vtkSmartPointer<vtkPolyLine>::New();
159  polyLineOne->GetPointIds()->SetNumberOfIds(2);
160  polyLineOne->GetPointIds()->SetId(0, 0);
161  polyLineOne->GetPointIds()->SetId(1, 1);
162 
163  vtkSmartPointer<vtkCellArray> polyLineArrayOne = vtkSmartPointer<vtkCellArray>::New();
164  polyLineArrayOne->InsertNextCell(polyLineOne);
165 
166  vtkSmartPointer<vtkPolyData> polyDataLine = vtkSmartPointer<vtkPolyData>::New();
167  polyDataLine->SetPoints(m_PointsOne);
168  polyDataLine->SetLines(polyLineArrayOne);
169 
170  mitk::Surface::Pointer surface3DLine = mitk::Surface::New();
171  surface3DLine->SetVtkPolyData(polyDataLine);
172 
173  MITK_ASSERT_NOT_EQUAL(m_Surface3D,
174  surface3DLine,
175  "A surface with the same timesteps and points and the same "
176  "number of cells, but different types of cells should not be "
177  "equal.");
178  }
179 
180  void Equal_DifferentPoints_ReturnsFalse()
181  {
182  mitk::Surface::Pointer surfaceWithADifferentPoint = m_Surface3D->Clone();
183  // modify points. m_Surface3D contains m_PointsOne
184  surfaceWithADifferentPoint->GetVtkPolyData()->SetPoints(m_PointsTwo);
185 
186  MITK_ASSERT_NOT_EQUAL(m_Surface3D,
187  surfaceWithADifferentPoint,
188  "A surface with a single timestep and different points should not be equal.");
189  }
190 };
191 
192 MITK_TEST_SUITE_REGISTRATION(mitkSurfaceEqual)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
#define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG)
Testing macro to test if two objects are not equal.
Test fixture for parameterized tests.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.