1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BRepBndLib.ixx>
16 #include <TopExp_Explorer.hxx>
17 #include <BRepAdaptor_Surface.hxx>
18 #include <BRepAdaptor_Curve.hxx>
19 #include <BRep_Tool.hxx>
21 #include <BndLib_Add3dCurve.hxx>
22 #include <BndLib_AddSurface.hxx>
23 #include <Geom_Surface.hxx>
24 #include <TopLoc_Location.hxx>
25 #include <Poly_Triangulation.hxx>
26 #include <Poly_PolygonOnTriangulation.hxx>
27 #include <Poly_Polygon3D.hxx>
28 #include <BRep_Polygon3D.hxx>
29 #include <TColStd_HArray1OfInteger.hxx>
30 #include <TColStd_Array1OfInteger.hxx>
31 #include <TColgp_Array1OfPnt.hxx>
32 #include <Geom_Curve.hxx>
33 #include <GeomAdaptor_Curve.hxx>
34 #include <BndLib_Add3dCurve.hxx>
37 //=======================================================================
39 //purpose : Add a shape bounding to a box
40 //=======================================================================
42 void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation)
47 BRepAdaptor_Surface BS;
48 Handle(Geom_Surface) GS;
49 Handle(Poly_Triangulation) T;
51 Standard_Integer i, nbNodes;
54 for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
55 const TopoDS_Face& F = TopoDS::Face(ex.Current());
56 T = BRep_Tool::Triangulation(F, l);
57 if (useTriangulation && !T.IsNull())
59 nbNodes = T->NbNodes();
60 const TColgp_Array1OfPnt& Nodes = T->Nodes();
61 for (i = 1; i <= nbNodes; i++) {
62 if (l.IsIdentity()) B.Add(Nodes(i));
63 else B.Add(Nodes(i).Transformed(l));
65 // B.Enlarge(T->Deflection());
66 B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
69 GS = BRep_Tool::Surface(F, l);
71 BS.Initialize(F, Standard_False);
72 if (BS.GetType() != GeomAbs_Plane) {
74 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
77 // on travaille directement sur les courbes 3d.
78 TopExp_Explorer ex2(F, TopAbs_EDGE);
81 BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
84 for (;ex2.More();ex2.Next()) {
85 BC.Initialize(TopoDS::Edge(ex2.Current()));
86 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B);
88 B.Enlarge(BRep_Tool::Tolerance(F));
95 // Add the edges not in faces
96 Handle(TColStd_HArray1OfInteger) HIndices;
97 Handle(Poly_PolygonOnTriangulation) Poly;
99 for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
101 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
102 Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
105 const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
106 nbNodes = P3d->NbNodes();
107 for (i = 1; i <= nbNodes; i++)
109 if (l.IsIdentity()) B.Add(Nodes(i));
110 else B.Add(Nodes(i).Transformed(l));
112 // B.Enlarge(P3d->Deflection());
113 B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
117 BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
118 if (useTriangulation && !Poly.IsNull())
120 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
121 const TColgp_Array1OfPnt& Nodes = T->Nodes();
122 nbNodes = Indices.Length();
123 for (i = 1; i <= nbNodes; i++)
125 if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
126 else B.Add(Nodes(Indices(i)).Transformed(l));
128 // B.Enlarge(T->Deflection());
129 B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
132 if (BRep_Tool::IsGeometric(E))
135 BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
141 // Add the vertices not in edges
143 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
144 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
145 B.Enlarge(BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
151 //=======================================================================
152 //function : AddClose
153 //purpose : Add a precise shape bounding to a box
154 //=======================================================================
156 void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
164 BRepAdaptor_Curve BC;
166 for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
167 BC.Initialize(TopoDS::Edge(ex.Current()));
168 BndLib_Add3dCurve::Add(BC,0.,B);
171 // Add the vertices not in edges
173 for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
174 B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));