# Extract a sub-mesh from its boundary

**URL:** https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325
**Category:** Support
**Created:** [February 25, 2019, 5:18pm UTC](https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325 "2019-02-25T17:18:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lmainguy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/c0e974/32.png) [@lmainguy](https://discourse.vtk.org/u/lmainguy)
#### Post date: [February 25, 2019, 5:18pm UTC](https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325/1 "2019-02-25T17:18:51Z")

</div>

Hi,  
Let’s say I have a list of connected edges in a mesh enclosing a part of it (the sub-mesh).  
Let’s say also I have an heuristic giving me a vertex V in the sub-mesh.  
Now I’d like to select all the vertices “inside” of the connected edges, i.e. containing the vertex V.

To illustrate the problem a bit, it would be going from that

 ![3dsmax_OWRDi5lG8J](https://discourse.vtk.org/uploads/default/original/1X/b3cf0453411479802bceaea0048f0954ba78456b.png)  
to that:  
 ![3dsmax_99ChYhDtnC](https://discourse.vtk.org/uploads/default/original/1X/9553cf7271040c34150f285152bfe4edb970dd5a.png)

A basic way of doing that would be a breadth first search with the vertex V as the root and the connected edges vertices as a list of already known vertices which should not be explored.

Unfortunately the BFS algorithm in VTK does not allow to have a list of already known vertices, which is understandable since the idea above is not the original algorithm.

Is there a way to achieve what I want from the VTK API or do I have to do it myself ?  
My main concern if I have to do it myself is a performance problem since I’d have to do it in Python.

Thanks for your help!  
Ludovic

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [February 25, 2019, 5:38pm UTC](https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325/2 "2019-02-25T17:38:26Z")

</div>

vtkSelectPolyData can do this. Use SetLoop method to define the edges.

---

<div class="post-metadata">

### Author: ![lmainguy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/c0e974/32.png) [@lmainguy](https://discourse.vtk.org/u/lmainguy)
#### Post date: [February 25, 2019, 10:25pm UTC](https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325/3 "2019-02-25T22:25:51Z")

</div>

Thanks Andras, I knew there must be something like that.

---

<div class="post-metadata">

### Author: ![lorensen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lorensen/32/20_2.png) [@lorensen](https://discourse.vtk.org/u/lorensen)
#### Post date: [June 7, 2019, 2:25am UTC](https://discourse.vtk.org/t/extract-a-sub-mesh-from-its-boundary/325/4 "2019-06-07T02:25:47Z")

</div>

This example [SelectPolyData](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/SelectPolyData/) part of the [VTKExamples Project](https://lorensen.github.io/VTKExamples/site/) may help.

Enjoy VTK,

Bill
