From 22d314a1ecf9783453e39f1ca1cd4d215d0122ed Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 15 Nov 2022 12:58:36 +0100 Subject: [PATCH] Don't use std::map (hash value is not unique) --- libsrc/meshing/basegeom.cpp | 5 -- libsrc/meshing/basegeom.hpp | 6 +- libsrc/occ/occ_face.cpp | 6 +- libsrc/occ/occgenmesh.cpp | 2 +- libsrc/occ/occgeom.cpp | 131 ++++++++++++++++++++---------------- libsrc/occ/occgeom.hpp | 34 ++++++++-- 6 files changed, 106 insertions(+), 78 deletions(-) diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index 367d4ec8..7926f938 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -230,11 +230,6 @@ namespace netgen void NetgenGeometry :: Clear() { - vertex_map.clear(); - edge_map.clear(); - face_map.clear(); - solid_map.clear(); - vertices.SetSize0(); edges.SetSize0(); faces.SetSize0(); diff --git a/libsrc/meshing/basegeom.hpp b/libsrc/meshing/basegeom.hpp index 272f8374..e1d56e43 100644 --- a/libsrc/meshing/basegeom.hpp +++ b/libsrc/meshing/basegeom.hpp @@ -188,10 +188,6 @@ namespace netgen Box<3> bounding_box; int dimension = 3; - std::map vertex_map; - std::map edge_map; - std::map face_map; - std::map solid_map; public: NetgenGeometry() @@ -208,7 +204,7 @@ namespace netgen const GeometryEdge & GetEdge(int i) const { return *edges[i]; } const GeometryVertex & GetVertex(int i) const { return *vertices[i]; } - virtual Array GetFaceVertices(const GeometryFace& face) const { return Array{}; } + virtual Array GetFaceVertices(const GeometryFace& face) const { return Array{}; } void Clear(); diff --git a/libsrc/occ/occ_face.cpp b/libsrc/occ/occ_face.cpp index 7a04c623..65d5d897 100644 --- a/libsrc/occ/occ_face.cpp +++ b/libsrc/occ/occ_face.cpp @@ -38,7 +38,7 @@ namespace netgen { auto & geom = dynamic_cast(*mesh.GetGeometry()); - auto n_edges = geom.edge_map.size(); + auto n_edges = geom.GetNEdges(); constexpr int UNUSED = 0; constexpr int FORWARD = 1; constexpr int REVERSED = 2; @@ -58,9 +58,7 @@ namespace netgen for(auto edge_ : GetEdges(face)) { auto edge = TopoDS::Edge(edge_); - if(geom.edge_map.count(edge)==0) - continue; - auto edgenr = geom.edge_map[edge]; + auto edgenr = geom.GetEdge(edge).nr; auto & orientation = edge_orientation[edgenr]; double s0, s1; auto cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1); diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 5fb12985..89db71dd 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -534,7 +534,7 @@ namespace netgen bool is_identified_edge = false; // TODO: change to use hash value - const auto& gedge = geom.GetEdge(geom.edge_map.at(e)); + const auto& gedge = geom.GetEdge(e); auto& v0 = gedge.GetStartVertex(); auto& v1 = gedge.GetEndVertex(); for(auto & ident : v0.identifications) diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 5416e6a3..0ad29755 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -156,6 +156,37 @@ namespace netgen } } + const GeometryShape & OCCGeometry :: GetShape(const TopoDS_Shape & shape) const + { + switch (shape.ShapeType()) + { + case TopAbs_VERTEX: + return GetVertex(shape); + case TopAbs_EDGE: + return GetEdge(shape); + case TopAbs_FACE: + return GetFace(shape); + default: + throw Exception("unknown shape type"); + } + } + + const GeometryVertex & OCCGeometry :: GetVertex(const TopoDS_Shape & shape) const + { + return *vertices[vmap.FindIndex(shape)-1]; + } + + const GeometryEdge & OCCGeometry :: GetEdge(const TopoDS_Shape & shape) const + { + return *edges[emap.FindIndex(shape)-1]; + } + + const GeometryFace & OCCGeometry :: GetFace(const TopoDS_Shape & shape) const + { + return *faces[fmap.FindIndex(shape)-1]; + } + + string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader) { const Handle(XSControl_WorkSession)& theSession = aReader->Reader().WS(); @@ -1113,20 +1144,13 @@ namespace netgen fsingular = esingular = vsingular = false; NetgenGeometry::Clear(); - edge_map.clear(); - vertex_map.clear(); - face_map.clear(); - solid_map.clear(); // Add shapes for(auto i1 : Range(1, vmap.Extent()+1)) { auto v = vmap(i1); - if(vertex_map.count(v)!=0) - continue; auto occ_vertex = make_unique(TopoDS::Vertex(v)); occ_vertex->nr = vertices.Size(); - vertex_map[v] = occ_vertex->nr; if(global_shape_properties.count(v)>0) occ_vertex->properties = global_shape_properties[v]; @@ -1137,11 +1161,8 @@ namespace netgen { auto e = emap(i1); auto edge = TopoDS::Edge(e); - if(edge_map.count(e)!=0) - continue; - edge_map[e] = edges.Size(); auto verts = GetVertices(e); - auto occ_edge = make_unique(edge, *vertices[vertex_map[verts[0]]], *vertices[vertex_map[verts[1]]] ); + auto occ_edge = make_unique(edge, GetVertex(verts[0]), GetVertex(verts[1]) ); occ_edge->properties = global_shape_properties[e]; edges.Append(std::move(occ_edge)); } @@ -1149,81 +1170,73 @@ namespace netgen for(auto i1 : Range(1, fmap.Extent()+1)) { auto f = fmap(i1); - if(face_map.count(f)==0) - { - auto k = faces.Size(); - face_map[f] = k; - auto occ_face = make_unique(f); + auto k = faces.Size(); + auto occ_face = make_unique(f); + for(auto e : GetEdges(f)) + occ_face->edges.Append( &GetEdge(e) ); + + if(global_shape_properties.count(f)>0) + occ_face->properties = global_shape_properties[f]; + faces.Append(std::move(occ_face)); + + if(dimension==2) for(auto e : GetEdges(f)) - occ_face->edges.Append( edges[edge_map[e]].get() ); - - if(global_shape_properties.count(f)>0) - occ_face->properties = global_shape_properties[f]; - faces.Append(std::move(occ_face)); - - if(dimension==2) - for(auto e : GetEdges(f)) - { - auto & edge = *edges[edge_map[e]]; - if(e.Orientation() == TopAbs_REVERSED) - edge.domout = k; - else - edge.domin = k; - } - } + { + auto & edge = GetEdge(e); + if(e.Orientation() == TopAbs_REVERSED) + edge.domout = k; + else + edge.domin = k; + } } for(auto i1 : Range(1, somap.Extent()+1)) { auto s = somap(i1); - int k; - if(solid_map.count(s)==0) - { - k = solids.Size(); - solid_map[s] = k; - auto occ_solid = make_unique(s); - if(global_shape_properties.count(s)>0) - occ_solid->properties = global_shape_properties[s]; - solids.Append(std::move(occ_solid)); - } + int k = solids.Size(); + auto occ_solid = make_unique(s); + if(global_shape_properties.count(s)>0) + occ_solid->properties = global_shape_properties[s]; + solids.Append(std::move(occ_solid)); for(auto f : GetFaces(s)) { - auto face_nr = face_map[f]; - auto & face = faces[face_nr]; - if(face->domin==-1) - face->domin = k; + auto & face = GetFace(f); + if(face.domin==-1) + face.domin = k; else - face->domout = k; + face.domout = k; } } // Add identifications auto add_identifications = [&](auto & shapes, auto & shape_map) { - for(auto &[shape, nr] : shape_map) + for(auto i1 : Range(1, shape_map.Extent()+1)) + { + auto shape = shape_map(i1); if(identifications.count(shape)) for(auto & ident : identifications[shape]) { - if(shape_map.count(ident.from)==0 || shape_map.count(ident.to)==0) + if(!shape_map.Contains(ident.from) || !shape_map.Contains(ident.to)) continue; - ShapeIdentification si{ - shapes[shape_map[ident.from]].get(), - shapes[shape_map[ident.to]].get(), + &GetShape(ident.from), + &GetShape(ident.to), ident.trafo, ident.type, ident.name }; - shapes[nr]->identifications.Append(si); + shapes[i1-1]->identifications.Append(si); } + } }; - add_identifications( vertices, vertex_map ); - add_identifications( edges, edge_map ); - add_identifications( faces, face_map ); + add_identifications( vertices, vmap ); + add_identifications( edges, emap ); + add_identifications( faces, fmap ); bounding_box = ::netgen::GetBoundingBox( shape ); ProcessIdentifications(); @@ -1312,12 +1325,12 @@ namespace netgen } - Array OCCGeometry :: GetFaceVertices(const GeometryFace& face) const + Array OCCGeometry :: GetFaceVertices(const GeometryFace& face) const { - Array verts; + Array verts; const auto& occface = dynamic_cast(face); for(auto& vert : GetVertices(occface.Shape())) - verts.Append(vertices[vertex_map.at(vert)].get()); + verts.Append(&GetVertex(vert)); return move(verts); } diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 33db9082..4000f9e1 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -153,12 +153,10 @@ namespace netgen static std::map> identifications; TopoDS_Shape shape; - TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; // legacy maps + TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; NgArray fsingular, esingular, vsingular; Box<3> boundingbox; - std::map solid_map, face_map, edge_map, vertex_map; - mutable int changed; mutable NgArray facemeshstatus; @@ -211,6 +209,34 @@ namespace netgen void SetOCCParameters(const OCCParameters& par) { occparam = par; } + using NetgenGeometry::GetVertex; + using NetgenGeometry::GetEdge; + using NetgenGeometry::GetFace; + + GeometryShape & GetShape(const TopoDS_Shape & shape) + { + return const_cast(as_const(*this).GetShape(shape)); + } + GeometryVertex & GetVertex(const TopoDS_Shape & shape) + { + return const_cast(as_const(*this).GetVertex(shape)); + } + + GeometryEdge & GetEdge(const TopoDS_Shape & shape) + { + return const_cast(as_const(*this).GetEdge(shape)); + } + + GeometryFace & GetFace(const TopoDS_Shape & shape) + { + return const_cast(as_const(*this).GetFace(shape)); + } + + const GeometryShape & GetShape(const TopoDS_Shape & shape) const; + const GeometryVertex & GetVertex(const TopoDS_Shape & shape) const; + const GeometryEdge & GetEdge(const TopoDS_Shape & shape) const; + const GeometryFace & GetFace(const TopoDS_Shape & shape) const; + void Analyse(Mesh& mesh, const MeshingParameters& mparam) const override; bool MeshFace(Mesh& mesh, const MeshingParameters& mparam, @@ -267,7 +293,7 @@ namespace netgen void MakeSolid(); - Array GetFaceVertices(const GeometryFace& face) const override; + Array GetFaceVertices(const GeometryFace& face) const override; void HealGeometry(); void GlueGeometry();