1 // Created on: 1993-05-07
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 <Standard_NotImplemented.hxx>
20 #include <Standard_ProgramError.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRep_EdgesIntersector.hxx>
24 #include <TopOpeBRep_ShapeIntersector2d.hxx>
25 #include <TopOpeBRepTool_box.hxx>
26 #include <TopOpeBRepTool_HBoxTool.hxx>
29 extern Standard_Boolean TopOpeBRep_GettraceSI();
30 extern Standard_Boolean TopOpeBRep_GetcontextFFOR();
33 //=======================================================================
34 //function : TopOpeBRep_ShapeIntersector2d
36 //=======================================================================
38 TopOpeBRep_ShapeIntersector2d::TopOpeBRep_ShapeIntersector2d()
41 myHBoxTool = FBOX_GetHBoxTool();
42 myFaceScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
43 myEdgeScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
46 //=======================================================================
49 //=======================================================================
51 void TopOpeBRep_ShapeIntersector2d::Reset()
53 myIntersectionDone = Standard_False;
55 myFFDone = Standard_False;
56 myEEFFDone = Standard_False;
58 myFFInit = Standard_False;
59 myEEFFInit = Standard_False;
62 //=======================================================================
65 //=======================================================================
67 void TopOpeBRep_ShapeIntersector2d::Init
68 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
76 //=======================================================================
77 //function : SetIntersectionDone
79 //=======================================================================
81 void TopOpeBRep_ShapeIntersector2d::SetIntersectionDone()
83 myIntersectionDone = (myFFDone ||
88 //=======================================================================
89 //function : CurrentGeomShape
91 //=======================================================================
93 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::CurrentGeomShape
94 (const Standard_Integer Index) const
96 if ( myIntersectionDone ) {
98 if ( Index == 1 ) return myFaceScanner.Current();
99 else if ( Index == 2 ) return myFaceExplorer.Current();
101 else if (myEEFFDone) {
102 if ( Index == 1 ) return myEdgeScanner.Current();
103 else if ( Index == 2 ) return myEdgeExplorer.Current();
107 throw Standard_ProgramError("CurrentGeomShape : no intersection 2d");
111 //=======================================================================
112 //function : InitIntersection
114 //=======================================================================
116 void TopOpeBRep_ShapeIntersector2d::InitIntersection
117 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
120 InitFFIntersection();
124 //=======================================================================
125 //function : MoreIntersection
127 //=======================================================================
129 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreIntersection() const
131 Standard_Boolean res = myIntersectionDone;
134 if (TopOpeBRep_GettraceSI() && res) {
135 if ( myFFDone ) cout<<"FF : ";
136 else if ( myEEFFDone ) cout<<" EE : ";
146 //=======================================================================
147 //function : DumpCurrent
149 //=======================================================================
152 void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer K) const
155 if ( K == 1 ) myFaceScanner.DumpCurrent(cout);
156 else if ( K == 2 ) myFaceExplorer.DumpCurrent(cout);
158 else if ( myEEFFDone ) {
159 if ( K == 1 ) myEdgeScanner.DumpCurrent(cout);
160 else if ( K == 2 ) myEdgeExplorer.DumpCurrent(cout);
163 void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer) const
168 //=======================================================================
171 //=======================================================================
174 Standard_Integer TopOpeBRep_ShapeIntersector2d::Index
175 (const Standard_Integer K)const
177 Standard_Integer i = 0;
180 if ( K == 1 ) i = myFaceScanner.Index();
181 else if ( K == 2 ) i = myFaceExplorer.Index();
183 else if ( myEEFFDone ) {
184 if ( K == 1 ) i = myEdgeScanner.Index();
185 else if ( K == 2 ) i = myEdgeExplorer.Index();
191 Standard_Integer TopOpeBRep_ShapeIntersector2d::Index (const Standard_Integer)const { return 0;}
195 //=======================================================================
196 //function : NextIntersection
198 //=======================================================================
200 void TopOpeBRep_ShapeIntersector2d::NextIntersection()
202 myIntersectionDone = Standard_False;
205 // precedant etat du More() : 2 faces
206 myFFDone = Standard_False;
207 InitEEFFIntersection();
208 FindEEFFIntersection();
209 if ( !myIntersectionDone ) {
211 FindFFIntersection();
214 else if ( myEEFFDone ) {
216 FindEEFFIntersection();
217 if ( !myIntersectionDone ) {
219 FindFFIntersection();
223 if ( !myIntersectionDone ) {
224 InitFFIntersection();
234 //=======================================================================
235 //function : InitFFIntersection
237 //=======================================================================
239 void TopOpeBRep_ShapeIntersector2d::InitFFIntersection()
242 TopAbs_ShapeEnum tscann = TopAbs_FACE;
243 TopAbs_ShapeEnum texplo = TopAbs_FACE;
244 myFaceScanner.Clear();
245 myFaceScanner.AddBoxesMakeCOB(myShape1,tscann);
246 myFaceExplorer.Init(myShape2,texplo);
247 myFaceScanner.Init(myFaceExplorer);
248 FindFFIntersection();
250 myFFInit = Standard_True;
254 //=======================================================================
255 //function : FindFFIntersection
257 //=======================================================================
259 void TopOpeBRep_ShapeIntersector2d::FindFFIntersection()
261 myFFDone = Standard_False;
262 // myFFSameDomain = Standard_False;
264 if ( MoreFFCouple() ) {
266 // The two candidate intersecting GeomShapes GS1,GS2 and their types t1,t2
267 const TopoDS_Shape& GS1 = myFaceScanner.Current();
268 const TopoDS_Shape& GS2 = myFaceExplorer.Current();
271 if (TopOpeBRep_GettraceSI()) {
273 myFaceScanner.DumpCurrent(cout);
274 myFaceExplorer.DumpCurrent(cout);
279 const TopOpeBRepTool_BoxSort& BS = myFaceScanner.BoxSort();
282 myFFDone = Standard_True;
285 SetIntersectionDone();
289 //=======================================================================
290 //function : MoreFFCouple
292 //=======================================================================
294 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreFFCouple() const
296 Standard_Boolean more1 = myFaceScanner.More();
297 Standard_Boolean more2 = myFaceExplorer.More();
298 return (more1 && more2);
302 //=======================================================================
303 //function : NextFFCouple
305 //=======================================================================
307 void TopOpeBRep_ShapeIntersector2d::NextFFCouple()
309 myFaceScanner.Next();
310 Standard_Boolean b1,b2;
312 b1 = (!myFaceScanner.More());
313 b2 = (myFaceExplorer.More());
315 myFaceExplorer.Next();
316 myFaceScanner.Init(myFaceExplorer);
317 b1 = (!myFaceScanner.More());
318 b2 = (myFaceExplorer.More());
329 //=======================================================================
330 //function : InitEEFFIntersection
332 //=======================================================================
334 void TopOpeBRep_ShapeIntersector2d::InitEEFFIntersection()
336 // prepare exploration of the edges of the two current SameDomain faces
337 TopoDS_Shape face1 = myFaceScanner.Current(); // -26-08-96
338 TopoDS_Shape face2 = myFaceExplorer.Current(); // -26-08-96
341 if (TopOpeBRep_GetcontextFFOR()) {
342 face1.Orientation(TopAbs_FORWARD); //-05/07
343 face2.Orientation(TopAbs_FORWARD); //-05/07
344 cout<<"ctx : InitEEFFIntersection : faces FORWARD"<<endl;
348 myEEIntersector.SetFaces(face1,face2);
350 TopAbs_ShapeEnum tscann = TopAbs_EDGE;
351 TopAbs_ShapeEnum texplo = TopAbs_EDGE;
352 myEdgeScanner.Clear();
353 myEdgeScanner.AddBoxesMakeCOB(face1,tscann);
354 myEdgeExplorer.Init(face2,texplo);
355 myEdgeScanner.Init(myEdgeExplorer);
357 myEEFFInit = Standard_True;
361 //=======================================================================
362 //function : FindEEFFIntersection
364 //=======================================================================
366 void TopOpeBRep_ShapeIntersector2d::FindEEFFIntersection()
368 myEEFFDone = Standard_False;
369 while ( MoreEEFFCouple() ) {
370 const TopoDS_Shape& GS1 = myEdgeScanner.Current();
371 const TopoDS_Shape& GS2 = myEdgeExplorer.Current();
372 myEEIntersector.Perform(GS1,GS2);
375 if (TopOpeBRep_GettraceSI() && myEEIntersector.IsEmpty()) {
377 myEdgeScanner.DumpCurrent(cout);
378 myEdgeExplorer.DumpCurrent(cout);
379 cout<<"(EE of FF SameDomain)";
380 cout<<" : EMPTY INTERSECTION";
385 myEEFFDone = ! (myEEIntersector.IsEmpty());
386 if (myEEFFDone) break;
387 else NextEEFFCouple();
389 SetIntersectionDone();
393 //=======================================================================
394 //function : MoreEEFFCouple
396 //=======================================================================
398 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreEEFFCouple() const
400 Standard_Boolean more1 = myEdgeScanner.More();
401 Standard_Boolean more2 = myEdgeExplorer.More();
402 return (more1 && more2);
406 //=======================================================================
407 //function : NextEEFFCouple
409 //=======================================================================
411 void TopOpeBRep_ShapeIntersector2d::NextEEFFCouple()
413 myEdgeScanner.Next();
414 while ( ! myEdgeScanner.More() && myEdgeExplorer.More() ) {
415 myEdgeExplorer.Next();
416 myEdgeScanner.Init(myEdgeExplorer);
421 //=======================================================================
424 //=======================================================================
426 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::Shape
427 ( const Standard_Integer Index )const
429 if ( Index == 1 ) return myShape1;
430 else if ( Index == 2 ) return myShape2;
432 throw Standard_ProgramError("ShapeIntersector : no shape");
435 //=======================================================================
436 //function : ChangeEdgesIntersector
438 //=======================================================================
440 TopOpeBRep_EdgesIntersector&
441 TopOpeBRep_ShapeIntersector2d::ChangeEdgesIntersector()
442 { return myEEIntersector; }