1 // Created on: 1993-07-12
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_BoxSort.ixx>
19 #include <TopExp_Explorer.hxx>
21 #include <BRep_Tool.hxx>
23 #include <TopoDS_Vertex.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <GeomAdaptor_Surface.hxx>
27 #include <Geom_Surface.hxx>
28 #include <GeomAbs_SurfaceType.hxx>
30 #include <TopOpeBRepTool_box.hxx>
31 #include <TopOpeBRepTool_define.hxx>
32 #include <Standard_ProgramError.hxx>
35 #define TBOX TopOpeBRepTool_GettraceBOX()
38 #define MTOhbt Handle(TopOpeBRepTool_HBoxTool)
39 #define MTClioloi TColStd_ListIteratorOfListOfInteger
41 //=======================================================================
42 //function : TopOpeBRepTool_BoxSort
44 //=======================================================================
45 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort()
49 //=======================================================================
50 //function : TopOpeBRepTool_BoxSort
52 //=======================================================================
53 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort(const MTOhbt& HBT)
58 //modified by NIZNHY-PKV Mon Dec 16 10:26:00 2002 f
59 //=======================================================================
61 //purpose : alias ~TopOpeBRepTool_BoxSort
62 //=======================================================================
63 void TopOpeBRepTool_BoxSort::Destroy()
65 if (!myHBT.IsNull()) {
69 //modified by NIZNHY-PKV Mon Dec 16 10:26:02 2002 t
71 //=======================================================================
72 //function : SetHBoxTool
74 //=======================================================================
75 void TopOpeBRepTool_BoxSort::SetHBoxTool(const MTOhbt& HBT)
80 //=======================================================================
83 //=======================================================================
84 const MTOhbt& TopOpeBRepTool_BoxSort::HBoxTool() const
89 //=======================================================================
92 //=======================================================================
93 void TopOpeBRepTool_BoxSort::Clear()
100 //=======================================================================
101 //function : AddBoxes
103 //=======================================================================
104 void TopOpeBRepTool_BoxSort::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
106 if (myHBT.IsNull()) myHBT = new TopOpeBRepTool_HBoxTool();
107 myHBT->AddBoxes(S,TS,TA);
110 //=======================================================================
113 //=======================================================================
114 void TopOpeBRepTool_BoxSort::MakeHAB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
120 Standard_Integer n = 0; TopExp_Explorer ex;
121 for (ex.Init(S,TS,TA);ex.More();ex.Next()) n++;
123 myHAB = new Bnd_HArray1OfBox(0,n);
124 Bnd_Array1OfBox& AB = myHAB->ChangeArray1();
125 myHAI = new TColStd_HArray1OfInteger(0,n);
126 TColStd_Array1OfInteger& AI = myHAI->ChangeArray1();
128 Standard_Integer i = 0;
129 for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
131 const TopoDS_Shape& ss = ex.Current();
132 Standard_Boolean hb = myHBT->HasBox(ss);
133 if (!hb) myHBT->AddBox(ss);
134 Standard_Integer im = myHBT->Index(ss);
135 const Bnd_Box& B = myHBT->Box(ss);
136 AI.ChangeValue(i) = im;
137 AB.ChangeValue(i) = B;
142 cout<<"# BS::MakeHAB : ";TopAbs::Print(t,cout);cout<<" : "<<n<<"\n";
149 //=======================================================================
152 //=======================================================================
153 const Handle(Bnd_HArray1OfBox)& TopOpeBRepTool_BoxSort::HAB() const
158 //=======================================================================
159 //function : MakeHABCOB
161 //=======================================================================
162 void TopOpeBRepTool_BoxSort::MakeHABCOB(const Handle(Bnd_HArray1OfBox)& HAB,
166 Standard_Integer n = HAB->Upper();
167 const Bnd_Array1OfBox& AB = HAB->Array1();
168 for (Standard_Integer i = 1; i <= n; i++) {
169 const Bnd_Box& B = AB(i);
174 //=======================================================================
175 //function : HABShape
177 //=======================================================================
178 const TopoDS_Shape& TopOpeBRepTool_BoxSort::HABShape(const Standard_Integer I) const
180 Standard_Integer iu = myHAI->Upper();
181 Standard_Boolean b = (I >= 1 && I <= iu);
183 Standard_ProgramError::Raise("BS::Box3");
185 Standard_Integer im = myHAI->Value(I);
186 const TopoDS_Shape& S = myHBT->Shape(im);
190 //=======================================================================
193 //=======================================================================
194 void TopOpeBRepTool_BoxSort::MakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
197 MakeHABCOB(myHAB,myCOB);
198 myBSB.Initialize(myCOB,myHAB);
200 if (TBOX) {myHBT->DumpB(myCOB);cout<<";# BS::MakeCOB"<<endl;}
204 //=======================================================================
205 //function : AddBoxesMakeCOB
207 //=======================================================================
208 void TopOpeBRepTool_BoxSort::AddBoxesMakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
214 //=======================================================================
217 //=======================================================================
218 const MTClioloi& TopOpeBRepTool_BoxSort::Compare(const TopoDS_Shape &S)
220 if ( myHBT.IsNull() ) myHBT = new TopOpeBRepTool_HBoxTool();
223 Standard_Boolean isPlane = Standard_False;
224 TopAbs_ShapeEnum t = S.ShapeType();
225 Standard_Boolean hasb = myHBT->HasBox(S);
226 if (!hasb) myHBT->AddBox(S);
228 myLastCompareShape = S;
229 myLastCompareShapeBox.SetVoid();
231 if ( t == TopAbs_FACE) {
232 const TopoDS_Face& F = TopoDS::Face(S);
233 Standard_Boolean natu = BRep_Tool::NaturalRestriction(F);
235 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
236 GeomAdaptor_Surface GAS(surf);
237 GeomAbs_SurfaceType suty = GAS.GetType();
238 isPlane = (suty == GeomAbs_Plane);
239 if (isPlane) P = GAS.Plane();
241 myLastCompareShapeBox = myHBT->Box(F);
245 myLastCompareShapeBox = myHBT->Box(F);
248 else if (t == TopAbs_EDGE) {
249 const TopoDS_Edge& E = TopoDS::Edge(S);
250 TopoDS_Vertex V1,V2; TopExp::Vertices(E,V1,V2);
251 Standard_Boolean perso = (V1.IsNull() || V2.IsNull());
253 myHBT->ComputeBoxOnVertices(E,myLastCompareShapeBox);
256 myLastCompareShapeBox = myHBT->Box(E);
260 const TColStd_ListOfInteger* L;
261 if (isPlane) L = &myBSB.Compare(P);
262 else L = &myBSB.Compare(myLastCompareShapeBox);
263 myIterator.Initialize(*L);
267 Standard_Integer nl = (*L).Extent();
268 cout<<"#------------------------"<<endl;
269 myHBT->DumpB(myLastCompareShapeBox);cout<<"; # BS::Compare"<<endl;
270 cout<<"# touche "<<nl<<" boites ";cout.flush();
272 for (MTClioloi idd((*L));idd.More();idd.Next()) {
273 il=idd.Value();cout<<il<<" ";cout.flush();
275 cout<<endl<<"#------------------------"<<endl;
282 //=======================================================================
283 //function : TouchedShape
285 //=======================================================================
286 const TopoDS_Shape& TopOpeBRepTool_BoxSort::TouchedShape(const MTClioloi& LI) const
288 Standard_Integer icur = LI.Value();
289 const TopoDS_Shape& Scur = HABShape(icur);
293 //=======================================================================
296 //=======================================================================
297 const Bnd_Box& TopOpeBRepTool_BoxSort::Box(const TopoDS_Shape& S) const
299 if ( myHBT.IsNull() ) {
300 *((MTOhbt*)&myHBT) = new TopOpeBRepTool_HBoxTool();
303 if ( myHBT->HasBox(S) ) {
304 const Bnd_Box& B = myHBT->Box(S);
307 else if ( !myLastCompareShape.IsNull() ) {
308 if ( S.IsEqual(myLastCompareShape) ) {
309 if ( !myLastCompareShapeBox.IsVoid() ) {
310 return myLastCompareShapeBox;
315 const Bnd_Box& B = myHBT->Box(S);