diff --git a/CMakeExternals/MITKData.cmake b/CMakeExternals/MITKData.cmake index 3363e4c247..bf29c186d3 100644 --- a/CMakeExternals/MITKData.cmake +++ b/CMakeExternals/MITKData.cmake @@ -1,38 +1,38 @@ #----------------------------------------------------------------------------- # MITK Data #----------------------------------------------------------------------------- # Sanity checks if(DEFINED MITK_DATA_DIR AND NOT EXISTS ${MITK_DATA_DIR}) message(FATAL_ERROR "MITK_DATA_DIR variable is defined but corresponds to non-existing directory") endif() set(proj MITK-Data) set(proj_DEPENDENCIES) set(MITK-Data_DEPENDS ${proj}) if(BUILD_TESTING) - set(revision_tag ae9267c8) + set(revision_tag c2acb6ec) #if(${proj}_REVISION_TAG) # set(revision_tag ${${proj}_REVISION_TAG}) #endif() ExternalProject_Add(${proj} URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/MITK-Data_${revision_tag}.tar.gz UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS ${proj_DEPENDENCIES} ) set(MITK_DATA_DIR ${ep_source_dir}/${proj}) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif(BUILD_TESTING) diff --git a/Modules/Segmentation/Testing/CMakeLists.txt b/Modules/Segmentation/Testing/CMakeLists.txt index d45daf111d..8131d1c3ea 100644 --- a/Modules/Segmentation/Testing/CMakeLists.txt +++ b/Modules/Segmentation/Testing/CMakeLists.txt @@ -1 +1,2 @@ -MITK_CREATE_MODULE_TESTS() \ No newline at end of file +MITK_CREATE_MODULE_TESTS() +mitkAddCustomModuleTest(mitkSegmentationInterpolationTest mitkSegmentationInterpolationTest ${MITK_DATA_DIR}/interpolation_test_manual.pic.gz ${MITK_DATA_DIR}/interpolation_test_result.pic.gz) diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index cff4926b4c..53592eaac9 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,24 +1,24 @@ set(MODULE_TESTS mitkContourMapper2DTest.cpp mitkContourTest.cpp mitkDataNodeSegmentationTest.cpp -# mitkSegmentationInterpolationTest.cpp + mitkSegmentationInterpolationTest.cpp ) set(MODULE_IMAGE_TESTS mitkManualSegmentationToSurfaceFilterTest.cpp mitkOverwriteSliceImageFilterTest.cpp #Deactivate due to Bug 12340. Should be fixed soon! # mitkOverwriteSliceFilterTest.cpp ) set(MODULE_CUSTOM_TESTS ) set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png binary.stl ball.stl ) diff --git a/Modules/Segmentation/Testing/mitkSegmentationInterpolationTest.cpp b/Modules/Segmentation/Testing/mitkSegmentationInterpolationTest.cpp index e97cf61b92..cf9f2356aa 100644 --- a/Modules/Segmentation/Testing/mitkSegmentationInterpolationTest.cpp +++ b/Modules/Segmentation/Testing/mitkSegmentationInterpolationTest.cpp @@ -1,365 +1,343 @@ /*=================================================================== 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 "mitkSegmentationInterpolationController.h" #include "mitkCoreObjectFactory.h" #include "mitkStandardFileLocations.h" #include "mitkDataNodeFactory.h" #include "ipSegmentation.h" -#include "mitkCompareImageSliceTestHelper.h"s +#include "mitkCompareImageSliceTestHelper.h" class mitkSegmentationInterpolationTestClass { public: mitkSegmentationInterpolationTestClass() {} ~mitkSegmentationInterpolationTestClass() {} - bool Test() + bool Test(std::string filename1, std::string filename2) { return CreateNewInterpolator() && CreateSegmentation() && ClearSegmentation() && CreateTwoSlices(2) && TestInterpolation(2) && ClearSegmentation() && CreateTwoSlices(1) && TestInterpolation(1) && ClearSegmentation() && CreateTwoSlices(0) && TestInterpolation(0) && DeleteInterpolator() && CreateNewInterpolator() - && LoadTestImages() + && LoadTestImages(filename1, filename2) && CompareInterpolationsToDefinedReference(); } protected: bool CreateNewInterpolator(); bool CreateSegmentation(); bool ClearSegmentation(); bool CreateTwoSlices(int); bool TestInterpolation(int); bool DeleteInterpolator(); - bool LoadTestImages(); + bool LoadTestImages(std::string filename1, std::string filename2); bool CompareInterpolationsToDefinedReference(); mitk::Image::Pointer LoadImage(const std::string& filename); mitk::SegmentationInterpolationController::Pointer m_Interpolator; mitk::Image::Pointer m_Image; mitk::Image::Pointer m_ManualSlices; mitk::Image::Pointer m_InterpolatedSlices; unsigned int dim[3]; int pad[3]; }; bool mitkSegmentationInterpolationTestClass::CreateNewInterpolator() { std::cout << "Instantiation" << std::endl; // instantiation m_Interpolator = mitk::SegmentationInterpolationController::New(); if (m_Interpolator.IsNotNull()) { std::cout << " (II) Instantiation works." << std::endl; } else { std::cout << " Instantiation test failed!" << std::endl; return false; } return true; } bool mitkSegmentationInterpolationTestClass::CreateSegmentation() { m_Image = mitk::Image::New(); dim[0]=15; dim[1]=20; dim[2]=25; pad[0]=2; pad[1]=3; pad[2]=4; m_Image->Initialize( mitk::MakeScalarPixelType(), 3, dim); return true; } bool mitkSegmentationInterpolationTestClass::ClearSegmentation() { int* p = (int*)m_Image->GetData(); // pointer to pixel data int size = dim[0]*dim[1]*dim[2]; for(int i=0; iGetData(); // pointer to pixel data int size = dim[0]*dim[1]*dim[2]; for(int i=0; i= pad[xdim]) && (x < ( (signed) dim[xdim]-pad[xdim])) && (y >= pad[ydim]) && (y < ( (signed) dim[ydim]-pad[ydim])) ) { *p = 1; } else { *p = 0; } } m_Interpolator->SetSegmentationVolume( m_Image ); std::cout << " (II) SetSegmentationVolume works (slicedim " << slicedim << ")" << std::endl; return true; } /** * Checks if interpolation would create a square in slice 1 */ bool mitkSegmentationInterpolationTestClass::TestInterpolation(int slicedim) { int slice = 1; mitk::Image::Pointer interpolated = m_Interpolator->Interpolate( slicedim, slice, 0 ); // interpolate second slice transversal if (interpolated.IsNull()) { std::cerr << " (EE) Interpolation did not return anything for slicedim == " << slicedim << " (although it should)." << std::endl; return false; } int xdim,ydim; switch (slicedim) { case 0: xdim = 1; ydim = 2; // different than above! break; case 1: xdim = 0; ydim = 2; break; case 2: default: xdim = 0; ydim = 1; break; } ipMITKSegmentationTYPE* p = (ipMITKSegmentationTYPE*)interpolated->GetData(); // pointer to pixel data int size = dim[xdim]*dim[ydim]; if ( (signed) interpolated->GetDimension(0) * (signed) interpolated->GetDimension(1) != size ) { std::cout << " (EE) Size of interpolated image differs from original segmentation..." << std::endl; return false; } for(int i=0; i= pad[xdim]) && (x < ((signed) dim[xdim]-pad[xdim])) && (y >= pad[ydim]) && (y < ((signed) dim[ydim]-pad[ydim])) && (value != 1) ) { std::cout << " (EE) Interpolation of a square figure failed" << std::endl; std::cout << " Value at " << x << " " << y << ": " << (int)value << std::endl; return false; } } std::cout << " (II) Interpolation of a square figure works like expected (slicedim " << slicedim << ")" << std::endl; return true; } bool mitkSegmentationInterpolationTestClass::DeleteInterpolator() { std::cout << "Object destruction" << std::endl; // freeing m_Interpolator = NULL; std::cout << " (II) Freeing works." << std::endl; return true; } -bool mitkSegmentationInterpolationTestClass::LoadTestImages() +bool mitkSegmentationInterpolationTestClass::LoadTestImages(std::string filename1, std::string filename2) { - std::string filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "../mitk/Core/Testing/Data/"); - if ( filename1.empty() ) - { - filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "Testing/Data/"); - } - - std::cout << "Found test image (manual slices) in '" << filename1 << "'" << std::endl; - - std::string filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "../mitk/Core/Testing/Data/"); - if ( filename2.empty() ) - { - filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "Testing/Data/"); - } - - std::cout << "Found test image (reference for interpolation) in '" << filename2 << "'" << std::endl; - - if ( filename1.empty() || filename2.empty() ) - { - return false; - } - else - { - m_ManualSlices = LoadImage( filename1 ); - m_InterpolatedSlices = LoadImage( filename2 ); - - return ( m_ManualSlices.IsNotNull() && m_InterpolatedSlices.IsNotNull() ); - } + m_ManualSlices = LoadImage( filename1 ); + m_InterpolatedSlices = LoadImage( filename2 ); - return true; + return ( m_ManualSlices.IsNotNull() && m_InterpolatedSlices.IsNotNull() ); } mitk::Image::Pointer mitkSegmentationInterpolationTestClass::LoadImage(const std::string& filename) { mitk::Image::Pointer image = NULL; mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); try { factory->SetFileName( filename ); factory->Update(); if(factory->GetNumberOfOutputs()<1) { std::cerr<<"File " << filename << " could not be loaded [FAILED]"<GetOutput( 0 ); image = dynamic_cast(node->GetData()); if(image.IsNull()) { std::cout<<"File " << filename << " is not an image! [FAILED]"<SetSegmentationVolume( m_ManualSlices ); std::cout << "OK" << std::endl; std::cout << " (II) Testing interpolation result for slice " << std::flush; for (unsigned int slice = 1; slice < 98; ++slice) { if (slice % 2 == 0) continue; // these were manually drawn, no interpolation possible std::cout << slice << " " << std::flush; mitk::Image::Pointer interpolation = m_Interpolator->Interpolate( 2, slice, 0 ); if ( interpolation.IsNull() ) { std::cerr << " (EE) Interpolated image is NULL." << std::endl; return false; } if ( !CompareImageSliceTestHelper::CompareSlice( m_InterpolatedSlices, 2, slice, interpolation ) ) { std::cerr << " (EE) interpolated image is not identical to reference in slice " << slice << std::endl; return false; } } std::cout << std::endl; std::cout << " (II) Interpolations are the same as the saved references." << std::endl; return true; } /// ctest entry point -int mitkSegmentationInterpolationTest(int /*argc*/, char* /*argv*/[]) +int mitkSegmentationInterpolationTest(int argc, char* argv[]) { // one big variable to tell if anything went wrong - std::cout << "Creating CoreObjectFactory" << std::endl; - itk::ObjectFactoryBase::RegisterFactory(mitk::CoreObjectFactory::New()); - +// std::cout << "Creating CoreObjectFactory" << std::endl; +// itk::ObjectFactoryBase::RegisterFactory(mitk::CoreObjectFactory::New()); + if (argc < 3) + { + std::cerr << " (EE) Missing arguments for testing" << std::endl; + } mitkSegmentationInterpolationTestClass test; - if ( test.Test() ) + if ( test.Test(argv[1], argv[2]) ) { std::cout << "[PASSED]" << std::endl; return EXIT_SUCCESS; } else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } }