diff --git a/Modules/QtPython/Testing/files.cmake b/Modules/QtPython/Testing/files.cmake index 4acaf49de5..d4301946da 100644 --- a/Modules/QtPython/Testing/files.cmake +++ b/Modules/QtPython/Testing/files.cmake @@ -1,13 +1,3 @@ set(MODULE_TESTS mitkPythonTest.cpp ) - -#TODO: temporarily disabled untill segfault is fixed (bug-19152) -if(UNIX) - set(MODULE_TESTS ${MODULE_TESTS} mitkVtkPythonTest.cpp) -endif() - -if(MITK_USE_OpenCV) - set(MODULE_TESTS ${MODULE_TESTS} mitkCvPythonTest.cpp) -endif() - diff --git a/Modules/QtPython/Testing/mitkCvPythonTest.cpp b/Modules/QtPython/Testing/mitkCvPythonTest.cpp deleted file mode 100644 index 8125553574..0000000000 --- a/Modules/QtPython/Testing/mitkCvPythonTest.cpp +++ /dev/null @@ -1,82 +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 - -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 deleted file mode 100644 index 48d1f8a049..0000000000 --- a/Modules/QtPython/Testing/mitkVtkPythonTest.cpp +++ /dev/null @@ -1,132 +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 -#include -#include - -class mitkVtkPythonTestSuite : public mitk::TestFixture -{ - CPPUNIT_TEST_SUITE(mitkVtkPythonTestSuite); - MITK_TEST(testSurfaceTransfer); -// 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()); - - // 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()); - -// 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) ); - } - - 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) diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.python/plugin.xml b/Plugins/org.mitk.gui.qt.diffusionimaging.python/plugin.xml index de706ba265..74b3161e1c 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.python/plugin.xml +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.python/plugin.xml @@ -1,33 +1,48 @@ + + + + + + + + + + + + + + +