0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TopOpeBRep / TopOpeBRep_ShapeIntersector2d.cxx
1 // File:        TopOpeBRep_ShapeIntersector2d.cxx
2 // Created:     Fri May  7 17:36:28 1993
3 // Author:      Jean Yves LEBEY
4 //              <jyl@topsn3>
5
6 #include <TopOpeBRep_ShapeIntersector2d.ixx>
7
8 #include <Standard_ProgramError.hxx>
9 #include <Standard_NotImplemented.hxx>
10 #include <TopAbs.hxx>
11 #include <Bnd_Box.hxx>
12 #include <TopOpeBRepTool_box.hxx>
13
14 #ifdef DEB
15 extern Standard_Boolean TopOpeBRep_GettraceSI(); 
16 extern Standard_Boolean TopOpeBRep_GetcontextFFOR();
17 #endif
18
19 //=======================================================================
20 //function : TopOpeBRep_ShapeIntersector2d
21 //purpose  : 
22 //=======================================================================
23
24 TopOpeBRep_ShapeIntersector2d::TopOpeBRep_ShapeIntersector2d()
25 {
26   Reset();
27   myHBoxTool = FBOX_GetHBoxTool();
28   myFaceScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
29   myEdgeScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
30 }
31
32 //=======================================================================
33 //function : Reset
34 //purpose  : 
35 //=======================================================================
36
37 void TopOpeBRep_ShapeIntersector2d::Reset()
38 {
39   myIntersectionDone = Standard_False;
40   
41   myFFDone = Standard_False;
42   myEEFFDone = Standard_False;
43   
44   myFFInit = Standard_False;
45   myEEFFInit = Standard_False;
46 }
47
48 //=======================================================================
49 //function : Init
50 //purpose  : 
51 //=======================================================================
52
53 void TopOpeBRep_ShapeIntersector2d::Init
54 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
55 {
56   Reset();
57   myShape1 = S1;
58   myShape2 = S2;
59   myHBoxTool->Clear();
60 }
61
62 //=======================================================================
63 //function : SetIntersectionDone
64 //purpose  : 
65 //=======================================================================
66
67 void TopOpeBRep_ShapeIntersector2d::SetIntersectionDone()
68 {
69   myIntersectionDone = (myFFDone || 
70                         myEEFFDone);
71 }
72
73
74 //=======================================================================
75 //function : CurrentGeomShape
76 //purpose  : 
77 //=======================================================================
78
79 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::CurrentGeomShape
80 (const Standard_Integer Index) const
81 {
82   if ( myIntersectionDone ) {
83     if      (myFFDone) {
84       if      ( Index == 1 ) return myFaceScanner.Current();
85       else if ( Index == 2 ) return myFaceExplorer.Current();
86     }
87     else if (myEEFFDone) {
88       if      ( Index == 1 ) return myEdgeScanner.Current();
89       else if ( Index == 2 ) return myEdgeExplorer.Current();
90     }
91   }
92   
93   Standard_ProgramError::Raise("CurrentGeomShape : no intersection 2d");
94   TopoDS_Shape* bid = new TopoDS_Shape();
95   return *bid;
96 }
97
98
99 //=======================================================================
100 //function : InitIntersection
101 //purpose  : 
102 //=======================================================================
103
104 void TopOpeBRep_ShapeIntersector2d::InitIntersection
105 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
106 {
107   Init(S1,S2);
108   InitFFIntersection();
109 }
110
111
112 //=======================================================================
113 //function : MoreIntersection
114 //purpose  : 
115 //=======================================================================
116
117 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreIntersection() const
118 {
119   Standard_Boolean res = myIntersectionDone;
120   
121 #ifdef DEB
122   if (TopOpeBRep_GettraceSI() && res) {
123     if      ( myFFDone )   cout<<"FF : ";
124     else if ( myEEFFDone ) cout<<"    EE : ";
125     DumpCurrent(1);
126     DumpCurrent(2);
127   }    
128 #endif
129   
130   return res;
131 }
132
133
134 //=======================================================================
135 //function : DumpCurrent
136 //purpose  : 
137 //=======================================================================
138
139 void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer K) const
140 {
141 #ifdef DEB
142   if      ( myFFDone ) {
143     if      ( K == 1 ) myFaceScanner.DumpCurrent(cout);
144     else if ( K == 2 ) myFaceExplorer.DumpCurrent(cout);
145   }
146   else if ( myEEFFDone ) {
147     if      ( K == 1 ) myEdgeScanner.DumpCurrent(cout);
148     else if ( K == 2 ) myEdgeExplorer.DumpCurrent(cout);
149   }
150 #endif
151 }
152
153 //=======================================================================
154 //function : Index
155 //purpose  : 
156 //=======================================================================
157
158 Standard_Integer TopOpeBRep_ShapeIntersector2d::Index
159 (const Standard_Integer K)const
160 {
161   Standard_Integer i = 0;
162 #ifdef DEB
163   if      ( myFFDone ) {
164     if      ( K == 1 ) i = myFaceScanner.Index();
165     else if ( K == 2 ) i = myFaceExplorer.Index();
166   }
167   else if ( myEEFFDone ) {
168     if      ( K == 1 ) i = myEdgeScanner.Index();
169     else if ( K == 2 ) i = myEdgeExplorer.Index();
170   }
171 #endif
172   return i;
173 }
174
175
176 //=======================================================================
177 //function : NextIntersection
178 //purpose  : 
179 //=======================================================================
180
181 void TopOpeBRep_ShapeIntersector2d::NextIntersection()
182 {
183   myIntersectionDone = Standard_False;
184   
185   if (myFFDone) {
186     // precedant etat du More() : 2 faces
187     myFFDone = Standard_False;
188     InitEEFFIntersection();
189     FindEEFFIntersection();
190     if ( !myIntersectionDone ) {
191       NextFFCouple();
192       FindFFIntersection();
193     }
194   }
195   else if ( myEEFFDone ) {
196     NextEEFFCouple();
197     FindEEFFIntersection();
198     if ( !myIntersectionDone ) {
199       NextFFCouple();
200       FindFFIntersection();
201     }
202   }
203   
204   if ( !myIntersectionDone ) {
205     InitFFIntersection();
206   }
207 }
208
209
210 // ========
211 // FFFFFFFF
212 // ========
213
214
215 //=======================================================================
216 //function : InitFFIntersection
217 //purpose  : 
218 //=======================================================================
219
220 void TopOpeBRep_ShapeIntersector2d::InitFFIntersection()
221 {
222   if ( !myFFInit) { 
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();
230   }
231   myFFInit = Standard_True;
232 }
233
234
235 //=======================================================================
236 //function : FindFFIntersection
237 //purpose  : 
238 //=======================================================================
239
240 void TopOpeBRep_ShapeIntersector2d::FindFFIntersection()
241 {
242   myFFDone = Standard_False;
243 //  myFFSameDomain = Standard_False;
244   
245   while ( MoreFFCouple() ) {
246     
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();
250     
251 #ifdef DEB
252     if (TopOpeBRep_GettraceSI()) {
253       cout<<"?? FF : ";
254       myFaceScanner.DumpCurrent(cout); 
255       myFaceExplorer.DumpCurrent(cout);
256       cout<<endl;
257     }    
258 #endif
259
260     const TopOpeBRepTool_BoxSort& BS = myFaceScanner.BoxSort();
261     BS.Box(GS1);
262     BS.Box(GS2);
263     myFFDone = Standard_True;
264     break;
265     NextFFCouple();
266   }
267   
268   SetIntersectionDone();
269 }
270
271
272 //=======================================================================
273 //function : MoreFFCouple
274 //purpose  : 
275 //=======================================================================
276
277 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreFFCouple() const
278 {
279   Standard_Boolean more1 = myFaceScanner.More();
280   Standard_Boolean more2 = myFaceExplorer.More();
281   return (more1 && more2);
282 }
283
284
285 //=======================================================================
286 //function : NextFFCouple
287 //purpose  : 
288 //=======================================================================
289
290 void TopOpeBRep_ShapeIntersector2d::NextFFCouple()
291 {
292   myFaceScanner.Next();
293   Standard_Boolean b1,b2;
294   
295   b1 = (!myFaceScanner.More());
296   b2 = (myFaceExplorer.More());
297   while ( b1 && b2 ) {
298     myFaceExplorer.Next();
299     myFaceScanner.Init(myFaceExplorer);
300     b1 = (!myFaceScanner.More());
301     b2 = (myFaceExplorer.More());
302   }
303
304 }
305
306
307 // ========
308 // EEFFEEFF
309 // ========
310
311
312 //=======================================================================
313 //function : InitEEFFIntersection
314 //purpose  : 
315 //=======================================================================
316
317 void TopOpeBRep_ShapeIntersector2d::InitEEFFIntersection()
318 {
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
322   
323 #ifdef DEB
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;
328   }
329 #endif
330   
331   myEEIntersector.SetFaces(face1,face2);
332   
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);
339   
340   myEEFFInit = Standard_True;
341 }
342
343
344 //=======================================================================
345 //function : FindEEFFIntersection
346 //purpose  : 
347 //=======================================================================
348
349 void TopOpeBRep_ShapeIntersector2d::FindEEFFIntersection()
350 {
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);
356     
357 #ifdef DEB
358     if (TopOpeBRep_GettraceSI() && myEEIntersector.IsEmpty()) {
359       cout<<"    EE : ";
360       myEdgeScanner.DumpCurrent(cout);
361       myEdgeExplorer.DumpCurrent(cout);
362       cout<<"(EE of FF SameDomain)";
363       cout<<" : EMPTY INTERSECTION";
364       cout<<endl;
365     }    
366 #endif
367     
368     myEEFFDone = ! (myEEIntersector.IsEmpty());
369     if (myEEFFDone) break;
370     else NextEEFFCouple();
371   }
372   SetIntersectionDone();
373 }
374
375
376 //=======================================================================
377 //function : MoreEEFFCouple
378 //purpose  : 
379 //=======================================================================
380
381 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreEEFFCouple() const
382 {
383   Standard_Boolean more1 = myEdgeScanner.More();
384   Standard_Boolean more2 = myEdgeExplorer.More();
385   return (more1 && more2);
386 }
387
388
389 //=======================================================================
390 //function : NextEEFFCouple
391 //purpose  : 
392 //=======================================================================
393
394 void TopOpeBRep_ShapeIntersector2d::NextEEFFCouple()
395 {
396   myEdgeScanner.Next();
397   while ( ! myEdgeScanner.More() && myEdgeExplorer.More() ) {
398     myEdgeExplorer.Next();
399     myEdgeScanner.Init(myEdgeExplorer);
400   }
401 }
402
403
404 //=======================================================================
405 //function : Shape
406 //purpose  : 
407 //=======================================================================
408
409 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::Shape
410 ( const Standard_Integer Index )const
411 {
412   if      ( Index == 1 ) return myShape1;
413   else if ( Index == 2 ) return myShape2;
414   
415   Standard_ProgramError::Raise("ShapeIntersector : no shape");
416   TopoDS_Shape* bid = new TopoDS_Shape();
417   return *bid;
418 }
419
420 //=======================================================================
421 //function : ChangeEdgesIntersector
422 //purpose  : 
423 //=======================================================================
424
425 TopOpeBRep_EdgesIntersector& 
426 TopOpeBRep_ShapeIntersector2d::ChangeEdgesIntersector()
427 { return myEEIntersector; }
428