[vtk-developers] const arrays in Set methods

David Gobbi dgobbi at irus.rri.ca
Wed Nov 28 17:11:45 EST 2001

I've just thought of a reasonable way to handle non-const array
parameters in the python wrappers.

The main problem with wrapping non-const arrays is that sometimes
(e.g. in GetXX(float x[3]) they are used to return values.  Usually
in cases like this there is a "float *GetXX()" method with a
corresponding hint but not always.

What the python wrappers can do is turn the tuple (or list) into an
array, pass the array to the C++ method, and (after the C++ method
has returned) check the array values against the original tuple or
list to see if any values have changed.  For every value that has
changed, a python SetItem() call will be used to change the list/tuple
value.  Trying to change the contents of a tuple will raise an exception,
which is exactly the desired behaviour.

This won't take much work to implement and will result in many more 
methods being wrapped.  So I'll try to scare up some time to get it
done before 4.0 is released.

 - David

On Wed, 28 Nov 2001, David Gobbi wrote:

> On Wed, 28 Nov 2001, Brad King wrote:
> > > Some of the python code I have doesn't work with the recent VTK 4.0
> > > because the SetPosition(float _arg[3]) etc.  methods don't have
> > > const arguments and therefore aren't being wrapped.
> > Is there a specific class for which the SetPosition method is not showing
> > up?  I don't think the VTK wrappers wrap any methods that take array
> > arguments unless a hint is specified or the method is defined by a macro
> > like vtkSetVector3Macro.
> No, as long as the array is declared as const it is wrapped.  I made
> that change to vtkParse.y around two years ago or so.
> My plan (at least for the python wrappers) was to eventually wrap
> non-const arrays as well but to associate them with python lists
> instead of with python tuples.  That way the returned array elements
> could be copied into the lists.  I never got around to it, but it
> would be straightforward to do.
> Anyway, I've changed my own VTK source to wrap all arrays and will
> probably commit the change later today if there are no objections.
> I had to add //BTX //ETX around all VTK methods with parameters
> of the form <type>[n][m] because vtkParse.l/vtkParse.y don't
> correctly parse multi-dimensional arrays.
>  - David

More information about the vtk-developers mailing list