[vtkusers] c api and python and vtk - with SWIG

Mark Asbach mark.asbach at post.rwth-aachen.de
Tue Jan 27 15:44:29 EST 2004


Hi Ross,

> I have a set of C codes that manipulate a data structure, one
> component of which is an array of doubles.  I've managed to
> wrap the C codes with SWIG so I have access to the structure
> with the typical SWIG accessor functions, i.e. Sp4Array_data_get()
> What do I have to do to get this data array into vtk?

The way I took for my code is to just write the conversion to vtk data 
structures in C, wrap them with SWIG and mix that with the vtk python 
stuff. There is a bug in the current SWIG adaptor code of VTK though, 
and I don't know, if David committed my fix to the repository already 
(David?).

Here it just looks like:

In C header and SWIG interface description.
     vtkUnstructuredGrid *  GetSubMesh           (const int              
       number = 1);

Usage in Python:
import vtk
import myStuff

mygrid=vtk.vtkUnstructuredGrid( GetSubMesh (2))
mymapper=vtk.vtkDataSetMapper()
mymapper.SetInput (mygrid)


So you'll have to "cast" the SWIG returned data to the vtk data type. 
The other way 'round you can take the .__this__ member of any vtk data 
structure as a fully functional SWIG pointer.

Please remember that you'll need the SWIG fix applied on the vtk 
sources to have that working. Currently the SWIG mangling handles 
endianness differently than vtk's emulation of it.

Yours, Mark





More information about the vtkusers mailing list