From 7852c06ab7c6b31c992aa035467da17b53222267 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 2 Feb 2021 23:40:43 +0100 Subject: [PATCH 1/3] Fix issue with iterator invalidation --- src/ifcgeom/kernels/cgal/CgalKernel.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.cpp b/src/ifcgeom/kernels/cgal/CgalKernel.cpp index 1d66f5a940..659a81430a 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.cpp +++ b/src/ifcgeom/kernels/cgal/CgalKernel.cpp @@ -831,15 +831,16 @@ bool CgalKernel::process_extrusion(const cgal_face_t& bottom_face, const taxonom } auto p = external_edges.insert({ { i0, i1 }, { i, j} }); if (!p.second) { + // Mark as internal before erasure in external + // This is {i,j} at the time the edge use was inserted. + internal_edges.insert(p.first->second); + // not inserted, remove external_edges.erase(p.first); // @nb note the difference here in indices, {i0, i1} is point indices in // point_map. i is index in faces_to_extrude, j is segment index in wire. internal_edges.insert({ i, j }); - - // This is {i,j} at the time the edge use was inserted. - internal_edges.insert(p.first->second); } } i++; From 7812ecb1897362d240755d414e243b498e86f98a Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 21 Feb 2021 16:34:34 +0100 Subject: [PATCH 2/3] C++17 compat --- src/ifcgeom/taxonomy.h | 2 +- src/ifcparse/IfcSchema.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 11ba421914..c0d5aaa894 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -346,7 +346,7 @@ struct collection : public geom_item { collection() {} collection(const collection& other) { - std::transform(other.children.begin(), other.children.end(), std::back_inserter(children), std::mem_fun(&item::clone)); + std::transform(other.children.begin(), other.children.end(), std::back_inserter(children), std::mem_fn(&item::clone)); } template diff --git a/src/ifcparse/IfcSchema.h b/src/ifcparse/IfcSchema.h index 158dcd1547..9cd54d9a9f 100644 --- a/src/ifcparse/IfcSchema.h +++ b/src/ifcparse/IfcSchema.h @@ -243,7 +243,7 @@ namespace IfcParse { std::vector inverse_attributes_; - class attribute_by_name_cmp : public std::unary_function { + class attribute_by_name_cmp { private: std::string name_; public: @@ -399,14 +399,14 @@ namespace IfcParse { std::vector enumeration_types_; std::vector entities_; - class declaration_by_name_cmp : public std::binary_function { + class declaration_by_name_cmp { public: bool operator()(const declaration* decl, const std::string& name) { return decl->name_lc() < name; } }; - class declaration_by_index_sort : public std::binary_function { + class declaration_by_index_sort { public: bool operator()(const declaration* a, const declaration* b) { return a->index_in_schema() < b->index_in_schema(); From 4ec24e93a6dc57e7bca65eb69de879a432f9e9d1 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 21 Feb 2021 16:34:51 +0100 Subject: [PATCH 3/3] Don't store precision cube (multi-threading) --- src/ifcgeom/kernels/cgal/CgalKernel.cpp | 4 ++++ src/ifcgeom/kernels/cgal/CgalKernel.h | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.cpp b/src/ifcgeom/kernels/cgal/CgalKernel.cpp index 659a81430a..ce36a6599d 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.cpp +++ b/src/ifcgeom/kernels/cgal/CgalKernel.cpp @@ -1079,6 +1079,8 @@ CGAL::Polyhedron_3 ifcopenshell::geometry::utils::create_cube(const Ker bool CgalKernel::thin_solid(const CGAL::Nef_polyhedron_3& a, CGAL::Nef_polyhedron_3& result) { // @todo this should be possible as a minkowski sum of facet & cube. rather than a set of boolean ops. + auto precision_cube_ = precision_cube(); + auto a_nonconst = a; auto ax = CGAL::minkowski_sum_3(a_nonconst, precision_cube_); auto x = ax - a; @@ -1136,6 +1138,8 @@ bool CgalKernel::preprocess_boolean_operand(const IfcUtil::IfcBaseClass* log_ref return false; } + auto precision_cube_ = precision_cube(); + if (dilate) { try { // @todo don't dilate in 3 dimensions but only in the XY plane, orthogonal to wall axis. diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.h b/src/ifcgeom/kernels/cgal/CgalKernel.h index 947581fe28..7fcbd0d1ac 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.h +++ b/src/ifcgeom/kernels/cgal/CgalKernel.h @@ -70,10 +70,15 @@ namespace kernels { private: double precision_; size_t circle_segments_; - CGAL::Nef_polyhedron_3 precision_cube_; + // CGAL::Nef_polyhedron_3 precision_cube_; bool preprocess_boolean_operand(const IfcUtil::IfcBaseClass* log_reference, const cgal_shape_t& shape_const, CGAL::Nef_polyhedron_3& result, bool dilate); bool thin_solid(const CGAL::Nef_polyhedron_3& a, CGAL::Nef_polyhedron_3& result); + + CGAL::Nef_polyhedron_3 create_precision_cube_() const { + auto cc = utils::create_cube(precision_); + return CGAL::Nef_polyhedron_3(cc); + } public: CgalKernel() @@ -82,8 +87,7 @@ namespace kernels { , precision_(1.e-5) , circle_segments_(16) { - auto cc = utils::create_cube(precision_); - precision_cube_ = CGAL::Nef_polyhedron_3(cc); + } void remove_duplicate_points_from_loop(cgal_wire_t& polygon); @@ -102,7 +106,7 @@ namespace kernels { virtual bool convert_impl(const taxonomy::extrusion*, ifcopenshell::geometry::ConversionResults&); virtual bool convert_impl(const taxonomy::boolean_result*, ifcopenshell::geometry::ConversionResults&); - const CGAL::Nef_polyhedron_3& precision_cube() const { return precision_cube_; } + CGAL::Nef_polyhedron_3 precision_cube() const { return create_precision_cube_(); } }; }