How can I split a polyline into its linear segments?

Here’s the best answer to this question. Just use a triangle filter:

def polylineToMultiline(source):
    triangles = vtk.vtkTriangleFilter()
    triangles.SetInputData(source)
    triangles.Update()
    return ensurePolyData(triangles)

The documentation of vtkTriangleFilter states:

… [vtkTriangleFilter] also generates line segments from polylines unless PassLines is off, and generates individual vertex cells from vtkVertex point lists unless PassVerts is off.

The remaining question: vtkTriangleFilter to apply an operation on a polyline, what the hack?! It’s sometimes so difficult to find the right method in vtk. :confused: :sleepy:

1 Like