The Python Programmable Filter is a powerful tool for data analysis in ParaView, as it enables you to implement ParaView readers and filters using Python. Developing filters with Python has several advantages– it's fast to prototype and easy to share, since there's no compiled code. You can use the convenient features of the standard Python library, and use NumPy to perform fast, vectorized operations on VTK data arrays. However, the Programmable Filter interface presented in the property panel is not user friendly because there is no way to hide the Python implementation details. Most users want to adjust the filter by setting filter property values, not by editing Python source code. This blog post will show you how to hide the Python implementation details to make the programmable filter easier to use.
Figure 1. Double Helix Python Programmable Source. Left: custom properties panel. Right: visualization with tube filter. No code compiling required!
Python Programmable Filter with a Custom Property Panel
Aha! Well, it turns out that you can customize the programmable filter's property panel, but you've got to use the development version of ParaView, or any version of ParaView newer than 4.0.1. You can download that from the ParaView downloads page under the section titled Nightly Builds.
In Figure 1., I've used the Double Helix programmable source example and created a custom property panel for it. I took this example from the Python Programmable Filter wiki page. Visit that page to find many more example filters and sources.
How it Works
ParaView can load filters from XML plugins. An XLM plugin is an xml file that describes one-or-more filters using the ParaView server manager xml language. You can read all about that on the Plugin HowTo wiki page.
Through a neat trick in the server manager xml language, you can declare custom properties that will appear in the properties panel using standard property value entry widgets. The Programmable Filter & Source also have Script properties. These are string properties where you enter the filter implementation as Python source code. The Script properties can be given a hint attribute so that they are marked as advanced properties, which will be hidden by default. That way, the user will not be distracted by the properties, but advanced users still have the option of modifying the Python code. Alternatively, the Script properties can be hidden completely from the properties panel.
Make it easier — Automatically Generate XML
I developed a tool that generates the XML file for you. All you have to do is write a Python script that defines the filter function and the filter properties, and other information like the filter name and documentation. Your Python script is used as input to generate XML automatically. For example, your Python filter might look like this:
Then use the python_filter_generator.py script line to generate the XML file. Here's the program usage:
Attached to this blog post are all the files you need to get started. I attached both the Python input files and the generated XML files, which are human readable for the most part. As I wrote earlier, this requires ParaView with a version newer than 4.0.1. At the time of this posting, you can download that from the ParaView downloads page under the section titled Nightly Builds. After you have generated an XML file from a Python input script, or written an XML file by hand, then you can load the XML plugin into ParaView using the menu Tools –> Manage Plugins and then click Load New and select your xml file.