[ITK-users] Suggestions about Python wrapping of cpp project

Michka Popoff michkapopoff at gmail.com
Thu Jul 24 16:39:35 EDT 2014


For VTK, I don’t know what would be the best way to tacle the problem.

For the interface files, the best would be you compile the whole ITK project once to get the .i files.
(You can set the wrapped images dimensions from 2;3 to 2 only, and wrap only the core group, to compile faster).
You can then find the .i files in some folder of the build (I don’t remember in which folder exactly, you will have to search a little bit for them).
You can also look at the base .i file we use, though I will not be able to help you a lot with it, as I did not write it, so it may take some time to decipher:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/PyBase/pyBase.i

So maybe the starting point would to have a first part of your code compiled with Swig. Build a minimal c++ dummy example to understand how it all works,
And then you’ll need to go step by step. I can not guarantee you will succeed, but I would be definitively interested if it works.
Maybe if you find something out, it would be very nice to have a tutorial on how to do this.

Ho, and I just thought about something else. Once ITK is compiled and installed, you can use it as an external project, even with python:
See one example: https://github.com/InsightSoftwareConsortium/itkPyBuffer
Or this one, at the very end of the page: http://cmake.org/Wiki/index.php?title=ITK/Release_4/Wrapping/BuildProcess&oldid=44313
This is not a tested feature for the moment so you may run into some trouble.

Michka



On 24 juil. 2014, at 20:47, Satyananda Kashyap <ksatyananda at gmail.com> wrote:

> Thank you for that. VTK is pretty deeply nested in my code. I will have to write a similar interface file. 
> 
> Can you suggest a starting point in the ITK interface files I can start looking at. I want to try and wrap a simple piece of my code modifying them.
> 
> Regards,
> Kashyap
> 
> 
> On Thu, Jul 24, 2014 at 12:15 PM, Michka Popoff <michkapopoff at gmail.com> wrote:
> Nested classes are supported by Swig 3.0.0 natively:
> http://www.swig.org/Doc3.0/SWIGDocumentation.html#SWIGPlus_nested_classes
> I have no clue if we have nested classes in ITK, and how it was wrapped. Maybe I’ll stumble upon this one day.
> So I can not really help here but should work.
> 
> 1. gccxml is limited to VS2008, and we have no replacement for it. This is a known limitation which is also blocking for ITK.
> 
> 2. For VTK, is this deeply nested in your c++ code ? Maybe you could just rewrite the VTK part using python directly ? This would remove one dependency.
> For OpenCV, I don’t know how this could be done. This would need to be researched on google, I found this blog post for example:
> 
> 
> Michka
> 
> 
> 
> On 24 juil. 2014, at 17:41, Satyananda Kashyap <ksatyananda at gmail.com> wrote:
> 
>> Hi Mickha,
>> 
>> When using SWIG I read that it cannot handle nested classes and that the interface classes would be needed to expose them separately to python. So I did actually try to use the interface file pipeline designed for ITK  with gccxml to see if I could exposes the classes I had written. I am using a Visual Studio 2010 build. I had two main issues with it :
>> 
>> 1. gccxml does not seem to be compatible with versions beyond VS2008. Now I wasn't sure if redoing my full cpp development in VS2008 would be a good idea. I could not find a workaround for this (Hence my attempt to try and use boost.python). 
>> 
>> 2. Also I needed to modify the interface files so that the other packages dependencies (i.e. VTK and OpenCV) could also work. I was not sure how to do that. 
>> 
>> Any suggestions on how/where I could start modifying. I like the fact that I will be able to automate the process and not write any interface files once I can get it working. 
>> 
>> Thanks,
>> Regards,
>> Kashyap
>> 
>> 
>> On Thu, Jul 24, 2014 at 3:54 AM, Michka Popoff <michkapopoff at gmail.com> wrote:
>> Hi
>> 
>> I am currently maintaining the Python part of ITK, but I don’t know if I can help you. I just started with this some time ago and can not really compare it to the boost python method as I don’t know it.
>> There is an old (but outdated) discussion about boost and swig here [1]. But this was written for swig 1.34, and now we already have swig 3.0.2, which brought a lot of improvements.
>> 
>> Swig has been under heavy development lately. What I find nice with Swig is that you get other languages for free, it does not only support python but also Java, Ruby, TCL, … (you will need to write some code for this support though).
>> The Swig method is nice once you automatized your process. Depending on the c++ code you wrote, you don’t even need to write interface files for Swig.
>> For ITK, we have a small pipeline which reads the c++ code with gccxml, and uses a python script [3] (which uses pygccxml) to create interface files from the xml files.
>> 
>> What problems did you encounter when trying the Swig route ? Maybe I can help.
>> 
>> Michka
>> 
>> [1] https://dev.lsstcorp.org/trac/wiki/SwigVsBoostPython
>> [2] https://github.com/swig/swig
>> [3] https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/SwigInterface/igenerator.py
>> 
>> On 23 juil. 2014, at 17:11, Satyananda Kashyap <ksatyananda at gmail.com> wrote:
>> 
>> > Hello,
>> >
>> > I am looking for your expert opinions here. I have a relatively large C++ project I am working on which uses ITK mainly (hence the question here) and to some extent VTK and OpenCV. I do think that my code is fairly well written. I was thinking of wrapping my code to python using either SWIG or boost.python. Here are my questions :
>> >
>> >
>> > 1. I am led to believe that prototyping and code development is much faster in Python. Given that I have such a big cpp base code is it really worth the effort to wrap into python and then continue there.
>> >
>> > 2. From what I have read ITK uses SWIG wrappings for wrapping into Python while VTK uses the boost.python route. My initial attempts with both have been relatively unsuccessful. Any opinion on which one is more user friendly/better when I have to wrap my own custom classes which use a combination of both ITK and VTK in them.
>> >
>> > 3. Any suggestion on a road map as to how to proceed. I am not sure at what base class level I should wrap them and rewrite the dependencies in python.
>> >
>> > Thanks,
>> > Regards,
>> > Kashyap
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.php
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://public.kitware.com/mailman/listinfo/insight-users
>> 
>> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20140724/e27e8d21/attachment.html>


More information about the Insight-users mailing list