Hi all,
I got a vtp file which probably contains a set of stl files (topologically not connected). I use the connectivity filter to get the region ids as you can see from the image.
Is there a way to create a collection of blocks (i.e. a multi block structure) based on the region id?
Not practical indeed! I will try something with programmable filter although I already feel that I will regret it :). I am not that advanced in programming!
I made the following script but the result is not what I expected. I get a Multi-Block but all the blocks have the same data. All blocks are the same with the last value of “ic”.
Do you see the problem?
import vtk
inp = self.GetInputDataObject(0, 0)
out = self.GetOutput()
outData = vtk.vtkMultiBlockDataSet()
thresh = vtk.vtkThreshold()
thresh.SetInputData(inp)
thresh.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,'RegionId')
rangeID = inputs[0].CellData.GetArray('RegionId').GetRange()
for ic in range(int(rangeID[0]), int(rangeID[1])):
thresh.ThresholdBetween(ic-0.5,ic+0.5)
thresh.Update()
tooutData = thresh.GetOutputDataObject(0)
outData.SetBlock(ic,tooutData)
out.DeepCopy(outData)
I noted that this solution is not working in ParaView 5.11. The threshold filter no longer supports the ThresholdBetween method. Also, although vtkMultiBlockDataSet is still supported, I believe vtkPartitionedDataSet is now preferred. Here is an update programmable filter script that seems to work.
import vtk
inp = self.GetInputDataObject(0, 0)
out = self.GetOutput()
outData = vtk.vtkPartitionedDataSet()
rangeID = inputs[0].CellData.GetArray('RegionId').GetRange()
outData.SetNumberOfPartitions(int(rangeID[1]) + 1)
for ic in range(int(rangeID[0]), int(rangeID[1]) + 1):
thresh = vtk.vtkThreshold()
thresh.SetInputData(inp)
thresh.SetInputArrayToProcess(0,0,0,
vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,'RegionId')
thresh.SetLowerThreshold(ic-0.5)
thresh.SetUpperThreshold(ic+0.5)
thresh.Update()
tooutData = thresh.GetOutputDataObject(0)
outData.SetPartition(ic, tooutData)
out.DeepCopy(outData)