Page MenuHomePhabricator

Python wrapping for MITK classes
Closed, ResolvedPublic

Event Timeline

[SVN revision 25947]
ENH (#5286): branch for python wrapping code

[SVN revision 25948]
ENH (#5286): initial version of python wrapping

[SVN revision 28478]
ENH (#5286): added Mediator, QmitkPythonVariableStackTreeWidget for Drag&Drop

[SVN revision 28494]
FIX (#5286): reverting accidental changes in python wrapping branch

[SVN revision 28520]
FIX (#5286): Changed Variable MITK_CSWIG_PYTHON to MITK_USE_PYTHON

[SVN revision 28523]
FIX (#5286): Changed Variable MITK_CSWIG_PYTHON to MITK_USE_PYTHON

[SVN revision 28594]
ENH (#5286): QmitkPythonVariableStackTreeWidget for Drag&Drop

[SVN revision 28810]
ENH (#5286): Added Drag and Drop for VariableStack and Python Perspective

[SVN revision 28817]
ENH (#5286): CTK Find Libs

[SVN revision 28890]
COMP (#5286): merged python wrapping code

COMP since a directory is missing

TODOs (so far):

  • Still got errors due to changed visibility of ExecuteOperation method in mitk::Interactor
  • Fix documentation errors
    • Orthographical errors
    • CMake 2.8.2 is needed for CTK?
  • Move documentation from internal mbiwiki to external mitk.org homepage
  • Email to the users list
  • Provide more template casting possibilities in ImageCaster

further TODO:

  • test if wrapping also works for any other module and what happens with unwrapped code

CC Ingmar.
I still have trouble with the mixed visibility of the ExecuteOperation() method in mitk::StateMachine. I wrote a simple programm to test what happens if you would downcast a StateMachine to an OperationActor object and call ExecuteOperation():

main.cpp

#include <iostream>

using namespace std;

class Base
{
public:

virtual void ExecuteOperation() = 0;

};

class PublicBase: public Base
{
public:

void ExecuteOperation()
{
  cout << "hello world PUBLIC" << endl;
}

};

class ProtectedBase: public Base
{
protected:

void ExecuteOperation()
{
  cout << "hello world PROTECTED" << endl;
}

};

int main (int argc, char *argv[])
{

PublicBase pB;
// prints out "hello world PUBLIC"
pB.ExecuteOperation();

ProtectedBase prB;
// does not work
// prB.ExecuteOperation();
// but what happens here
Base* b = &prB;
b->ExecuteOperation();
 
// !!! prints out "hello world PROTECTED" !!! 
// tested on Windows VS 2008

system("PAUSE");
return 0;

}

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (cpp-test)

add_executable(cpp-test main.cpp)

This is a very strange C++ behaviour. You see the visibility of ExecuteOperation() is more or less a convention if you declare it protected. I would prefer to make the method public and add a bold note to the documentation that ExecuteOperation() should not be called from other classes. If we leave it like that I will have to deactivate each wrapped class that reference StateMachine objects?

or maybe we can think of another object oriented solution like writing a base "tagging" interface or something like that. but i am not into the whole mechanism, so lets talk when you are back. so far, get well soon

  • work today:
    • tested cv wrappers on windows and adapted docs (test documentation on linux again)
    • Moved documentation to public wiki: http://www.mitk.org/wiki/Documentation/PythonWrapping#preview
    • Made StateMachine::ExecuteOperation public -> wrapper generation succeeded -> has to be discussed with ingmar (no commit yet)
    • Crucial Todos for the next time: fix WrapITK (seems not to work on windows), test documentation for VTK on Windows and Linux, OpenCV on Linux, commit StateMachine fixes, finish documentation, write email to users list
    • Other Todos: Test Wrapping for other Modules

That sounds reasonable. To finalize it let's talk in person.

Python in Debug mode on Windows is pure pain:
The installer does not ship the debug library ("python2x_d.lib") but the, but the header file pyconfig.h enforces the use of it by using VS Macros:

...
#ifdef _DEBUG
#pragma comment(lib,"python27_d.lib")
...

Thus when including this file the VS linker will complain if the library isn`t there. Well, we could use the python wrapping only in release mode (btw: wrapping debug code is senseless). Unfortunately, we have to find a solution that the python.console bundle will also be built in Debug mode. Otherwise one cannot built his ExtApp in Debug mode when the python.console bundle is activated.

ok the trick is to only use the Release library by using

  1. ifdef _DEBUG
  2. undef _DEBUG
  3. if defined(_MSC_VER) && _MSC_VER >= 1400
  4. define _CRT_NOFORCE_MANIFEST 1
  5. endif
  6. include <Python.h>
  7. define _DEBUG
  8. else
  9. include <Python.h>
  10. endif

of just

#include <Python.h>

everywhere one needs to include the python headers

TODO:
find out with dependency walker why python wrapping does not show up when activating the bundle

todo: ctk dir and pythonQt dir to the path when using the python console bundle

[29b749]: Merge branch 'bug-5286-python-wrapping'

Conflicts:
CMake/mitkMacroCh

Merged commits:

2011-03-24 18:00:04 Michael Mueller [080433]
adding new image cast methods along with more mitk to vtk conversion methods


2011-03-15 10:51:57 Michael Mueller [b5e6d4]
Instantiated more templates for image casting in Python Wrapping


2011-03-15 09:29:45 Michael Mueller [e75cd0]
Activating mitkInteractor for wrapping


2011-03-04 10:34:50 Michael Mueller [dabf50]
Further bugfixes for Debug builds with python wrapping (do not use optimized CMake keyword if no Debug lib is available)


2011-03-03 17:58:44 Michael Mueller [ffcddd]
reverted order of creation of WRAPPIND_SOURCE_DIR to be before adding subdirectory Modules


2011-03-03 17:20:18 Michael Mueller [067814]
adding VTK/ITK_INCLUDE_DIRS explicitly to the list of ALL_INCLUDE_DIRECTORIES for wrapping


2011-03-03 15:30:24 Michael Mueller [e7315c]
fixed case typos for linux in wrapping CMake code. fixed small bug in
macrocheckmodule


2011-03-02 15:04:33 Michael Mueller [98d635]
Removed unused CMakeListsWin.txr


2011-02-24 14:00:55 Michael Mueller [fcbe9a]
adding final changes for MITK Python Wrapping

changing visibility of mitk::StateMachine::ExecuteCommand() to public in order to make Wrapping work with that class and all dependent classes
forcing python.console classes to not include non-debug headers

closing now. open new bugs for python wrapping