mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
colors from python-occ
This commit is contained in:
parent
411a850d41
commit
42c6601aae
@ -410,6 +410,13 @@ namespace netgen
|
||||
}
|
||||
else
|
||||
{
|
||||
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});
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ namespace netgen
|
||||
{
|
||||
|
||||
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)
|
||||
|
@ -210,6 +210,7 @@ namespace netgen
|
||||
|
||||
public:
|
||||
static std::map<Handle(TopoDS_TShape), string> global_shape_names;
|
||||
static std::map<Handle(TopoDS_TShape), Vec<3>> global_shape_cols;
|
||||
|
||||
TopoDS_Shape shape;
|
||||
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
|
||||
|
@ -314,6 +314,18 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
for (auto & s : shapes)
|
||||
{
|
||||
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();
|
||||
|
||||
@ -388,8 +435,7 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
||||
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
|
||||
{
|
||||
auto name = OCCGeometry::global_shape_names[e.Current().TShape()];
|
||||
TopTools_ListOfShape modlist = history->Modified(e.Current());
|
||||
for (auto mods : modlist)
|
||||
for (auto mods : history->Modified(e.Current()))
|
||||
OCCGeometry::global_shape_names[mods.TShape()] = name;
|
||||
}
|
||||
#endif // OCC_HAVE_HISTORY
|
||||
|
Loading…
Reference in New Issue
Block a user