Trouble with vtkPythonAlgorithm

I’m having trouble reproducing the vtkPythonAlgorithm example from here:
4. Programmable Filter — ParaView Documentation 5.10.0 documentation

The plugin appears to load correctly, and I can control the output data type, but the resulting data object is empty. I tested this on a Wavelet source, using 5.10.0 and 5.9.1. Can anyone help me understand what is going on?

# setup the data processing pipelines
# ----------------------------------------------------------------

# create a new 'Wavelet'
wavelet1 = Wavelet(registrationName='Wavelet1')

# create a new 'Calculator'
calculator1 = Calculator(registrationName='Calculator1', Input=wavelet1)
calculator1.ResultArrayName = 'V'
calculator1.Function = 'RTData'

# create a new 'Half-V Filter'
halfVFilter1 = HalfVFilter(registrationName='HalfVFilter1', Input=calculator1)

The plugin source:

from vtkmodules.vtkCommonDataModel import vtkDataSet
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtkmodules.numpy_interface import dataset_adapter as dsa

# new module for ParaView-specific decorators.
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain

@smproxy.filter(label="Half-V Filter")
@smproperty.input(name="Input")
class HalfVFilter(VTKPythonAlgorithmBase):
    # the rest of the code here is unchanged.
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self, outputType='vtkImageData')

    def RequestData(self, request, inInfo, outInfo):
        # get the first input.
        input0 = dsa.WrapDataObject(vtkDataSet.GetData(inInfo[0]))

        # compute a value.
        data = input0.PointData["V"] / 2.0

        # add to output
        output = dsa.WrapDataObject(vtkDataSet.GetData(outInfo))
        output.PointData.append(data, "V_half");
        return 1

In the plugin code, the output is not initialized… You should add a ShallowCopy in RequestData:

output = dsa.WrapDataObject(vtkDataSet.GetData(outInfo))
output.ShallowCopy(input0.VTKObject)
output.PointData.append(data, "V_half")

That did it. The documentation on the website should be corrected.

Thanks!

Documentation update happening here: https://gitlab.kitware.com/paraview/paraview-docs/-/merge_requests/30

2 Likes