2 #include <BRepBndLib.ixx>
3 #include <TopExp_Explorer.hxx>
4 #include <BRepAdaptor_Surface.hxx>
5 #include <BRepAdaptor_Curve.hxx>
6 #include <BRep_Tool.hxx>
8 #include <BndLib_Add3dCurve.hxx>
9 #include <BndLib_AddSurface.hxx>
10 #include <Geom_Surface.hxx>
11 #include <TopLoc_Location.hxx>
12 #include <Poly_Triangulation.hxx>
13 #include <Poly_PolygonOnTriangulation.hxx>
14 #include <Poly_Polygon3D.hxx>
15 #include <BRep_Polygon3D.hxx>
16 #include <TColStd_HArray1OfInteger.hxx>
17 #include <TColStd_Array1OfInteger.hxx>
18 #include <TColgp_Array1OfPnt.hxx>
19 #include <Geom_Curve.hxx>
20 #include <GeomAdaptor_Curve.hxx>
21 #include <BndLib_Add3dCurve.hxx>
24 //=======================================================================
26 //purpose : Add a shape bounding to a box
27 //=======================================================================
29 void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
35 BRepAdaptor_Surface BS;
36 Handle(Geom_Surface) GS;
37 Handle(Poly_Triangulation) T;
39 Standard_Integer i, nbNodes;
42 for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
43 const TopoDS_Face& F = TopoDS::Face(ex.Current());
44 T = BRep_Tool::Triangulation(F, l);
46 nbNodes = T->NbNodes();
47 const TColgp_Array1OfPnt& Nodes = T->Nodes();
48 for (i = 1; i <= nbNodes; i++) {
49 if (l.IsIdentity()) B.Add(Nodes(i));
50 else B.Add(Nodes(i).Transformed(l));
52 // B.Enlarge(T->Deflection());
53 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
56 GS = BRep_Tool::Surface(F, l);
58 BS.Initialize(F, Standard_False);
59 if (BS.GetType() != GeomAbs_Plane) {
61 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
64 // on travaille directement sur les courbes 3d.
65 TopExp_Explorer ex2(F, TopAbs_EDGE);
68 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
71 for (;ex2.More();ex2.Next()) {
72 BC.Initialize(TopoDS::Edge(ex2.Current()));
73 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B);
75 B.Enlarge(BRep_Tool::Tolerance(F));
82 // Add the edges not in faces
85 Handle(TColStd_HArray1OfInteger) HIndices;
86 Handle(Poly_PolygonOnTriangulation) Poly;
88 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next()) {
89 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
90 Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
92 const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
93 nbNodes = P3d->NbNodes();
94 for (i = 1; i <= nbNodes; i++) {
95 if (l.IsIdentity()) B.Add(Nodes(i));
96 else B.Add(Nodes(i).Transformed(l));
98 // B.Enlarge(P3d->Deflection());
99 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
102 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
103 if (!Poly.IsNull()) {
104 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
105 const TColgp_Array1OfPnt& Nodes = T->Nodes();
106 nbNodes = Indices.Length();
107 for (i = 1; i <= nbNodes; i++) {
108 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
109 else B.Add(Nodes(Indices(i)).Transformed(l));
111 // B.Enlarge(T->Deflection());
112 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
115 if (BRep_Tool::IsGeometric(E)) {
117 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
123 // Add the vertices not in edges
125 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
126 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
127 B.Enlarge(BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
133 //=======================================================================
134 //function : AddClose
135 //purpose : Add a precise shape bounding to a box
136 //=======================================================================
138 void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
146 BRepAdaptor_Curve BC;
148 for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
149 BC.Initialize(TopoDS::Edge(ex.Current()));
150 BndLib_Add3dCurve::Add(BC,0.,B);
153 // Add the vertices not in edges
155 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
156 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));