Fill contour created by line segments

601 Views Asked by At

I calculated the intersection of a mesh and a plane. As output I got an array of line segments, rendering the lines gives me the intersection contour. Now I would like to fill the area enclosed by the contour. The problem I'm facing is the line segments are not in any particular order. I am using OpenGL for rendering.

1

There are 1 best solutions below

0
On

You can use C++ libraries for geometry processing like VTK.

Assuming that you are intersecting a closed mesh with a plane, you should get one or more closed polylines. You can get what you want by following these steps below:

  • First, you will have to merge points that are overlapping, to create a contiguous polyline or a set of multiple closed polylines. This will be erroneous based on the tolerances you use. But that is part and parcel of geometry processing.
  • Second, you will have to pass individual polylines (closed loops) to a triangulation algorithm like Delaunay triangulation (vtkDelaunay2D). You must also pass the line segments of the polyline as a constraint on the output triangulation.

The problem is that this will not work in all cases, because it is hard to know, which side is inside and which side is outside, while filling the polylines. But it is a starting point.

Another more robust approach can be to use a dense mesh of the plane while computing intersection with the object. During intersection, you can compute if the vertex of the plane-mesh is inside or outside the object. In this manner you can keep track of which regions to fill.