1 // File: TopOpeBRep_ShapeIntersector2d.cxx
2 // Created: Fri May 7 17:36:28 1993
3 // Author: Jean Yves LEBEY
6 #include <TopOpeBRep_ShapeIntersector2d.ixx>
8 #include <Standard_ProgramError.hxx>
9 #include <Standard_NotImplemented.hxx>
11 #include <Bnd_Box.hxx>
12 #include <TopOpeBRepTool_box.hxx>
15 extern Standard_Boolean TopOpeBRep_GettraceSI();
16 extern Standard_Boolean TopOpeBRep_GetcontextFFOR();
19 //=======================================================================
20 //function : TopOpeBRep_ShapeIntersector2d
22 //=======================================================================
24 TopOpeBRep_ShapeIntersector2d::TopOpeBRep_ShapeIntersector2d()
27 myHBoxTool = FBOX_GetHBoxTool();
28 myFaceScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
29 myEdgeScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
32 //=======================================================================
35 //=======================================================================
37 void TopOpeBRep_ShapeIntersector2d::Reset()
39 myIntersectionDone = Standard_False;
41 myFFDone = Standard_False;
42 myEEFFDone = Standard_False;
44 myFFInit = Standard_False;
45 myEEFFInit = Standard_False;
48 //=======================================================================
51 //=======================================================================
53 void TopOpeBRep_ShapeIntersector2d::Init
54 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
62 //=======================================================================
63 //function : SetIntersectionDone
65 //=======================================================================
67 void TopOpeBRep_ShapeIntersector2d::SetIntersectionDone()
69 myIntersectionDone = (myFFDone ||
74 //=======================================================================
75 //function : CurrentGeomShape
77 //=======================================================================
79 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::CurrentGeomShape
80 (const Standard_Integer Index) const
82 if ( myIntersectionDone ) {
84 if ( Index == 1 ) return myFaceScanner.Current();
85 else if ( Index == 2 ) return myFaceExplorer.Current();
87 else if (myEEFFDone) {
88 if ( Index == 1 ) return myEdgeScanner.Current();
89 else if ( Index == 2 ) return myEdgeExplorer.Current();
93 Standard_ProgramError::Raise("CurrentGeomShape : no intersection 2d");
94 TopoDS_Shape* bid = new TopoDS_Shape();
99 //=======================================================================
100 //function : InitIntersection
102 //=======================================================================
104 void TopOpeBRep_ShapeIntersector2d::InitIntersection
105 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
108 InitFFIntersection();
112 //=======================================================================
113 //function : MoreIntersection
115 //=======================================================================
117 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreIntersection() const
119 Standard_Boolean res = myIntersectionDone;
122 if (TopOpeBRep_GettraceSI() && res) {
123 if ( myFFDone ) cout<<"FF : ";
124 else if ( myEEFFDone ) cout<<" EE : ";
134 //=======================================================================
135 //function : DumpCurrent
137 //=======================================================================
139 void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer K) const
143 if ( K == 1 ) myFaceScanner.DumpCurrent(cout);
144 else if ( K == 2 ) myFaceExplorer.DumpCurrent(cout);
146 else if ( myEEFFDone ) {
147 if ( K == 1 ) myEdgeScanner.DumpCurrent(cout);
148 else if ( K == 2 ) myEdgeExplorer.DumpCurrent(cout);
153 //=======================================================================
156 //=======================================================================
158 Standard_Integer TopOpeBRep_ShapeIntersector2d::Index
159 (const Standard_Integer K)const
161 Standard_Integer i = 0;
164 if ( K == 1 ) i = myFaceScanner.Index();
165 else if ( K == 2 ) i = myFaceExplorer.Index();
167 else if ( myEEFFDone ) {
168 if ( K == 1 ) i = myEdgeScanner.Index();
169 else if ( K == 2 ) i = myEdgeExplorer.Index();
176 //=======================================================================
177 //function : NextIntersection
179 //=======================================================================
181 void TopOpeBRep_ShapeIntersector2d::NextIntersection()
183 myIntersectionDone = Standard_False;
186 // precedant etat du More() : 2 faces
187 myFFDone = Standard_False;
188 InitEEFFIntersection();
189 FindEEFFIntersection();
190 if ( !myIntersectionDone ) {
192 FindFFIntersection();
195 else if ( myEEFFDone ) {
197 FindEEFFIntersection();
198 if ( !myIntersectionDone ) {
200 FindFFIntersection();
204 if ( !myIntersectionDone ) {
205 InitFFIntersection();
215 //=======================================================================
216 //function : InitFFIntersection
218 //=======================================================================
220 void TopOpeBRep_ShapeIntersector2d::InitFFIntersection()
223 TopAbs_ShapeEnum tscann = TopAbs_FACE;
224 TopAbs_ShapeEnum texplo = TopAbs_FACE;
225 myFaceScanner.Clear();
226 myFaceScanner.AddBoxesMakeCOB(myShape1,tscann);
227 myFaceExplorer.Init(myShape2,texplo);
228 myFaceScanner.Init(myFaceExplorer);
229 FindFFIntersection();
231 myFFInit = Standard_True;
235 //=======================================================================
236 //function : FindFFIntersection
238 //=======================================================================
240 void TopOpeBRep_ShapeIntersector2d::FindFFIntersection()
242 myFFDone = Standard_False;
243 // myFFSameDomain = Standard_False;
245 while ( MoreFFCouple() ) {
247 // The two candidate intersecting GeomShapes GS1,GS2 and their types t1,t2
248 const TopoDS_Shape& GS1 = myFaceScanner.Current();
249 const TopoDS_Shape& GS2 = myFaceExplorer.Current();
252 if (TopOpeBRep_GettraceSI()) {
254 myFaceScanner.DumpCurrent(cout);
255 myFaceExplorer.DumpCurrent(cout);
260 const TopOpeBRepTool_BoxSort& BS = myFaceScanner.BoxSort();
263 myFFDone = Standard_True;
268 SetIntersectionDone();
272 //=======================================================================
273 //function : MoreFFCouple
275 //=======================================================================
277 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreFFCouple() const
279 Standard_Boolean more1 = myFaceScanner.More();
280 Standard_Boolean more2 = myFaceExplorer.More();
281 return (more1 && more2);
285 //=======================================================================
286 //function : NextFFCouple
288 //=======================================================================
290 void TopOpeBRep_ShapeIntersector2d::NextFFCouple()
292 myFaceScanner.Next();
293 Standard_Boolean b1,b2;
295 b1 = (!myFaceScanner.More());
296 b2 = (myFaceExplorer.More());
298 myFaceExplorer.Next();
299 myFaceScanner.Init(myFaceExplorer);
300 b1 = (!myFaceScanner.More());
301 b2 = (myFaceExplorer.More());
312 //=======================================================================
313 //function : InitEEFFIntersection
315 //=======================================================================
317 void TopOpeBRep_ShapeIntersector2d::InitEEFFIntersection()
319 // prepare exploration of the edges of the two current SameDomain faces
320 TopoDS_Shape face1 = myFaceScanner.Current(); // -26-08-96
321 TopoDS_Shape face2 = myFaceExplorer.Current(); // -26-08-96
324 if (TopOpeBRep_GetcontextFFOR()) {
325 face1.Orientation(TopAbs_FORWARD); //-05/07
326 face2.Orientation(TopAbs_FORWARD); //-05/07
327 cout<<"ctx : InitEEFFIntersection : faces FORWARD"<<endl;
331 myEEIntersector.SetFaces(face1,face2);
333 TopAbs_ShapeEnum tscann = TopAbs_EDGE;
334 TopAbs_ShapeEnum texplo = TopAbs_EDGE;
335 myEdgeScanner.Clear();
336 myEdgeScanner.AddBoxesMakeCOB(face1,tscann);
337 myEdgeExplorer.Init(face2,texplo);
338 myEdgeScanner.Init(myEdgeExplorer);
340 myEEFFInit = Standard_True;
344 //=======================================================================
345 //function : FindEEFFIntersection
347 //=======================================================================
349 void TopOpeBRep_ShapeIntersector2d::FindEEFFIntersection()
351 myEEFFDone = Standard_False;
352 while ( MoreEEFFCouple() ) {
353 const TopoDS_Shape& GS1 = myEdgeScanner.Current();
354 const TopoDS_Shape& GS2 = myEdgeExplorer.Current();
355 myEEIntersector.Perform(GS1,GS2);
358 if (TopOpeBRep_GettraceSI() && myEEIntersector.IsEmpty()) {
360 myEdgeScanner.DumpCurrent(cout);
361 myEdgeExplorer.DumpCurrent(cout);
362 cout<<"(EE of FF SameDomain)";
363 cout<<" : EMPTY INTERSECTION";
368 myEEFFDone = ! (myEEIntersector.IsEmpty());
369 if (myEEFFDone) break;
370 else NextEEFFCouple();
372 SetIntersectionDone();
376 //=======================================================================
377 //function : MoreEEFFCouple
379 //=======================================================================
381 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreEEFFCouple() const
383 Standard_Boolean more1 = myEdgeScanner.More();
384 Standard_Boolean more2 = myEdgeExplorer.More();
385 return (more1 && more2);
389 //=======================================================================
390 //function : NextEEFFCouple
392 //=======================================================================
394 void TopOpeBRep_ShapeIntersector2d::NextEEFFCouple()
396 myEdgeScanner.Next();
397 while ( ! myEdgeScanner.More() && myEdgeExplorer.More() ) {
398 myEdgeExplorer.Next();
399 myEdgeScanner.Init(myEdgeExplorer);
404 //=======================================================================
407 //=======================================================================
409 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::Shape
410 ( const Standard_Integer Index )const
412 if ( Index == 1 ) return myShape1;
413 else if ( Index == 2 ) return myShape2;
415 Standard_ProgramError::Raise("ShapeIntersector : no shape");
416 TopoDS_Shape* bid = new TopoDS_Shape();
420 //=======================================================================
421 //function : ChangeEdgesIntersector
423 //=======================================================================
425 TopOpeBRep_EdgesIntersector&
426 TopOpeBRep_ShapeIntersector2d::ChangeEdgesIntersector()
427 { return myEEIntersector; }