How to extract the ids of the boundary points of a surface?

I know that it is possible to extract boundary edges using vtkFeatureEdges. See this example. The edges are returned as a new vtkPolyData consisting of one or more vtkPolyLines.

However, I require the point ids of the input surface, and not an independent poly with new points and edges. How to achieve that?

I tried to use vtkIdFilter (in the hope that vtkFeatureEdges preserves point data), to no avail. Alternatively, I could use a point locator to find the boundary points again in the original surface. However, this looks a bit awkward to me. Is there a simpler way to achieve this?

1 Like

My first attempt would be to assign the id’s to a scalar field (to the vertexes) in the original mesh as vtkFeatureEdges is supposed to preserve scalars in the output. This would be a little less awkward, IMO, than performing a spatial search.

1 Like

I totally agree. Using vtkIdFilter is the right way (it creates such a scalar array with the ids as point data). I had messed up something in my tests. The following works:

def extractBoundaryIds(source):
    idFilter = vtk.vtkIdFilter()
    idFilter.SetInputConnection(source.GetOutputPort())
    idFilter.SetIdsArrayName("ids")
    idFilter.SetPointIds(True)
    idFilter.SetCellIds(False)
    # Available for vtk>=8.3:
    #idFilter.SetPointIdsArrayName(arrayName)
    #idFilter.SetCellIdsArrayName(arrayName)
    idFilter.Update()

    edges = vtk.vtkFeatureEdges()
    edges.SetInputConnection(idFilter.GetOutputPort())
    edges.BoundaryEdgesOn()
    edges.ManifoldEdgesOff()
    edges.NonManifoldEdgesOff()
    edges.FeatureEdgesOff()
    edges.Update()

    array = edges.GetOutput().GetPointData().GetArray("ids")
    n = edges.GetOutput().GetNumberOfPoints()
    boundaryIds = []
    for i in range(n):
        boundaryIds.append(array.GetValue(i))
    return boundaryIds
1 Like