diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index 253dd2e6ef..3e0251697a 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,41 +1,40 @@ set(MODULE_TESTS - mitkComputeContourSetNormalsFilterTest.cpp + mitkContourExtractionTest.cpp mitkContourMapper2DTest.cpp mitkContourTest.cpp mitkDataNodeSegmentationTest.cpp mitkImageToContourFilterTest.cpp # mitkSegmentationInterpolationTest.cpp mitkOverwriteSliceFilterTest.cpp mitkOverwriteSliceFilterObliquePlaneTest.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 Sigmoid.nrrd Sigmoid-2D-as-3D.nrrd ) # 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/SurfaceInterpolation/CMakeLists.txt b/Modules/SurfaceInterpolation/CMakeLists.txt index 5eedf67a05..047662be67 100644 --- a/Modules/SurfaceInterpolation/CMakeLists.txt +++ b/Modules/SurfaceInterpolation/CMakeLists.txt @@ -1,4 +1,6 @@ MITK_CREATE_MODULE( DEPENDS MitkImageExtraction WARNINGS_AS_ERRORS ) + +add_subdirectory(Testing) diff --git a/Modules/SurfaceInterpolation/Testing/CMakeLists.txt b/Modules/SurfaceInterpolation/Testing/CMakeLists.txt new file mode 100644 index 0000000000..153cd81e2e --- /dev/null +++ b/Modules/SurfaceInterpolation/Testing/CMakeLists.txt @@ -0,0 +1 @@ +MITK_CREATE_MODULE_TESTS() diff --git a/Modules/SurfaceInterpolation/Testing/files.cmake b/Modules/SurfaceInterpolation/Testing/files.cmake new file mode 100644 index 0000000000..f1effd0152 --- /dev/null +++ b/Modules/SurfaceInterpolation/Testing/files.cmake @@ -0,0 +1,5 @@ +set(MODULE_TESTS + mitkComputeContourSetNormalsFilterTest.cpp + mitkCreateDistanceImageFromSurfaceFilterTest.cpp + mitkReduceContourSetFilterTest.cpp +) diff --git a/Modules/Segmentation/Testing/mitkComputeContourSetNormalsFilterTest.cpp b/Modules/SurfaceInterpolation/Testing/mitkComputeContourSetNormalsFilterTest.cpp similarity index 97% rename from Modules/Segmentation/Testing/mitkComputeContourSetNormalsFilterTest.cpp rename to Modules/SurfaceInterpolation/Testing/mitkComputeContourSetNormalsFilterTest.cpp index 90a4e72630..b146bb1b38 100644 --- a/Modules/Segmentation/Testing/mitkComputeContourSetNormalsFilterTest.cpp +++ b/Modules/SurfaceInterpolation/Testing/mitkComputeContourSetNormalsFilterTest.cpp @@ -1,89 +1,88 @@ /*=================================================================== 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 #include #include -#include class mitkComputeContourSetNormalsFilterTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkComputeContourSetNormalsFilterTestSuite); MITK_TEST(TestComputeNormals); MITK_TEST(TestComputeNormalsWithHole); CPPUNIT_TEST_SUITE_END(); private: mitk::ComputeContourSetNormalsFilter::Pointer m_ContourNormalsFilter; public: void setUp() { m_ContourNormalsFilter = mitk::ComputeContourSetNormalsFilter::New(); CPPUNIT_ASSERT_MESSAGE("Failed to initialize ReduceContourSetFilter", m_ContourNormalsFilter.IsNotNull()); } // Compute the normals for a regular contour void TestComputeNormals() { mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/Reference/SingleContour.vtk")); m_ContourNormalsFilter->SetInput(contour); m_ContourNormalsFilter->Update(); // Get the computed normals (basically lines) mitk::Surface::Pointer normals = m_ContourNormalsFilter->GetNormalsAsSurface(); // Get the actual surface object which has the contours stored as normals internally mitk::Surface::Pointer contourWithNormals = m_ContourNormalsFilter->GetOutput(); mitk::Surface::Pointer referenceContour = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/Reference/ContourWithNormals.vtk")); mitk::Surface::Pointer referenceNormals = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/Reference/ContourNormals.vtk")); CPPUNIT_ASSERT_MESSAGE("Unequal contours", mitk::Equal(contourWithNormals->GetVtkPolyData(), referenceContour->GetVtkPolyData(), 0.000001, true)); CPPUNIT_ASSERT_MESSAGE("Unequal contours", mitk::Equal(normals->GetVtkPolyData(), referenceNormals->GetVtkPolyData(), 0.000001, true)); } // Reduce contours with Douglas Peucker void TestComputeNormalsWithHole() { - mitk::Image::Pointer segmentationImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/LiverSegmentation.nrrd")); + mitk::Image::Pointer segmentationImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("SurfaceInterpolation/Reference/LiverSegmentation.nrrd")); mitk::Surface::Pointer contour = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/ComputeNormals/ContourWithHoles.vtk")); m_ContourNormalsFilter->SetInput(contour); m_ContourNormalsFilter->SetSegmentationBinaryImage(segmentationImage); m_ContourNormalsFilter->Update(); mitk::Surface::Pointer contourWithNormals = m_ContourNormalsFilter->GetOutput(); mitk::Surface::Pointer normals = m_ContourNormalsFilter->GetNormalsAsSurface(); mitk::Surface::Pointer contourReference = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/Reference/ContourWithHolesWithNormals.vtk")); mitk::Surface::Pointer normalsReference = mitk::IOUtil::LoadSurface(GetTestDataFilePath("SurfaceInterpolation/Reference/NormalsWithHoles.vtk")); CPPUNIT_ASSERT_MESSAGE("Error computing normals", mitk::Equal(normals->GetVtkPolyData(), normalsReference->GetVtkPolyData(), 0.000001, true)); CPPUNIT_ASSERT_MESSAGE("Error computing normals", contourWithNormals->GetVtkPolyData()->GetCellData()->GetNormals()->GetNumberOfTuples() == contourReference->GetVtkPolyData()->GetNumberOfPoints()); } }; MITK_TEST_SUITE_REGISTRATION(mitkComputeContourSetNormalsFilter) diff --git a/Modules/SurfaceInterpolation/Testing/mitkCreateDistanceImageFromSurfaceFilterTest.cpp b/Modules/SurfaceInterpolation/Testing/mitkCreateDistanceImageFromSurfaceFilterTest.cpp new file mode 100644 index 0000000000..ea429d4a4a --- /dev/null +++ b/Modules/SurfaceInterpolation/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/Reference/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/Reference/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) diff --git a/Modules/Segmentation/Testing/mitkReduceContourSetFilterTest.cpp b/Modules/SurfaceInterpolation/Testing/mitkReduceContourSetFilterTest.cpp similarity index 100% rename from Modules/Segmentation/Testing/mitkReduceContourSetFilterTest.cpp rename to Modules/SurfaceInterpolation/Testing/mitkReduceContourSetFilterTest.cpp