remove all std::maps<TopoDS_Shape, *> and std::set<TopoDS_Shape>

since hash conflicts may occur this is not safe.
This commit is contained in:
Christopher Lackner 2022-12-06 17:51:19 +01:00
parent 0a8bef493b
commit 0aa20603d9
6 changed files with 200 additions and 156 deletions

View File

@ -402,11 +402,12 @@ namespace netgen
// Philippose - 15/01/2009
double maxh = min2(geom.face_maxh[k-1], OCCGeometry::global_shape_properties[geom.fmap(k)].maxh);
auto& props = OCCGeometry::GetProperties(geom.fmap(k));
double maxh = min2(geom.face_maxh[k-1], props.maxh);
//double maxh = mparam.maxh;
// int noldpoints = mesh->GetNP();
int noldsurfel = mesh.GetNSE();
int layer = OCCGeometry::global_shape_properties[geom.fmap(k)].layer;
int layer = props.layer;
static Timer tsurfprop("surfprop");
tsurfprop.Start();
@ -474,8 +475,9 @@ namespace netgen
int dom = 0;
for (TopExp_Explorer e(geom.GetShape(), TopAbs_SOLID); e.More(); e.Next(), dom++)
{
maxhdom[dom] = min2(maxhdom[dom], OCCGeometry::global_shape_properties[e.Current()].maxh);
maxlayer = max2(maxlayer, OCCGeometry::global_shape_properties[e.Current()].layer);
auto& props = OCCGeometry::GetProperties(e.Current());
maxhdom[dom] = min2(maxhdom[dom], props.maxh);
maxlayer = max2(maxlayer, props.layer);
}
@ -518,7 +520,7 @@ namespace netgen
for (int i = 1; i <= nedges && !multithread.terminate; i++)
{
TopoDS_Edge e = TopoDS::Edge (geom.emap(i));
int layer = OCCGeometry::global_shape_properties[e].layer;
int layer = OCCGeometry::GetProperties(e).layer;
multithread.percent = 100 * (i-1)/double(nedges);
if (BRep_Tool::Degenerated(e)) continue;
@ -564,12 +566,12 @@ namespace netgen
int face_index = geom.fmap.FindIndex(parent_face);
if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]);
localh = min2(localh, OCCGeometry::global_shape_properties[parent_face].maxh);
localh = min2(localh, OCCGeometry::GetProperties(parent_face).maxh);
}
Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1);
localh = min2(localh, OCCGeometry::global_shape_properties[e].maxh);
localh = min2(localh, OCCGeometry::GetProperties(e).maxh);
maxedgelen = max (maxedgelen, len);
minedgelen = min (minedgelen, len);
int maxj = max((int) ceil(len/localh), 2);
@ -592,7 +594,7 @@ namespace netgen
double maxcur = 0;
multithread.percent = 100 * (i-1)/double(nedges);
TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
int layer = OCCGeometry::global_shape_properties[edge].layer;
int layer = OCCGeometry::GetProperties(edge).layer;
if (BRep_Tool::Degenerated(edge)) continue;
double s0, s1;
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
@ -627,7 +629,7 @@ namespace netgen
{
multithread.percent = 100 * (i-1)/double(nfaces);
TopoDS_Face face = TopoDS::Face(geom.fmap(i));
int layer = OCCGeometry::global_shape_properties[face].layer;
int layer = OCCGeometry::GetProperties(face).layer;
TopLoc_Location loc;
Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
@ -693,7 +695,7 @@ namespace netgen
for (int i = 1; i <= nedges && !multithread.terminate; i++)
{
TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
int layer = OCCGeometry::global_shape_properties[edge].layer;
int layer = OCCGeometry::GetProperties(edge).layer;
if (BRep_Tool::Degenerated(edge)) continue;
double s0, s1;

View File

@ -71,8 +71,10 @@ namespace netgen
void LoadOCCInto(OCCGeometry* occgeo, const filesystem::path & filename);
void PrintContents (OCCGeometry * geom);
std::map<TopoDS_Shape, ShapeProperties> OCCGeometry::global_shape_properties;
std::map<TopoDS_Shape, std::vector<OCCIdentification>> OCCGeometry::identifications;
TopTools_IndexedMapOfShape OCCGeometry::global_shape_property_indices;
std::vector<ShapeProperties> OCCGeometry::global_shape_properties;
TopTools_IndexedMapOfShape OCCGeometry::global_identification_indices;
std::vector<std::vector<OCCIdentification>> OCCGeometry::global_identifications;
TopoDS_Shape ListOfShapes::Max(gp_Vec dir)
{
@ -125,13 +127,15 @@ namespace netgen
ListOfShapes ListOfShapes::SubShapes(TopAbs_ShapeEnum type) const
{
std::set<TopoDS_Shape> unique_shapes;
TopTools_MapOfShape check_unique;
ListOfShapes sub;
for(const auto& shape : *this)
for(TopExp_Explorer e(shape, type); e.More(); e.Next())
unique_shapes.insert(e.Current());
ListOfShapes sub;
for(const auto& shape : unique_shapes)
sub.push_back(shape);
if(const auto& s = e.Current(); !check_unique.Contains(s))
{
check_unique.Add(s);
sub.push_back(s);
}
return sub;
}
@ -231,7 +235,7 @@ namespace netgen
{
MeshingParameters local_mp = mparam;
auto face = TopoDS::Face(fmap(nr+1));
if(auto quad_dominated = OCCGeometry::global_shape_properties[face].quad_dominated; quad_dominated.has_value())
if(auto quad_dominated = OCCGeometry::GetProperties(face).quad_dominated; quad_dominated.has_value())
local_mp.quad = *quad_dominated;
bool failed = OCCMeshFace(*this, mesh, glob2loc, local_mp, nr, PARAMETERSPACE, true);
@ -407,9 +411,9 @@ namespace netgen
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
{
if (auto name = OCCGeometry::global_shape_properties[e.Current()].name)
if (auto name = OCCGeometry::GetProperties(e.Current()).name)
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].name = *name;
OCCGeometry::GetProperties(mods).name = *name;
}
#endif // OCC_HAVE_HISTORY
@ -475,7 +479,7 @@ namespace netgen
for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
{
TopoDS_Face face = TopoDS::Face (exp0.Current());
auto props = global_shape_properties[face];
auto props = GetProperties(face);
sff = new ShapeFix_Face (face);
sff->FixAddNaturalBoundMode() = Standard_True;
@ -506,7 +510,7 @@ namespace netgen
// Set the original properties of the face to the newly created
// face (after the healing process)
global_shape_properties[face];
// GetProperties(face);
}
shape = rebuild->Apply(shape);
}
@ -1152,8 +1156,8 @@ namespace netgen
auto occ_vertex = make_unique<OCCVertex>(TopoDS::Vertex(v));
occ_vertex->nr = vertices.Size();
if(global_shape_properties.count(v)>0)
occ_vertex->properties = global_shape_properties[v];
if(HaveProperties(v))
occ_vertex->properties = GetProperties(v);
vertices.Append(std::move(occ_vertex));
}
@ -1163,7 +1167,7 @@ namespace netgen
auto edge = TopoDS::Edge(e);
auto verts = GetVertices(e);
auto occ_edge = make_unique<OCCEdge>(edge, GetVertex(verts[0]), GetVertex(verts[1]) );
occ_edge->properties = global_shape_properties[e];
occ_edge->properties = GetProperties(e);
edges.Append(std::move(occ_edge));
}
@ -1177,8 +1181,8 @@ namespace netgen
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];
if(HaveProperties(f))
occ_face->properties = GetProperties(f);
faces.Append(std::move(occ_face));
if(dimension==2)
@ -1198,8 +1202,8 @@ namespace netgen
auto s = somap(i1);
int k = solids.Size();
auto occ_solid = make_unique<OCCSolid>(s);
if(global_shape_properties.count(s)>0)
occ_solid->properties = global_shape_properties[s];
if(HaveProperties(s))
occ_solid->properties = GetProperties(s);
solids.Append(std::move(occ_solid));
for(auto f : GetFaces(s))
@ -1218,8 +1222,8 @@ namespace netgen
for(auto i1 : Range(1, shape_map.Extent()+1))
{
auto shape = shape_map(i1);
if(identifications.count(shape))
for(auto & ident : identifications[shape])
if(HaveIdentifications(shape))
for(auto & ident : GetIdentifications(shape))
{
if(!shape_map.Contains(ident.from) || !shape_map.Contains(ident.to))
continue;
@ -1624,7 +1628,7 @@ namespace netgen
auto occ_hash = key.HashCode(1<<31UL);
return std::hash<decltype(occ_hash)>()(occ_hash);
};
std::map<TopoDS_Shape, int> shape_map;
TopTools_IndexedMapOfShape shape_map;
Array<TopoDS_Shape> shape_list;
ar & dimension;
@ -1632,25 +1636,25 @@ namespace netgen
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto ds = e.Current();
if(shape_map.count(ds)==0)
if(shape_map.FindIndex(ds) == 0)
{
shape_map[ds] = shape_list.Size();
shape_map.Add(ds);
shape_list.Append(ds);
}
}
for (auto s : shape_list)
{
bool has_properties = global_shape_properties.count(s);
bool has_properties = HaveProperties(s);
ar & has_properties;
if(has_properties)
ar & global_shape_properties[s];
ar & GetProperties(s);
bool has_identifications = identifications.count(s);
bool has_identifications = HaveIdentifications(s);
ar & has_identifications;
if(has_identifications)
{
auto & idents = identifications[s];
auto & idents = GetIdentifications(s);
auto n_idents = idents.size();
ar & n_idents;
idents.resize(n_idents);
@ -1660,8 +1664,8 @@ namespace netgen
int id_from, id_to;
if(ar.Output())
{
id_from = shape_map[id.from];
id_to = shape_map[id.to];
id_from = shape_map.FindIndex(id.from)-1;
id_to = shape_map.FindIndex(id.to)-1;
}
ar & id_from & id_to & id.trafo & id.name;
if(ar.Input())
@ -1989,7 +1993,8 @@ namespace netgen
if(tree.GetTolerance() < Dist(trafo(c_me), c_you))
return false;
std::map<TopoDS_Shape, optional<TopoDS_Shape>> vmap;
TopTools_IndexedMapOfShape vmap;
std::vector<optional<TopoDS_Shape>> verts;
auto verts_me = GetVertices(me);
auto verts_you = GetVertices(you);
@ -2000,11 +2005,12 @@ namespace netgen
for (auto i : Range(verts_me.size()))
{
auto s = verts_me[i];
if(vmap.count(s)>0)
if(vmap.FindIndex(s) > 0)
continue;
auto p = trafo(occ2ng(s));
tree.Insert( p, i );
vmap[s] = nullopt;
vmap.Add(s);
verts.push_back(nullopt);
}
for (auto vert : verts_you)
@ -2013,7 +2019,8 @@ namespace netgen
auto p = occ2ng(s);
bool vert_mapped = false;
tree.GetFirstIntersecting( p, p, [&](size_t i ) {
vmap[verts_me[i]] = s;
vmap.Add(verts_me[i]);
verts[vmap.FindIndex(verts_me[i])-1] = s;
vert_mapped = true;
return true;
});
@ -2069,7 +2076,7 @@ namespace netgen
if(!IsMappedShape(trafo, shape_me, shape_you))
continue;
OCCGeometry::identifications[shape_me].push_back
OCCGeometry::GetIdentifications(shape_me).push_back
(OCCIdentification { shape_me, shape_you, trafo, name, type });
}
}
@ -2132,7 +2139,7 @@ namespace netgen
XCAFPrs_Style aStyle;
set.FindFromKey(e.Current(), aStyle);
auto & prop = OCCGeometry::global_shape_properties[e.Current()];
auto & prop = OCCGeometry::GetProperties(e.Current());
if(aStyle.IsSetColorSurf())
prop.col = step_utils::ReadColor(aStyle.GetColorSurfRGBA());
}
@ -2152,7 +2159,7 @@ namespace netgen
if (!transProc->IsBound(item))
continue;
OCCGeometry::global_shape_properties[shape].name = name;
OCCGeometry::GetProperties(shape).name = name;
}
@ -2176,7 +2183,7 @@ namespace netgen
if(name != "netgen_geometry_properties")
continue;
auto & prop = OCCGeometry::global_shape_properties[shape];
auto & prop = OCCGeometry::GetProperties(shape);
auto nprops = item->NbItemElement();
@ -2202,7 +2209,7 @@ namespace netgen
Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity(finder, shape);
if(!item)
return;
auto prop = OCCGeometry::global_shape_properties[shape];
auto prop = OCCGeometry::GetProperties(shape);
if(auto n = prop.name)
item->SetName(MakeName(*n));
@ -2231,7 +2238,9 @@ namespace netgen
void WriteIdentifications(const Handle(Interface_InterfaceModel) model, const TopoDS_Shape & shape, const Handle(Transfer_FinderProcess) finder)
{
Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity(finder, shape);
auto & identifications = OCCGeometry::identifications[shape];
if(!OCCGeometry::HaveIdentifications(shape))
return;
auto & identifications = OCCGeometry::GetIdentifications(shape);
if(identifications.size()==0)
return;
auto n = identifications.size();
@ -2282,7 +2291,7 @@ namespace netgen
result.push_back(ident);
}
OCCGeometry::identifications[shape_origin] = result;
OCCGeometry::GetIdentifications(shape_origin) = result;
}
void WriteSTEP(const TopoDS_Shape & shape, const filesystem::path & filename)
@ -2306,7 +2315,7 @@ namespace netgen
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE })
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
if(auto col = prop.col)
colortool->SetColor(e.Current(), step_utils::MakeColor(*col), XCAFDoc_ColorGen);
}

