<div dir="ltr"><div><div><div>Hi Nicolas,<br><br></div>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.<br><br> cc_filter = vtk.vtkPolyDataConnectivityFilter()<br> cc_filter.SetInputData(mesh)<br> cc_filter.SetExtractionModeToSpecifiedRegions()<br> <br> components = list()<br> idx = 0<br> <br> while True:<br> cc_filter.AddSpecifiedRegion(idx)<br> cc_filter.Update()<br><br> component = vtk.vtkPolyData()<br> component.DeepCopy(cc_filter.GetOutput())<br> # Make sure we got something<br> if component.GetNumberOfCells() <= 0:<br> break<br><br> components.append(component)<br> cc_filter.DeleteSpecifiedRegion(idx)<br> idx += 1<br><br> return components<br><br></div>Best regards,<br></div>CP<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 17, 2017 at 2:38 PM, Nicolas Cedilnik <span dir="ltr"><<a href="mailto:nicolas.cedilnik@inria.fr" target="_blank">nicolas.cedilnik@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
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.<br>
<br>
I can do that with paraview but I'm struggling to get it done using python vtk bindings.<br>
<br>
So far I've managed to extract the cells corresponding to the the largest region:<br>
<br>
rd = vtk.vtkGenericDataObjectReader<wbr>()<br>
rd.SetFileName(my_input_vtk_fi<wbr>le)<br>
rd.Update()<br>
ug = rd.GetOutput()<br>
f = vtk.vtkConnectivityFilter()<br>
f.SetInputData(ug)<br>
f.SetExtractionModeToLargestRe<wbr>gion()<br>
f.Update()<br>
out = f.GetOutput()<br>
<br>
ug.GetNumberOfCells() # 28396, the original number of cells<br>
out.GetNumberOfCells() # 27740, less cells, looks good<br>
<br>
from which I can work something out, but I have two problems with this approach:<br>
- I'd like to know the indices of the other connected regions<br>
- the `ug` input only has 1 point data array, I believe this is a known limitation<br>
<br>
I've found a SetExtractionModeToAllRegions method but I don't understand how to deal with it:<br>
f.SetExtractionModeToAllRegion<wbr>s()<br>
b = f.GetOutput()<br>
b.GetNumberOfCells() # 28396, same as input<br>
b.GetCellData().GetNumberOfArr<wbr>ays() # 0, I would have expected an array where the cells where labeled by region number...<br>
<br>
All in all, I have two questions:<br>
- How do I use the filter to get the cells labeled by region?<br>
- (less important) Is it possible to read different point data arrays with vtk python bindings?<br>
<br>
Thanks in advance for your help and advices on how to use vtk properly<br>
<br>
-- <br>
Nicolas<br>
______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FA<wbr>Q</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/vtkusers</a><br>
</blockquote></div><br></div>