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, Standard_Boolean useTriangulation)
34 BRepAdaptor_Surface BS;
35 Handle(Geom_Surface) GS;
36 Handle(Poly_Triangulation) T;
38 Standard_Integer i, nbNodes;
41 for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
42 const TopoDS_Face& F = TopoDS::Face(ex.Current());
43 T = BRep_Tool::Triangulation(F, l);
44 if (useTriangulation && !T.IsNull())
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
83 Handle(TColStd_HArray1OfInteger) HIndices;
84 Handle(Poly_PolygonOnTriangulation) Poly;
86 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
88 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
89 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++)
96 if (l.IsIdentity()) B.Add(Nodes(i));
97 else B.Add(Nodes(i).Transformed(l));
99 // B.Enlarge(P3d->Deflection());
100 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
104 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
105 if (useTriangulation && !Poly.IsNull())
107 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
108 const TColgp_Array1OfPnt& Nodes = T->Nodes();
109 nbNodes = Indices.Length();
110 for (i = 1; i <= nbNodes; i++)
112 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
113 else B.Add(Nodes(Indices(i)).Transformed(l));
115 // B.Enlarge(T->Deflection());
116 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
119 if (BRep_Tool::IsGeometric(E))
122 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
128 // Add the vertices not in edges
130 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
131 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
132 B.Enlarge(BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
138 //=======================================================================
139 //function : AddClose
140 //purpose : Add a precise shape bounding to a box
141 //=======================================================================
143 void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
151 BRepAdaptor_Curve BC;
153 for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
154 BC.Initialize(TopoDS::Edge(ex.Current()));
155 BndLib_Add3dCurve::Add(BC,0.,B);
158 // Add the vertices not in edges
160 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
161 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));