diff --git a/Wrapping/Python/CMakeLists.txt b/Wrapping/Python/CMakeLists.txt index 24baee8eb4..bc8e54130e 100644 --- a/Wrapping/Python/CMakeLists.txt +++ b/Wrapping/Python/CMakeLists.txt @@ -1,66 +1,68 @@ # Version 2.8.1 is the minium requirement for this script. # this is lower than the general minimum requirement. #cmake_minimum_required ( VERSION 2.8.1 FATAL_ERROR ) project( MITK_Python ) # function taken from # https://stackoverflow.com/questions/37205274/swig-and-cmake-make-use-of-information-provided-by-target-include-directories function(swig_add_library_dependencies swig_module library_names) foreach(library_name ${library_names}) get_property(LIBRARY_INCLUDES TARGET ${library_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES) foreach(INCLUDE_PATH ${LIBRARY_INCLUDES}) include_directories(${INCLUDE_PATH}) file(GLOB_RECURSE header_files "${INCLUDE_PATH}/*.h") list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${header_files}) message(STATUS ${header_files}) # export variable to parent scope set(SWIG_MODULE_${swig_module}_EXTRA_DEPS ${SWIG_MODULE_${swig_module}_EXTRA_DEPS} PARENT_SCOPE) endforeach() endforeach() endfunction() # # Find the necessary libraries etc.. # if ( MITK_UNDEFINED_SYMBOLS_ALLOWED ) set( _QUIET_LIBRARY "QUIET" ) else() set( _QUIET_LIBRARY "REQUIRED" ) endif() find_package ( PythonInterp REQUIRED ) find_package ( PythonLibs ${_QUIET_LIBRARY} ) # # Options # option ( MITK_PYTHON_THREADS "Enable threaded python usage by unlocking the GIL." ON ) mark_as_advanced( MITK_PYTHON_THREADS ) option ( MITK_PYTHON_EGG "Add building of python eggs to the dist target." OFF ) mark_as_advanced( MITK_PYTHON_EGG ) option ( MITK_PYTHON_WHEEL "Add building of python wheels to the dist target." ON ) mark_as_advanced( MITK_PYTHON_WHEEL ) set_source_files_properties ( MITK.i PROPERTIES CPLUSPLUS ON ) -set_source_files_properties ( MITK.i PROPERTIES SWIG_FLAGS "-IE:/Projects/MitkPython/mitk/Modules/Core/include" ) +set(ADDITIONAL_TMP_SWIG_INCLUDES "-IE:/Projects/MitkPython/mitk/Modules/Core/include" "-IE:/Projects/MitkPython/mitk-bin/ep/include/ITK-4.12" ) +#set_source_files_properties ( MITK.i PROPERTIES SWIG_FLAGS "${ADDITIONAL_TMP_SWIG_INCLUDES}" ) +set_property(SOURCE MITK.i PROPERTY SWIG_FLAGS ${ADDITIONAL_TMP_SWIG_INCLUDES} ) # Run swig set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS} -features autodoc=1 -keyword ) if( MITK_PYTHON_THREADS ) set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -threads) endif() set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) swig_add_module ( PythonMITK python MITK.i ) swig_link_libraries(PythonMITK MitkCore ) swig_link_libraries(PythonMITK ${PYTHON_LIBRARIES} ) include_directories( ${PYTHON_INCLUDE_DIR}) list(APPEND SWIG_MODULE_PythonMITK_EXTRA_DEPS ${PYTHON_INCLUDE_DIR}) swig_add_library_dependencies(PythonMITK "MitkCore;mbilog;CppMicroServices") \ No newline at end of file diff --git a/Wrapping/Python/MITK.i b/Wrapping/Python/MITK.i index b3b1f826ab..6e87d5df69 100644 --- a/Wrapping/Python/MITK.i +++ b/Wrapping/Python/MITK.i @@ -1,21 +1,68 @@ %module PythonMITK %{ +#include #include using namespace mitk; +using namespace itk; int hello() {return 1;}; mitk::BaseData::Pointer Load(const std::string &path) { return mitk::IOUtil::Load(path)[0]; } %} +// Use STL support +%include %include +%include +#if SWIGPYTHON || SWIGRUBY +%include +#endif +// Use C99 int support +%include #define MITKCORE_EXPORT +%define mitkClassMacroItkParent(className, SuperClassName) + typedef className Self; + typedef SuperClassName Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + static const char *GetStaticNameOfClass() { return #className; } + virtual std::vector GetClassHierarchy() const { return mitk::GetClassHierarchy(); } + // itkTypeMacro(className, SuperClassName) +%enddef +#define DEPRECATED(...) ##__VA_ARGS__ +#define ITK_NOEXCEPT +%include +%include %include + extern int hello(); extern mitk::BaseData::Pointer Load(const std::string &path); + +namespace std { + %template(VectorBaseDataPointer) vector< itk::SmartPointer >; + %template(VectorBaseData) vector< mitk::BaseData::Self *>; + + %template(VectorBool) vector; + %template(VectorUInt8) vector; + %template(VectorInt8) vector; + %template(VectorUInt16) vector; + %template(VectorInt16) vector; + %template(VectorUInt32) vector; + %template(VectorInt32) vector; + %template(VectorUInt64) vector; + %template(VectorInt64) vector; + %template(VectorFloat) vector; + %template(VectorDouble) vector; + %template(VectorUIntList) vector< vector >; + %template(VectorString) vector< std::string >; + + %template(DoubleDoubleMap) map; +} +%template(BaseDataPointer) itk::SmartPointer; +