[vtkusers] Making the python binding more pythonesque
David Gobbi
david.gobbi at gmail.com
Sat Feb 15 14:34:23 EST 2014
Hi Dov,
I'll answer in reverse order. Patches are submitted via gerrit, which
is a web-based git review tool. Some details are here:
http://www.vtk.org/Wiki/VTK/Git/Develop
The VTK wrapper-generation tools are written in C because,
historically, lex and yacc only worked with C (the VTK wrappers
were first written back in the 1990's). For my part, at least, I find it
much easier to simply modify and improve what is already there,
rather than re-write the wrapper tools in a new language.
Yes, the python wrappers are generated by vtkWrapPython.c. It
isn't very well documented, but all the documentation that exists is
on the VTK wiki (just do a google of "vtk wrappers" and you'll find
all the relevant wiki pages).
I think that supporting the iterator and sequence protocols is a good
idea, and I'd be willing to review the change. The VTK arrays already
support the old buffer protocol (see PythonCore/PyVTKObject.cxx).
David
On Sat, Feb 15, 2014 at 11:41 AM, Dov Grobgeld <dov.grobgeld at gmail.com> wrote:
> I've been thinking about how to make the vtk python binding more
> pythonesque? Here are a couple of examples and what I have in mind:
>
> Current syntax:
>
> # poly is vtkPolyLine
> num_points = poly.GetNumberOfPoints()
> pts = c.GetPoints()
> for i in range(num_points):
> p = pts.GetPoint(i)
> foo(p)
>
> New syntax:
>
> for p in poly:
> foo(p)
>
> Needed change:
>
> For all vtk array like objects, support python sequence iterator API tp_iter
> and tp_iternext.
>
> Current syntax:
>
> pts = c.GetPoints()
> p1 = pts.GetPoint(0)
> p2 = pts.GetPoint(1)
> p3 = pts.GetPoint(2)
> norm = [0,0,0]
> vtk.vtkTriangle.ComputeNormalDirection(p1,p2,p3,norm)
>
> New syntax:
>
> norm = vtk.vtkTriangle.ComputeNormalDirection(c.GetPoints()[0:3])
>
> Needed change:
>
> Support sequence methods sq_length, sq_concat, sq_item, sq_slice,
> For all methods returning values, if the arguments only contain the number
> of input parameters, return the result in a python tuple.
>
> Please let me know if you would accept patches for implementing the above
> behavior.
>
> I would also appreciate a description of the mechanism for the
> autogeneration of the python binding. I assume that
> VTK/Wrapping/Tools/vtkWrapPython.c is used. (Btw, why is it written in c and
> not in C++ (or even python)?)
>
> And finally, what is the proper way of submit patches? Is a pull request on
> github accepted?
>
> Regards,
> Dov
More information about the vtkusers
mailing list