0033040: Coding - get rid of unused headers [Storage to TopOpeBRepTool]
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_HBoxTool.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Tool.hxx>
19 #include <BRepBndLib.hxx>
20 #include <gp_Pnt.hxx>
21 #include <Precision.hxx>
22 #include <Standard_ProgramError.hxx>
23 #include <Standard_Type.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <TopoDS.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopOpeBRepTool_box.hxx>
28 #include <TopOpeBRepTool_define.hxx>
29 #include <TopOpeBRepTool_HBoxTool.hxx>
30
31 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRepTool_HBoxTool,Standard_Transient)
32
33 #ifdef OCCT_DEBUG
34 #define TBOX TopOpeBRepTool_GettraceBOX()
35 #endif
36
37 //=======================================================================
38 //function : TopOpeBRepTool_HBoxTool
39 //purpose  : 
40 //=======================================================================
41
42 TopOpeBRepTool_HBoxTool::TopOpeBRepTool_HBoxTool()
43 {
44 }
45
46 //=======================================================================
47 //function : Clear
48 //purpose  : 
49 //=======================================================================
50 void TopOpeBRepTool_HBoxTool::Clear()
51 {
52   myIMS.Clear();
53 }
54
55 //=======================================================================
56 //function : ComputeBoxes
57 //purpose  : 
58 //=======================================================================
59 void TopOpeBRepTool_HBoxTool::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
60 {
61   TopExp_Explorer ex;
62   for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
63 //  for (TopExp_Explorer ex(S,TS,TA);ex.More();ex.Next()) {
64     const TopoDS_Shape& ss = ex.Current();
65     AddBox(ss);
66   }
67 }
68
69 //=======================================================================
70 //function : AddBox
71 //purpose  : 
72 //=======================================================================
73 void TopOpeBRepTool_HBoxTool::AddBox(const TopoDS_Shape& S)
74 {
75 #ifdef OCCT_DEBUG
76   TopAbs_ShapeEnum t = 
77 #endif
78     S.ShapeType();
79   Standard_Boolean hasb = HasBox(S);
80   if (hasb) return;
81
82   Bnd_Box B;
83   ComputeBox(S,B);
84   myIMS.Add(S,B);
85 #ifdef OCCT_DEBUG
86   if (TBOX) {
87     DumpB(Box(S));std::cout<<"; # HBT::AddBox "<<Index(S)<<" : ";TopAbs::Print(t,std::cout);std::cout<<"\n";std::cout<<std::endl;
88   }
89 #endif
90 }
91
92 //=======================================================================
93 //function : ComputeBox
94 //purpose  : 
95 //=======================================================================
96 void TopOpeBRepTool_HBoxTool::ComputeBox(const TopoDS_Shape& S,Bnd_Box& B)
97 {
98   TopAbs_ShapeEnum t = S.ShapeType();
99   if      ( t == TopAbs_FACE ) BRepBndLib::Add(S,B);
100   else if ( t == TopAbs_EDGE ) BRepBndLib::Add(S,B);
101   //modified by NIZHNY-MZV  Tue Sep 21 14:04:33 1999
102   else if ( t == TopAbs_SOLID) BRepBndLib::Add(S,B);
103   else if ( t == TopAbs_COMPOUND) BRepBndLib::Add(S,B);
104   //modified by NIZHNY-MZV  Wed Apr  5 10:05:53 2000
105   else if ( t == TopAbs_VERTEX) BRepBndLib::Add(S,B);
106   else {
107     throw Standard_ProgramError("HBT::ComputeBox : invalid type");
108   }
109 }
110
111 //=======================================================================
112 //function : ComputeBoxOnVertices
113 //purpose  : 
114 //=======================================================================
115 void TopOpeBRepTool_HBoxTool::ComputeBoxOnVertices(const TopoDS_Shape& S,Bnd_Box& B)
116 {
117   TopExp_Explorer ex(S,TopAbs_VERTEX);
118   if (!ex.More()) {
119     B.Update(-1.e5,-1.e5,-1.e5,1.e5,1.e5,1.e5);
120     return;
121   }
122   Standard_Real tol = Precision::Confusion();
123   for (; ex.More(); ex.Next() ) {
124     Standard_Real x,y,z;
125     BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())).Coord(x,y,z);
126     B.Update(x,y,z);
127     tol = Max(tol,BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
128   }
129   B.Enlarge(tol);
130 }
131
132 //=======================================================================
133 //function : Box
134 //purpose  : 
135 //=======================================================================
136 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const TopoDS_Shape& S)
137 {
138   Standard_Boolean hb = HasBox(S);
139   if (!hb) {
140     throw Standard_ProgramError("HBT::Box1");
141   }
142
143   const Bnd_Box& B = myIMS.FindFromKey(S);
144   return B;
145 }
146
147 //=======================================================================
148 //function : Box
149 //purpose  : 
150 //=======================================================================
151 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const Standard_Integer I) const
152 {
153   Standard_Integer iu = Extent();
154   Standard_Integer hb = (I >= 1 && I <= iu);
155   if (!hb) {
156     throw Standard_ProgramError("HBT::Box2");
157   }
158   const Bnd_Box& B = myIMS.FindFromIndex(I);
159   return B;
160 }
161
162 //=======================================================================
163 //function : HasBox
164 //purpose  : 
165 //=======================================================================
166 Standard_Boolean TopOpeBRepTool_HBoxTool::HasBox(const TopoDS_Shape& S) const 
167 {
168   Standard_Boolean hb = myIMS.Contains(S);
169   return hb;
170 }
171
172 //=======================================================================
173 //function : Shape
174 //purpose  : 
175 //=======================================================================
176 const TopoDS_Shape& TopOpeBRepTool_HBoxTool::Shape(const Standard_Integer I) const
177 {
178   Standard_Integer iu = Extent();
179   Standard_Integer hs = (I >= 1 && I <= iu);
180   if (!hs) {
181     throw Standard_ProgramError("HBT::Box4");
182   }
183   const TopoDS_Shape& S = myIMS.FindKey(I);
184   return S;
185 }
186
187 //=======================================================================
188 //function : Index
189 //purpose  : 
190 //=======================================================================
191 Standard_Integer TopOpeBRepTool_HBoxTool::Index(const TopoDS_Shape& S) const 
192 {
193   Standard_Integer i = myIMS.FindIndex(S);
194   return i;
195 }
196
197 //=======================================================================
198 //function : Extent
199 //purpose  : 
200 //=======================================================================
201 Standard_Integer TopOpeBRepTool_HBoxTool::Extent() const 
202 {
203   Standard_Integer n = myIMS.Extent();
204   return n;
205 }
206
207 //=======================================================================
208 //function : ChangeIMS
209 //purpose  : 
210 //=======================================================================
211 TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::ChangeIMS()
212 {
213   return myIMS;
214 }
215
216 //=======================================================================
217 //function : IMS
218 //purpose  : 
219 //=======================================================================
220 const TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::IMS() const
221 {
222   return myIMS;
223 }
224
225 //=======================================================================
226 //function : DumpB
227 //purpose  : 
228 //=======================================================================
229 void TopOpeBRepTool_HBoxTool::DumpB 
230 #ifdef OCCT_DEBUG
231 (const Bnd_Box& B)
232 {
233   if      (B.IsVoid()) std::cout<<"# IsVoid";
234   else if (B.IsWhole()) std::cout<<"# IsWhole";
235   else {
236     Standard_Real x,y,z,X,Y,Z; 
237     B.Get(x,y,z,X,Y,Z);
238     std::cout<<"bounding "<<x<<" "<<y<<" "<<z<<" "<<X<<" "<<Y<<" "<<Z;
239     std::cout.flush();
240   }
241 }
242 #else
243 (const Bnd_Box& )
244 {
245 }
246 #endif
247