diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index d03309fead..69f81ec030 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,39 +1,40 @@ set(MODULE_TESTS mitkContourMapper2DTest.cpp mitkContourTest.cpp mitkDataNodeSegmentationTest.cpp mitkImageToContourFilterTest.cpp # mitkSegmentationInterpolationTest.cpp mitkOverwriteSliceFilterTest.cpp mitkOverwriteSliceFilterObliquePlaneTest.cpp #mitkContourModelTest.cpp #mitkContourModelIOTest.cpp # mitkToolManagerTest.cpp + mitkReduceContourSetFilterTest.cpp mitkToolManagerProviderTest.cpp ) set(MODULE_IMAGE_TESTS mitkManualSegmentationToSurfaceFilterTest.cpp #only runs on images mitkOverwriteSliceImageFilterTest.cpp #only runs on images ) set(MODULE_CUSTOM_TESTS ) set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) # Create an artificial module initializing class for # usServices set(testdriver_init_file ) usFunctionGenerateModuleInit(testdriver_init_file NAME SegmentationTestDriver DEPENDS "Segmentation" VERSION "0.1.0" ) set(TEST_CPP_FILES ${testdriver_init_file}) diff --git a/Modules/Segmentation/Testing/mitkReduceContourSetFilterTest.cpp b/Modules/Segmentation/Testing/mitkReduceContourSetFilterTest.cpp new file mode 100644 index 0000000000..1fe0b0a7ea --- /dev/null +++ b/Modules/Segmentation/Testing/mitkReduceContourSetFilterTest.cpp @@ -0,0 +1,74 @@ +/*=================================================================== + +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. + +===================================================================*/ + +#include +#include +#include +#include +#include +#include + +class mitkReduceContourSetFilterTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkReduceContourSetFilterTestSuite); + MITK_TEST(TestReduceContourWithNthPoint); + MITK_TEST(TestReduceContourWithDouglasPeuker); + CPPUNIT_TEST_SUITE_END(); + +private: + + mitk::ReduceContourSetFilter::Pointer m_ContourReducer; + +public: + + void setUp() + { + m_ContourReducer = mitk::ReduceContourSetFilter::New(); + CPPUNIT_ASSERT_MESSAGE("Failed to initialize ReduceContourSetFilter", m_ContourReducer.IsNotNull()); + } + + // Reduce contours with nth point + void TestReduceContourWithNthPoint() + { + mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/SingleContour_Reference.vtk")); + m_ContourReducer->SetInput(contour); + m_ContourReducer->SetReductionType(mitk::ReduceContourSetFilter::NTH_POINT); + m_ContourReducer->SetStepSize(20); + m_ContourReducer->Update(); + mitk::Surface::Pointer reducedContour = m_ContourReducer->GetOutput(); + + mitk::Surface::Pointer reference = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/ReducedContourNthPoint_20_Reference.vtk")); + + CPPUNIT_ASSERT_MESSAGE("Unequal contours", mitk::Equal(reducedContour->GetVtkPolyData(), reference->GetVtkPolyData(), 0.000001, true)); + } + + // Reduce contours with Douglas Peucker + void TestReduceContourWithDouglasPeuker() + { + mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/TwoContours_Reference.vtk")); + m_ContourReducer->SetInput(contour); + m_ContourReducer->SetReductionType(mitk::ReduceContourSetFilter::DOUGLAS_PEUCKER); + m_ContourReducer->Update(); + mitk::Surface::Pointer reducedContour = m_ContourReducer->GetOutput(); + + mitk::Surface::Pointer reference = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/ReducedContourDouglasPeucker_Reference.vtk")); + + CPPUNIT_ASSERT_MESSAGE("Unequal contours", mitk::Equal(reducedContour->GetVtkPolyData(), reference->GetVtkPolyData(), 0.000001, true)); + } + +}; + +MITK_TEST_SUITE_REGISTRATION(mitkReduceContourSetFilter)