022695: The algorithm BRepFilletAPI_MakeFillet2d crashes in cases when some original...
[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
29void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
30{
31 TopExp_Explorer ex;
32
33 // Add the faces
34
35 BRepAdaptor_Surface BS;
36 Handle(Geom_Surface) GS;
37 Handle(Poly_Triangulation) T;
38 TopLoc_Location l;
39 Standard_Integer i, nbNodes;
40 BRepAdaptor_Curve BC;
41
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);
45 if (!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));
51 }
52 // B.Enlarge(T->Deflection());
53 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
54 }
55 else {
56 GS = BRep_Tool::Surface(F, l);
57 if (!GS.IsNull()) {
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 }
78 }
79 }
80 }
81
82 // Add the edges not in faces
83
84
85 Handle(TColStd_HArray1OfInteger) HIndices;
86 Handle(Poly_PolygonOnTriangulation) Poly;
87
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);
91 if (!P3d.IsNull()) {
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));
97 }
98 // B.Enlarge(P3d->Deflection());
99 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
100 }
101 else {
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));
110 }
111 // B.Enlarge(T->Deflection());
112 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
113 }
114 else {
115 if (BRep_Tool::IsGeometric(E)) {
116 BC.Initialize(E);
117 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
118 }
119 }
120 }
121 }
122
123 // Add the vertices not in edges
124
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())));
128 }
129}
130
131
132
133//=======================================================================
134//function : AddClose
135//purpose : Add a precise shape bounding to a box
136//=======================================================================
137
138void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
139{
140 TopExp_Explorer ex;
141
142 // No faces
143
144 // Add the edges
145
146 BRepAdaptor_Curve BC;
147
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);
151 }
152
153 // Add the vertices not in edges
154
155 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
156 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
157 }
158}
159