[Insight-users] Wrapping a custom C++ function in Python
Gaëtan Lehmann
gaetan.lehmann at jouy.inra.fr
Tue Jun 9 15:23:59 EDT 2009
Le 9 juin 09 à 11:44, Julien Lamy a écrit :
> Gaëtan Lehmann a écrit :
>> Le 8 juin 09 à 15:12, Julien Lamy a écrit :
>>>
>>> I'm trying to wrap a simple C++ function in Python using WrapITK,
>>> but the Python script fails with the following traceback :
>>> TypeError: in method 'test_wrapper', argument 1 of type
>>> 'itk::Image< unsigned short,3 > *'
>>>
>>> My C++ function is :
>>>
>>> bool test_wrapper(itk::Image<unsigned short, 3>::Pointer input)
>>> {
>>> std::cout << input->GetRequestedRegion().GetSize() <<
>>> std::endl;
>>> }
>>>
>>> My Python script is :
>>> import numpy
>>> import itk
>>> from Wrapper import test_wrapper
>>>
>>> data = numpy.arange(3*5*7, dtype=numpy.uint16).reshape((3,5,7))
>>> image_itk = itk.PyBuffer[itk.Image[itk.US,
>>> 3]].GetImageFromArray(data)
>>> test_wrapper(image_itk)
>>>
>>> My SWIG wrapper is :
>>>
>>> %module Wrapper
>>> %{
>>> #include "test_Wrapper.hpp"
>>> %}
>>>
>>> bool test_wrapper(itk::Image<unsigned short, 3> * input);
>> this last line should be
>> bool test_wrapper(itkImageUS3 * input);
>> and you have to #include Base.includes (located at /usr/local/lib/
>> InsightToolkit/WrapITK/Configuration/Typedefs/Base.includes on my
>> system), to %include wrap_itkImage.i (/usr/local/lib/InsightToolkit/
>> WrapITK/Configuration/Typedefs/wrap_itkImage.i).
>
> I'm missing both files. There is actually no trace of a WrapITK/
> Configuration/Typedefs directory on my system, either in the source,
> build or installation directories. I compiled ITK 3.14.0 from source
> with the following cmake command :
> cmake -D BUILD_EXAMPLES=OFF -D BUILD_SHARED_LIBS=ON -D
> BUILD_TESTING=OFF \
> -D CMAKE_BUILD_TYPE=Release \
> -D CMAKE_INSTALL_PREFIX=MY_LOCAL_DIR \
> -D ITK_USE_REVIEW=ON \
> -D USE_WRAP_ITK=ON \
> -D PY_SITE_PACKAGES_PATH=MY_LOCAL_DIR/lib/python2.5/site-
> packages \
> -D WRAP_ITK_JAVA=OFF -D WRAP_ITK_TCL=OFF \
> ../InsightToolkit-3.14.0
>
Sorry, my mistake.
I thought you were using wrapitk from google code, because you have
listed swig in your programs, but I realize that you are using it only
for your own project.
You can't do that with wrapitk shipped with itk. I think the only way
to go is to use an external project.
> I looked through the CMake options, but I found nothing related to
> wrapping and typedefs. I'll give a try to the packages listed on
> your code.google.com page and see if I can come up with something.
>
Let me know if you found any problem.
Gaëtan
>> I'm not sure, because that's a function and wrapitk currently only
>> wrap classes, but it may be easier to do that with a wrapitk
>> external project.
>
> This is going to be complicated for our specific project. But I'll
> create a small external WrapITK project and look at the generated
> Makefiles.
>
> Thanks,
> --
> Julien
--
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
http://voxel.jouy.inra.fr http://www.itk.org
http://www.mandriva.org http://www.bepo.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090609/8a0cfdc4/attachment-0001.pgp>
More information about the Insight-users
mailing list