# ExtractEnclosedPoints giving additional points outside the mesh

**URL:** https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484
**Category:** Support
**Created:** [January 17, 2023, 8:06pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484 "2023-01-17T20:06:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![sjhbusch](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sjhbusch/32/6432_2.png) [@sjhbusch](https://discourse.vtk.org/u/sjhbusch)
#### Post date: [January 17, 2023, 8:06pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/1 "2023-01-17T20:06:04Z")

</div>

Hi, I am new to using more advanced features in VTK. I’m using PyVsta to generate a voxel grid then looking at extracting enclosed points from an STL or mesh. I’ve tried multiple geometries and had the filter return a lot of wrong point points outside the mesh. Some resolutions work okay, while others have a large error. I attached two examples of different mesh resolution. I’ve tried using the same filter in Paraview and obtain very similar results. Has anyone had this issue before or have any suggestions on what to try?

 ![MeshingError](https://discourse.vtk.org/uploads/default/original/2X/a/aa10c9b795bdcd7236ea55505bbb6e4d0a61cb74.png)  
 ![CorrectMesh](https://discourse.vtk.org/uploads/default/original/2X/2/22156b49b723d0a77b5bca3de06957829531f0af.png)

Thank you,  
Shawn

---

<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: [January 18, 2023, 11:37am UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/2 "2023-01-18T11:37:34Z")

</div>

That’s an interesting effect. It could be a weird numerical issue, or maybe something strange with the data like “cracks/gaps” in the mesh. Can you provide access to the data and a test demonstrating this behavior so I can take a deeper look?

---

<div class="post-metadata">

### Author: ![sjhbusch](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sjhbusch/32/6432_2.png) [@sjhbusch](https://discourse.vtk.org/u/sjhbusch)
#### Post date: [January 18, 2023, 1:59pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/3 "2023-01-18T13:59:40Z")

</div>

Hi Will,

I attached the grid, PyVista results, and the STL file below. I tried a few other different geometries, and they all seemed to work okay. I tried to flip this geometry by 180 degrees, and it seemed to mesh okay as well. It seems to only have issues on this particular design and some variations of it.

[https://drive.google.com/drive/folders/1d9Dw\_oS1KAb98Tz6w0Y7b2BpC5Csnsml?usp=sharing](https://drive.google.com/drive/folders/1d9Dw_oS1KAb98Tz6w0Y7b2BpC5Csnsml?usp=sharing)

Thank you very much!  
Shawn

---

<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: [January 18, 2023, 2:28pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/4 "2023-01-18T14:28:36Z")

</div>

Very strange indeed! I’ve got some deliverables this week so I’ll try and look over the weekend.

---

<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: [January 26, 2023, 4:18pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/5 "2023-01-26T16:18:26Z")

</div>

Can you send me a vtk python script that demonstrates the problem. I’m not sure what the data you sent me is all about, and what exactly you are doing.

---

<div class="post-metadata">

### Author: ![Jishnu](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jishnu/32/6221_2.png) [@Jishnu](https://discourse.vtk.org/u/Jishnu)
#### Post date: [January 27, 2023, 3:52am UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/6 "2023-01-27T03:52:49Z")

</div>

Hi Shawn,

vtkEnclosedPoints use cell locator to find whether a point is inside or outside of the surface. Here, they use a statistical approach. They will fire some random rays and check if these rays are intersecting with any surface. If more than 3 rays interact with a surface, then those points are considered inside. Since these rays are random, there are chances of getting such weird results. You can check the source code for mode clarity.

---

<div class="post-metadata">

### Author: ![sjhbusch](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sjhbusch/32/6432_2.png) [@sjhbusch](https://discourse.vtk.org/u/sjhbusch)
#### Post date: [February 9, 2023, 1:49pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/7 "2023-02-09T13:49:23Z")

</div>

I imported the Grid.vtk and pyramid.stl file into ParaView then applied the ExstractEnclosedPoints filter. I also tried it on PyVista and have the lines of Python code below. For the project I am working on, it is important to have an accurate representation of the geometry. Is there another way I can apply a filter to increase the accuracy of the results?

import pyvista  
mesh = pyvista.read(‘pyramid.stl’)  
voxels = pyvista.voxelize(mesh, density=0.5)  
voxels.plot(show\_edges=True)

Thank you,  
Shawn

---

<div class="post-metadata">

### Author: ![sjhbusch](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sjhbusch/32/6432_2.png) [@sjhbusch](https://discourse.vtk.org/u/sjhbusch)
#### Post date: [February 26, 2024, 9:49pm UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/8 "2024-02-26T21:49:42Z")

</div>

Hi Jishnu,

I had completed a work around previously, but I’m trying to work on developing some new algorithms. Is there a more robust function to check the implicit distance or check if a point is inside or outside a mesh? I was hoping to possibly add more arrays to reduce the errors, but am not very familiar with VTK code to figure out how to add more rays.

Thank you,  
Shawn

---

<div class="post-metadata">

### Author: ![olly-writes-code](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olly-writes-code/32/9237_2.png) [@olly-writes-code](https://discourse.vtk.org/u/olly-writes-code)
#### Post date: [November 29, 2025, 2:08am UTC](https://discourse.vtk.org/t/extractenclosedpoints-giving-additional-points-outside-the-mesh/10484/9 "2025-11-29T02:08:57Z")

</div>

Thanks for the clarification here Jishnu. This is definitely a pain when the user expects the alogrithm to be water tight 😉. I’ll do some searching for a method with guarenteed results and follow up here.

I’ve attached an example I’ve got when working with the cow

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0e1b0a786d7699cbb5ad9e936227888ec803529b.jpeg)
