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

Sorry, just getting around to this now. This works perfectly!

Should I fill out a bug report, since it seems that the tutorial code does not work in all instances?

Which tutorial is not working here ?

I would expect the tutorial here to work on any reasonable mesh type (including an unstructured mesh in the .pvtu format), given that there’s no stipulations on mesh type in the tutorial. For whatever reason it seems to set the output type to None, which I think is unexpected behavior.

Also I wouldn’t know where to find the information necessary to fix the filter (like you had previously) so I wonder if linking to a more in-depth set of documentation would be useful.

Indeed, this tutorial, specificaly this part:

    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self)

Does not specify the output type, this is why the output is created as a point set.

One way to fix this is to use the method I shared above to conserve the output.
Another way to fix this is to set the output to a fixed type as it is done in the step below in the tutorial:

        VTKPythonAlgorithmBase.__init__(self,
                nInputPorts=0,
                nOutputPorts=1,
                outputType='vtkPolyData')

IMO the polydata part should be added to the tutorial, would you like to take care of it ?

Also I wouldn’t know where to find the information necessary to fix the filter (like you had previously)

In Examples/Plugin/PythonAlgorithm.

1 Like