1 // Created on: 1993-07-08
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepBndLib.hxx>
22 #include <Precision.hxx>
23 #include <Standard_ProgramError.hxx>
24 #include <Standard_Type.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopOpeBRepTool_box.hxx>
30 #include <TopOpeBRepTool_define.hxx>
31 #include <TopOpeBRepTool_HBoxTool.hxx>
33 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRepTool_HBoxTool,Standard_Transient)
36 #define TBOX TopOpeBRepTool_GettraceBOX()
39 //=======================================================================
40 //function : TopOpeBRepTool_HBoxTool
42 //=======================================================================
44 TopOpeBRepTool_HBoxTool::TopOpeBRepTool_HBoxTool()
48 //=======================================================================
51 //=======================================================================
52 void TopOpeBRepTool_HBoxTool::Clear()
57 //=======================================================================
58 //function : ComputeBoxes
60 //=======================================================================
61 void TopOpeBRepTool_HBoxTool::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
64 for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
65 // for (TopExp_Explorer ex(S,TS,TA);ex.More();ex.Next()) {
66 const TopoDS_Shape& ss = ex.Current();
71 //=======================================================================
74 //=======================================================================
75 void TopOpeBRepTool_HBoxTool::AddBox(const TopoDS_Shape& S)
81 Standard_Boolean hasb = HasBox(S);
89 DumpB(Box(S));cout<<"; # HBT::AddBox "<<Index(S)<<" : ";TopAbs::Print(t,cout);cout<<"\n";cout<<endl;
94 //=======================================================================
95 //function : ComputeBox
97 //=======================================================================
98 void TopOpeBRepTool_HBoxTool::ComputeBox(const TopoDS_Shape& S,Bnd_Box& B)
100 TopAbs_ShapeEnum t = S.ShapeType();
101 if ( t == TopAbs_FACE ) BRepBndLib::Add(S,B);
102 else if ( t == TopAbs_EDGE ) BRepBndLib::Add(S,B);
103 //modified by NIZHNY-MZV Tue Sep 21 14:04:33 1999
104 else if ( t == TopAbs_SOLID) BRepBndLib::Add(S,B);
105 else if ( t == TopAbs_COMPOUND) BRepBndLib::Add(S,B);
106 //modified by NIZHNY-MZV Wed Apr 5 10:05:53 2000
107 else if ( t == TopAbs_VERTEX) BRepBndLib::Add(S,B);
109 throw Standard_ProgramError("HBT::ComputeBox : invalid type");
113 //=======================================================================
114 //function : ComputeBoxOnVertices
116 //=======================================================================
117 void TopOpeBRepTool_HBoxTool::ComputeBoxOnVertices(const TopoDS_Shape& S,Bnd_Box& B)
119 TopExp_Explorer ex(S,TopAbs_VERTEX);
121 B.Update(-1.e5,-1.e5,-1.e5,1.e5,1.e5,1.e5);
124 Standard_Real tol = Precision::Confusion();
125 for (; ex.More(); ex.Next() ) {
127 BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())).Coord(x,y,z);
129 tol = Max(tol,BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
134 //=======================================================================
137 //=======================================================================
138 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const TopoDS_Shape& S)
140 Standard_Boolean hb = HasBox(S);
142 throw Standard_ProgramError("HBT::Box1");
145 const Bnd_Box& B = myIMS.FindFromKey(S);
149 //=======================================================================
152 //=======================================================================
153 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const Standard_Integer I) const
155 Standard_Integer iu = Extent();
156 Standard_Integer hb = (I >= 1 && I <= iu);
158 throw Standard_ProgramError("HBT::Box2");
160 const Bnd_Box& B = myIMS.FindFromIndex(I);
164 //=======================================================================
167 //=======================================================================
168 Standard_Boolean TopOpeBRepTool_HBoxTool::HasBox(const TopoDS_Shape& S) const
170 Standard_Boolean hb = myIMS.Contains(S);
174 //=======================================================================
177 //=======================================================================
178 const TopoDS_Shape& TopOpeBRepTool_HBoxTool::Shape(const Standard_Integer I) const
180 Standard_Integer iu = Extent();
181 Standard_Integer hs = (I >= 1 && I <= iu);
183 throw Standard_ProgramError("HBT::Box4");
185 const TopoDS_Shape& S = myIMS.FindKey(I);
189 //=======================================================================
192 //=======================================================================
193 Standard_Integer TopOpeBRepTool_HBoxTool::Index(const TopoDS_Shape& S) const
195 Standard_Integer i = myIMS.FindIndex(S);
199 //=======================================================================
202 //=======================================================================
203 Standard_Integer TopOpeBRepTool_HBoxTool::Extent() const
205 Standard_Integer n = myIMS.Extent();
209 //=======================================================================
210 //function : ChangeIMS
212 //=======================================================================
213 TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::ChangeIMS()
218 //=======================================================================
221 //=======================================================================
222 const TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::IMS() const
227 //=======================================================================
230 //=======================================================================
231 void TopOpeBRepTool_HBoxTool::DumpB
235 if (B.IsVoid()) cout<<"# IsVoid";
236 else if (B.IsWhole()) cout<<"# IsWhole";
238 Standard_Real x,y,z,X,Y,Z;
240 cout<<"bounding "<<x<<" "<<y<<" "<<z<<" "<<X<<" "<<Y<<" "<<Z;