6 #include "GmshConfig.h"
17 #include <BRepBndLib.hxx>
18 #include <BRepClass3d_SolidClassifier.hxx>
19 #include <BRepTools.hxx>
20 #include <BRep_Builder.hxx>
21 #include <Bnd_Box.hxx>
22 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Compound.hxx>
26 OCCRegion::OCCRegion(
GModel *m, TopoDS_Solid s,
int num)
34 void OCCRegion::_setup()
37 TopExp_Explorer exp2, exp3;
38 for(exp2.Init(_s, TopAbs_SHELL); exp2.More(); exp2.Next()) {
39 const TopoDS_Shape &shell = exp2.Current();
40 Msg::Debug(
"OCC volume %d - new shell", tag());
41 for(exp3.Init(shell, TopAbs_FACE); exp3.More(); exp3.Next()) {
42 TopoDS_Face face = TopoDS::Face(exp3.Current());
44 if(model()->getOCCInternals())
45 f = model()->getOCCInternals()->getFaceForOCCShape(model(), face);
46 if(!
f) {
Msg::Error(
"Unknown surface in volume %d", tag()); }
47 else if(face.Orientation() == TopAbs_INTERNAL &&
49 Msg::Debug(
"Adding embedded surface %d in volume %d",
f->tag(), tag());
50 embedded_faces.push_back(
f);
57 if(face.Orientation() == TopAbs_REVERSED)
66 for(exp3.Init(_s, TopAbs_EDGE, TopAbs_FACE); exp3.More(); exp3.Next()) {
67 TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
69 if(model()->getOCCInternals())
70 e = model()->getOCCInternals()->getEdgeForOCCShape(model(), edge);
71 if(!e) {
Msg::Error(
"Unknown curve in volume %d", tag()); }
72 else if(edge.Orientation() == TopAbs_INTERNAL &&
74 Msg::Debug(
"Adding embedded curve %d in volume %d", e->
tag(), tag());
75 embedded_edges.push_back(e);
81 for(exp3.Init(_s, TopAbs_VERTEX, TopAbs_FACE); exp3.More(); exp3.Next()) {
82 TopoDS_Vertex vertex = TopoDS::Vertex(exp3.Current());
84 if(model()->getOCCInternals())
85 v = model()->getOCCInternals()->getVertexForOCCShape(model(), vertex);
86 if(!v) {
Msg::Error(
"Unknown point in volume %d", tag()); }
87 else if(vertex.Orientation() == TopAbs_INTERNAL &&
89 Msg::Debug(
"Adding embedded point %d in volume %d", v->
tag(), tag());
90 embedded_vertices.push_back(v);
94 Msg::Debug(
"OCC volume %d with %d surfaces", tag(), l_faces.size());
100 std::vector<GFace *>
f =
faces();
102 for(std::size_t i = 0; i <
f.size(); i++) {
103 f[i]->buildSTLTriangulation();
104 bbox +=
f[i]->bounds();
111 BRepBndLib::Add(_s, b);
112 }
catch(Standard_Failure &err) {
113 Msg::Error(
"OpenCASCADE exception %s", err.GetMessageString());
116 double xmin, ymin, zmin, xmax, ymax, zmax;
117 b.Get(xmin, ymin, zmin, xmax, ymax, zmax);
124 bool OCCRegion::containsPoint(
const SPoint3 &pt)
const
126 BRepClass3d_SolidClassifier solidClassifier(_s);
127 solidClassifier.Perform(gp_Pnt{pt.
x(), pt.
y(), pt.
z()},
129 const TopAbs_State state = solidClassifier.State();
130 return (state == TopAbs_IN || state == TopAbs_ON);
133 void OCCRegion::writeBREP(
const char *filename)
139 BRepTools::Write(
c, filename);