Python algorithm does not render in 3D

I’m currently using Paraview 5.12.0 and I cannot get the default Python Algorithm filter to render. My data is a .pvtu file along with the accompanying .vtu files for an unstructured grid. I’ve copied and pasted the finished Python Algorithm from here (appropriately modifying the name from V to Q0 to match my data).

When I try to apply my filter, the colorbar looks correct but the mesh is completely invisible. If I then use the Slice tool to make the data 2D and then apply the example Python Algorithm filter then it renders fine.

Finally, if I create a cylinder source and then give it some data with a Programmable Filter (I just outputted the z-values) the Python Algorithm works perfectly.

It seems to me that there must be some kind of a bug, but I’m not sure how to get it to show up without using my data (perhaps it has something to do with the data type, or the fact that a Reader object is involved?). Any help is appreciated.

please share your data.

Here are my data and script. To use the script, I do ToolsManage PluginsLoad New and select my script. Then I use it just like any other filter.

If it’s relevant, I’m running Ubuntu 22.04.4.

algorithm_example.py (981 Bytes)

Q_components_nematic_configuration_5000.zip (619.3 KB)

You do not generate any cells, you want to generate at least vertex cells.

You can workaround this by adding a ConvertToPointCloud filter.

Got it, thanks for the tip!

Two follow-up questions: Is there any way to make the Python Algorithm method work like the Programmable Filter method (i.e. have the output mesh be the same as the input, just with different data on top)? And if so, is it possible to add that to the official documentation?

Yes, just use ShallowCopy

And if so, is it possible to add that to the official documentation?

Already documented in the main plugin example

https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py#L32

I’m a little bit confused now. In my algorithm_example.py on line 25 I do a ShallowCopy, but in that case my output is not rendering. What is the issue here?

I’m not sure why to be honest, but here is a version that works:

from paraview.util.vtkAlgorithm import *

@smproxy.filter(name="MyPreserveInput")
@smproperty.input(name="Input")
@smdomain.datatype(dataTypes=["vtkDataSet"], composite_data_supported=False)
class PreserveInputTypeFilter(VTKPythonAlgorithmBase):
    """ 
    Example filter demonstrating how to write a filter that preserves the input
    dataset type.
    """
    def __init__(self):
        super().__init__(nInputPorts=1, nOutputPorts=1, outputType="vtkDataSet")

    def RequestDataObject(self, request, inInfo, outInfo):
        inData = self.GetInputData(inInfo, 0, 0)
        outData = self.GetOutputData(outInfo, 0)
        assert inData is not None
        if outData is None or (not outData.IsA(inData.GetClassName())):
            outData = inData.NewInstance()
            outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
        return super().RequestDataObject(request, inInfo, outInfo)

    def RequestData(self, request, inInfo, outInfo):
        inData = self.GetInputData(inInfo, 0, 0)
        outData = self.GetOutputData(outInfo, 0)
        print("input type =", inData.GetClassName())
        print("output type =", outData.GetClassName())
        assert outData.IsA(inData.GetClassName())
        outData.ShallowCopy(inData)
        return 1