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.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <Geom_Surface.hxx>
21 #include <GeomAbs_SurfaceType.hxx>
22 #include <GeomAdaptor_Surface.hxx>
24 #include <Standard_ProgramError.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopOpeBRepTool_box.hxx>
33 #include <TopOpeBRepTool_BoxSort.hxx>
34 #include <TopOpeBRepTool_define.hxx>
35 #include <TopOpeBRepTool_HBoxTool.hxx>
38 #define TBOX TopOpeBRepTool_GettraceBOX()
41 #define MTOhbt Handle(TopOpeBRepTool_HBoxTool)
42 #define MTClioloi TColStd_ListIteratorOfListOfInteger
44 //=======================================================================
45 //function : TopOpeBRepTool_BoxSort
47 //=======================================================================
48 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort()
52 //=======================================================================
53 //function : TopOpeBRepTool_BoxSort
55 //=======================================================================
56 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort(const MTOhbt& HBT)
61 //modified by NIZNHY-PKV Mon Dec 16 10:26:00 2002 f
62 //=======================================================================
64 //purpose : alias ~TopOpeBRepTool_BoxSort
65 //=======================================================================
66 void TopOpeBRepTool_BoxSort::Destroy()
68 if (!myHBT.IsNull()) {
72 //modified by NIZNHY-PKV Mon Dec 16 10:26:02 2002 t
74 //=======================================================================
75 //function : SetHBoxTool
77 //=======================================================================
78 void TopOpeBRepTool_BoxSort::SetHBoxTool(const MTOhbt& HBT)
83 //=======================================================================
86 //=======================================================================
87 const MTOhbt& TopOpeBRepTool_BoxSort::HBoxTool() const
92 //=======================================================================
95 //=======================================================================
96 void TopOpeBRepTool_BoxSort::Clear()
103 //=======================================================================
104 //function : AddBoxes
106 //=======================================================================
107 void TopOpeBRepTool_BoxSort::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
109 if (myHBT.IsNull()) myHBT = new TopOpeBRepTool_HBoxTool();
110 myHBT->AddBoxes(S,TS,TA);
113 //=======================================================================
116 //=======================================================================
117 void TopOpeBRepTool_BoxSort::MakeHAB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
123 Standard_Integer n = 0; TopExp_Explorer ex;
124 for (ex.Init(S,TS,TA);ex.More();ex.Next()) n++;
126 myHAB = new Bnd_HArray1OfBox(0,n);
127 Bnd_Array1OfBox& AB = myHAB->ChangeArray1();
128 myHAI = new TColStd_HArray1OfInteger(0,n);
129 TColStd_Array1OfInteger& AI = myHAI->ChangeArray1();
131 Standard_Integer i = 0;
132 for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
134 const TopoDS_Shape& ss = ex.Current();
135 Standard_Boolean hb = myHBT->HasBox(ss);
136 if (!hb) myHBT->AddBox(ss);
137 Standard_Integer im = myHBT->Index(ss);
138 const Bnd_Box& B = myHBT->Box(ss);
139 AI.ChangeValue(i) = im;
140 AB.ChangeValue(i) = B;
145 cout<<"# BS::MakeHAB : ";TopAbs::Print(t,cout);cout<<" : "<<n<<"\n";
152 //=======================================================================
155 //=======================================================================
156 const Handle(Bnd_HArray1OfBox)& TopOpeBRepTool_BoxSort::HAB() const
161 //=======================================================================
162 //function : MakeHABCOB
164 //=======================================================================
165 void TopOpeBRepTool_BoxSort::MakeHABCOB(const Handle(Bnd_HArray1OfBox)& HAB,
169 Standard_Integer n = HAB->Upper();
170 const Bnd_Array1OfBox& AB = HAB->Array1();
171 for (Standard_Integer i = 1; i <= n; i++) {
172 const Bnd_Box& B = AB(i);
177 //=======================================================================
178 //function : HABShape
180 //=======================================================================
181 const TopoDS_Shape& TopOpeBRepTool_BoxSort::HABShape(const Standard_Integer I) const
183 Standard_Integer iu = myHAI->Upper();
184 Standard_Boolean b = (I >= 1 && I <= iu);
186 Standard_ProgramError::Raise("BS::Box3");
188 Standard_Integer im = myHAI->Value(I);
189 const TopoDS_Shape& S = myHBT->Shape(im);
193 //=======================================================================
196 //=======================================================================
197 void TopOpeBRepTool_BoxSort::MakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
200 MakeHABCOB(myHAB,myCOB);
201 myBSB.Initialize(myCOB,myHAB);
203 if (TBOX) {myHBT->DumpB(myCOB);cout<<";# BS::MakeCOB"<<endl;}
207 //=======================================================================
208 //function : AddBoxesMakeCOB
210 //=======================================================================
211 void TopOpeBRepTool_BoxSort::AddBoxesMakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
217 //=======================================================================
220 //=======================================================================
221 const MTClioloi& TopOpeBRepTool_BoxSort::Compare(const TopoDS_Shape &S)
223 if ( myHBT.IsNull() ) myHBT = new TopOpeBRepTool_HBoxTool();
226 Standard_Boolean isPlane = Standard_False;
227 TopAbs_ShapeEnum t = S.ShapeType();
228 Standard_Boolean hasb = myHBT->HasBox(S);
229 if (!hasb) myHBT->AddBox(S);
231 myLastCompareShape = S;
232 myLastCompareShapeBox.SetVoid();
234 if ( t == TopAbs_FACE) {
235 const TopoDS_Face& F = TopoDS::Face(S);
236 Standard_Boolean natu = BRep_Tool::NaturalRestriction(F);
238 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
239 GeomAdaptor_Surface GAS(surf);
240 GeomAbs_SurfaceType suty = GAS.GetType();
241 isPlane = (suty == GeomAbs_Plane);
242 if (isPlane) P = GAS.Plane();
244 myLastCompareShapeBox = myHBT->Box(F);
248 myLastCompareShapeBox = myHBT->Box(F);
251 else if (t == TopAbs_EDGE) {
252 const TopoDS_Edge& E = TopoDS::Edge(S);
253 TopoDS_Vertex V1,V2; TopExp::Vertices(E,V1,V2);
254 Standard_Boolean perso = (V1.IsNull() || V2.IsNull());
256 myHBT->ComputeBoxOnVertices(E,myLastCompareShapeBox);
259 myLastCompareShapeBox = myHBT->Box(E);
263 const TColStd_ListOfInteger* L;
264 if (isPlane) L = &myBSB.Compare(P);
265 else L = &myBSB.Compare(myLastCompareShapeBox);
266 myIterator.Initialize(*L);
270 Standard_Integer nl = (*L).Extent();
271 cout<<"#------------------------"<<endl;
272 myHBT->DumpB(myLastCompareShapeBox);cout<<"; # BS::Compare"<<endl;
273 cout<<"# touche "<<nl<<" boites ";cout.flush();
275 for (MTClioloi idd((*L));idd.More();idd.Next()) {
276 il=idd.Value();cout<<il<<" ";cout.flush();
278 cout<<endl<<"#------------------------"<<endl;
285 //=======================================================================
286 //function : TouchedShape
288 //=======================================================================
289 const TopoDS_Shape& TopOpeBRepTool_BoxSort::TouchedShape(const MTClioloi& LI) const
291 Standard_Integer icur = LI.Value();
292 const TopoDS_Shape& Scur = HABShape(icur);
296 //=======================================================================
299 //=======================================================================
300 const Bnd_Box& TopOpeBRepTool_BoxSort::Box(const TopoDS_Shape& S) const
302 if ( myHBT.IsNull() ) {
303 *((MTOhbt*)&myHBT) = new TopOpeBRepTool_HBoxTool();
306 if ( myHBT->HasBox(S) ) {
307 const Bnd_Box& B = myHBT->Box(S);
310 else if ( !myLastCompareShape.IsNull() ) {
311 if ( S.IsEqual(myLastCompareShape) ) {
312 if ( !myLastCompareShapeBox.IsVoid() ) {
313 return myLastCompareShapeBox;
318 const Bnd_Box& B = myHBT->Box(S);