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 <BRep_Tool.hxx>
19 #include <BRepBndLib.hxx>
21 #include <Precision.hxx>
22 #include <Standard_ProgramError.hxx>
23 #include <Standard_Type.hxx>
24 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopOpeBRepTool_box.hxx>
28 #include <TopOpeBRepTool_define.hxx>
29 #include <TopOpeBRepTool_HBoxTool.hxx>
31 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRepTool_HBoxTool,Standard_Transient)
34 #define TBOX TopOpeBRepTool_GettraceBOX()
37 //=======================================================================
38 //function : TopOpeBRepTool_HBoxTool
40 //=======================================================================
42 TopOpeBRepTool_HBoxTool::TopOpeBRepTool_HBoxTool()
46 //=======================================================================
49 //=======================================================================
50 void TopOpeBRepTool_HBoxTool::Clear()
55 //=======================================================================
56 //function : ComputeBoxes
58 //=======================================================================
59 void TopOpeBRepTool_HBoxTool::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
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();
69 //=======================================================================
72 //=======================================================================
73 void TopOpeBRepTool_HBoxTool::AddBox(const TopoDS_Shape& S)
79 Standard_Boolean hasb = HasBox(S);
87 DumpB(Box(S));std::cout<<"; # HBT::AddBox "<<Index(S)<<" : ";TopAbs::Print(t,std::cout);std::cout<<"\n";std::cout<<std::endl;
92 //=======================================================================
93 //function : ComputeBox
95 //=======================================================================
96 void TopOpeBRepTool_HBoxTool::ComputeBox(const TopoDS_Shape& S,Bnd_Box& B)
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);
107 throw Standard_ProgramError("HBT::ComputeBox : invalid type");
111 //=======================================================================
112 //function : ComputeBoxOnVertices
114 //=======================================================================
115 void TopOpeBRepTool_HBoxTool::ComputeBoxOnVertices(const TopoDS_Shape& S,Bnd_Box& B)
117 TopExp_Explorer ex(S,TopAbs_VERTEX);
119 B.Update(-1.e5,-1.e5,-1.e5,1.e5,1.e5,1.e5);
122 Standard_Real tol = Precision::Confusion();
123 for (; ex.More(); ex.Next() ) {
125 BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())).Coord(x,y,z);
127 tol = Max(tol,BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
132 //=======================================================================
135 //=======================================================================
136 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const TopoDS_Shape& S)
138 Standard_Boolean hb = HasBox(S);
140 throw Standard_ProgramError("HBT::Box1");
143 const Bnd_Box& B = myIMS.FindFromKey(S);
147 //=======================================================================
150 //=======================================================================
151 const Bnd_Box& TopOpeBRepTool_HBoxTool::Box(const Standard_Integer I) const
153 Standard_Integer iu = Extent();
154 Standard_Integer hb = (I >= 1 && I <= iu);
156 throw Standard_ProgramError("HBT::Box2");
158 const Bnd_Box& B = myIMS.FindFromIndex(I);
162 //=======================================================================
165 //=======================================================================
166 Standard_Boolean TopOpeBRepTool_HBoxTool::HasBox(const TopoDS_Shape& S) const
168 Standard_Boolean hb = myIMS.Contains(S);
172 //=======================================================================
175 //=======================================================================
176 const TopoDS_Shape& TopOpeBRepTool_HBoxTool::Shape(const Standard_Integer I) const
178 Standard_Integer iu = Extent();
179 Standard_Integer hs = (I >= 1 && I <= iu);
181 throw Standard_ProgramError("HBT::Box4");
183 const TopoDS_Shape& S = myIMS.FindKey(I);
187 //=======================================================================
190 //=======================================================================
191 Standard_Integer TopOpeBRepTool_HBoxTool::Index(const TopoDS_Shape& S) const
193 Standard_Integer i = myIMS.FindIndex(S);
197 //=======================================================================
200 //=======================================================================
201 Standard_Integer TopOpeBRepTool_HBoxTool::Extent() const
203 Standard_Integer n = myIMS.Extent();
207 //=======================================================================
208 //function : ChangeIMS
210 //=======================================================================
211 TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::ChangeIMS()
216 //=======================================================================
219 //=======================================================================
220 const TopOpeBRepTool_IndexedDataMapOfShapeBox& TopOpeBRepTool_HBoxTool::IMS() const
225 //=======================================================================
228 //=======================================================================
229 void TopOpeBRepTool_HBoxTool::DumpB
233 if (B.IsVoid()) std::cout<<"# IsVoid";
234 else if (B.IsWhole()) std::cout<<"# IsWhole";
236 Standard_Real x,y,z,X,Y,Z;
238 std::cout<<"bounding "<<x<<" "<<y<<" "<<z<<" "<<X<<" "<<Y<<" "<<Z;