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

**URL:** https://discourse.vtk.org/t/how-to-extract-the-ids-of-the-boundary-points-of-a-surface/2530
**Category:** Support
**Created:** [February 1, 2020, 2:30am UTC](https://discourse.vtk.org/t/how-to-extract-the-ids-of-the-boundary-points-of-a-surface/2530 "2020-02-01T02:30:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [February 1, 2020, 2:30am UTC](https://discourse.vtk.org/t/how-to-extract-the-ids-of-the-boundary-points-of-a-surface/2530/1 "2020-02-01T02:30:34Z")

</div>

I know that it is possible to extract boundary edges using [`vtkFeatureEdges`](https://vtk.org/doc/nightly/html/classvtkFeatureEdges.html). See [this example](https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/BoundaryEdges/). 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?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 1, 2020, 5:38pm UTC](https://discourse.vtk.org/t/how-to-extract-the-ids-of-the-boundary-points-of-a-surface/2530/2 "2020-02-01T17:38:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [February 1, 2020, 7:01pm UTC](https://discourse.vtk.org/t/how-to-extract-the-ids-of-the-boundary-points-of-a-surface/2530/3 "2020-02-01T19:01:46Z")

</div>

I totally agree. Using [`vtkIdFilter`](https://vtk.org/doc/nightly/html/classvtkIdFilter.html) 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
```
