[vtkusers] connecting wrapped VTK and swig output

Amy Squillacote ahs at cfdrc.com
Thu Feb 14 09:27:50 EST 2008

Mathieu Malaterre wrote:
> 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.
> HTH,
Hi Mathieu!

Thanks for the suggestion, but I can't get it to work. (In fact, I tried 
it yesterday.) I put #include "vtkPolyData.h" as the first include in my 
"%{ ... }%" section. (I don't want to do %include "vtkPolyData.h" since 
I don't want vtkPolyData.h wrapped by swig.) For the methods in my 
classes that use vtkPolyData* as a parameter or return type, swig uses a 
SWIGTYPE_p_vtkPolyData instead.

I'm using swig 1.3.33 on Windows, if that makes any difference.

- Amy

Amy Squillacote                    Phone: (256) 726-4839
Computer Scientist                 Fax: (256) 726-4806
CDF Research Corporation           Web: http://www.cfdrc.com
215 Wynn Drive, Suite 501
Huntsville, AL  35805

More information about the vtkusers mailing list