Problem with vtkSelectEnclosedPoints

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):


If I increase the resolution blanks are getting filled - resolution 12 points per mm:

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

  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.

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.

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 is a link for the file.

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…

1 Like

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