[vtk-developers] Python template wrapping

David Gobbi david.gobbi at gmail.com
Tue May 31 10:20:18 EDT 2011


Hi All (Marcus and Tim especially),

I merged my python template wrapping code yesterday, so the templated
vtkArray and vtkVector classes are now being wrapped. In general, the
specializations that are wrapped are those for which typedefs or subclasses
exist, but for vtkDense/SparseArray I've also coded the list of array types
into the wrappers.

A brief discussion of how to use templated types in python is given here:
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Wrapping/Python/README_WRAP.txt

>From the above document:


Templated classes
-----------------

Templated classes are rare in VTK.  Where they occur, they can be
instantiated much like they can be in C++, except that [ ] brackets
are used for the template arguments instead of < > brackets:

>>> v = vtkVector['float64',3]([1.0, 2.0, 3.0])
>>> a = vtkDenseArray[str]()

Only a limited number of specializations are available, usually limited
by which specializations are used by typedefs and by other classes in
the C++ code.  A list of the specializations available for a particular
template can be found by calling help() on the template:

>>> help(vtkVector)

The types are usually given as strings, in the form 'int32', 'uint16',
'float32', 'float64', 'bool', 'char', 'str', 'vtkVariant'.
Python type objects are acceptable, too, if the name of the type is
the same as one of the accepted type strings:

>>> a = vtkDenseArray[int]()

Note that python 'int' is the same size as a C++ 'long', and python
'float' is the same size as C++ 'double'.  For compatibility with the
python array module, single-character typecodes are allowed, taken
from this list: '?', 'c', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q',
'Q', 'f', 'd'.  See the python array documentation for more details.

 - David



More information about the vtk-developers mailing list