[Insight-users] Wrapping a custom C++ function in Python
Gaëtan Lehmann
gaetan.lehmann at jouy.inra.fr
Mon Jun 8 13:35:30 EDT 2009
Le 8 juin 09 à 15:12, Julien Lamy a écrit :
> Hi list,
Hi,
>
> 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 > *'
>
> WrapITK otherwise works fine (thank you for those wrappers :) )
you're welcome :-)
>
>
> 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 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.
Note that those names are not good enough and will change in a future
release - hopefully soon - to remove the useless wrap_ prefix, to
use .h instead of .includes, and to add a prefix to have something
less common than Base.h. Those changes shouldn't require any changes
in the sources if the wrapitk external projects are used.
Gaëtan
>
>
> Is there a specific module I should add to the SWIG wrapper ? I'm
> using ITK 3.14, SWIG 1.3.35, gcc 4.3.2, and Python 2.5.2.
>
> Thanks in advance,
> --
> Julien Lamy
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> 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://www.itk.org/mailman/listinfo/insight-users
--
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/20090608/0cef7cae/attachment.pgp>
More information about the Insight-users
mailing list