mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
colors from python-occ
This commit is contained in:
parent
411a850d41
commit
42c6601aae
@ -410,7 +410,14 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mesh.GetFaceDescriptor(facenr).SetSurfColour({0.0,1.0,0.0});
|
auto it = OCCGeometry::global_shape_cols.find(face.TShape());
|
||||||
|
if (it != OCCGeometry::global_shape_cols.end())
|
||||||
|
{
|
||||||
|
Vec<3> col = it->second;
|
||||||
|
mesh.GetFaceDescriptor(facenr).SetSurfColour(col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mesh.GetFaceDescriptor(facenr).SetSurfColour({0.0,1.0,0.0});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(geom.fnames.Size()>=facenr)
|
if(geom.fnames.Size()>=facenr)
|
||||||
|
@ -42,6 +42,7 @@ namespace netgen
|
|||||||
{
|
{
|
||||||
|
|
||||||
std::map<Handle(TopoDS_TShape), string> OCCGeometry::global_shape_names;
|
std::map<Handle(TopoDS_TShape), string> OCCGeometry::global_shape_names;
|
||||||
|
std::map<Handle(TopoDS_TShape), Vec<3>> OCCGeometry::global_shape_cols;
|
||||||
|
|
||||||
|
|
||||||
OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape)
|
OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape)
|
||||||
|
@ -210,6 +210,7 @@ namespace netgen
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static std::map<Handle(TopoDS_TShape), string> global_shape_names;
|
static std::map<Handle(TopoDS_TShape), string> global_shape_names;
|
||||||
|
static std::map<Handle(TopoDS_TShape), Vec<3>> global_shape_cols;
|
||||||
|
|
||||||
TopoDS_Shape shape;
|
TopoDS_Shape shape;
|
||||||
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
|
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
|
||||||
|
@ -313,6 +313,18 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
|||||||
OCCGeometry::global_shape_names[e.Current().TShape()] = name;
|
OCCGeometry::global_shape_names[e.Current().TShape()] = name;
|
||||||
return shape;
|
return shape;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.def_property("col", [](const TopoDS_Shape & self) {
|
||||||
|
auto it = OCCGeometry::global_shape_cols.find(self.TShape());
|
||||||
|
Vec<3> col(0.2, 0.2, 0.2);
|
||||||
|
if (it != OCCGeometry::global_shape_cols.end())
|
||||||
|
col = it->second;
|
||||||
|
return std::vector<double> ( { col(0), col(1), col(2) } );
|
||||||
|
}, [](const TopoDS_Shape & self, std::vector<double> c) {
|
||||||
|
Vec<3> col(c[0], c[1], c[2]);
|
||||||
|
OCCGeometry::global_shape_cols[self.TShape()] = col;
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
.def("__add__", [] (const TopoDS_Shape & shape1, const TopoDS_Shape & shape2) {
|
.def("__add__", [] (const TopoDS_Shape & shape1, const TopoDS_Shape & shape2) {
|
||||||
return BRepAlgoAPI_Fuse(shape1, shape2).Shape();
|
return BRepAlgoAPI_Fuse(shape1, shape2).Shape();
|
||||||
@ -355,7 +367,38 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
|||||||
})
|
})
|
||||||
|
|
||||||
.def("__sub__", [] (const TopoDS_Shape & shape1, const TopoDS_Shape & shape2) {
|
.def("__sub__", [] (const TopoDS_Shape & shape1, const TopoDS_Shape & shape2) {
|
||||||
return BRepAlgoAPI_Cut(shape1, shape2).Shape();
|
// return BRepAlgoAPI_Cut(shape1, shape2).Shape();
|
||||||
|
|
||||||
|
BRepAlgoAPI_Cut builder(shape1, shape2);
|
||||||
|
#ifdef OCC_HAVE_HISTORY
|
||||||
|
Handle(BRepTools_History) history = builder.History ();
|
||||||
|
|
||||||
|
for (auto s : { shape1, shape2 })
|
||||||
|
for (TopExp_Explorer e(s, TopAbs_FACE); e.More(); e.Next())
|
||||||
|
{
|
||||||
|
const string & name = OCCGeometry::global_shape_names[e.Current().TShape()];
|
||||||
|
for (auto s : history->Modified(e.Current()))
|
||||||
|
OCCGeometry::global_shape_names[s.TShape()] = name;
|
||||||
|
|
||||||
|
auto it = OCCGeometry::global_shape_cols.find(e.Current().TShape());
|
||||||
|
if (it != OCCGeometry::global_shape_cols.end())
|
||||||
|
for (auto s : history->Modified(e.Current()))
|
||||||
|
OCCGeometry::global_shape_cols[s.TShape()] = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (TopExp_Explorer e(shape2, TopAbs_FACE); e.More(); e.Next())
|
||||||
|
{
|
||||||
|
auto it = OCCGeometry::global_shape_cols[e.Current().TShape()];
|
||||||
|
if (it != OCCGeometry::global_shape_cols.end())
|
||||||
|
for (auto s : history->Modified(e.Current()))
|
||||||
|
OCCGeometry::global_shape_cols[s.TShape()] = it->second;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#endif // OCC_HAVE_HISTORY
|
||||||
|
|
||||||
|
|
||||||
|
return builder.Shape();
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -376,8 +419,12 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
|||||||
{
|
{
|
||||||
BOPAlgo_Builder builder;
|
BOPAlgo_Builder builder;
|
||||||
for (auto & s : shapes)
|
for (auto & s : shapes)
|
||||||
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
|
{
|
||||||
builder.AddArgument(e.Current());
|
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
|
||||||
|
builder.AddArgument(e.Current());
|
||||||
|
if (s.ShapeType() == TopAbs_FACE)
|
||||||
|
builder.AddArgument(s);
|
||||||
|
}
|
||||||
|
|
||||||
builder.Perform();
|
builder.Perform();
|
||||||
|
|
||||||
@ -388,8 +435,7 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
|||||||
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
|
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
|
||||||
{
|
{
|
||||||
auto name = OCCGeometry::global_shape_names[e.Current().TShape()];
|
auto name = OCCGeometry::global_shape_names[e.Current().TShape()];
|
||||||
TopTools_ListOfShape modlist = history->Modified(e.Current());
|
for (auto mods : history->Modified(e.Current()))
|
||||||
for (auto mods : modlist)
|
|
||||||
OCCGeometry::global_shape_names[mods.TShape()] = name;
|
OCCGeometry::global_shape_names[mods.TShape()] = name;
|
||||||
}
|
}
|
||||||
#endif // OCC_HAVE_HISTORY
|
#endif // OCC_HAVE_HISTORY
|
||||||
|
Loading…
Reference in New Issue
Block a user