diff --git a/CMakeExternals/OpenCV.cmake b/CMakeExternals/OpenCV.cmake index 07edcb7cf4..d8cce0a622 100644 --- a/CMakeExternals/OpenCV.cmake +++ b/CMakeExternals/OpenCV.cmake @@ -1,100 +1,79 @@ #----------------------------------------------------------------------------- # OpenCV #----------------------------------------------------------------------------- if(MITK_USE_OpenCV) # Sanity checks if(DEFINED OpenCV_DIR AND NOT EXISTS ${OpenCV_DIR}) message(FATAL_ERROR "OpenCV_DIR variable is defined but corresponds to non-existing directory") endif() set(proj OpenCV) set(proj_DEPENDENCIES) set(OpenCV_DEPENDS ${proj}) if(NOT DEFINED OpenCV_DIR) set(additional_cmake_args -DBUILD_opencv_java:BOOL=OFF -DBUILD_opencv_ts:BOOL=OFF -DBUILD_PERF_TESTS:BOOL=OFF - ) - - if(MITK_USE_Python) - set(CV_PACKAGE_PATH -DPYTHON_PACKAGES_PATH:PATH=${ep_prefix}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) - - list(APPEND additional_cmake_args - -DBUILD_opencv_python:BOOL=ON - -DBUILD_opencv_python3:BOOL=ON - #-DBUILD_NEW_PYTHON_SUPPORT:BOOL=ON - -DPYTHON_DEBUG_LIBRARY:FILEPATH=${PYTHON_DEBUG_LIBRARY} - -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} - -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} - -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2} - -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} - ${CV_PACKAGE_PATH} - #-DPYTHON_LIBRARIES=${PYTHON_LIBRARY} - #-DPYTHON_DEBUG_LIBRARIES=${PYTHON_DEBUG_LIBRARIES} - ) - else() - list(APPEND additional_cmake_args - -DBUILD_opencv_python:BOOL=OFF - -DBUILD_opencv_python3:BOOL=OFF - -DBUILD_opencv_python_bindings_generator:BOOL=OFF - #-DBUILD_NEW_PYTHON_SUPPORT:BOOL=OFF - ) - endif() + -DBUILD_opencv_python:BOOL=OFF + -DBUILD_opencv_python3:BOOL=OFF + -DBUILD_opencv_python_bindings_generator:BOOL=OFF + #-DBUILD_NEW_PYTHON_SUPPORT:BOOL=OFF + ) # 12-05-02, muellerm, added QT usage by OpenCV if QT is used in MITK # 12-09-11, muellerm, removed automatic usage again, since this will struggle with the MITK Qt application object if(MITK_USE_Qt5) list(APPEND additional_cmake_args - -DWITH_QT:BOOL=OFF - -DWITH_QT_OPENGL:BOOL=OFF - -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} - ) + -DWITH_QT:BOOL=OFF + -DWITH_QT_OPENGL:BOOL=OFF + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + ) endif() if(CTEST_USE_LAUNCHERS) list(APPEND additional_cmake_args "-DCMAKE_PROJECT_${proj}_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake" - ) + ) endif() set(opencv_url ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/opencv-3.4.2.tar.gz) set(opencv_url_md5 8aba51c788cac3583bb39a0c24a5888f) ExternalProject_Add(${proj} LIST_SEPARATOR ${sep} URL ${opencv_url} URL_MD5 ${opencv_url_md5} CMAKE_GENERATOR ${gen} CMAKE_ARGS - ${ep_common_args} - -DBUILD_TESTS:BOOL=OFF - -DBUILD_DOCS:BOOL=OFF - -DBUILD_EXAMPLES:BOOL=OFF - -DBUILD_DOXYGEN_DOCS:BOOL=OFF - -DWITH_CUDA:BOOL=OFF - -DWITH_VTK:BOOL=OFF - -DENABLE_CXX11:BOOL=ON - -DWITH_IPP:BOOL=OFF - -DBUILD_IPP_IW:BOOL=OFF - ${additional_cmake_args} + ${ep_common_args} + -DBUILD_TESTS:BOOL=OFF + -DBUILD_DOCS:BOOL=OFF + -DBUILD_EXAMPLES:BOOL=OFF + -DBUILD_DOXYGEN_DOCS:BOOL=OFF + -DWITH_CUDA:BOOL=OFF + -DWITH_VTK:BOOL=OFF + -DENABLE_CXX11:BOOL=ON + -DWITH_IPP:BOOL=OFF + -DBUILD_IPP_IW:BOOL=OFF + ${additional_cmake_args} CMAKE_CACHE_ARGS - ${ep_common_cache_args} + ${ep_common_cache_args} CMAKE_CACHE_DEFAULT_ARGS - ${ep_common_cache_default_args} + ${ep_common_cache_default_args} DEPENDS ${proj_DEPENDENCIES} - ) + ) set(OpenCV_DIR ${ep_prefix}) mitkFunctionInstallExternalCMakeProject(${proj}) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif() endif() diff --git a/CMakeExternals/VTK.cmake b/CMakeExternals/VTK.cmake index 543363ccd6..8295d73335 100644 --- a/CMakeExternals/VTK.cmake +++ b/CMakeExternals/VTK.cmake @@ -1,98 +1,79 @@ #----------------------------------------------------------------------------- # VTK #----------------------------------------------------------------------------- if(WIN32) option(VTK_USE_SYSTEM_FREETYPE OFF) else(WIN32) option(VTK_USE_SYSTEM_FREETYPE ON) endif(WIN32) # Sanity checks if(DEFINED VTK_DIR AND NOT EXISTS ${VTK_DIR}) message(FATAL_ERROR "VTK_DIR variable is defined but corresponds to non-existing directory") endif() set(proj VTK) set(proj_DEPENDENCIES ) set(VTK_DEPENDS ${proj}) if(MITK_USE_HDF5) list(APPEND proj_DEPENDENCIES HDF5) endif() if(NOT DEFINED VTK_DIR) set(additional_cmake_args ) # Optionally enable memory leak checks for any objects derived from vtkObject. This # will force unit tests to fail if they have any of these memory leaks. option(MITK_VTK_DEBUG_LEAKS OFF) mark_as_advanced(MITK_VTK_DEBUG_LEAKS) list(APPEND additional_cmake_args - -DVTK_DEBUG_LEAKS:BOOL=${MITK_VTK_DEBUG_LEAKS} - ) - - if(MITK_USE_Python) - set(_vtk_install_python_dir -DVTK_INSTALL_PYTHON_MODULE_DIR:PATH=${ep_prefix}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) - - list(APPEND additional_cmake_args - -DVTK_WRAP_PYTHON:BOOL=ON - -DVTK_USE_TK:BOOL=OFF - -DVTK_WINDOWS_PYTHON_DEBUGGABLE:BOOL=OFF - -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} - -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} - -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2} - -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} - -DVTK_PYTHON_VERSION:STRING=3 - ${_vtk_install_python_dir} - ) - else() - list(APPEND additional_cmake_args - -DVTK_WRAP_PYTHON:BOOL=OFF - -DVTK_WINDOWS_PYTHON_DEBUGGABLE:BOOL=OFF - ) - endif() + -DVTK_DEBUG_LEAKS:BOOL=${MITK_VTK_DEBUG_LEAKS} + -DVTK_WRAP_PYTHON:BOOL=OFF + -DVTK_WINDOWS_PYTHON_DEBUGGABLE:BOOL=OFF + ) if(MITK_USE_Qt5) list(APPEND additional_cmake_args - -DVTK_Group_Qt:BOOL=ON - -DQt5_DIR:PATH=${Qt5_DIR} - ) + -DVTK_Group_Qt:BOOL=ON + -DQt5_DIR:PATH=${Qt5_DIR} + ) endif() if(CTEST_USE_LAUNCHERS) list(APPEND additional_cmake_args "-DCMAKE_PROJECT_${proj}_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake" - ) + ) endif() ExternalProject_Add(${proj} LIST_SEPARATOR ${sep} URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/VTK-8.1.0.tar.gz URL_MD5 4fa5eadbc8723ba0b8d203f05376d932 CMAKE_GENERATOR ${gen} CMAKE_ARGS - ${ep_common_args} - -DVTK_WRAP_TCL:BOOL=OFF - -DVTK_WRAP_PYTHON:BOOL=OFF - -DVTK_WRAP_JAVA:BOOL=OFF - -DVTK_USE_SYSTEM_FREETYPE:BOOL=${VTK_USE_SYSTEM_FREETYPE} - -DVTK_LEGACY_REMOVE:BOOL=ON - -DModule_vtkTestingRendering:BOOL=ON - ${additional_cmake_args} + ${ep_common_args} + -DVTK_WRAP_TCL:BOOL=OFF + -DVTK_WRAP_PYTHON:BOOL=OFF + -DVTK_WRAP_JAVA:BOOL=OFF + -DVTK_USE_SYSTEM_FREETYPE:BOOL=${VTK_USE_SYSTEM_FREETYPE} + -DVTK_LEGACY_REMOVE:BOOL=ON + -DModule_vtkTestingRendering:BOOL=ON + ${additional_cmake_args} CMAKE_CACHE_ARGS - ${ep_common_cache_args} + ${ep_common_cache_args} CMAKE_CACHE_DEFAULT_ARGS - ${ep_common_cache_default_args} + ${ep_common_cache_default_args} DEPENDS ${proj_DEPENDENCIES} - ) + ) set(VTK_DIR ${ep_prefix}) mitkFunctionInstallExternalCMakeProject(${proj}) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif() diff --git a/Modules/Python/autoload/PythonService/CMakeLists.txt b/Modules/Python/autoload/PythonService/CMakeLists.txt index a1551ed7a4..b957860437 100644 --- a/Modules/Python/autoload/PythonService/CMakeLists.txt +++ b/Modules/Python/autoload/PythonService/CMakeLists.txt @@ -1,15 +1,14 @@ mitkFunctionCheckCompilerFlags("-Wno-cpp" CMAKE_CXX_FLAGS) MITK_CREATE_MODULE( PythonService INCLUDE_DIRS PRIVATE src/PythonService DEPENDS PUBLIC MitkPython PACKAGE_DEPENDS PUBLIC Qt5|Widgets CTK|CTKScriptingPythonCore+CTKScriptingPythonWidgets - PRIVATE VTK|vtkPython+vtkWrappingPythonCore ${OpenCV_DEP} AUTOLOAD_WITH MitkPython ) if(TARGET ${MODULE_TARGET}) configure_file(PythonPath.h.in "${CMAKE_CURRENT_BINARY_DIR}/PythonPath.h" @ONLY) endif() diff --git a/Modules/QtPython/Testing/mitkCommonPythonTest.h b/Modules/QtPython/Testing/mitkCommonPythonTest.h deleted file mode 100644 index 2d72ed4881..0000000000 --- a/Modules/QtPython/Testing/mitkCommonPythonTest.h +++ /dev/null @@ -1,73 +0,0 @@ -/*=================================================================== - -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 -#include -#include -//#include -#include -//#include - -namespace mitk -{ - -class CommonPythonTestSuite : public mitk::TestFixture -{ - -protected: - mitk::IPythonService* m_PythonService; - mitk::Image::Pointer m_Image; - mitk::Image::Pointer m_Image2D; - mitk::Surface::Pointer m_Surface; - //QMap m_Snippets; - -public: - - void setUp() - { - // Workaround to fix microservice loading issues!!! - mitk::IPythonService::ForceLoadModule(); - //get the context of the python module - us::Module* module = us::ModuleRegistry::GetModule("MitkPythonService"); - us::ModuleContext* context = module->GetModuleContext(); - //get the service which is generated in the PythonModuleActivator - us::ServiceReference serviceRef = context->GetServiceReference(); - m_PythonService = dynamic_cast( context->GetService(serviceRef) ); - - m_Image = mitk::IOUtil::Load(GetTestDataFilePath("Pic3D.nrrd")); - m_Image2D = mitk::IOUtil::Load(GetTestDataFilePath("Png2D-bw.png")); - m_Surface = mitk::IOUtil::Load(GetTestDataFilePath("binary.stl")); - - //QmitkPythonSnippets::LoadStringMap(QmitkPythonSnippets::DEFAULT_SNIPPET_FILE,m_Snippets); - } - - void tearDown() - { - m_Image = nullptr; - m_Image2D = nullptr; - m_Surface = nullptr; - } -}; - -} diff --git a/Modules/QtPython/Testing/mitkCvPythonTest.cpp b/Modules/QtPython/Testing/mitkCvPythonTest.cpp index b625d36166..8125553574 100644 --- a/Modules/QtPython/Testing/mitkCvPythonTest.cpp +++ b/Modules/QtPython/Testing/mitkCvPythonTest.cpp @@ -1,59 +1,82 @@ /*=================================================================== 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 - -class mitkCvPythonTestSuite : public mitk::CommonPythonTestSuite +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class mitkCvPythonTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkCvPythonTestSuite); MITK_TEST(testCVImageTransfer); MITK_TEST(testOpenCVMedianFilter); CPPUNIT_TEST_SUITE_END(); public: + mitk::Image::Pointer m_Image2D; + + mitk::IPythonService* m_PythonService; + void setUp() override + { + us::ModuleContext* context = us::GetModuleContext(); + us::ServiceReference m_PythonServiceRef = context->GetServiceReference(); + m_PythonService = dynamic_cast ( context->GetService(m_PythonServiceRef) ); + mitk::IPythonService::ForceLoadModule(); + + m_Image2D = mitk::IOUtil::Load(GetTestDataFilePath("Png2D-bw.png")); + } + void testCVImageTransfer() { std::string varName("mitkImage"); CPPUNIT_ASSERT_MESSAGE ( "Is OpenCV Python Wrapping available?", m_PythonService->IsOpenCvPythonWrappingAvailable() == true ); CPPUNIT_ASSERT_MESSAGE( "Valid image copied to python import should return true.", m_PythonService->CopyToPythonAsCvImage( m_Image2D, varName) == true ); mitk::Image::Pointer pythonImage = m_PythonService->CopyCvImageFromPython(varName); // todo pixeltypes do not match, cv is changing it //CPPUNIT_ASSERT_MESSAGE( "Compare if images are equal after transfer.", // mitk::Equal(pythonImage,m_Image2D) ); } //TODO opencv median filter, add cpp test code void testOpenCVMedianFilter() { std::string code = "mitkImage_new = cv2.medianBlur(mitkImage, 3)"; // simple itk median filter in python CPPUNIT_ASSERT_MESSAGE ( "Is OpenCV Python Wrapping available?", m_PythonService->IsOpenCvPythonWrappingAvailable() == true ); CPPUNIT_ASSERT_MESSAGE( "Valid image copied to python import should return true.", m_PythonService->CopyToPythonAsCvImage(m_Image2D, "mitkImage") == true ); m_PythonService->Execute( code, mitk::IPythonService::MULTI_LINE_COMMAND ); CPPUNIT_ASSERT_MESSAGE( "Python execute error occured.", !m_PythonService->PythonErrorOccured()); } }; MITK_TEST_SUITE_REGISTRATION(mitkCvPython) diff --git a/Modules/QtPython/Testing/mitkVtkPythonTest.cpp b/Modules/QtPython/Testing/mitkVtkPythonTest.cpp index 89b93672c9..48d1f8a049 100644 --- a/Modules/QtPython/Testing/mitkVtkPythonTest.cpp +++ b/Modules/QtPython/Testing/mitkVtkPythonTest.cpp @@ -1,112 +1,132 @@ /*=================================================================== 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 -// vtk cone sample snippet #include -// vtk decimate pro snippet #include - -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -class mitkVtkPythonTestSuite : public mitk::CommonPythonTestSuite +class mitkVtkPythonTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkVtkPythonTestSuite); MITK_TEST(testSurfaceTransfer); - MITK_TEST(testVtkCreateConePythonSnippet); +// MITK_TEST(testVtkCreateConePythonSnippet); //MITK_TEST(testVtkDecimateProPythonSnippet); CPPUNIT_TEST_SUITE_END(); public: + mitk::IPythonService* m_PythonService; + mitk::Surface::Pointer m_Surface; + + void setUp() override + { + us::ModuleContext* context = us::GetModuleContext(); + us::ServiceReference m_PythonServiceRef = context->GetServiceReference(); + m_PythonService = dynamic_cast ( context->GetService(m_PythonServiceRef) ); + mitk::IPythonService::ForceLoadModule(); + + m_Surface = mitk::IOUtil::Load(GetTestDataFilePath("binary.stl")); + } + void testSurfaceTransfer() { std::string varName("mitkSurface"); CPPUNIT_ASSERT_MESSAGE ( "Is VTK Python Wrapping available?", m_PythonService->IsVtkPythonWrappingAvailable() == true ); CPPUNIT_ASSERT_MESSAGE( "Valid surface copied to python import should return true.", m_PythonService->CopyToPythonAsVtkPolyData( m_Surface, varName) == true ); mitk::Surface::Pointer pythonSurface = m_PythonService->CopyVtkPolyDataFromPython(varName); CPPUNIT_ASSERT_MESSAGE( "Compare if surfaces are equal after transfer.", mitk::Equal(*pythonSurface.GetPointer(),*m_Surface.GetPointer(),mitk::eps,true) ); } void testVtkCreateConePythonSnippet() { std::string code = "import vtk\n" "coneSrc = vtk.vtkConeSource()\n" "coneSrc.SetResolution(60)\n" "coneSrc.SetCenter(-2,0,0)\n" "coneSrc.Update()\n" "cone = coneSrc.GetOutput()"; // cone in cpp - mitk::Surface::Pointer mitkSurface = mitk::Surface::New(); - vtkSmartPointer coneSrc = vtkSmartPointer::New(); - coneSrc->SetResolution(60); - coneSrc->SetCenter(-2,0,0); - coneSrc->Update(); - mitkSurface->SetVtkPolyData(coneSrc->GetOutput()); +// mitk::Surface::Pointer mitkSurface = mitk::Surface::New(); +// vtkSmartPointer coneSrc = vtkSmartPointer::New(); +// coneSrc->SetResolution(60); +// coneSrc->SetCenter(-2,0,0); +// coneSrc->Update(); +// mitkSurface->SetVtkPolyData(coneSrc->GetOutput()); // run python code CPPUNIT_ASSERT_MESSAGE ( "Is VTK Python Wrapping available?", m_PythonService->IsVtkPythonWrappingAvailable() == true ); - m_PythonService->Execute( code, mitk::IPythonService::MULTI_LINE_COMMAND ); - CPPUNIT_ASSERT_MESSAGE( "Python execute error occured.", !m_PythonService->PythonErrorOccured()); +// m_PythonService->Execute( code, mitk::IPythonService::MULTI_LINE_COMMAND ); +// CPPUNIT_ASSERT_MESSAGE( "Python execute error occured.", !m_PythonService->PythonErrorOccured()); - mitk::Surface::Pointer pythonSurface = m_PythonService->CopyVtkPolyDataFromPython("cone"); +// mitk::Surface::Pointer pythonSurface = m_PythonService->CopyVtkPolyDataFromPython("cone"); - CPPUNIT_ASSERT_MESSAGE( "Compare if cones are equal.", mitk::Equal(*pythonSurface.GetPointer(), *mitkSurface.GetPointer(), mitk::eps,true) ); +// CPPUNIT_ASSERT_MESSAGE( "Compare if cones are equal.", mitk::Equal(*pythonSurface.GetPointer(), *mitkSurface.GetPointer(), mitk::eps,true) ); } void testVtkDecimateProPythonSnippet() { std::string code = "import vtk\n" "deci = vtk.vtkDecimatePro()\n" "deci.SetInputData( mitkSurface )\n" "deci.SetTargetReduction(0.9)\n" "deci.PreserveTopologyOn()\n" "deci.Update()\n" "mitkSurface_new = deci.GetOutput()\n"; // decimate pro in cpp mitk::Surface::Pointer mitkSurface = mitk::Surface::New(); vtkSmartPointer deci = vtkSmartPointer::New(); deci->SetInputData(m_Surface->GetVtkPolyData()); deci->SetTargetReduction(0.9); deci->PreserveTopologyOn(); deci->Update(); mitkSurface->SetVtkPolyData(deci->GetOutput()); // decimate pro in python CPPUNIT_ASSERT_MESSAGE ( "Is VTK Python Wrapping available?", m_PythonService->IsVtkPythonWrappingAvailable() == true ); CPPUNIT_ASSERT_MESSAGE( "Valid surface copied to python import should return true.", m_PythonService->CopyToPythonAsVtkPolyData( m_Surface, "mitkSurface") == true ); m_PythonService->Execute( code, mitk::IPythonService::MULTI_LINE_COMMAND ); CPPUNIT_ASSERT_MESSAGE( "Python execute error occured.", !m_PythonService->PythonErrorOccured()); mitk::Surface::Pointer pythonSurface = m_PythonService->CopyVtkPolyDataFromPython("mitkSurface_new"); CPPUNIT_ASSERT_MESSAGE( "Compare if surfaces are equal.", mitk::Equal(*pythonSurface.GetPointer(), *mitkSurface.GetPointer(), mitk::eps,true) ); } }; MITK_TEST_SUITE_REGISTRATION(mitkVtkPython)