diff --git a/Modules/Remeshing/CMakeLists.txt b/Modules/Remeshing/CMakeLists.txt index edeb1b1724..f887c4bdda 100644 --- a/Modules/Remeshing/CMakeLists.txt +++ b/Modules/Remeshing/CMakeLists.txt @@ -1,5 +1,7 @@ if(MITK_USE_ACVD) MITK_CREATE_MODULE(Remeshing PACKAGE_DEPENDS ACVD ) + + add_subdirectory(Testing) endif() diff --git a/Modules/Remeshing/Testing/CMakeLists.txt b/Modules/Remeshing/Testing/CMakeLists.txt new file mode 100644 index 0000000000..a29ccbc947 --- /dev/null +++ b/Modules/Remeshing/Testing/CMakeLists.txt @@ -0,0 +1,5 @@ +if(MITK_USE_ACVD) + MITK_CREATE_MODULE_TESTS() + + mitkAddCustomModuleTest(mitkACVDTest mitkACVDTest ${MITK_DATA_DIR}/binary.stl 0 1228 1.0 10 0.0 1 0 0) +endif() diff --git a/Modules/Remeshing/Testing/files.cmake b/Modules/Remeshing/Testing/files.cmake new file mode 100644 index 0000000000..055665bf46 --- /dev/null +++ b/Modules/Remeshing/Testing/files.cmake @@ -0,0 +1,6 @@ +set(MODULE_TESTS +) + +set(MODULE_CUSTOM_TESTS + mitkACVDTest.cpp +) diff --git a/Modules/Remeshing/Testing/mitkACVDTest.cpp b/Modules/Remeshing/Testing/mitkACVDTest.cpp new file mode 100644 index 0000000000..daace542b4 --- /dev/null +++ b/Modules/Remeshing/Testing/mitkACVDTest.cpp @@ -0,0 +1,111 @@ +/*=================================================================== + +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 + +template +static T lexical_cast(const std::string& string) +{ + std::istringstream sstream(string); + T value; + + sstream >> value; + + if (sstream.fail()) + { + MITK_ERROR << "Lexical cast failed for '" << string << "'!"; + exit(EXIT_FAILURE); + } + + return value; +} + +static void Remesh_SurfaceIsNull_ReturnsNull() +{ + mitk::Surface::Pointer surface; + mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(surface, 0, 100, 0.0); + MITK_TEST_CONDITION(remeshedSurface.IsNull(), "Remesh_SurfaceIsNull_ReturnsNull") +} + +static void Remesh_PolyDataIsNull_ReturnsNull() +{ + mitk::Surface::Pointer surface = mitk::Surface::New(); + mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(surface, 0, 100, 0.0); + MITK_TEST_CONDITION(remeshedSurface.IsNull(), "Remesh_PolyDataIsNull_ReturnsNull") +} + +static void Remesh_SurfaceDoesNotHaveDataAtTimeStep_ReturnsNull() +{ + mitk::Surface::Pointer surface = mitk::Surface::New(); + mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(surface, 1, 100, 0.0); + MITK_TEST_CONDITION(remeshedSurface.IsNull(), "Remesh_SurfaceDoesNotHaveDataAtTimeStep_ReturnsNull") +} + +static void Remesh_SurfaceHasNoPolygons_ReturnsNull() +{ + mitk::Surface::Pointer surface = mitk::Surface::New(); + vtkSmartPointer polyData = vtkSmartPointer::New(); + surface->SetVtkPolyData(polyData); + mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(surface, 0, 100, 0.0); + MITK_TEST_CONDITION(remeshedSurface.IsNull(), "Remesh_SurfaceHasNoPolygons_ReturnsNull") +} + +static void Remesh_SurfaceIsValid_ReturnsRemeshedSurface(const std::string& filename, unsigned int t, int numVertices, double gradation, int subsampling, double edgeSplitting, int optimizationLevel, bool forceManifold, bool boundaryFixing) +{ + mitk::Surface::Pointer surface = mitk::IOUtil::LoadSurface(filename); + mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(surface, t, numVertices, gradation, subsampling, edgeSplitting, optimizationLevel, forceManifold, boundaryFixing); + MITK_TEST_CONDITION(remeshedSurface.IsNotNull() && remeshedSurface->GetVtkPolyData() != NULL && remeshedSurface->GetVtkPolyData()->GetNumberOfPolys() != 0, "Remesh_SurfaceIsValid_ReturnsRemeshedSurface") +} + +int mitkACVDTest(int argc, char* argv[]) +{ + if (argc != 10) + { + MITK_ERROR << "Invalid argument count!\n" + << "Usage: mitkACVDTest \n" + << " \n" + << " \n" + << " See MITK API documentation of mitk::ACVD::Remesh() for details."; + + return EXIT_FAILURE; + } + + const std::string filename = argv[1]; + const unsigned int t = lexical_cast(argv[2]); + const int numVertices = lexical_cast(argv[3]); + const double gradation = lexical_cast(argv[4]); + const int subsampling = lexical_cast(argv[5]); + const double edgeSplitting = lexical_cast(argv[6]); + const int optimizationLevel = lexical_cast(argv[7]); + const bool forceManifold = lexical_cast(argv[8]); + const bool boundaryFixing = lexical_cast(argv[9]); + + MITK_TEST_BEGIN("mitkACVDTest") + + Remesh_SurfaceIsNull_ReturnsNull(); + Remesh_PolyDataIsNull_ReturnsNull(); + Remesh_SurfaceDoesNotHaveDataAtTimeStep_ReturnsNull(); + Remesh_SurfaceHasNoPolygons_ReturnsNull(); + + Remesh_SurfaceIsValid_ReturnsRemeshedSurface(filename, t, numVertices, gradation, subsampling, edgeSplitting, optimizationLevel, forceManifold, boundaryFixing); + + MITK_TEST_END() +}