diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index 503dac73ea..2ee430561f 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,41 +1,42 @@ set(MODULE_TESTS mitkComputeContourSetNormalsFilterTest.cpp mitkContourMapper2DTest.cpp mitkContourTest.cpp + mitkCreateDistanceImageFromSurfaceFilterTest.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/mitkCreateDistanceImageFromSurfaceFilterTest.cpp b/Modules/Segmentation/Testing/mitkCreateDistanceImageFromSurfaceFilterTest.cpp new file mode 100644 index 0000000000..06a0315004 --- /dev/null +++ b/Modules/Segmentation/Testing/mitkCreateDistanceImageFromSurfaceFilterTest.cpp @@ -0,0 +1,134 @@ +/*=================================================================== + +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 mitkCreateDistanceImageFromSurfaceFilterTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkCreateDistanceImageFromSurfaceFilterTestSuite); + MITK_TEST(TestCreateDistanceImageForLiver); + MITK_TEST(TestCreateDistanceImageForTube); + CPPUNIT_TEST_SUITE_END(); + +private: + + std::vector contourList; + +public: + + void setUp() + { + + } + + template + void GetImageBase(itk::Image* input, itk::ImageBase<3>::Pointer& result) + { + result->Graft(input); + } + + // Interpolate the shape of a liver + void TestCreateDistanceImageForLiver() + { + // That's the number of available liver contours in MITK-Data + unsigned int NUMBER_OF_LIVER_CONTOURS = 18; + + for (unsigned int i = 0; i <= NUMBER_OF_LIVER_CONTOURS; ++i) + { + std::stringstream s; + s << "SurfaceInterpolation/InterpolateLiver/LiverContourWithNormals_"; + s << i; + s << ".vtk"; + mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath(s.str())); + contourList.push_back(contour); + } + + mitk::Image::Pointer segmentationImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/InterpolateLiver/LiverSegmentation.nrrd")); + + mitk::ComputeContourSetNormalsFilter::Pointer m_NormalsFilter = mitk::ComputeContourSetNormalsFilter::New(); + mitk::CreateDistanceImageFromSurfaceFilter::Pointer m_InterpolateSurfaceFilter = mitk::CreateDistanceImageFromSurfaceFilter::New(); + + itk::ImageBase<3>::Pointer itkImage = itk::ImageBase<3>::New(); + AccessFixedDimensionByItk_1( segmentationImage, GetImageBase, 3, itkImage ); + m_InterpolateSurfaceFilter->SetReferenceImage( itkImage.GetPointer() ); + + for (unsigned int j = 0; j < contourList.size(); j++) + { + m_NormalsFilter->SetInput(j, contourList.at(j)); + m_InterpolateSurfaceFilter->SetInput(j, m_NormalsFilter->GetOutput(j)); + } + + m_InterpolateSurfaceFilter->Update(); + + mitk::Image::Pointer liverDistanceImage = m_InterpolateSurfaceFilter->GetOutput(); + + CPPUNIT_ASSERT(liverDistanceImage.IsNotNull()); + mitk::Image::Pointer liverDistanceImageReference = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/Reference/LiverDistanceImage.nrrd")); + + MITK_ASSERT_EQUAL(liverDistanceImageReference, liverDistanceImage, "LiverDistanceImages are not equal!"); + } + + + + void TestCreateDistanceImageForTube() + { + // That's the number of available contours with holes in MITK-Data + unsigned int NUMBER_OF_TUBE_CONTOURS = 5; + + for (unsigned int i = 0; i < NUMBER_OF_TUBE_CONTOURS; ++i) + { + std::stringstream s; + s << "SurfaceInterpolation/InterpolateWithHoles/ContourWithHoles_"; + s << i; + s << ".vtk"; + mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath(s.str())); + contourList.push_back(contour); + } + + mitk::Image::Pointer segmentationImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/InterpolateWithHoles/SegmentationWithHoles.nrrd")); + + mitk::ComputeContourSetNormalsFilter::Pointer m_NormalsFilter = mitk::ComputeContourSetNormalsFilter::New(); + mitk::CreateDistanceImageFromSurfaceFilter::Pointer m_InterpolateSurfaceFilter = mitk::CreateDistanceImageFromSurfaceFilter::New(); + + m_NormalsFilter->SetSegmentationBinaryImage(segmentationImage); + itk::ImageBase<3>::Pointer itkImage = itk::ImageBase<3>::New(); + AccessFixedDimensionByItk_1( segmentationImage, GetImageBase, 3, itkImage ); + m_InterpolateSurfaceFilter->SetReferenceImage( itkImage.GetPointer() ); + + for (unsigned int j = 0; j < contourList.size(); j++) + { + m_NormalsFilter->SetInput(j, contourList.at(j)); + m_InterpolateSurfaceFilter->SetInput(j, m_NormalsFilter->GetOutput(j)); + } + + m_InterpolateSurfaceFilter->Update(); + + mitk::Image::Pointer holeDistanceImage = m_InterpolateSurfaceFilter->GetOutput(); + + CPPUNIT_ASSERT(holeDistanceImage.IsNotNull()); + mitk::Image::Pointer holesDistanceImageReference = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/Reference/HolesDistanceImage.nrrd")); + + MITK_ASSERT_EQUAL(holesDistanceImageReference, holeDistanceImage, "HolesDistanceImages are not equal!"); + } + +}; + +MITK_TEST_SUITE_REGISTRATION(mitkCreateDistanceImageFromSurfaceFilter)