1 // File: TopOpeBRepTool_BoxSort.cxx
2 // Created: Mon Jul 12 16:33:26 1993
3 // Author: Jean Yves LEBEY
6 #include <TopOpeBRepTool_BoxSort.ixx>
8 #include <TopExp_Explorer.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Vertex.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Face.hxx>
15 #include <GeomAdaptor_Surface.hxx>
16 #include <Geom_Surface.hxx>
17 #include <GeomAbs_SurfaceType.hxx>
19 #include <TopOpeBRepTool_box.hxx>
20 #include <TopOpeBRepTool_define.hxx>
21 #include <Standard_ProgramError.hxx>
24 #define TBOX TopOpeBRepTool_GettraceBOX()
27 #define MTOhbt Handle(TopOpeBRepTool_HBoxTool)
28 #define MTClioloi TColStd_ListIteratorOfListOfInteger
30 //=======================================================================
31 //function : TopOpeBRepTool_BoxSort
33 //=======================================================================
34 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort()
38 //=======================================================================
39 //function : TopOpeBRepTool_BoxSort
41 //=======================================================================
42 TopOpeBRepTool_BoxSort::TopOpeBRepTool_BoxSort(const MTOhbt& HBT)
47 //modified by NIZNHY-PKV Mon Dec 16 10:26:00 2002 f
48 //=======================================================================
50 //purpose : alias ~TopOpeBRepTool_BoxSort
51 //=======================================================================
52 void TopOpeBRepTool_BoxSort::Destroy()
54 if (!myHBT.IsNull()) {
58 //modified by NIZNHY-PKV Mon Dec 16 10:26:02 2002 t
60 //=======================================================================
61 //function : SetHBoxTool
63 //=======================================================================
64 void TopOpeBRepTool_BoxSort::SetHBoxTool(const MTOhbt& HBT)
69 //=======================================================================
72 //=======================================================================
73 const MTOhbt& TopOpeBRepTool_BoxSort::HBoxTool() const
78 //=======================================================================
81 //=======================================================================
82 void TopOpeBRepTool_BoxSort::Clear()
89 //=======================================================================
92 //=======================================================================
93 void TopOpeBRepTool_BoxSort::AddBoxes(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
95 if (myHBT.IsNull()) myHBT = new TopOpeBRepTool_HBoxTool();
96 myHBT->AddBoxes(S,TS,TA);
99 //=======================================================================
102 //=======================================================================
103 void TopOpeBRepTool_BoxSort::MakeHAB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
109 Standard_Integer n = 0; TopExp_Explorer ex;
110 for (ex.Init(S,TS,TA);ex.More();ex.Next()) n++;
112 myHAB = new Bnd_HArray1OfBox(0,n);
113 Bnd_Array1OfBox& AB = myHAB->ChangeArray1();
114 myHAI = new TColStd_HArray1OfInteger(0,n);
115 TColStd_Array1OfInteger& AI = myHAI->ChangeArray1();
117 Standard_Integer i = 0;
118 for (ex.Init(S,TS,TA);ex.More();ex.Next()) {
120 const TopoDS_Shape& ss = ex.Current();
121 Standard_Boolean hb = myHBT->HasBox(ss);
122 if (!hb) myHBT->AddBox(ss);
123 Standard_Integer im = myHBT->Index(ss);
124 const Bnd_Box& B = myHBT->Box(ss);
125 AI.ChangeValue(i) = im;
126 AB.ChangeValue(i) = B;
131 cout<<"# BS::MakeHAB : ";TopAbs::Print(t,cout);cout<<" : "<<n<<"\n";
138 //=======================================================================
141 //=======================================================================
142 const Handle(Bnd_HArray1OfBox)& TopOpeBRepTool_BoxSort::HAB() const
147 //=======================================================================
148 //function : MakeHABCOB
150 //=======================================================================
151 void TopOpeBRepTool_BoxSort::MakeHABCOB(const Handle(Bnd_HArray1OfBox)& HAB,
155 Standard_Integer n = HAB->Upper();
156 const Bnd_Array1OfBox& AB = HAB->Array1();
157 for (Standard_Integer i = 1; i <= n; i++) {
158 const Bnd_Box& B = AB(i);
163 //=======================================================================
164 //function : HABShape
166 //=======================================================================
167 const TopoDS_Shape& TopOpeBRepTool_BoxSort::HABShape(const Standard_Integer I) const
169 Standard_Integer iu = myHAI->Upper();
170 Standard_Boolean b = (I >= 1 && I <= iu);
172 Standard_ProgramError::Raise("BS::Box3");
174 Standard_Integer im = myHAI->Value(I);
175 const TopoDS_Shape& S = myHBT->Shape(im);
179 //=======================================================================
182 //=======================================================================
183 void TopOpeBRepTool_BoxSort::MakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
186 MakeHABCOB(myHAB,myCOB);
187 myBSB.Initialize(myCOB,myHAB);
189 if (TBOX) {myHBT->DumpB(myCOB);cout<<";# BS::MakeCOB"<<endl;}
193 //=======================================================================
194 //function : AddBoxesMakeCOB
196 //=======================================================================
197 void TopOpeBRepTool_BoxSort::AddBoxesMakeCOB(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS,const TopAbs_ShapeEnum TA)
203 //=======================================================================
206 //=======================================================================
207 const MTClioloi& TopOpeBRepTool_BoxSort::Compare(const TopoDS_Shape &S)
209 if ( myHBT.IsNull() ) myHBT = new TopOpeBRepTool_HBoxTool();
212 Standard_Boolean isPlane = Standard_False;
213 TopAbs_ShapeEnum t = S.ShapeType();
214 Standard_Boolean hasb = myHBT->HasBox(S);
215 if (!hasb) myHBT->AddBox(S);
217 myLastCompareShape = S;
218 myLastCompareShapeBox.SetVoid();
220 if ( t == TopAbs_FACE) {
221 const TopoDS_Face& F = TopoDS::Face(S);
222 Standard_Boolean natu = BRep_Tool::NaturalRestriction(F);
224 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
225 GeomAdaptor_Surface GAS(surf);
226 GeomAbs_SurfaceType suty = GAS.GetType();
227 isPlane = (suty == GeomAbs_Plane);
228 if (isPlane) P = GAS.Plane();
230 myLastCompareShapeBox = myHBT->Box(F);
234 myLastCompareShapeBox = myHBT->Box(F);
237 else if (t == TopAbs_EDGE) {
238 const TopoDS_Edge& E = TopoDS::Edge(S);
239 TopoDS_Vertex V1,V2; TopExp::Vertices(E,V1,V2);
240 Standard_Boolean perso = (V1.IsNull() || V2.IsNull());
242 myHBT->ComputeBoxOnVertices(E,myLastCompareShapeBox);
245 myLastCompareShapeBox = myHBT->Box(E);
249 const TColStd_ListOfInteger* L;
250 if (isPlane) L = &myBSB.Compare(P);
251 else L = &myBSB.Compare(myLastCompareShapeBox);
252 myIterator.Initialize(*L);
256 Standard_Integer nl = (*L).Extent();
257 cout<<"#------------------------"<<endl;
258 myHBT->DumpB(myLastCompareShapeBox);cout<<"; # BS::Compare"<<endl;
259 cout<<"# touche "<<nl<<" boites ";cout.flush();
261 for (MTClioloi idd((*L));idd.More();idd.Next()) {
262 il=idd.Value();cout<<il<<" ";cout.flush();
264 cout<<endl<<"#------------------------"<<endl;
271 //=======================================================================
272 //function : TouchedShape
274 //=======================================================================
275 const TopoDS_Shape& TopOpeBRepTool_BoxSort::TouchedShape(const MTClioloi& LI) const
277 Standard_Integer icur = LI.Value();
278 const TopoDS_Shape& Scur = HABShape(icur);
282 //=======================================================================
285 //=======================================================================
286 const Bnd_Box& TopOpeBRepTool_BoxSort::Box(const TopoDS_Shape& S) const
288 if ( myHBT.IsNull() ) {
289 *((MTOhbt*)&myHBT) = new TopOpeBRepTool_HBoxTool();
292 if ( myHBT->HasBox(S) ) {
297 const Bnd_Box& B = myHBT->Box(S);
300 else if ( !myLastCompareShape.IsNull() ) {
301 if ( S.IsEqual(myLastCompareShape) ) {
302 if ( !myLastCompareShapeBox.IsVoid() ) {
303 return myLastCompareShapeBox;
308 const Bnd_Box& B = myHBT->Box(S);