# Problem with vtkSelectEnclosedPoints

**URL:** https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988
**Category:** Support
**Created:** [October 27, 2021, 11:52am UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988 "2021-10-27T11:52:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mrwsl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@mrwsl](https://discourse.vtk.org/u/mrwsl)
#### Post date: [October 27, 2021, 11:52am UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988/1 "2021-10-27T11:52:41Z")

</div>

Hi there,  
I’m loading STL files which come from various CAD Software. My goal is to create a grid of points in the x,y-plane at the top of the STL. I do this by creating the pattern according to the STL’s bounds and getting rid of the unwanted points by using `vtkSelectEnclosedPoints`.  
There a some points missing which are clearly part of the STL (resolution is 1 point per mm):

 ![grafik](https://discourse.vtk.org/uploads/default/original/2X/0/0123346650954bbe7e83bc33e114cfa1ceb9283a.png)  
If I increase the resolution blanks are getting filled - resolution 12 points per mm:  
 ![grafik](https://discourse.vtk.org/uploads/default/original/2X/6/60f5ae42a40b32f51407edc958fddee3cea5daf9.png)

But still it is not an equidistant grid like I would expect. Here is the code that is doing the picking of points:

```auto
  for (vtkIdType i = 0;
       i < selectEnclosedPoints->GetOutput()->GetNumberOfPoints(); i++) {
    if (selectEnclosedPoints->IsInside(i) == 1) {
      double pt[3];
      selectEnclosedPoints->GetOutput()->GetPoint(i, pt);
      PointT pclPt;
      pclPt.x = pt[0];
      pclPt.y = pt[1];
      pclPt.z = pt[2];
      cloud_out->push_back(pclPt);
    } else {
      double pt[3];
      selectEnclosedPoints->GetOutput()->GetPoint(i, pt);
      qDebug() << "Point: " << pt[0] << " " << pt[1] << " " << pt[2];
    }
  }

```

The cube shown is centered and has the dimension 20x20x20mm. For example with 1 point per mm the point [-9, -8, 20] is not “inside” although it should be. What am I missing? Thanks!

Sadly I’m too new to attach the stl in question.

---

<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: [October 27, 2021, 1:10pm UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988/2 "2021-10-27T13:10:46Z")

</div>

It’s hard to say what the issue is without having access to the data. It could be a numerical issue, or it could be “bad” data. By bad data I mean surfaces with openings (i.e., the surface is not closed), cracks/t-junctions, overlapping cells, self-intersections, etc. I can’t exactly tell from the image you sent, but it appears that you might have an open surface in which case the filter would certainly fail.

---

<div class="post-metadata">

### Author: ![mrwsl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@mrwsl](https://discourse.vtk.org/u/mrwsl)
#### Post date: [October 27, 2021, 1:17pm UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988/3 "2021-10-27T13:17:19Z")

</div>

Thanks for your reply!  
I actually checked the STL for such errors but could not find any. As soon as I’m allowed I will provide the file.

EDIT: [Here](https://tubcloud.tu-berlin.de/s/9yWT6nyP2xyff7F)is a link for the file.

---

<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: [October 27, 2021, 1:50pm UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988/4 "2021-10-27T13:50:01Z")

</div>

On further thought, do I understand correctly that you are trying to place points on the surface of the stl mesh? If so, this is asking for trouble because vtkSelectEnclosedPoints is presuming that points are _inside_ an enclosed surface (it uses a ray-casting approach). There can be inherent tolerancing issues when points are placed _on_ the surface.

Have you looked at other filters such as vtkPolyDataPointSampler or vtkPoissonDiskSampler ? which are meant to place points on a mesh…

---

<div class="post-metadata">

### Author: ![mrwsl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@mrwsl](https://discourse.vtk.org/u/mrwsl)
#### Post date: [October 27, 2021, 1:54pm UTC](https://discourse.vtk.org/t/problem-with-vtkselectenclosedpoints/6988/5 "2021-10-27T13:54:12Z")

</div>

Yes, you are correct. I misread the example for `vtkSelectEnclosedPoints`. I will have a look at the filters you mentioned!
