[vtkusers] connecting wrapped VTK and swig output

Mathieu Malaterre mathieu.malaterre at gmail.com
Thu Feb 14 04:28:33 EST 2008

Hi Amy !

On Wed, Feb 13, 2008 at 7:50 PM, Amy Squillacote <ahs at cfdrc.com> wrote:
> Hi all,
>  I have written some C++ code that makes use of VTK, including using VTK
>  objects as parameters and return values for some methods. My VTK is from
>  CVS on 1/22/08. It is wrapped in Tcl, Python, and Java. I am trying to
>  wrap the C++ code I have written into Java and Python. Since my new
>  classes are not subclasses of vtkObject, I don't think I can use the
>  wrappers in VTK. (Please correct me if I am wrong about this.) Thus, I
>  am trying to use swig to do the wrapping since it can output wrappers in
>  both Java and Python. The problem is that the swig wrapping isn't aware
>  of VTK, so for example, it creates objects of type
>  SWIGTYPE_p_vtkPolyData to hold vtkPolyData* in the wrapped languages.
>  I'm not sure how to make the conversion between this and the vtkPolyData
>  that's wrapped in Java by VTK.
>  Related to this, I saw this message from a few years ago on the vtkusers
>  list:
>  http://public.kitware.com/pipermail/vtkusers/2003-October/070054.html.
>  However, it only applies to python-wrapping, and I need java-wrapping as
>  well.
>  Does anyone have experience with mixing swig-wrapped code and
>  VTK-wrapped code?

We do that quite extensively here ! The only difference is that we
have the gdcm library wrapped with swig, and we also have a vtkgdcm
library where all classes are in fact VTK class (derives from
vtk*filters) that are wrapped with vtkWrapPython.
So in summary I never tried your mixture, but I am pretty confident
that if you do in your swig interface:

#include "vtkPolyData.h"
%include "my_class_to_wrap_containing_vtkpolydata.h"

Then swig should be able to do the wrapping properly. In the past I
have had some subbtle issues, with the ordering of the #include in the
swig interface file, so be sure to include them in the right order.

Ps: the post you are refering to is a very old issue and should only
apply when you are using swig 1.1 and VTK > 4.2 or swig 1.3 and VTK <=
4.2. David Gobbi made a patch so that pointer in vtkWrapPython are
swig 1.3 compatible (but not swig 1.1).

More information about the vtkusers mailing list