How to create a collection of blocks (multi block) based on connectivity

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?

Thanks in advance
Fotos

You can create a selection then extract it, repeat for each block, then group all the resulting dataset together. Yes, not really practical.

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!

Hi Mathieu,

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)

You need to deepcopy the block before setting it at the end of the loop.

I fixed it by moving some lines inside the loop.

import vtk
inp = self.GetInputDataObject(0, 0)
out = self.GetOutput()

outData = vtk.vtkMultiBlockDataSet()

rangeID = inputs[0].CellData.GetArray('RegionId').GetRange()

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.ThresholdBetween(ic-0.5,ic+0.5)
    thresh.Update()
    tooutData = thresh.GetOutputDataObject(0)
    outData.SetBlock(ic,tooutData)

out.DeepCopy(outData)