I'm trying to make use of Csg Tree by libigl to do multiple boolean operations at once. In the linked tutorial, there is just this one line:
// Compute result of (A ∩ B) \ ((C ∪ D) ∪ E)
igl::copyleft::cgal::CSGTree<MatrixXi> CSGTree =
{{{VA,FA},{VB,FB},"i"},{{{VC,FC},{VD,FD},"u"},{VE,FE},"u"},"m"};
I couldn't figure out how to use the CSGTree class API. Can anybody help ideally by a boilerplate example?
According to the libigl tutorial:
In simple words - you can construct CSG meshes using the
mesh_booleanfunction, but in this case you have to explicitly take care of robustness of intermediate calculations. TheCSGTreeclass does that for you automatically because it uses the CGAL exact arithmetic for all the intermediate calculations with coordinates. Another benefit of theCSGTreeclass - you can construct a multilevel CSG tree in just one line of code. An example below shows how to construct a simplest CSG tree from two meshes and visualize it:Such a one-line construction is possible because the
CSGTreehas the following constructor (among others):As you can see above - the resulting array of coordinates can be converted to an array of doubles by the
cast_Vtemplated function if it's necessary - for example, for visualization. The result of this visualization is below: