0023024: Update headers of OCCT files
[occt.git] / src / BRepBndLib / BRepBndLib.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
20#include <BRepBndLib.ixx>
21#include <TopExp_Explorer.hxx>
22#include <BRepAdaptor_Surface.hxx>
23#include <BRepAdaptor_Curve.hxx>
24#include <BRep_Tool.hxx>
25#include <TopoDS.hxx>
26#include <BndLib_Add3dCurve.hxx>
27#include <BndLib_AddSurface.hxx>
28#include <Geom_Surface.hxx>
29#include <TopLoc_Location.hxx>
30#include <Poly_Triangulation.hxx>
31#include <Poly_PolygonOnTriangulation.hxx>
32#include <Poly_Polygon3D.hxx>
33#include <BRep_Polygon3D.hxx>
34#include <TColStd_HArray1OfInteger.hxx>
35#include <TColStd_Array1OfInteger.hxx>
36#include <TColgp_Array1OfPnt.hxx>
37#include <Geom_Curve.hxx>
38#include <GeomAdaptor_Curve.hxx>
39#include <BndLib_Add3dCurve.hxx>
40
41
42//=======================================================================
43//function : Add
44//purpose : Add a shape bounding to a box
45//=======================================================================
46
3c34883c 47void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation)
7fd59977 48{
49 TopExp_Explorer ex;
50
51 // Add the faces
7fd59977 52 BRepAdaptor_Surface BS;
53 Handle(Geom_Surface) GS;
54 Handle(Poly_Triangulation) T;
55 TopLoc_Location l;
56 Standard_Integer i, nbNodes;
57 BRepAdaptor_Curve BC;
58
59 for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
60 const TopoDS_Face& F = TopoDS::Face(ex.Current());
61 T = BRep_Tool::Triangulation(F, l);
3c34883c
O
62 if (useTriangulation && !T.IsNull())
63 {
7fd59977 64 nbNodes = T->NbNodes();
65 const TColgp_Array1OfPnt& Nodes = T->Nodes();
66 for (i = 1; i <= nbNodes; i++) {
3c34883c
O
67 if (l.IsIdentity()) B.Add(Nodes(i));
68 else B.Add(Nodes(i).Transformed(l));
7fd59977 69 }
70 // B.Enlarge(T->Deflection());
71 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
3c34883c
O
72 } else
73 {
7fd59977 74 GS = BRep_Tool::Surface(F, l);
75 if (!GS.IsNull()) {
3c34883c
O
76 BS.Initialize(F, Standard_False);
77 if (BS.GetType() != GeomAbs_Plane) {
78 BS.Initialize(F);
79 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
80 }
81 else {
82 // on travaille directement sur les courbes 3d.
83 TopExp_Explorer ex2(F, TopAbs_EDGE);
84 if (!ex2.More()) {
85 BS.Initialize(F);
86 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
87 }
88 else {
89 for (;ex2.More();ex2.Next()) {
90 BC.Initialize(TopoDS::Edge(ex2.Current()));
91 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B);
92 }
93 B.Enlarge(BRep_Tool::Tolerance(F));
94 }
95 }
7fd59977 96 }
97 }
98 }
99
100 // Add the edges not in faces
7fd59977 101 Handle(TColStd_HArray1OfInteger) HIndices;
102 Handle(Poly_PolygonOnTriangulation) Poly;
103
3c34883c
O
104 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
105 {
7fd59977 106 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
107 Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
3c34883c
O
108 if (!P3d.IsNull())
109 {
7fd59977 110 const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
111 nbNodes = P3d->NbNodes();
3c34883c
O
112 for (i = 1; i <= nbNodes; i++)
113 {
114 if (l.IsIdentity()) B.Add(Nodes(i));
115 else B.Add(Nodes(i).Transformed(l));
7fd59977 116 }
117 // B.Enlarge(P3d->Deflection());
118 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
119 }
3c34883c
O
120 else
121 {
7fd59977 122 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
3c34883c
O
123 if (useTriangulation && !Poly.IsNull())
124 {
125 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
126 const TColgp_Array1OfPnt& Nodes = T->Nodes();
127 nbNodes = Indices.Length();
128 for (i = 1; i <= nbNodes; i++)
129 {
130 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
131 else B.Add(Nodes(Indices(i)).Transformed(l));
132 }
133 // B.Enlarge(T->Deflection());
134 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
7fd59977 135 }
136 else {
3c34883c
O
137 if (BRep_Tool::IsGeometric(E))
138 {
139 BC.Initialize(E);
140 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
141 }
7fd59977 142 }
143 }
144 }
145
146 // Add the vertices not in edges
147
148 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
149 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
150 B.Enlarge(BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
151 }
152}
153
154
155
156//=======================================================================
157//function : AddClose
158//purpose : Add a precise shape bounding to a box
159//=======================================================================
160
161void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
162{
163 TopExp_Explorer ex;
164
165 // No faces
166
167 // Add the edges
168
169 BRepAdaptor_Curve BC;
170
171 for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
172 BC.Initialize(TopoDS::Edge(ex.Current()));
173 BndLib_Add3dCurve::Add(BC,0.,B);
174 }
175
176 // Add the vertices not in edges
177
178 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
179 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
180 }
181}
182