Build all volumes when converting between nef and poly

This commit is contained in:
Thomas Krijnen
2026-06-23 20:26:16 +02:00
parent c592018b3f
commit 13681cdf9b
2 changed files with 12 additions and 5 deletions
@@ -337,7 +337,7 @@ const cgal_shape_t& ifcopenshell::geometry::CgalShape::poly() const {
void ifcopenshell::geometry::CgalShape::to_poly() const {
if (!shape_) {
cgal_shape_t poly;
convert_to_polyhedron(*nef_, poly);
convert_to_polyhedron(*nef_, poly, std::numeric_limits<std::size_t>::max());
if (poly.size_of_vertices() > 0) {
// @todo why is this necessary? we have the mark of the volumes?
CGAL::Polygon_mesh_processing::orient_to_bound_a_volume(poly);
@@ -1332,20 +1332,27 @@ size_t edge_contract(Graph<Kernel>& G) {
// For some reason gives better results then Nef_polyhedron_3.convert_to_polyhedron() in some cases
template <typename Kernel>
bool convert_to_polyhedron(const CGAL::Nef_polyhedron_3<Kernel>& a, CGAL::Polyhedron_3<Kernel>& b, size_t volume_index=0) {
const bool all_volumes = volume_index == std::numeric_limits<size_t>::max();
size_t v = 0;
Polysoup_builder<Kernel> vis;
for (auto it = a.volumes_begin(); it != a.volumes_end(); ++it) {
if (!it->mark()) {
continue;
}
for (auto jt = it->shells_begin(); jt != it->shells_end(); ++jt) {
if (v++ == volume_index) {
Polysoup_builder<Kernel> vis;
if (v++ == volume_index || all_volumes) {
a.visit_shell_objects(typename CGAL::Nef_polyhedron_3<Kernel>::SFace_const_handle(jt), vis);
vis.build(b);
return true;
if (!all_volumes) {
vis.build(b);
return true;
}
}
}
}
if (all_volumes && v > 0) {
vis.build(b);
return true;
}
return false;
}