Inspect certain field data of a pipeline object in a Paraview python script

Hello,

I’m writing a Python script (macro) in Paraview and I’m currently facing the following problem: My data source is a VTK XML file that is opened in Paraview, which, apart from the geometry and point data, should also contain some additional custom data. I intend to store it simply as unaligned field data there. Now depending on this custom data, from my Python script, I have to apply a varying number of filters to the data. So the main question is how to best access this field data from the client-side Paraview script.

I know that I can use servermanager.Fetch() to get the whole object sent to the client, which would be somewhat okay since so far, I’m not using a remote server. However since I’m only interested in a tiny piece of data (that one field), I wanted to ask if there’s a better method to access it, since I really want to refrain from transmitting the whole structure if at some point I’m actually using a remote connection.

Thanks in advance!

Why are you accessing the data ? If you want to process the data, you should use a Programmable Filter.

Hi, thanks for the response.

The problem is that I want to extract a varying number of objects out of the data. As far as I know, there is no possibility of having a filter with a variable number of outputs, or am I mistaken? This is why I thought to apply the same filter a number of times, parameterized by the object to extract. But this I would have to do client-side, right?

As far as I know, there is no possibility of having a filter with a variable number of outputs

Indeed, for that usecase we tend to use multiblocks output.

In any case, your idea could work using fetch(). You can use param to recover only a integrated version of the data, but I’m not sure that the field data would still be available. Another solution could be to write a programmable filter to do the integration before you do the fetch.

Oh, I was not aware that something like this exists. Actually, multiple blocks as output would be perfectly fine. So can I write a programmable filter that takes a single-block dataset as input and creates a multi-block output? Can you provide me with some reference for this? In the docs I only found how to process already-existing multiblock data.

Sorry, but what do you mean by that? Unfortunately I’m not that familiar with VTK, so what would an integrated version of the data be?

Yes.

Can you provide me with some reference for this? In the docs I only found how to process already-existing multiblock data.

You can use VTKPython example for this : https://lorensen.github.io/VTKExamples/site/Python/CompositeData/MultiBlockDataSet/

Especially this part :

# PART 1 Make some Data.
# Make a tree.
root = vtk.vtkMultiBlockDataSet()

branch = vtk.vtkMultiBlockDataSet()
root.SetBlock(0, branch)

# Make some leaves.
leaf1 = vtk.vtkSphereSource()
leaf1.SetCenter(0, 0, 0)
leaf1.Update()
branch.SetBlock(0, leaf1.GetOutput())

leaf2 = vtk.vtkSphereSource()
leaf2.SetCenter(1.75, 2.5, 0)
leaf2.SetRadius(1.5)
leaf2.Update()
branch.SetBlock(1, leaf2.GetOutput())

leaf3 = vtk.vtkSphereSource()
leaf3.SetCenter(4, 0, 0)
leaf3.SetRadius(2)
leaf3.Update()
root.SetBlock(1, leaf3.GetOutput())