get a continuous line from a polydata structure

Hi,

I would like to create different continuous lines from a polydata made of cells (sparse segments).
For now I have successfully found the different regions by using a vtk.vtkPolyDataConnectivityFilter().

I have a question on this problem on stackoverflow but this discourse forum might be a better place.

If I’ve understood your question, you can join contiguous segments into polylines with vtkStripper.

Do you need each outline as a separate polyline, or do you need each outline as a separate dataset?

each outline as a separate polyline will be fine.
I will save them later in a netcdf file.

Indeed, vtkStripper was the filter I was looking for.

import pyvista as pv
import vtk
import random

! wget -q -nc https://thredds-su.ipsl.fr/thredds/fileServer/ipsl_thredds/brocksce/pyvista/mesh.vtk
mesh = pv.PolyData('mesh.vtk')
edges = mesh.extract_feature_edges(boundary_edges=True)

pl = pv.Plotter()

pl.add_mesh(pv.Sphere(radius=0.999, theta_resolution=360, phi_resolution=180))
pl.add_mesh(mesh, show_edges=True, edge_color="gray")

regions = edges.connectivity()
regCount = len(set(pv.get_array(regions, name="RegionId")))

connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
stripper = vtk.vtkStripper()

for r in range(regCount):
    connectivityFilter.SetInputData(edges)
    connectivityFilter.SetExtractionModeToSpecifiedRegions()
    connectivityFilter.InitializeSpecifiedRegionList()
    connectivityFilter.AddSpecifiedRegion(r)
    connectivityFilter.Update()
    
    stripper.SetInputData(connectivityFilter.GetOutput())
    stripper.SetJoinContiguousSegments(True)
    stripper.Update()
    reg = stripper.GetOutput()
   
    random_color = "#"+''.join([random.choice('0123456789ABCDEF') for i in range(6)])
    pl.add_mesh(reg, color=random_color, line_width=4)

viewer = pl.show(jupyter_backend='pythreejs', return_viewer=True)
display(viewer)

Many thanks !