[vtkusers] How to explicitely get the different regions with ConnectivityFilter?

Nicolas Cedilnik nicolas.cedilnik at inria.fr
Fri Feb 17 08:38:41 EST 2017


Hello,

I have an unstructured grid with several point data arrays and would 
like to extract the connected regions and their associated data into 
separate files.

I can do that with paraview but I'm struggling to get it done using 
python vtk bindings.

So far I've managed to extract the cells corresponding to the the 
largest region:

rd = vtk.vtkGenericDataObjectReader()
rd.SetFileName(my_input_vtk_file)
rd.Update()
ug = rd.GetOutput()
f = vtk.vtkConnectivityFilter()
f.SetInputData(ug)
f.SetExtractionModeToLargestRegion()
f.Update()
out = f.GetOutput()

ug.GetNumberOfCells() # 28396, the original number of cells
out.GetNumberOfCells() # 27740, less cells, looks good

from which I can work something out, but I have two problems with this 
approach:
- I'd like to know the indices of the other connected regions
- the `ug` input only has 1 point data array, I believe this is a known 
limitation

I've found a SetExtractionModeToAllRegions method but I don't understand 
how to deal with it:
f.SetExtractionModeToAllRegions()
b = f.GetOutput()
b.GetNumberOfCells() # 28396, same as input
b.GetCellData().GetNumberOfArrays() # 0, I would have expected an array 
where the cells where labeled by region number...

All in all, I have two questions:
- How do I use the filter to get the cells labeled by region?
- (less important) Is it possible to read different point data arrays 
with vtk python bindings?

Thanks in advance for your help and advices on how to use vtk properly

-- 
Nicolas


More information about the vtkusers mailing list