diff --git a/Modules/Core/test/mitkSurfaceTest.cpp b/Modules/Core/test/mitkSurfaceTest.cpp index 63389c8cba..8141033c1a 100644 --- a/Modules/Core/test/mitkSurfaceTest.cpp +++ b/Modules/Core/test/mitkSurfaceTest.cpp @@ -1,149 +1,318 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include + +// std includes +#include + +//MITK includes #include "mitkCommon.h" #include "mitkNumericTypes.h" #include "mitkSurface.h" -#include "mitkTestingMacros.h" +// MITK includes +#include + +// VTK includes #include "vtkPolyData.h" #include "vtkSphereSource.h" +//stream includes #include -int mitkSurfaceTest(int /*argc*/, char * /*argv*/ []) +class mitkSurfaceTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("Surface"); - - mitk::Surface::Pointer surface = mitk::Surface::New(); - MITK_TEST_CONDITION_REQUIRED(surface.GetPointer(), "Testing initialization!"); - - mitk::Surface::Pointer cloneSurface = surface->Clone(); - MITK_TEST_CONDITION_REQUIRED(cloneSurface.GetPointer(), "Testing clone surface initialization!"); - - vtkSphereSource *sphereSource = vtkSphereSource::New(); - sphereSource->SetCenter(0, 0, 0); - sphereSource->SetRadius(5.0); - sphereSource->SetThetaResolution(10); - sphereSource->SetPhiResolution(10); - sphereSource->Update(); - - vtkPolyData *polys = sphereSource->GetOutput(); - MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData() == nullptr, "Testing initial state of vtkPolyData"); - surface->SetVtkPolyData(polys); - sphereSource->Delete(); - MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData() != nullptr, "Testing set vtkPolyData"); - - cloneSurface = surface->Clone(); - MITK_TEST_CONDITION_REQUIRED(cloneSurface->GetVtkPolyData() != nullptr, "Testing set vtkPolyData of cloned surface!"); - cloneSurface = nullptr; - - double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - polys->ComputeBounds(); - polys->GetBounds(bounds); - - surface->UpdateOutputInformation(); - surface->SetRequestedRegionToLargestPossibleRegion(); - auto *bb = const_cast(surface->GetGeometry()->GetBoundingBox()); - mitk::BoundingBox::BoundsArrayType surfBounds = bb->GetBounds(); - - bool passed = false; - if (bounds[0] == surfBounds[0] && bounds[1] == surfBounds[1] && bounds[2] == surfBounds[2] && - bounds[3] == surfBounds[3] && bounds[4] == surfBounds[4] && bounds[5] == surfBounds[5]) - { - passed = true; - } - MITK_TEST_CONDITION_REQUIRED(passed, "Testing GetBoundingBox()!"); - - surface->Expand(5); - surface->Update(); - surface->SetRequestedRegionToLargestPossibleRegion(); - mitk::Surface::RegionType requestedRegion = surface->GetRequestedRegion(); - MITK_TEST_CONDITION_REQUIRED(requestedRegion.GetSize(3) == 5, "Testing mitk::Surface::Expand( timesteps ): "); - - double boundsMat[5][6]; - - for (int i = 0; i < 5; i++) - { - vtkSphereSource *sphereSource = vtkSphereSource::New(); - sphereSource->SetCenter(0, 0, 0); - sphereSource->SetRadius(1.0 * (i + 1.0)); - sphereSource->SetThetaResolution(10); - sphereSource->SetPhiResolution(10); - sphereSource->Update(); - sphereSource->GetOutput()->ComputeBounds(); - sphereSource->GetOutput()->GetBounds(boundsMat[i]); - surface->SetVtkPolyData(sphereSource->GetOutput(), i); - sphereSource->Delete(); - } - - surface->UpdateOutputInformation(); - surface->SetRequestedRegionToLargestPossibleRegion(); - - passed = true; - for (int i = 0; i < 5; i++) - { - mitk::BoundingBox::BoundsArrayType surfBounds = - (const_cast(surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox())) - ->GetBounds(); - - if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] || - boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5]) - { - passed = false; - break; - } - } - MITK_TEST_CONDITION_REQUIRED(passed, "Testing mitk::Surface::Testing 4D surface data creation!"); - - const mitk::TimeGeometry *inputTimeGeometry = surface->GetUpdatedTimeGeometry(); - - int time = 3; - int timestep = 0; - timestep = inputTimeGeometry->TimePointToTimeStep(time); - MITK_TEST_CONDITION_REQUIRED(time == timestep, - "Testing correctness of geometry for surface->GetUpdatedTimeGeometry()!"); - - sphereSource = vtkSphereSource::New(); - sphereSource->SetCenter(0, 0, 0); - sphereSource->SetRadius(100.0); - sphereSource->SetThetaResolution(10); - sphereSource->SetPhiResolution(10); - sphereSource->Update(); - surface->SetVtkPolyData(sphereSource->GetOutput(), 3); - sphereSource->Delete(); - - inputTimeGeometry = surface->GetUpdatedTimeGeometry(); - time = 3; - - timestep = inputTimeGeometry->TimePointToTimeStep(time); - MITK_TEST_CONDITION_REQUIRED( - time == timestep, - "Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again!"); - - unsigned int numberoftimesteps = surface->GetTimeSteps(); - mitk::Surface::Pointer dummy = mitk::Surface::New(); - dummy->Graft(surface); - MITK_TEST_CONDITION_REQUIRED(dummy->GetVtkPolyData() != nullptr, "Testing copying a Surface with Graft()!"); - MITK_TEST_CONDITION_REQUIRED( - dummy->GetTimeSteps() == numberoftimesteps, - "orig-numberofTimeSteps:" << numberoftimesteps << " copy-numberofTimeSteps:" << dummy->GetTimeSteps()); - - surface = nullptr; - MITK_TEST_CONDITION_REQUIRED(surface.IsNull(), "Testing destruction of surface!"); - - MITK_TEST_END(); -} + CPPUNIT_TEST_SUITE(mitkSurfaceTestSuite); + + MITK_TEST(InitializationSurfacePointer_Success); + MITK_TEST(InitializationCloneSurfacePointer_Success); + + MITK_TEST(StateOfVtkPolyDataEqualNullPointer_Success); + + MITK_TEST(SetVtkPolyDataNotNullPointer_Failure); + MITK_TEST(SetClonedVtkPolyDataNotNullPointer_Failure); + + MITK_TEST(GetBoundingBox_Success); + + MITK_TEST(SurfaceExpandTimestepsAreFive_Success); + MITK_TEST(Surface4DDataCreation_Success); + + MITK_TEST(TimeGeometrySurface_Success); + MITK_TEST(ChangingDataOfSpecificTimestepSurface_Success); + MITK_TEST(SurfaceCopyWithGraft_Failure); + MITK_TEST(CopyingNumberOfTimesteps_Success); + + MITK_TEST(DestructionOfSurface_Success); + + CPPUNIT_TEST_SUITE_END(); + + + private: + mitk::Surface::Pointer m_Surface; + mitk::Surface::Pointer m_CloneSurface; + vtkSphereSource *m_SphereSource; + const mitk::TimeGeometry *m_InputTimeGeometry; + + bool m_Passed; + int m_Time; + int m_Timestep; + + public: + void setUp() + { + m_Surface = mitk::Surface::New(); + m_CloneSurface = m_Surface->Clone(); + m_SphereSource = vtkSphereSource::New(); + m_InputTimeGeometry = m_Surface->GetUpdatedTimeGeometry(); + + m_SphereSource->SetCenter(0, 0, 0); + m_SphereSource->SetRadius(5.0); + m_SphereSource->SetThetaResolution(10); + m_SphereSource->SetPhiResolution(10); + m_SphereSource->Update(); + + m_Time = 3; + m_Timestep = 0; + } + + void tearDown() + { + m_Surface = nullptr; + m_CloneSurface = nullptr; + m_SphereSource = nullptr; + } + + void InitializationSurfacePointer_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing initialization", m_Surface.GetPointer()); + } + + void InitializationCloneSurfacePointer_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing clone surface initialization", m_CloneSurface.GetPointer()); + } + + void StateOfVtkPolyDataEqualNullPointer_Success() + { + vtkPolyData *polys = m_SphereSource->GetOutput(); + CPPUNIT_ASSERT_MESSAGE("Testing initial state of vtkPolyData", m_Surface->GetVtkPolyData() == nullptr); + } + + void SetVtkPolyDataNotNullPointer_Failure() + { + vtkPolyData *polys = m_SphereSource->GetOutput(); + m_Surface->SetVtkPolyData(polys); + m_SphereSource->Delete(); + CPPUNIT_ASSERT_MESSAGE("Testing set vtkPolyData", m_Surface->GetVtkPolyData() != nullptr); + } + + void SetClonedVtkPolyDataNotNullPointer_Failure() + { + vtkPolyData *polys = m_SphereSource->GetOutput(); + m_Surface->SetVtkPolyData(polys); + m_SphereSource->Delete(); + m_CloneSurface = m_Surface->Clone(); + CPPUNIT_ASSERT_MESSAGE("Testing set vtkPolyData of cloned surface!", m_CloneSurface->GetVtkPolyData() != nullptr); + } + + void GetBoundingBox_Success() + { + vtkPolyData *polys = m_SphereSource->GetOutput(); + m_Surface->SetVtkPolyData(polys); + m_SphereSource->Delete(); + + double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + polys->ComputeBounds(); + polys->GetBounds(bounds); + + m_Surface->UpdateOutputInformation(); + m_Surface->SetRequestedRegionToLargestPossibleRegion(); + auto *bb = const_cast(m_Surface->GetGeometry()->GetBoundingBox()); + mitk::BoundingBox::BoundsArrayType surfBounds = bb->GetBounds(); + + m_Passed = false; + if (bounds[0] == surfBounds[0] && bounds[1] == surfBounds[1] && bounds[2] == surfBounds[2] && + bounds[3] == surfBounds[3] && bounds[4] == surfBounds[4] && bounds[5] == surfBounds[5]) + { + m_Passed = true; + } + + CPPUNIT_ASSERT_MESSAGE("Testing GetBoundingBox()", m_Passed); + } + + void SurfaceExpandTimestepsAreFive_Success() + { + m_Surface->Expand(5); + m_Surface->Update(); + m_Surface->SetRequestedRegionToLargestPossibleRegion(); + mitk::Surface::RegionType requestedRegion = m_Surface->GetRequestedRegion(); + CPPUNIT_ASSERT_MESSAGE("Testing mitk::Surface::Expand( timesteps ): ", requestedRegion.GetSize(3) == 5); + } + + void Surface4DDataCreation_Success() + { + double boundsMat[5][6]; + + for (int i = 0; i < 5; i++) + { + vtkSphereSource *sphereSource = vtkSphereSource::New(); + sphereSource->SetCenter(0, 0, 0); + sphereSource->SetRadius(1.0 * (i + 1.0)); + sphereSource->SetThetaResolution(10); + sphereSource->SetPhiResolution(10); + sphereSource->Update(); + sphereSource->GetOutput()->ComputeBounds(); + sphereSource->GetOutput()->GetBounds(boundsMat[i]); + m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i); + sphereSource->Delete(); + } + + m_Surface->UpdateOutputInformation(); + m_Surface->SetRequestedRegionToLargestPossibleRegion(); + + m_Passed = true; + for (int i = 0; i < 5; i++) + { + mitk::BoundingBox::BoundsArrayType surfBounds = + (const_cast(m_Surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox())) + ->GetBounds(); + + if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] || + boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5]) + { + m_Passed = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("Testing mitk::Surface::Testing 4D surface data creation", m_Passed); + } + + void TimeGeometrySurface_Success() + { + m_Timestep = m_InputTimeGeometry->TimePointToTimeStep(m_Time); + CPPUNIT_ASSERT_MESSAGE("Testing correctness of geometry for surface->GetUpdatedTimeGeometry()", m_Time == m_Timestep); + } + + void ChangingDataOfSpecificTimestepSurface_Success() + { + vtkSphereSource *sphereSource = vtkSphereSource::New(); + sphereSource->SetCenter(0, 0, 0); + sphereSource->SetRadius(100.0); + sphereSource->SetThetaResolution(10); + sphereSource->SetPhiResolution(10); + sphereSource->Update(); + m_Surface->SetVtkPolyData(sphereSource->GetOutput(), 3); + sphereSource->Delete(); + + m_Timestep = m_InputTimeGeometry->TimePointToTimeStep(m_Time); + CPPUNIT_ASSERT_MESSAGE("Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again", m_Time == m_Timestep); + } + + void SurfaceCopyWithGraft_Failure() + { + double boundsMat[5][6]; + + for (int i = 0; i < 5; i++) + { + vtkSphereSource *sphereSource = vtkSphereSource::New(); + sphereSource->SetCenter(0, 0, 0); + sphereSource->SetRadius(1.0 * (i + 1.0)); + sphereSource->SetThetaResolution(10); + sphereSource->SetPhiResolution(10); + sphereSource->Update(); + sphereSource->GetOutput()->ComputeBounds(); + sphereSource->GetOutput()->GetBounds(boundsMat[i]); + m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i); + sphereSource->Delete(); + } + + m_Surface->UpdateOutputInformation(); + m_Surface->SetRequestedRegionToLargestPossibleRegion(); + + m_Passed = true; + for (int i = 0; i < 5; i++) + { + mitk::BoundingBox::BoundsArrayType surfBounds = + (const_cast(m_Surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox())) + ->GetBounds(); + + if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] || + boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5]) + { + m_Passed = false; + break; + } + } + + unsigned int numberoftimesteps = m_Surface->GetTimeSteps(); + mitk::Surface::Pointer dummy = mitk::Surface::New(); + dummy->Graft(m_Surface); + CPPUNIT_ASSERT_MESSAGE("Testing copying a Surface with Graft()", dummy->GetVtkPolyData() != nullptr); + } + + void CopyingNumberOfTimesteps_Success() + { + double boundsMat[5][6]; + + for (int i = 0; i < 5; i++) + { + vtkSphereSource *sphereSource = vtkSphereSource::New(); + sphereSource->SetCenter(0, 0, 0); + sphereSource->SetRadius(1.0 * (i + 1.0)); + sphereSource->SetThetaResolution(10); + sphereSource->SetPhiResolution(10); + sphereSource->Update(); + sphereSource->GetOutput()->ComputeBounds(); + sphereSource->GetOutput()->GetBounds(boundsMat[i]); + m_Surface->SetVtkPolyData(sphereSource->GetOutput(), i); + sphereSource->Delete(); + } + + m_Surface->UpdateOutputInformation(); + m_Surface->SetRequestedRegionToLargestPossibleRegion(); + + m_Passed = true; + for (int i = 0; i < 5; i++) + { + mitk::BoundingBox::BoundsArrayType surfBounds = + (const_cast(m_Surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox())) + ->GetBounds(); + + if (boundsMat[i][0] != surfBounds[0] || boundsMat[i][1] != surfBounds[1] || boundsMat[i][2] != surfBounds[2] || + boundsMat[i][3] != surfBounds[3] || boundsMat[i][4] != surfBounds[4] || boundsMat[i][5] != surfBounds[5]) + { + m_Passed = false; + break; + } + } + + unsigned int numberoftimesteps = m_Surface->GetTimeSteps(); + mitk::Surface::Pointer dummy = mitk::Surface::New(); + dummy->Graft(m_Surface); + + CPPUNIT_ASSERT_MESSAGE(" Old timesteps == copy of timesteps ", dummy->GetTimeSteps() == numberoftimesteps); + } + + void DestructionOfSurface_Success() + { + m_Surface = nullptr; + CPPUNIT_ASSERT_MESSAGE("Testing destruction of surface", m_Surface.IsNull()); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkSurface) \ No newline at end of file