0022627: Change OCCT memory management defaults
[occt.git] / src / BRepBndLib / BRepBndLib.cxx
CommitLineData
7fd59977 1
2#include <BRepBndLib.ixx>
3#include <TopExp_Explorer.hxx>
4#include <BRepAdaptor_Surface.hxx>
5#include <BRepAdaptor_Curve.hxx>
6#include <BRep_Tool.hxx>
7#include <TopoDS.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>
22
23
24//=======================================================================
25//function : Add
26//purpose : Add a shape bounding to a box
27//=======================================================================
28
3c34883c 29void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation)
7fd59977 30{
31 TopExp_Explorer ex;
32
33 // Add the faces
7fd59977 34 BRepAdaptor_Surface BS;
35 Handle(Geom_Surface) GS;
36 Handle(Poly_Triangulation) T;
37 TopLoc_Location l;
38 Standard_Integer i, nbNodes;
39 BRepAdaptor_Curve BC;
40
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);
3c34883c
O
44 if (useTriangulation && !T.IsNull())
45 {
7fd59977 46 nbNodes = T->NbNodes();
47 const TColgp_Array1OfPnt& Nodes = T->Nodes();
48 for (i = 1; i <= nbNodes; i++) {
3c34883c
O
49 if (l.IsIdentity()) B.Add(Nodes(i));
50 else B.Add(Nodes(i).Transformed(l));
7fd59977 51 }
52 // B.Enlarge(T->Deflection());
53 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
3c34883c
O
54 } else
55 {
7fd59977 56 GS = BRep_Tool::Surface(F, l);
57 if (!GS.IsNull()) {
3c34883c
O
58 BS.Initialize(F, Standard_False);
59 if (BS.GetType() != GeomAbs_Plane) {
60 BS.Initialize(F);
61 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
62 }
63 else {
64 // on travaille directement sur les courbes 3d.
65 TopExp_Explorer ex2(F, TopAbs_EDGE);
66 if (!ex2.More()) {
67 BS.Initialize(F);
68 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
69 }
70 else {
71 for (;ex2.More();ex2.Next()) {
72 BC.Initialize(TopoDS::Edge(ex2.Current()));
73 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B);
74 }
75 B.Enlarge(BRep_Tool::Tolerance(F));
76 }
77 }
7fd59977 78 }
79 }
80 }
81
82 // Add the edges not in faces
7fd59977 83 Handle(TColStd_HArray1OfInteger) HIndices;
84 Handle(Poly_PolygonOnTriangulation) Poly;
85
3c34883c
O
86 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
87 {
7fd59977 88 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
89 Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
3c34883c
O
90 if (!P3d.IsNull())
91 {
7fd59977 92 const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
93 nbNodes = P3d->NbNodes();
3c34883c
O
94 for (i = 1; i <= nbNodes; i++)
95 {
96 if (l.IsIdentity()) B.Add(Nodes(i));
97 else B.Add(Nodes(i).Transformed(l));
7fd59977 98 }
99 // B.Enlarge(P3d->Deflection());
100 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
101 }
3c34883c
O
102 else
103 {
7fd59977 104 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
3c34883c
O
105 if (useTriangulation && !Poly.IsNull())
106 {
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++)
111 {
112 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
113 else B.Add(Nodes(Indices(i)).Transformed(l));
114 }
115 // B.Enlarge(T->Deflection());
116 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
7fd59977 117 }
118 else {
3c34883c
O
119 if (BRep_Tool::IsGeometric(E))
120 {
121 BC.Initialize(E);
122 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
123 }
7fd59977 124 }
125 }
126 }
127
128 // Add the vertices not in edges
129
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())));
133 }
134}
135
136
137
138//=======================================================================
139//function : AddClose
140//purpose : Add a precise shape bounding to a box
141//=======================================================================
142
143void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
144{
145 TopExp_Explorer ex;
146
147 // No faces
148
149 // Add the edges
150
151 BRepAdaptor_Curve BC;
152
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);
156 }
157
158 // Add the vertices not in edges
159
160 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
161 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
162 }
163}
164