1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
20 #include <BRepBndLib.ixx>
21 #include <TopExp_Explorer.hxx>
22 #include <BRepAdaptor_Surface.hxx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRep_Tool.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>
42 //=======================================================================
44 //purpose : Add a shape bounding to a box
45 //=======================================================================
47 void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation)
52 BRepAdaptor_Surface BS;
53 Handle(Geom_Surface) GS;
54 Handle(Poly_Triangulation) T;
56 Standard_Integer i, nbNodes;
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);
62 if (useTriangulation && !T.IsNull())
64 nbNodes = T->NbNodes();
65 const TColgp_Array1OfPnt& Nodes = T->Nodes();
66 for (i = 1; i <= nbNodes; i++) {
67 if (l.IsIdentity()) B.Add(Nodes(i));
68 else B.Add(Nodes(i).Transformed(l));
70 // B.Enlarge(T->Deflection());
71 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
74 GS = BRep_Tool::Surface(F, l);
76 BS.Initialize(F, Standard_False);
77 if (BS.GetType() != GeomAbs_Plane) {
79 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
82 // on travaille directement sur les courbes 3d.
83 TopExp_Explorer ex2(F, TopAbs_EDGE);
86 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
89 for (;ex2.More();ex2.Next()) {
90 BC.Initialize(TopoDS::Edge(ex2.Current()));
91 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B);
93 B.Enlarge(BRep_Tool::Tolerance(F));
100 // Add the edges not in faces
101 Handle(TColStd_HArray1OfInteger) HIndices;
102 Handle(Poly_PolygonOnTriangulation) Poly;
104 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
106 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
107 Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
110 const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
111 nbNodes = P3d->NbNodes();
112 for (i = 1; i <= nbNodes; i++)
114 if (l.IsIdentity()) B.Add(Nodes(i));
115 else B.Add(Nodes(i).Transformed(l));
117 // B.Enlarge(P3d->Deflection());
118 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
122 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
123 if (useTriangulation && !Poly.IsNull())
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++)
130 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
131 else B.Add(Nodes(Indices(i)).Transformed(l));
133 // B.Enlarge(T->Deflection());
134 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
137 if (BRep_Tool::IsGeometric(E))
140 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
146 // Add the vertices not in edges
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())));
156 //=======================================================================
157 //function : AddClose
158 //purpose : Add a precise shape bounding to a box
159 //=======================================================================
161 void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
169 BRepAdaptor_Curve BC;
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);
176 // Add the vertices not in edges
178 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
179 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));