From 5d4b01e10fe71084c54991afaafe95f203a0d201 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 31 May 2023 22:15:01 +0200 Subject: [PATCH] apply boolean results in batches as well #3201 --- .../kernels/opencascade/boolean_result.cpp | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ifcgeom/kernels/opencascade/boolean_result.cpp b/src/ifcgeom/kernels/opencascade/boolean_result.cpp index 768b9859ef..2c2ebd7caf 100644 --- a/src/ifcgeom/kernels/opencascade/boolean_result.cpp +++ b/src/ifcgeom/kernels/opencascade/boolean_result.cpp @@ -7,6 +7,46 @@ using namespace IfcGeom; using namespace ifcopenshell::geometry; using namespace ifcopenshell::geometry::kernels; +// @todo should we reapply the technique to apply openings in batches? +namespace { + struct opening_sorter { + bool operator()(const std::pair& a, const std::pair& b) const { + return a.first > b.first; + } + }; + + bool apply_in_batches(IfcGeom::util::boolean_settings bst, const TopoDS_Shape& first_operand, std::vector< std::pair >& opening_vector, BOPAlgo_Operation occ_op, TopoDS_Shape& result) { + auto it = opening_vector.begin(); + auto jt = it; + + result = first_operand; + for (;; ++it) { + if (it == opening_vector.end() || jt->first / it->first > 10.) { + + TopTools_ListOfShape opening_list; + for (auto kt = jt; kt < it; ++kt) { + opening_list.Append(kt->second); + } + + TopoDS_Shape intermediate_result; + if (IfcGeom::util::boolean_operation(bst, result, opening_list, BOPAlgo_CUT, intermediate_result)) { + result = intermediate_result; + } else { + return false; + } + + jt = it; + } + + if (it == opening_vector.end()) { + break; + } + } + + return true; + } +} + namespace { BOPAlgo_Operation op_to_occt(taxonomy::boolean_result::operation_t t) { switch (t) {