[vtkusers] Making the python binding more pythonesque

Dov Grobgeld dov.grobgeld at gmail.com
Sat Feb 15 13:41:33 EST 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140215/0ca1bd22/attachment.html>


More information about the vtkusers mailing list