<div dir="ltr"><div>Hi All,</div><div><br></div>The VTK master branch has some new features in the Python wrappers.<div><br></div><div>First, pass-by-reference is now done with a special "vtk.reference()" object.  Some of you might have used vtk.mutable() in the past.  Well, vtk.reference() is the same except that it also allows references to pointers.  For example, consider this previously unwrapped method in vtkCellArray:</div><div><br></div><div>    void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts)<br></div><div><br></div><div>This returns a pointer in the third parameter.  To call this method from Python, use the following code:</div><div><br></div><div><div>    npts = vtk.reference(0)    # create a proxy to a Python int object</div><div>    pts = vtk.reference((0,))  # create a proxy to a Python tuple</div><div>    cellarray.GetCell(0, npts, pts)</div></div><div><br></div><div>The "reference" is simply a container with set()/get() methods that the wrappers can use to return values.  So when GetCell() returns a pointer by reference, the wrappers convert the pointer to a tuple (since they know how values are pointed to) and then they assign the reference to that tuple.</div><div><br></div><div>A "vtk.reference()" object also acts as a proxy to whatever object it references.  So vtk.reference(0.0) can be used as a number, and vtk.reference((1,2,3)) can be used anywhere you would use a tuple.</div><div><br></div><div><br></div><div>Also, parameter checks (method preconditions) were added to the array methods a couple weeks ago.  This means that if you write code like this in Python, you will no longer get a segfault:</div><div><br></div><div>    a = vtk.vtkFloatArray()</div><div>    a.SetNumberOfValues(3)</div><div>    a.SetValue(10, 1.0)</div><div><br></div><div>In this case, the wrappers will raise a ValueError because the index is out of range.  This is nice, because you can catch the exception and respond appropriately.</div><div><br></div><div> - David</div></div>