Is it possible to use the vtkDataAssemblyVisitor pattern from Python?

Hello!!!

I’m working on vtkPartitionedDataSetCollections in Python and I’m trying to use the vtkDataAssemblyVisitor to traverse the associated assembly.

However, when I try to create my specialized Python class (shown below) derived from vtkDataAssemblyVisitor I get a “TypeError: this is an abstract class and cannot be instantiated” error…

Is there any way I can use this Visitor pattern from Python?

Any guidance will be gratefully received…

class VTKDatasetToApexMesh(vtkDataAssemblyVisitor):
    def __init__(self):
        self.target=None

    def Visit(self, node):
        print('Visiting {}'.format(node))

There’s nothing in VTK’s wrapping that makes inheriting from a C++ class callable from C++ automatically. It would need something like vtkPythonAlgorithm that looks at the “self” object and calls Python methods in the C++ implementation to work properly.

Cc: @dgobbi, @berk.geveci, @jaswantp

The VTK python wrappers don’t implement a virtual method hook that would allow this to work. By “hook”, I mean wrapper code that would call the Python subclass method (e.g. “Visit”) when the corresponding C++ virtual method is called. I know that this description makes it sound like a trivial thing, but implementing it is definitely non-trivial.

I’ve though about implementing this many times, but have never gotten around to actually doing it.

Thanks David,

At least I now know for sure it isn’t going to work…

I guess I need to go back to using the tree iterator instead which isn’t quite as clean, but still workable

Makes sense. I REALLY like vtkPythonAlgorithm… :slight_smile: