[vtkusers] vtk and python - some questions.

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Thu Nov 9 01:59:01 EST 2000


hi,

>>>>> "David" == David Gobbi <dgobbi at irus.rri.on.ca> writes:

    David> Hi Prabhu, I've made some massive changes to the python
    David> wrappers that should be useful to you.  They'll appear in
    David> the nightlies tomorrow (they're already in CVS).

Wow! and thanks a ton!!  I really appreciate your efforts.

<snipped greatly appreciated new features etc.>

    David> The new VTK/Python classes and objects have a similar 'look
    David> & feel' to Python's own classes and class instances,
    David> however, you cannot derive a Python class from a VTK/Python
    David> class unless you write your own wrapper class.

Having complained about the python bindings, I, for my part, have
figured out how to use py_cpp, and actually have managed to wrap (with
a TON of help from the py_cpp developer - David Abrahams) the
vtkObject class.  There were and still are a few issues with vtk's
reference counting and python's.  I have a small fix but more on that
later.

As far as the py_cpp wrapped vtkObject class goes, it is easy to code,
behaves as a true python object under python and allows one to
override virtual functions of the original c++ class and requires no
shadow python class.  This paragraph from the py_cpp docs explains
this much better.

      "Another obstacle that most people run into eventually when
      extending Python is that there's no way to make a true Python
      class in an extension module. The typical solution is to create
      a new Python type in the extension module, and then write an
      additional module in 100% Python. The Python module defines a
      Python class which dispatches to an instance of the extension
      type, which it contains. This allows users to write subclasses
      of the class in the Python module, almost as though they were
      sublcassing the extension type. Aside from being tedious, it's
      not really the same as having a true class, because there's no
      way for the user to override a method of the extension type
      which is called from the extension module. ..."

Py_cpp does not suffer this problem.  Which in plain english means,
that not only can I wrap the vtkObject class (or any other class) to a
python class, I can override virtual methods of the class and the c++
code will think that the python class is a subclass written in c++ for
all practical purposes!!  It works, although I have not _really_
tested it because I dont have any other vtk classes that I have
wrapped.

I am going to be busy for the next week or so, but already have
started some work on automated generation of wrapper code (using the
stuff in wrap/ and python).  Hopefully, if everything goes well, I
will have something to really shout about in a few weeks. :)

David, thanks for all your efforts.  I really appreciate it.  My
present work on py_cpp is not to dampen your spirits or compete with
your efforts.  It is unlikely that the first py_cpp based wrapping
will be anywhere as good as the current python bindings but this is my
shot at getting the best possible python wrappers for vtk.

Thanks again.

regards,
prabhu




More information about the vtkusers mailing list