vtkThreshold not working with vtkMultiBlockDataSet?

I’m trying to threshold datasets in a vtkMultiBlockDataSet, but the filter returns a None type - I’m working in Python 3.8.2 and vtk 9.0.1

The code fragment is shown below and export is returned as None

The input is a vtkMultiBlockDataSet containing vtkUnstrucutredGrids. I’ve exported it and confirmed using Paraview that it’s in good shape - and I can do the threshold in Paraview.

Does vtkThrehold support multiblock datasets?

Thanks in advance for amy help…

threshold_filter = vtk.vtkThreshold()
threshold_filter.SetInputData(mesh)
threshold_filter.ThresholdByLower(tolerance)
threshold_filter.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Distance")
threshold_filter.Update()
export = threshold_filter.GetOutput()

Yeaa, don’t do that. Change your last line to this and it should work.

export = threshold_filter.GetOutputDataObject(0) # Output port: 0

Why?
vtkThreshold sub-classes vtkUnstructuredGridAlgorithm. If you look at it’s ::GetOutput() method, it returns an unstructured grid instead of a multi-block dataset. It tries to down-cast the multi-block dataset output to an unstructured grid. Doing that in C++ gives a nullptr, hence you get None :slight_smile:

::GetOutputDataObject() returns the real data object. Lucky for you the wrappers take care of the down-cast magic and you get a multiblock dataset

>>> threshold_filter.GetOutputDataObject(0))
(vtkmodules.vtkCommonDataModel.vtkMultiBlockDataSet)0x7f94baaebb20

Hth

Thanks @jaswantp!!! That makes sense.
In fact, I worked around the issue by just iterating over the blocks in the mbds and calling threhold on the individual; ugrids.
Then last night I discovered vtkPythonAlgorithm… and as I worked my way through that I noticed that Algorithms don’t actually support GetOutput()… which helped me understand some issues about using GetOutput(), GetOutputDataObject() that I hadn’t really taken on board before…

Doug

Good to know you found a solution.

In fact, I worked around the issue by just iterating over the blocks in the mbds and calling threhold on the individual; ugrids.

You are duplicating whatever the vtk library already does automatically. vtkCompositeDataPipeline (the default pipeline for almost every vtk filter) already does this for you when input is a multi-block dataset and puts those blocks into an output multiblock dataset… You could iterate over this output rather than calling an update in a python loop for each block!