View File

@ -31,20 +31,6 @@
#define OCC_HAVE_HISTORY
#endif
namespace std
{
template<>
struct less<TopoDS_Shape>
{
bool operator() (const TopoDS_Shape& s1, const TopoDS_Shape& s2) const
{
return s1.HashCode(std::numeric_limits<Standard_Integer>::max()) <
s2.HashCode(std::numeric_limits<Standard_Integer>::max());
}
};
}
namespace netgen
{
@ -149,8 +135,38 @@ namespace netgen
Point<3> center;
OCCParameters occparam;
public:
static std::map<TopoDS_Shape, ShapeProperties> global_shape_properties;
static std::map<TopoDS_Shape, std::vector<OCCIdentification>> identifications;
static TopTools_IndexedMapOfShape global_shape_property_indices;
static std::vector<ShapeProperties> global_shape_properties;
static TopTools_IndexedMapOfShape global_identification_indices;
static std::vector<std::vector<OCCIdentification>> global_identifications;
static ShapeProperties& GetProperties(const TopoDS_Shape& shape)
{
auto index = OCCGeometry::global_shape_property_indices.FindIndex(shape);
if(index > 0)
return OCCGeometry::global_shape_properties
[index-1];
OCCGeometry::global_shape_property_indices.Add(shape);
OCCGeometry::global_shape_properties.push_back({});
return OCCGeometry::global_shape_properties.back();
}
static bool HaveProperties(const TopoDS_Shape& shape)
{
return OCCGeometry::global_shape_property_indices.FindIndex(shape) > 1;
}
static std::vector<OCCIdentification>& GetIdentifications(const TopoDS_Shape& shape)
{
auto index = OCCGeometry::global_identification_indices.FindIndex(shape);
if(index > 0)
return OCCGeometry::global_identifications[index-1];
OCCGeometry::global_identification_indices.Add(shape);
OCCGeometry::global_identifications.push_back({});
return OCCGeometry::global_identifications.back();
}
static bool HaveIdentifications(const TopoDS_Shape& shape)
{
return OCCGeometry::global_identification_indices.FindIndex(shape) > 1;
}
TopoDS_Shape shape;
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
@ -422,8 +438,10 @@ namespace netgen
template <class TBuilder>
void PropagateIdentifications (TBuilder & builder, TopoDS_Shape shape, std::optional<Transformation<3>> trafo = nullopt)
{
std::map<TopoDS_Shape, std::set<TopoDS_Shape>> mod_map;
std::map<TopoDS_Shape, bool> shape_handled;
TopTools_IndexedMapOfShape mod_indices;
std::vector<TopTools_IndexedMapOfShape> modifications;
TopTools_MapOfShape shape_handled;
Transformation<3> trafo_inv;
if(trafo)
trafo_inv = trafo->CalcInverse();
@ -432,8 +450,9 @@ namespace netgen
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto s = e.Current();
mod_map[s].insert(s);
shape_handled[s] = false;
mod_indices.Add(s);
modifications.push_back({});
modifications.back().Add(s);
}
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX })
@ -441,7 +460,10 @@ namespace netgen
{
auto s = e.Current();
for (auto mods : builder.Modified(s))
mod_map[s].insert(mods);
{
auto index = mod_indices.FindIndex(s)-1;
modifications[index].Add(mods);
}
}
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX })
@ -449,27 +471,32 @@ namespace netgen
{
auto s = e.Current();
if(shape_handled[s])
if(shape_handled.Contains(s))
continue;
shape_handled[s] = true;
shape_handled.Add(s);
if(OCCGeometry::identifications.count(s)==0)
if(!OCCGeometry::HaveIdentifications(s))
continue;
auto& identifications = OCCGeometry::GetIdentifications(s);
auto shape_mapped = mod_map[s];
auto& shape_mapped = modifications[mod_indices.FindIndex(s)-1];
for(auto ident : OCCGeometry::identifications[s])
for(auto ident : identifications)
{
// nothing happened
if(mod_map[ident.to].size()==1 && mod_map[ident.from].size() ==1)
auto& mods_to = modifications[mod_indices.FindIndex(ident.to)-1];
auto& mods_from = modifications[mod_indices.FindIndex(ident.from)-1];
if(mods_to.Extent()==1 && mods_from.Extent() ==1)
continue;
auto from = ident.from;
auto to = ident.to;
for(auto from_mapped : mod_map[from])
for(auto to_mapped : mod_map[to])
for(auto it = mods_from.cbegin(); it != mods_from.cend(); it++)
for(auto it2 = mods_to.cbegin(); it2 != mods_to.cend(); it2++)
{
auto& from_mapped = it.Iterator().Value();
auto& to_mapped = it2.Iterator().Value();
if(from.IsSame(from_mapped) && to.IsSame(to_mapped))
continue;
@ -489,7 +516,7 @@ namespace netgen
id_new.from = from_mapped;
id_new.trafo = trafo_mapped;
auto id_owner = from.IsSame(s) ? from_mapped : to_mapped;
OCCGeometry::identifications[id_owner].push_back(id_new);
OCCGeometry::GetIdentifications(id_owner).push_back(id_new);
}
}
}
@ -504,10 +531,12 @@ namespace netgen
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto s = e.Current();
auto & prop = OCCGeometry::global_shape_properties[s];
have_identifications |= OCCGeometry::HaveIdentifications(s);
if(!OCCGeometry::HaveProperties(s))
continue;
auto & prop = OCCGeometry::GetProperties(s);
for (auto mods : builder.Modified(s))
OCCGeometry::global_shape_properties[mods].Merge(prop);
have_identifications |= OCCGeometry::identifications.count(s) > 0;
OCCGeometry::GetProperties(mods).Merge(prop);
}
if(have_identifications)
PropagateIdentifications(builder, shape, trafo);

