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

REGAT-BARREL Aurélien arbvtk at yahoo.fr
Wed Jan 28 14:02:17 EST 2004


I don't think you need any cast if instead of returning a vtkUnstructuredGrid * in your C++ code you return the PyObject * returned by vtkPythonGetObjectFromPointer( your_vtkUnstructuredGrid * ).
Example :
C++ :
 
#include <vtkPythonUtil.h>
PyObject * GetSubMesh( const int number = 1)
{
    vtkUnstructuredGrid * grid = vtkUnstructuredGrid::New();
// fill it
    return vtkPythonGetObjectFromPointer( grid );
}
 
SWIG Interface :

PyObject * GetSubMesh( const int number = 1);
 
Python :

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

Aurélien

Mark Asbach <mark.asbach at post.rwth-aachen.de> wrote:
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


_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: 
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers


---------------------------------
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040128/72a22346/attachment.htm>


More information about the vtkusers mailing list