Creating custom filter in Python

I’ve not found many examples of creating custom vtk filters in python so I followed this one: Developing Custom Filters and Algorithms in VTK

However, it doesn’t seem to work:
custom_filter.ipynb (7.8 KB)

It doesn’t seem that the RequestData method is being called (at least my dummy print statements don’t seem to be run) and the output is basically empty.

Could someone point me to updated python examples of custom filters / inform me what changes have happened since this example was published?

Thanks!

This tutorial is not official as you may have realized.

Find hundreds of examples here:

https://examples.vtk.org/site/

Creating custom filters with Python alone via subclassing won’t work. The C++ virtual dispatch mechanism won’t consider your Python overridden methods. One way to create a customer filter in Python is to create it in C++ and then let VTK’s language wrapping tools provide Python bindings for you. But that’s a fair amount of work.

A better route is to use vtkPythonAlgorithm. You can find out more about them in blog posts vtkPythonAlgorithm is great and Developing HDF5 readers using vtkPythonAlgorithm. There are numerous examples in the VTK code base in the form of tests:

I hope that helps.

1 Like