Reputation: 1310
I need to calculate volume intersection and penetration depth between 3D triangular meshes (e.g. in .obj format), but I am quite new to computational geometry.
In a previous post (Mesh to mesh intersections) and from my google search, I found a few C++ libraries which might be appropriate to do the job:
Though, I am not sure which one could be the most appropriate for a beginner. Any suggestion?
Upvotes: 11
Views: 8065
Reputation: 21307
One additional possibility is to use open-source C++ library MeshLib. It can read and write meshes in Wavefront format (.obj) and robustly perform Boolean operations (intersection, union, difference) on meshes: documentation of the appropriate functions.
As far as I know, Boolean operations in MeshLib
are faster than in CGAL
and libigl
, see video of MeshInspector application based on MeshLib
.
Upvotes: 1
Reputation: 6264
libigl as of version 1.1 has robust mesh boolean operations in igl/boolean/mesh_boolean.h
. This uses either an implementation using CGAL's exact arithmetic kernel or a wrapper of cork (another option for you).
For now, libigl also contains a patched version of cork in libigl/external/cork
, which greatly improves robustness.
While implementing libigl's boolean ops, I found that cork is faster but does not always produce the correct result (specifically, it fails to resolve all intersections).
Libigl, using CGAL as a backend, is the most robust and still fast compared to converting a mesh to CGAL's Nef_polyhedron
, conducting CSG operations and converting back to a mesh. This final conversion would be possible only if the result is manifold. Instead, libigl only uses CGAL for exact triangle-triangle intersection and 2D meshing. Correct, non-manifold output is no problem.
Libigl's interface is very simple and familiar to users of Eigen. For example, to find the intersection between a solid mesh with vertices in the rows of VA
and triangles indices in the rows of FA
and another mesh (VB,FB)
and store the output in a new mesh (VC,FC)
:
#include <igl/boolean/mesh_boolean.h>
...
igl::mesh_boolean(VA,FA,VB,FB,MESH_BOOLEAN_TYPE_UNION,VC,FC);
Upvotes: 13