From c3f352c0184678faa84623b51927516162290ee8 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 6 Aug 2023 14:27:31 +0800 Subject: [PATCH] #3546 Filter duplicate edge indices --- .../IfcGeomRepresentation.cpp | 30 +++++++++++-------- .../IfcGeomRepresentation.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.cpp b/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.cpp index 7b0bd95756..e606304b63 100644 --- a/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.cpp +++ b/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.cpp @@ -268,6 +268,10 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model) weld_offset_ += welds.size(); welds.clear(); + // When welding vertices, vertex coords will be shared among faces so we need to per-shape set + // to keep track of which edges were already emitted. + std::set> emitted_edges; + int surface_style_id = -1; if (iit->hasStyle()) { Material adapter(iit->StylePtr()); @@ -319,7 +323,6 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model) // Keep track of the number of times an edge is used // Manifold edges (i.e. edges used twice) are deemed invisible std::map, int> edgecount; - std::vector > edges_temp; std::vector coords; BRepGProp_Face prop(face); @@ -389,15 +392,20 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model) _material_ids.push_back(surface_style_id); _item_ids.push_back(iit->ItemId()); - addEdge(dict[n1], dict[n2], edgecount, edges_temp); - addEdge(dict[n2], dict[n3], edgecount, edges_temp); - addEdge(dict[n3], dict[n1], edgecount, edges_temp); + addEdge(dict[n1], dict[n2], edgecount); + addEdge(dict[n2], dict[n3], edgecount); + addEdge(dict[n3], dict[n1], edgecount); } - for (std::vector >::const_iterator jt = edges_temp.begin(); jt != edges_temp.end(); ++jt) { - if (edgecount[*jt] == 1) { + for (auto& p : edgecount) { + // @todo should be != 2? + if (p.second == 1 && emitted_edges.find(p.first) == emitted_edges.end()) { // non manifold edge, face boundary - _edges.push_back(jt->first); - _edges.push_back(jt->second); + _edges.push_back(p.first.first); + _edges.push_back(p.first.second); + if (settings().get(IteratorSettings::WELD_VERTICES)) { + // only relevant while welding, because otherwise vertices are not shared among distinct faces + emitted_edges.insert(p.first); + } } } } @@ -526,9 +534,7 @@ int IfcGeom::Representation::Triangulation::addVertex(int item_index, int materi return i; } -void IfcGeom::Representation::Triangulation::addEdge(int n1, int n2, std::map, int>& edgecount, std::vector>& edges_temp) { +void IfcGeom::Representation::Triangulation::addEdge(int n1, int n2, std::map, int>& edgecount) { const Edge e = Edge((std::min)(n1, n2), (std::max)(n1, n2)); - if (edgecount.find(e) == edgecount.end()) edgecount[e] = 1; - else edgecount[e] ++; - edges_temp.push_back(e); + edgecount[e] ++; } diff --git a/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.h b/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.h index 2762e40321..0d7df7d7d1 100644 --- a/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.h +++ b/src/ifcgeom_schema_agnostic/IfcGeomRepresentation.h @@ -176,7 +176,7 @@ namespace IfcGeom { private: /// Welds vertices that belong to different faces int addVertex(int item_index, int material_index, const gp_XYZ& p); - void addEdge(int n1, int n2, std::map, int>& edgecount, std::vector >& edges_temp); + void addEdge(int n1, int n2, std::map, int>& edgecount); Triangulation(); Triangulation(const Triangulation&);