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.
17 #include <TopOpeBRepTool_HBoxTool.ixx>
20 #include <TopExp_Explorer.hxx>
21 #include <BRep_Tool.hxx>
24 #include <BRepBndLib.hxx>
25 #include <Standard_ProgramError.hxx>
26 #include <TopOpeBRepTool_box.hxx>
27 #include <TopOpeBRepTool_define.hxx>
28 #include <Precision.hxx>
31 #define TBOX TopOpeBRepTool_GettraceBOX()
34 //=======================================================================
35 //function : TopOpeBRepTool_HBoxTool
37 //=======================================================================
39 TopOpeBRepTool_HBoxTool::TopOpeBRepTool_HBoxTool()
43 //=======================================================================
46 //=======================================================================
47 void TopOpeBRepTool_HBoxTool::Clear()
52 //=======================================================================
53 //function : ComputeBoxes
55 //=======================================================================
56 void TopOpeBRepTool_HBoxTool::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
59 for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
60 // for (TopExp_Explorer ex(S,TS,TA);ex.More();ex.Next()) {
61 const TopoDS_Shape& ss = ex.Current();
66 //=======================================================================
69 //=======================================================================
70 void TopOpeBRepTool_HBoxTool::AddBox(const TopoDS_Shape& S)
76 Standard_Boolean hasb = HasBox(S);
84 DumpB(Box(S));cout<<"; # HBT::AddBox "<<Index(S)<<" : ";TopAbs::Print(t,cout);cout<<"\n";cout<<endl;
89 //=======================================================================
90 //function : ComputeBox
92 //=======================================================================
93 void TopOpeBRepTool_HBoxTool::ComputeBox(const TopoDS_Shape& S,Bnd_Box& B)
95 TopAbs_ShapeEnum t = S.ShapeType();
96 if ( t == TopAbs_FACE ) BRepBndLib::Add(S,B);
97 else if ( t == TopAbs_EDGE ) BRepBndLib::Add(S,B);
98 //modified by NIZHNY-MZV Tue Sep 21 14:04:33 1999
99 else if ( t == TopAbs_SOLID) BRepBndLib::Add(S,B);
100 else if ( t == TopAbs_COMPOUND) BRepBndLib::Add(S,B);
101 //modified by NIZHNY-MZV Wed Apr 5 10:05:53 2000
102 else if ( t == TopAbs_VERTEX) BRepBndLib::Add(S,B);
104 Standard_ProgramError::Raise("HBT::ComputeBox : invalid type");
108 //=======================================================================
109 //function : ComputeBoxOnVertices
111 //=======================================================================
112 void TopOpeBRepTool_HBoxTool::ComputeBoxOnVertices(const TopoDS_Shape& S,Bnd_Box& B)
114 TopExp_Explorer ex(S,TopAbs_VERTEX);
116 B.Update(-1.e5,-1.e5,-1.e5,1.e5,1.e5,1.e5);
119 Standard_Real tol = Precision::Confusion();
120 for (; ex.More(); ex.Next() ) {
122 BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())).Coord(x,y,z);
124 tol = Max(tol,BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
129 //=======================================================================
132 //=======================================================================
133 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const TopoDS_Shape& S)
135 Standard_Boolean hb = HasBox(S);
137 Standard_ProgramError::Raise("HBT::Box1");
140 const Bnd_Box& B = myIMS.FindFromKey(S);
144 //=======================================================================
147 //=======================================================================
148 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const Standard_Integer I) const
150 Standard_Integer iu = Extent();
151 Standard_Integer hb = (I >= 1 && I <= iu);
153 Standard_ProgramError::Raise("HBT::Box2");
155 const Bnd_Box& B = myIMS.FindFromIndex(I);
159 //=======================================================================
162 //=======================================================================
163 Standard_Boolean TopOpeBRepTool_HBoxTool::HasBox(const TopoDS_Shape& S) const
165 Standard_Boolean hb = myIMS.Contains(S);
169 //=======================================================================
172 //=======================================================================
173 const TopoDS_Shape& TopOpeBRepTool_HBoxTool::Shape(const Standard_Integer I) const
175 Standard_Integer iu = Extent();
176 Standard_Integer hs = (I >= 1 && I <= iu);
178 Standard_ProgramError::Raise("HBT::Box4");
180 const TopoDS_Shape& S = myIMS.FindKey(I);
184 //=======================================================================
187 //=======================================================================
188 Standard_Integer TopOpeBRepTool_HBoxTool::Index(const TopoDS_Shape& S) const
190 Standard_Integer i = myIMS.FindIndex(S);
194 //=======================================================================
197 //=======================================================================
198 Standard_Integer TopOpeBRepTool_HBoxTool::Extent() const
200 Standard_Integer n = myIMS.Extent();
204 //=======================================================================
205 //function : ChangeIMS
207 //=======================================================================
208 TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::ChangeIMS()
213 //=======================================================================
216 //=======================================================================
217 const TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::IMS() const
222 //=======================================================================
225 //=======================================================================
226 void TopOpeBRepTool_HBoxTool::DumpB
227 #ifdef TOPOPEBREPTOOL_DEB
230 if (B.IsVoid()) cout<<"# IsVoid";
231 else if (B.IsWhole()) cout<<"# IsWhole";
233 Standard_Real x,y,z,X,Y,Z;
235 cout<<"bounding "<<x<<" "<<y<<" "<<z<<" "<<X<<" "<<Y<<" "<<Z;