# Extract part of a vtkPolyData based on vertices ids

**URL:** https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399
**Category:** Support
**Created:** [August 17, 2021, 11:45am UTC](https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399 "2021-08-17T11:45:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Manuel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.vtk.org/u/Manuel)
#### Post date: [August 17, 2021, 11:45am UTC](https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399/1 "2021-08-17T11:45:55Z")

</div>

Dear All, I am currently looking for the best way to extract a subpart of a vtkPolyData from known vertices ids on this vtkPolyData.  
The input of the function should be a vtkPolyData and a list of vtkIdType and the output should be a vtkPolyData corresponding to the extraction on the input vtkPolyData of the vertices corresponding to the list of vtkIdType.  
After searching in the documentation, the way I do it for now is to use a vtkExtractPolyDataGeometry with a custom vtkImplicitFunction to keep only vertices that are contained into the list of vtkIdType. Then I use this pipeline : vtkExtractPolyDataGeometry =\> vtkConnectivityFilter =\> vtkDataSetSurfaceFilter =\> vtkClipPolyData which seems to be quite complex, long, and requires to create a vtkKdTreePointLocator onto the input vtkPolyData to implement the custom vtkImplicitFunction.

Is there a simpler way to achieve this task?  
Greatly appreciate any help.

Thank you

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 17, 2021, 11:52am UTC](https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399/2 "2021-08-17T11:52:50Z")

</div>

If the point ids are in a consecutive range [pointIdMin,pointIdMax], I believe that you can use vtkGeometryFilter, set PointClippingOn, and then set the PointMinimum and PointMaximum.

You might also be able to use the filter vtkExtractSelectedIds. I haven’t used this filter in a long time, but I think it could be made to work.

---

<div class="post-metadata">

### Author: ![Manuel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.vtk.org/u/Manuel)
#### Post date: [August 17, 2021, 1:49pm UTC](https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399/3 "2021-08-17T13:49:49Z")

</div>

Thank you for your answer.

Unfortunately the points ids are not in a consecutive range.

I tried to use vtkExtractSelectedIds, which seems to work but the output is a vtkUnstructuredGrid. Is there any method or filter to convert a vtkUnstructuredGrid to a vtkPolyData?  
I mostly used this example : [https://kitware.github.io/vtk-examples/site/Cxx/PolyData/ExtractSelectedIds/](https://kitware.github.io/vtk-examples/site/Cxx/PolyData/ExtractSelectedIds/)

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 17, 2021, 1:57pm UTC](https://discourse.vtk.org/t/extract-part-of-a-vtkpolydata-based-on-vertices-ids/6399/4 "2021-08-17T13:57:16Z")

</div>

vtkGeometryFilter converts any dataset type to polydata
