Suppose to have a polyhedron representing an object A, and to want to get its concavities.
An option for doing that consists in computing the convex hull CH of the object A and splitting the difference CH - A into connected components.
For doing that I tried to use the Nef Polyhedrons module in CGAL. This allows to convert A and CH into Nef Polyhedrons, for easily applying boolean operations like the set difference.
Once the difference is obtained as a Nef Polyhedron, its volumes labeled with a 1 in the mark
field should represent the finite connected components of the difference, and can be converted back into Polyhedrons with the function convert_inner_shell_to_polyhedron
.
In theory this approach should work fine, but in practice there is a problem that arises when the Polyhedrons used are the result of a conversion from a STEP file into a triangular mesh that defines the Polyhedron. In fact, consider for example a quadrilateral face in the STEP file. During the conversion, it must be converted in at least two triangles. The problem is that when saving the generated triangles into the file representing the converted mesh (for example an OFF file, or a STL, or OBJ), they risk to lose their coplanarity because of vertices coordinate approximation.
This causes, when the Nef Polyhedrons difference is computed, the following undesired behaviors:
- some very thin volumes are generated, because one of the diagonals of the quadrilateral (supposing the quadrilateral has been split in two triangles) has "moved" towards the internal of the polyhedron;
- the function
convert_inner_shell_to_polyhedron
prints an error message likelookup_halfedge(): input error: facet 11 shares a halfedge from vertex 2 to vertex 1 with facet 0.
The first behavior is not a big problem: every volume converted to a Polyhedron can be checked for its thickness and eventually discarded. The second one, however, returns an empty Polyhedron, and there is no way, as far as I know, to get the desired volume.
So I ask you for methods for solving this problem. Here I report some observations I did about that:
- CGAL Polyhedrons allow to use polygonal faces instead of triangular ones, so a solution could be to convert the STEP file into a polygonal mesh: this should allow to maintain the coplanarity of points of the same faces. However, I was not able to find software that performs the conversion without passing through a triangular mesh;
- convert directly the STEP file into a CGAL Polyhedron instance. I think this approach is far from being affordable in a reasonable amount of time;
- implementing some method for correcting coplanarity of points of neighboring faces. This may be a practicable method, but there may be some other problem arising when changing manually the position of the vertices of a polyhedron.