[vtk-developers] Problem with Python wrappers
Prabhu Ramachandran
prabhu at aero.iitb.ac.in
Fri Jul 15 15:45:57 EDT 2011
On Friday 15 July 2011 09:00 PM, David Gobbi wrote:
> Don't you already have vtkVector2i, vtkVector2f etc. which really
> are specific instantiations or am I missing something -- I'm away
> from my laptop where I built things so cannot verify?
>
> Those have been defined in the C++ header files as subclasses for some
> of the template instantiations. But they cannot be used in place of the
> template instantiations in the wrappers. For example, tracing the
> hierarchy for vtkVector3f:
>
> class vtkVector3f : public vtkVector3<float>
>
> template<typename T>
> class vtkVector3 : public vtkVector<T, 3>
>
> template<typename T, int Size>
> class vtkVector
>
> To capture the complete hierarchy, it is necessary to wrap all of these:
> vtkVector3f, vtkVector3<float>, vtkVector<float, 3>. Wrapping just the
> leaf class vtkVector3f would be insufficient. Right now, in python I
> have named the latter two classes vtkVector3[float32] and
> vtkVector[float32,3] and they can be instantiated as such by evaluation,
> because vtkVector3[] and vtkVector[] are dicts that take the template
> parameters 'float32' and ('float32', 3) as keys. A more thorough
> explanation is provided in the template section of this document:
> http://vtk.org/gitweb?p=VTK.git;a=blob;f=Wrapping/Python/README_WRAP.txt
Well, my problem is that I wrap the entire VTK class hierarchy and
create a 1:1 mapping between VTK classes and the wrapped classes. The
present change makes this impossible since vtkVector[float32,3] etc. are
illegal and actually unavailable in the vtk module. vtkVector itself
isn't even a proper vtk class so this makes things rather painful. In
the past there were abstract classes that cause no problem because one
needs to only map the methods of the class and there is no need to
instantiate them.
So it seems like the only way around this is to actually mangle the
names to make them legitimate as you say below.
> I could change the python names of the template instantiations to a
> mangled form to make them python-legit,
>
> vtkVector3<float> -> 'T10vtkVector3IfE'
> vtkVector<float,3> -> 'T9vtkVectorIfLi3EE'
Why not, vtkVector3_float or vtkVector3_float_3? Underscores are not
used in any other VTK class names.
I've attached a really simple script. I have a test suite to catch
these so once this is fixed I'll report any additional issues.
If you'd like, I can also send you the full wrapper generation code
off-list. It only depends on standard Python + VTK-Python.
Thanks!
cheers,
Prabhu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk58.py
Type: text/x-python
Size: 963 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110716/c9f16dee/attachment-0001.py>
More information about the vtk-developers
mailing list