[vtkusers] connecting wrapped VTK and swig output
Mathieu Malaterre
mathieu.malaterre at gmail.com
Sun Feb 17 15:01:43 EST 2008
On Feb 14, 2008 3:27 PM, Amy Squillacote <ahs at cfdrc.com> wrote:
>
> 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.
Hi Amy,
Sorry I meant to answer, but forgot to...
Have you read this part of Wrapping/Python/README:
Creating a Python object from just the address of a VTK object
--------------------------------------------------------------
When you instantiate a class, you can provide a hexidecimal string
containing the address of an existing vtk object, e.g.
t = vtkTransform('_1010e068_vtkTransform_p')
The string follows SWIG mangling conventions. If a wrapper for the
specified object already exists, then that wrapper will be used rather
than a new wrapper being created. If you want to use this feature
of vtkpython, please think twice.
HTH
--
Mathieu
More information about the vtkusers
mailing list