29 #include "vtkPolyData.h" 30 #include "vtkSphereSource.h" 37 CPPUNIT_TEST_SUITE(mitkSurfaceTestSuite);
39 MITK_TEST(InitializationSurfacePointer_Success);
40 MITK_TEST(InitializationCloneSurfacePointer_Success);
42 MITK_TEST(StateOfVtkPolyDataEqualNullPointer_Success);
44 MITK_TEST(SetVtkPolyDataNotNullPointer_Failure);
45 MITK_TEST(SetClonedVtkPolyDataNotNullPointer_Failure);
49 MITK_TEST(SurfaceExpandTimestepsAreFive_Success);
53 MITK_TEST(ChangingDataOfSpecificTimestepSurface_Success);
55 MITK_TEST(CopyingNumberOfTimesteps_Success);
59 CPPUNIT_TEST_SUITE_END();
64 vtkSmartPointer<vtkSphereSource> m_SphereSource;
74 m_CloneSurface = m_Surface->Clone();
75 m_SphereSource = vtkSmartPointer<vtkSphereSource>::New();
76 m_InputTimeGeometry = m_Surface->GetUpdatedTimeGeometry();
78 m_SphereSource->SetCenter(0, 0, 0);
79 m_SphereSource->SetRadius(5.0);
80 m_SphereSource->SetThetaResolution(10);
81 m_SphereSource->SetPhiResolution(10);
82 m_SphereSource->Update();
88 void tearDown()
override 91 m_CloneSurface =
nullptr;
94 void InitializationSurfacePointer_Success()
96 CPPUNIT_ASSERT_MESSAGE(
"Testing initialization", m_Surface.GetPointer());
99 void InitializationCloneSurfacePointer_Success()
101 CPPUNIT_ASSERT_MESSAGE(
"Testing clone surface initialization", m_CloneSurface.GetPointer());
104 void StateOfVtkPolyDataEqualNullPointer_Success()
106 CPPUNIT_ASSERT_MESSAGE(
"Testing initial state of vtkPolyData", m_Surface->GetVtkPolyData() ==
nullptr);
109 void SetVtkPolyDataNotNullPointer_Failure()
111 vtkSmartPointer<vtkPolyData> polys = m_SphereSource->GetOutput();
112 m_Surface->SetVtkPolyData(polys);
113 CPPUNIT_ASSERT_MESSAGE(
"Testing set vtkPolyData", m_Surface->GetVtkPolyData() !=
nullptr);
116 void SetClonedVtkPolyDataNotNullPointer_Failure()
118 vtkSmartPointer<vtkPolyData> polys = m_SphereSource->GetOutput();
119 m_Surface->SetVtkPolyData(polys);
120 m_CloneSurface = m_Surface->Clone();
121 CPPUNIT_ASSERT_MESSAGE(
"Testing set vtkPolyData of cloned surface!", m_CloneSurface->GetVtkPolyData() !=
nullptr);
124 void GetBoundingBox_Success()
126 vtkSmartPointer<vtkPolyData> polys = m_SphereSource->GetOutput();
127 m_Surface->SetVtkPolyData(polys);
129 double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
130 polys->ComputeBounds();
131 polys->GetBounds(bounds);
133 m_Surface->UpdateOutputInformation();
134 m_Surface->SetRequestedRegionToLargestPossibleRegion();
135 auto *bb =
const_cast<mitk::BoundingBox *
>(m_Surface->GetGeometry()->GetBoundingBox());
139 if (bounds[0] == surfBounds[0] && bounds[1] == surfBounds[1] && bounds[2] == surfBounds[2] &&
140 bounds[3] == surfBounds[3] && bounds[4] == surfBounds[4] && bounds[5] == surfBounds[5])
145 CPPUNIT_ASSERT_MESSAGE(
"Testing GetBoundingBox()", passed);
148 void SurfaceExpandTimestepsAreFive_Success()
150 m_Surface->Expand(5);
152 m_Surface->SetRequestedRegionToLargestPossibleRegion();
154 CPPUNIT_ASSERT_MESSAGE(
"Testing mitk::Surface::Expand( timesteps ): ", requestedRegion.GetSize(3) == 5);
157 void Surface4DDataCreation_Success()
159 double boundsMat[5][6];
161 for (
int i = 0; i < 5; i++)
163 vtkNew<vtkSphereSource> sphereSource;
164 sphereSource->SetCenter(0, 0, 0);
165 sphereSource->SetRadius(1.0 * (i + 1.0));
166 sphereSource->SetThetaResolution(10);
167 sphereSource->SetPhiResolution(10);
168 sphereSource->Update();
169 sphereSource->GetOutput()->ComputeBounds();
170 sphereSource->GetOutput()->GetBounds(boundsMat[i]);
171 m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i);
174 m_Surface->UpdateOutputInformation();
175 m_Surface->SetRequestedRegionToLargestPossibleRegion();
178 for (
int i = 0; i < 5; i++)
181 (
const_cast<mitk::BoundingBox *
>(m_Surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox()))
184 if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] ||
185 boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5])
191 CPPUNIT_ASSERT_MESSAGE(
"Testing mitk::Surface::Testing 4D surface data creation", passed);
194 void TimeGeometrySurface_Success()
197 CPPUNIT_ASSERT_MESSAGE(
"Testing correctness of geometry for surface->GetUpdatedTimeGeometry()",
198 m_Time == m_Timestep);
201 void ChangingDataOfSpecificTimestepSurface_Success()
203 vtkNew<vtkSphereSource> sphereSource;
204 sphereSource->SetCenter(0, 0, 0);
205 sphereSource->SetRadius(100.0);
206 sphereSource->SetThetaResolution(10);
207 sphereSource->SetPhiResolution(10);
208 sphereSource->Update();
209 m_Surface->SetVtkPolyData(sphereSource->GetOutput(), 3);
212 CPPUNIT_ASSERT_MESSAGE(
213 "Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again",
214 m_Time == m_Timestep);
217 void SurfaceCopyWithGraft_Failure()
219 double boundsMat[5][6];
221 for (
int i = 0; i < 5; i++)
223 vtkNew<vtkSphereSource> sphereSource;
224 sphereSource->SetCenter(0, 0, 0);
225 sphereSource->SetRadius(1.0 * (i + 1.0));
226 sphereSource->SetThetaResolution(10);
227 sphereSource->SetPhiResolution(10);
228 sphereSource->Update();
229 sphereSource->GetOutput()->ComputeBounds();
230 sphereSource->GetOutput()->GetBounds(boundsMat[i]);
231 m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i);
234 m_Surface->UpdateOutputInformation();
235 m_Surface->SetRequestedRegionToLargestPossibleRegion();
238 dummy->Graft(m_Surface);
239 CPPUNIT_ASSERT_MESSAGE(
"Testing copying a Surface with Graft()", dummy->GetVtkPolyData() !=
nullptr);
242 void CopyingNumberOfTimesteps_Success()
244 double boundsMat[5][6];
246 for (
int i = 0; i < 5; i++)
248 vtkNew<vtkSphereSource> sphereSource;
249 sphereSource->SetCenter(0, 0, 0);
250 sphereSource->SetRadius(1.0 * (i + 1.0));
251 sphereSource->SetThetaResolution(10);
252 sphereSource->SetPhiResolution(10);
253 sphereSource->Update();
254 sphereSource->GetOutput()->ComputeBounds();
255 sphereSource->GetOutput()->GetBounds(boundsMat[i]);
256 m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i);
259 m_Surface->UpdateOutputInformation();
260 m_Surface->SetRequestedRegionToLargestPossibleRegion();
262 unsigned int numberoftimesteps = m_Surface->GetTimeSteps();
264 dummy->Graft(m_Surface);
266 CPPUNIT_ASSERT_MESSAGE(
" Old timesteps == copy of timesteps ", dummy->GetTimeSteps() == numberoftimesteps);
269 void DestructionOfSurface_Success()
272 CPPUNIT_ASSERT_MESSAGE(
"Testing destruction of surface", m_Surface.IsNull());
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
Test fixture for parameterized tests.
itk::ImageRegion< 5 > RegionType
BoundingBoxType::BoundsArrayType BoundsArrayType