View File

@ -118,11 +118,11 @@ DLL_HEADER void ExportNgOCC(py::module &m)
for (auto & s : shapes)
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
if (auto name = OCCGeometry::global_shape_properties[e.Current()].name)
if (auto name = OCCGeometry::GetProperties(e.Current()).name)
{
TopTools_ListOfShape modlist = history->Modified(e.Current());
for (auto mods : modlist)
OCCGeometry::global_shape_properties[mods].name = *name;
OCCGeometry::GetProperties(mods).name = *name;
}
#endif // OCC_HAVE_HISTORY

View File

@ -304,7 +304,7 @@ public:
// auto edge = BRepBuilderAPI_MakeEdge(curve).Edge();
if (name)
OCCGeometry::global_shape_properties[edge].name = name;
OCCGeometry::GetProperties(edge).name = name;
wire_builder.Add(edge);
if (closing) Finish();
@ -591,7 +591,7 @@ public:
auto NameVertex (string name)
{
if (!lastvertex.IsNull())
OCCGeometry::global_shape_properties[lastvertex].name = name;
OCCGeometry::GetProperties(lastvertex).name = name;
return shared_from_this();
}
@ -814,37 +814,37 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def("bc", [](const TopoDS_Shape & shape, const string & name)
{
for (TopExp_Explorer e(shape, TopAbs_FACE); e.More(); e.Next())
OCCGeometry::global_shape_properties[e.Current()].name = name;
OCCGeometry::GetProperties(e.Current()).name = name;
return shape;
}, py::arg("name"), "sets 'name' property for all faces of shape")
.def("mat", [](const TopoDS_Shape & shape, const string & name)
{
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
OCCGeometry::global_shape_properties[e.Current()].name = name;
OCCGeometry::GetProperties(e.Current()).name = name;
return shape;
}, py::arg("name"), "sets 'name' property to all solids of shape")
.def_property("name", [](const TopoDS_Shape & self) -> optional<string> {
if (auto name = OCCGeometry::global_shape_properties[self].name)
if (auto name = OCCGeometry::GetProperties(self).name)
return *name;
else
return nullopt;
}, [](const TopoDS_Shape & self, optional<string> name) {
OCCGeometry::global_shape_properties[self].name = name;
OCCGeometry::GetProperties(self).name = name;
}, "'name' of shape")
.def_property("maxh",
[](const TopoDS_Shape& self)
{
return OCCGeometry::global_shape_properties[self].maxh;
return OCCGeometry::GetProperties(self).maxh;
},
[](TopoDS_Shape& self, double val)
{
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX })
for (TopExp_Explorer e(self, typ); e.More(); e.Next())
{
auto & maxh = OCCGeometry::global_shape_properties[e.Current()].maxh;
auto & maxh = OCCGeometry::GetProperties(e.Current()).maxh;
maxh = min2(val, maxh);
}
}, "maximal mesh-size for shape")
@ -852,25 +852,24 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def_property("hpref",
[](const TopoDS_Shape& self)
{
return OCCGeometry::global_shape_properties[self].hpref;
return OCCGeometry::GetProperties(self).hpref;
},
[](TopoDS_Shape& self, double val)
{
auto & hpref = OCCGeometry::global_shape_properties[self].hpref;
auto & hpref = OCCGeometry::GetProperties(self).hpref;
hpref = max2(val, hpref);
}, "number of refinement levels for geometric refinement")
.def_property("col", [](const TopoDS_Shape & self) {
auto it = OCCGeometry::global_shape_properties.find(self);
Vec<4> col(0.2, 0.2, 0.2);
if (it != OCCGeometry::global_shape_properties.end() && it->second.col)
col = *it->second.col;
return std::vector<double> ( { col(0), col(1), col(2) } );
if(!OCCGeometry::HaveProperties(self) || !OCCGeometry::GetProperties(self).col)
return std::vector<double>({ 0.2, 0.2, 0.2, 1. });
auto col = *OCCGeometry::GetProperties(self).col;
return std::vector<double>({ col(0), col(1), col(2), col(3) });
}, [](const TopoDS_Shape & self, std::vector<double> c) {
Vec<4> col(c[0], c[1], c[2], 1.0);
if(c.size() == 4)
col[3] = c[3];
OCCGeometry::global_shape_properties[self].col = col;
OCCGeometry::GetProperties(self).col = col;
}, "color of shape as RGB - tuple")
.def("UnifySameDomain", [](const TopoDS_Shape& shape,
bool edges, bool faces,
@ -883,9 +882,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE })
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
return unify.Shape();
}, py::arg("unifyEdges")=true, py::arg("unifyFaces")=true,
@ -911,9 +910,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto & s : { shape1, shape2 })
for (TopExp_Explorer e(s, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
#endif
*/
@ -937,9 +936,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE })
for (TopExp_Explorer e(fused, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
// #endif
// PropagateProperties (unify, fused);
@ -963,9 +962,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto & s : { shape1, shape2 })
for (TopExp_Explorer e(s, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
#endif // OCC_HAVE_HISTORY
*/
@ -986,9 +985,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto & s : { shape1, shape2 })
for (TopExp_Explorer e(s, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
#endif // OCC_HAVE_HISTORY
*/
@ -1027,9 +1026,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX })
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : builder.Generated(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
return builder.Shape();
@ -1050,9 +1049,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto typ : { TopAbs_EDGE, TopAbs_VERTEX })
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : builder.Generated(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
return builder.Shape();
@ -1068,7 +1067,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
PropagateProperties (mkFillet, shape);
for (auto e : edges)
for (auto gen : mkFillet.Generated(e))
OCCGeometry::global_shape_properties[gen].name = "fillet";
OCCGeometry::GetProperties(gen).name = "fillet";
return mkFillet.Shape();
}, py::arg("edges"), py::arg("r"), "make fillets for edges 'edges' of radius 'r'")
@ -1081,7 +1080,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
PropagateProperties (mkChamfer, shape);
for (auto e : edges)
for (auto gen : mkChamfer.Generated(e))
OCCGeometry::global_shape_properties[gen].name = "chamfer";
OCCGeometry::GetProperties(gen).name = "chamfer";
return mkChamfer.Shape();
#else
throw Exception("MakeChamfer not available for occ-version < 7.4");
@ -1189,7 +1188,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
// Handle(TopoDS_Face) face = e.Current();
fmap.Add(face);
ExtractFaceData(face, index, p, n, box);
auto & props = OCCGeometry::global_shape_properties[face];
auto & props = OCCGeometry::GetProperties(face);
if(props.col)
{
auto & c = *props.col;
@ -1212,7 +1211,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for(auto& face : GetFaces(solid))
faces.push_back(fmap.FindIndex(face)-1);
solid_face_map.push_back(move(faces));
auto& props = OCCGeometry::global_shape_properties[solid];
auto& props = OCCGeometry::GetProperties(solid);
if(props.name)
solid_names.append(*props.name);
else
@ -1226,7 +1225,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
{
TopoDS_Edge edge = TopoDS::Edge(e.Current());
ExtractEdgeData(edge, index, edge_p, box);
auto & props = OCCGeometry::global_shape_properties[edge];
auto & props = OCCGeometry::GetProperties(edge);
if(props.col)
{
auto & c = *props.col;
@ -1454,11 +1453,11 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
}))
.def_property("quad_dominated", [](const TopoDS_Face& self) -> optional<bool>
{
return OCCGeometry::global_shape_properties[self].quad_dominated;
return OCCGeometry::GetProperties(self).quad_dominated;
},
[](TopoDS_Face& self, optional<bool> quad_dominated)
{
OCCGeometry::global_shape_properties[self].quad_dominated = quad_dominated;
OCCGeometry::GetProperties(self).quad_dominated = quad_dominated;
})
.def_property_readonly("surf", [] (TopoDS_Face face) -> Handle(Geom_Surface)
{
@ -1507,15 +1506,14 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
builder.Add(comp, shapes[i]);
if(separate_layers)
{
auto & props = OCCGeometry::global_shape_properties;
for(auto & s : GetSolids(shapes[i]))
props[s].layer = i+1;
OCCGeometry::GetProperties(s).layer = i+1;
for(auto & s : GetFaces(shapes[i]))
props[s].layer = i+1;
OCCGeometry::GetProperties(s).layer = i+1;
for(auto & s : GetEdges(shapes[i]))
props[s].layer = i+1;
OCCGeometry::GetProperties(s).layer = i+1;
for(auto & s : GetVertices(shapes[i]))
props[s].layer = i+1;
OCCGeometry::GetProperties(s).layer = i+1;
}
}
@ -1597,7 +1595,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
ListOfShapes selected;
std::regex pattern(name);
for (auto s : self)
if (auto sname = OCCGeometry::global_shape_properties[s].name)
if (auto sname = OCCGeometry::GetProperties(s).name)
if (std::regex_match(*sname, pattern))
selected.push_back(s);
return selected;
@ -1620,9 +1618,13 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def("Sorted",[](ListOfShapes self, gp_Vec dir)
{
std::map<TopoDS_Shape, double> sortval;
TopTools_IndexedMapOfShape indices;
std::vector<double> sortval;
for (auto shape : self)
{
if(indices.FindIndex(shape) > 0)
continue;
GProp_GProps props;
gp_Pnt center;
@ -1640,12 +1642,14 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
}
double val = center.X()*dir.X() + center.Y()*dir.Y() + center.Z() * dir.Z();
sortval[shape] = val;
indices.Add(shape);
sortval.push_back(val);
}
std::sort (std::begin(self), std::end(self),
[&](const TopoDS_Shape& a, const TopoDS_Shape& b)
{ return sortval[a] < sortval[b]; });
{ return sortval[indices.FindIndex(a)-1] <
sortval[indices.FindIndex(b)-1]; });
return self;
}, py::arg("dir"), "returns list of shapes, where center of gravity is sorted in direction of 'dir'")
@ -1672,7 +1676,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
{
for(auto& shape : shapes)
{
OCCGeometry::global_shape_properties[shape].name = name;
OCCGeometry::GetProperties(shape).name = name;
}
}, "set name for all elements of list")
.def_property("col", [](ListOfShapes& shapes) {
@ -1682,7 +1686,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
if(c.size() == 4)
col[3] = c[3];
for(auto& shape : shapes)
OCCGeometry::global_shape_properties[shape].col = col;
OCCGeometry::GetProperties(shape).col = col;
}, "set col for all elements of list")
.def_property("maxh", [](ListOfShapes& shapes)
@ -1694,13 +1698,13 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for(auto& shape : shapes)
{
for(auto& s : GetSolids(shape))
OCCGeometry::global_shape_properties[s].maxh = maxh;
OCCGeometry::GetProperties(s).maxh = maxh;
for(auto& s : GetFaces(shape))
OCCGeometry::global_shape_properties[s].maxh = maxh;
OCCGeometry::GetProperties(s).maxh = maxh;
for(auto& s : GetEdges(shape))
OCCGeometry::global_shape_properties[s].maxh = maxh;
OCCGeometry::GetProperties(s).maxh = maxh;
for(auto& s : GetVertices(shape))
OCCGeometry::global_shape_properties[s].maxh = maxh;
OCCGeometry::GetProperties(s).maxh = maxh;
}
}, "set maxh for all elements of list")
.def_property("hpref", [](ListOfShapes& shapes)
@ -1711,7 +1715,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
{
for(auto& shape : shapes)
{
auto& val = OCCGeometry::global_shape_properties[shape].hpref;
auto& val = OCCGeometry::GetProperties(shape).hpref;
val = max2(hpref, val);
}
}, "set hpref for all elements of list")
@ -1722,7 +1726,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
[](ListOfShapes& shapes, optional<bool> quad_dominated)
{
for(auto& shape : shapes)
OCCGeometry::global_shape_properties[shape].quad_dominated = quad_dominated;
OCCGeometry::GetProperties(shape).quad_dominated = quad_dominated;
})
.def("Identify", [](const ListOfShapes& me,
@ -1820,7 +1824,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
optional<string> bot, optional<string> top, optional<string> mantle) {
auto builder = BRepPrimAPI_MakeCylinder (gp_Ax2(cpnt, cdir), r, h);
if(mantle)
OCCGeometry::global_shape_properties[builder.Face()].name = *mantle;
OCCGeometry::GetProperties(builder.Face()).name = *mantle;
auto pyshape = py::cast(builder.Solid());
gp_Vec v = cdir;
if(bot)
@ -2073,9 +2077,9 @@ tangents : Dict[int, gp_Vec2d]
for (auto & s : shapes)
for (TopExp_Explorer e(s, typ); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
#endif // OCC_HAVE_HISTORY
*/
@ -2104,9 +2108,9 @@ tangents : Dict[int, gp_Vec2d]
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
{
auto prop = OCCGeometry::global_shape_properties[e.Current()];
auto prop = OCCGeometry::GetProperties(e.Current());
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods].Merge(prop);
OCCGeometry::GetProperties(mods).Merge(prop);
}
#endif // OCC_HAVE_HISTORY
*/

View File

@ -548,7 +548,7 @@ namespace netgen
if (!occgeometry->fvispar[i-1].IsHighlighted())
{
auto c = OCCGeometry::global_shape_properties[face].col.value_or(Vec<4>(0,1,0,1) );
auto c = OCCGeometry::GetProperties(face).col.value_or(Vec<4>(0,1,0,1) );
for(auto j : Range(4))
mat_col[j] = c[j];
}