From 380cf4eca5a409bd74901282f640e60f424b790c Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 14 Sep 2023 21:57:49 +0200 Subject: [PATCH] cgal kernel: permissiveness for multiple outer bounds in face --- src/ifcgeom/kernels/cgal/CgalKernel.cpp | 31 ++++++++++++++----------- src/ifcgeom/kernels/cgal/CgalKernel.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.cpp b/src/ifcgeom/kernels/cgal/CgalKernel.cpp index e1b7716597..ea4c3fad04 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.cpp +++ b/src/ifcgeom/kernels/cgal/CgalKernel.cpp @@ -189,10 +189,8 @@ bool CgalKernel::convert(const taxonomy::shell::ptr l, cgal_shape_t& shape) { std::list face_list; for (auto& f : l->children) { bool success = false; - cgal_face_t face; - try { - success = convert(f, face); + success = convert(f, face_list); } catch (...) {} if (!success) { @@ -204,22 +202,20 @@ bool CgalKernel::convert(const taxonomy::shell::ptr l, cgal_shape_t& shape) { // for (auto &point: face.outer) { // std::cout << "\tPoint(" << point << ")" << std::endl; // } - - face_list.push_back(face); } shape = utils::create_polyhedron(face_list); return shape.size_of_facets(); } -bool CgalKernel::convert(const taxonomy::face::ptr face, cgal_face_t& result) { +bool CgalKernel::convert(const taxonomy::face::ptr face, std::list& result) { int num_outer_bounds = 0; for (auto& bound : face->children) { if (bound->external.get_value_or(false)) num_outer_bounds++; } - if (num_outer_bounds != 1) { + if (num_outer_bounds != 1 && num_outer_bounds != face->children.size()) { Logger::Message(Logger::LOG_ERROR, "Invalid configuration of boundaries for:", face->instance); return false; } @@ -241,9 +237,16 @@ bool CgalKernel::convert(const taxonomy::face::ptr face, cgal_face_t& result) { } else { mf.inner.push_back(wire); } + + if (num_outer_bounds > 1) { + result.push_back(mf); + mf = cgal_face_t{}; + } } - result = mf; + if (num_outer_bounds == 1) { + result.push_back(mf); + } // std::cout << "Face: " << std::endl; // for (auto &point: face.outer) { @@ -1114,12 +1117,12 @@ bool CgalKernel::convert(const taxonomy::extrusion::ptr extrusion, cgal_shape_t return false; } - cgal_face_t bottom_face; - if (!convert(extrusion->basis, bottom_face)) { + std::list bottom_face; + if (!convert(extrusion->basis, bottom_face) || bottom_face.size() != 1) { return false; } - return process_extrusion(bottom_face, extrusion->direction, extrusion->depth, shape); + return process_extrusion(bottom_face.front(), extrusion->direction, extrusion->depth, shape); } CGAL::Polyhedron_3 ifcopenshell::geometry::utils::create_cube(double d) { @@ -1844,14 +1847,14 @@ bool CgalKernel::convert_impl(const taxonomy::boolean_result::ptr br, Conversion } if (!face->children.empty()) { - cgal_face_t f; - if (!convert(face, f)) { + std::list fs; + if (!convert(face, fs) || fs.size() != 1) { return false; } // static auto z = taxonomy::make(0, 0, 1); cgal_shape_t poly; - process_extrusion(f, z, 200, poly); + process_extrusion(fs.front(), z, 200, poly); for (auto& v : vertices(poly)) { v->point() = Kernel_::Point_3( v->point().cartesian(0), diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.h b/src/ifcgeom/kernels/cgal/CgalKernel.h index 0bda2ee5a7..64a72fc523 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.h +++ b/src/ifcgeom/kernels/cgal/CgalKernel.h @@ -100,7 +100,7 @@ namespace ifcopenshell { void remove_duplicate_points_from_loop(cgal_wire_t& polygon); bool convert(const taxonomy::extrusion::ptr, cgal_shape_t&); - bool convert(const taxonomy::face::ptr, cgal_face_t&); + bool convert(const taxonomy::face::ptr, std::list&); bool convert(const taxonomy::loop::ptr, cgal_wire_t&); // bool convert(const taxonomy::matrix4::ptr, cgal_placement_t&); bool convert(const taxonomy::shell::ptr, cgal_shape_t&);