[vtkusers] Re: Subclassing abstract vtk classes in Python

David Gobbi dgobbi at imaging.robarts.ca
Tue Nov 12 11:10:34 EST 2002


Hi Reinhold,

The reason that abstract classes cannot be subclassed in Python
is that the virtual methods are not hooked through into Python.
That means that when some C++ code somewhere calls a virtual method
of the class, only the C++ definition of the method is called and the
Python definition of the method is ignored.  The python definitions
are only used when the methods are called from python.

So if you subclass an abstract class, there is no way to provide
definitions for the pure virtual methods.  But it shouldn't segfault,
it should give this exception:
  TypeError: this is an abstract class and cannot be instantiated

Cheers,
  David

-- 
  David Gobbi, MSc                dgobbi at imaging.robarts.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Tue, 12 Nov 2002, Reinhold Niesner wrote:

>
> Hello vtk users,
>
> Now that the nightly release allows subclassing of vtk classes in Python
> (which is a very nice feature, thanks), I wondered if there is a a way
> to sublass abstract vtk classes in Python. I tried this with
> vtkPolyDataToPolyDataFilter and got a segmentation fault.
>
> I also tried to subclass a concrete filter class and overwrite its
> Execute method, hoping that on update my Exeute method will be executed,
> but had no success.
>
> Is there a way to achieve this?
>
> Thanks,
> Reinhold
>




More information about the vtkusers mailing list