[vtkusers] How to explicitely get the different regions with ConnectivityFilter?
C P
cp.vtk.user at googlemail.com
Wed Mar 8 08:42:04 EST 2017
Hi Nicolas,
I had a similar problem: I want to extract all connected components of a
surface mesh and copy each one to a separate vtkPolyData object. Here is
what I did. Maybe this could help you.
cc_filter = vtk.vtkPolyDataConnectivityFilter()
cc_filter.SetInputData(mesh)
cc_filter.SetExtractionModeToSpecifiedRegions()
components = list()
idx = 0
while True:
cc_filter.AddSpecifiedRegion(idx)
cc_filter.Update()
component = vtk.vtkPolyData()
component.DeepCopy(cc_filter.GetOutput())
# Make sure we got something
if component.GetNumberOfCells() <= 0:
break
components.append(component)
cc_filter.DeleteSpecifiedRegion(idx)
idx += 1
return components
Best regards,
CP
On Fri, Feb 17, 2017 at 2:38 PM, Nicolas Cedilnik <nicolas.cedilnik at inria.fr
> wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensou
> rce/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170308/4b1e8a24/attachment.html>
More information about the vtkusers
mailing list