b311480e |
1 | // Created on: 1993-05-07 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1993-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | #include <TopOpeBRep_ShapeIntersector2d.ixx> |
23 | |
24 | #include <Standard_ProgramError.hxx> |
25 | #include <Standard_NotImplemented.hxx> |
26 | #include <TopAbs.hxx> |
27 | #include <Bnd_Box.hxx> |
28 | #include <TopOpeBRepTool_box.hxx> |
29 | |
30 | #ifdef DEB |
31 | extern Standard_Boolean TopOpeBRep_GettraceSI(); |
32 | extern Standard_Boolean TopOpeBRep_GetcontextFFOR(); |
33 | #endif |
34 | |
35 | //======================================================================= |
36 | //function : TopOpeBRep_ShapeIntersector2d |
37 | //purpose : |
38 | //======================================================================= |
39 | |
40 | TopOpeBRep_ShapeIntersector2d::TopOpeBRep_ShapeIntersector2d() |
41 | { |
42 | Reset(); |
43 | myHBoxTool = FBOX_GetHBoxTool(); |
44 | myFaceScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool); |
45 | myEdgeScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : Reset |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | void TopOpeBRep_ShapeIntersector2d::Reset() |
54 | { |
55 | myIntersectionDone = Standard_False; |
56 | |
57 | myFFDone = Standard_False; |
58 | myEEFFDone = Standard_False; |
59 | |
60 | myFFInit = Standard_False; |
61 | myEEFFInit = Standard_False; |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : Init |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void TopOpeBRep_ShapeIntersector2d::Init |
70 | (const TopoDS_Shape& S1, const TopoDS_Shape& S2) |
71 | { |
72 | Reset(); |
73 | myShape1 = S1; |
74 | myShape2 = S2; |
75 | myHBoxTool->Clear(); |
76 | } |
77 | |
78 | //======================================================================= |
79 | //function : SetIntersectionDone |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | void TopOpeBRep_ShapeIntersector2d::SetIntersectionDone() |
84 | { |
85 | myIntersectionDone = (myFFDone || |
86 | myEEFFDone); |
87 | } |
88 | |
89 | |
90 | //======================================================================= |
91 | //function : CurrentGeomShape |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::CurrentGeomShape |
96 | (const Standard_Integer Index) const |
97 | { |
98 | if ( myIntersectionDone ) { |
99 | if (myFFDone) { |
100 | if ( Index == 1 ) return myFaceScanner.Current(); |
101 | else if ( Index == 2 ) return myFaceExplorer.Current(); |
102 | } |
103 | else if (myEEFFDone) { |
104 | if ( Index == 1 ) return myEdgeScanner.Current(); |
105 | else if ( Index == 2 ) return myEdgeExplorer.Current(); |
106 | } |
107 | } |
108 | |
109 | Standard_ProgramError::Raise("CurrentGeomShape : no intersection 2d"); |
110 | TopoDS_Shape* bid = new TopoDS_Shape(); |
111 | return *bid; |
112 | } |
113 | |
114 | |
115 | //======================================================================= |
116 | //function : InitIntersection |
117 | //purpose : |
118 | //======================================================================= |
119 | |
120 | void TopOpeBRep_ShapeIntersector2d::InitIntersection |
121 | (const TopoDS_Shape& S1, const TopoDS_Shape& S2) |
122 | { |
123 | Init(S1,S2); |
124 | InitFFIntersection(); |
125 | } |
126 | |
127 | |
128 | //======================================================================= |
129 | //function : MoreIntersection |
130 | //purpose : |
131 | //======================================================================= |
132 | |
133 | Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreIntersection() const |
134 | { |
135 | Standard_Boolean res = myIntersectionDone; |
136 | |
137 | #ifdef DEB |
7fd59977 |
138 | if (TopOpeBRep_GettraceSI() && res) { |
139 | if ( myFFDone ) cout<<"FF : "; |
140 | else if ( myEEFFDone ) cout<<" EE : "; |
141 | DumpCurrent(1); |
142 | DumpCurrent(2); |
143 | } |
144 | #endif |
145 | |
146 | return res; |
147 | } |
148 | |
149 | |
150 | //======================================================================= |
151 | //function : DumpCurrent |
152 | //purpose : |
153 | //======================================================================= |
154 | |
498ce76b |
155 | #ifdef DEB |
7fd59977 |
156 | void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer K) const |
157 | { |
7fd59977 |
158 | if ( myFFDone ) { |
159 | if ( K == 1 ) myFaceScanner.DumpCurrent(cout); |
160 | else if ( K == 2 ) myFaceExplorer.DumpCurrent(cout); |
161 | } |
162 | else if ( myEEFFDone ) { |
163 | if ( K == 1 ) myEdgeScanner.DumpCurrent(cout); |
164 | else if ( K == 2 ) myEdgeExplorer.DumpCurrent(cout); |
165 | } |
498ce76b |
166 | #else |
167 | void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer) const |
168 | { |
7fd59977 |
169 | #endif |
170 | } |
171 | |
172 | //======================================================================= |
173 | //function : Index |
174 | //purpose : |
175 | //======================================================================= |
176 | |
498ce76b |
177 | #ifdef DEB |
7fd59977 |
178 | Standard_Integer TopOpeBRep_ShapeIntersector2d::Index |
179 | (const Standard_Integer K)const |
180 | { |
181 | Standard_Integer i = 0; |
498ce76b |
182 | |
7fd59977 |
183 | if ( myFFDone ) { |
184 | if ( K == 1 ) i = myFaceScanner.Index(); |
185 | else if ( K == 2 ) i = myFaceExplorer.Index(); |
186 | } |
187 | else if ( myEEFFDone ) { |
188 | if ( K == 1 ) i = myEdgeScanner.Index(); |
189 | else if ( K == 2 ) i = myEdgeExplorer.Index(); |
190 | } |
498ce76b |
191 | |
7fd59977 |
192 | return i; |
193 | } |
498ce76b |
194 | #else |
195 | Standard_Integer TopOpeBRep_ShapeIntersector2d::Index (const Standard_Integer)const { return 0;} |
196 | #endif |
7fd59977 |
197 | |
198 | |
199 | //======================================================================= |
200 | //function : NextIntersection |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | void TopOpeBRep_ShapeIntersector2d::NextIntersection() |
205 | { |
206 | myIntersectionDone = Standard_False; |
207 | |
208 | if (myFFDone) { |
209 | // precedant etat du More() : 2 faces |
210 | myFFDone = Standard_False; |
211 | InitEEFFIntersection(); |
212 | FindEEFFIntersection(); |
213 | if ( !myIntersectionDone ) { |
214 | NextFFCouple(); |
215 | FindFFIntersection(); |
216 | } |
217 | } |
218 | else if ( myEEFFDone ) { |
219 | NextEEFFCouple(); |
220 | FindEEFFIntersection(); |
221 | if ( !myIntersectionDone ) { |
222 | NextFFCouple(); |
223 | FindFFIntersection(); |
224 | } |
225 | } |
226 | |
227 | if ( !myIntersectionDone ) { |
228 | InitFFIntersection(); |
229 | } |
230 | } |
231 | |
232 | |
233 | // ======== |
234 | // FFFFFFFF |
235 | // ======== |
236 | |
237 | |
238 | //======================================================================= |
239 | //function : InitFFIntersection |
240 | //purpose : |
241 | //======================================================================= |
242 | |
243 | void TopOpeBRep_ShapeIntersector2d::InitFFIntersection() |
244 | { |
245 | if ( !myFFInit) { |
246 | TopAbs_ShapeEnum tscann = TopAbs_FACE; |
247 | TopAbs_ShapeEnum texplo = TopAbs_FACE; |
248 | myFaceScanner.Clear(); |
249 | myFaceScanner.AddBoxesMakeCOB(myShape1,tscann); |
250 | myFaceExplorer.Init(myShape2,texplo); |
251 | myFaceScanner.Init(myFaceExplorer); |
252 | FindFFIntersection(); |
253 | } |
254 | myFFInit = Standard_True; |
255 | } |
256 | |
257 | |
258 | //======================================================================= |
259 | //function : FindFFIntersection |
260 | //purpose : |
261 | //======================================================================= |
262 | |
263 | void TopOpeBRep_ShapeIntersector2d::FindFFIntersection() |
264 | { |
265 | myFFDone = Standard_False; |
266 | // myFFSameDomain = Standard_False; |
267 | |
4e76d93b |
268 | if ( MoreFFCouple() ) { |
7fd59977 |
269 | |
270 | // The two candidate intersecting GeomShapes GS1,GS2 and their types t1,t2 |
271 | const TopoDS_Shape& GS1 = myFaceScanner.Current(); |
272 | const TopoDS_Shape& GS2 = myFaceExplorer.Current(); |
273 | |
274 | #ifdef DEB |
275 | if (TopOpeBRep_GettraceSI()) { |
7fd59977 |
276 | cout<<"?? FF : "; |
277 | myFaceScanner.DumpCurrent(cout); |
278 | myFaceExplorer.DumpCurrent(cout); |
279 | cout<<endl; |
280 | } |
281 | #endif |
282 | |
283 | const TopOpeBRepTool_BoxSort& BS = myFaceScanner.BoxSort(); |
6e6cd5d9 |
284 | BS.Box(GS1); |
285 | BS.Box(GS2); |
7fd59977 |
286 | myFFDone = Standard_True; |
7fd59977 |
287 | } |
288 | |
289 | SetIntersectionDone(); |
290 | } |
291 | |
292 | |
293 | //======================================================================= |
294 | //function : MoreFFCouple |
295 | //purpose : |
296 | //======================================================================= |
297 | |
298 | Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreFFCouple() const |
299 | { |
300 | Standard_Boolean more1 = myFaceScanner.More(); |
301 | Standard_Boolean more2 = myFaceExplorer.More(); |
302 | return (more1 && more2); |
303 | } |
304 | |
305 | |
306 | //======================================================================= |
307 | //function : NextFFCouple |
308 | //purpose : |
309 | //======================================================================= |
310 | |
311 | void TopOpeBRep_ShapeIntersector2d::NextFFCouple() |
312 | { |
313 | myFaceScanner.Next(); |
314 | Standard_Boolean b1,b2; |
315 | |
316 | b1 = (!myFaceScanner.More()); |
317 | b2 = (myFaceExplorer.More()); |
318 | while ( b1 && b2 ) { |
319 | myFaceExplorer.Next(); |
320 | myFaceScanner.Init(myFaceExplorer); |
321 | b1 = (!myFaceScanner.More()); |
322 | b2 = (myFaceExplorer.More()); |
323 | } |
324 | |
325 | } |
326 | |
327 | |
328 | // ======== |
329 | // EEFFEEFF |
330 | // ======== |
331 | |
332 | |
333 | //======================================================================= |
334 | //function : InitEEFFIntersection |
335 | //purpose : |
336 | //======================================================================= |
337 | |
338 | void TopOpeBRep_ShapeIntersector2d::InitEEFFIntersection() |
339 | { |
340 | // prepare exploration of the edges of the two current SameDomain faces |
341 | TopoDS_Shape face1 = myFaceScanner.Current(); // -26-08-96 |
342 | TopoDS_Shape face2 = myFaceExplorer.Current(); // -26-08-96 |
343 | |
344 | #ifdef DEB |
345 | if (TopOpeBRep_GetcontextFFOR()) { |
346 | face1.Orientation(TopAbs_FORWARD); //-05/07 |
347 | face2.Orientation(TopAbs_FORWARD); //-05/07 |
348 | cout<<"ctx : InitEEFFIntersection : faces FORWARD"<<endl; |
349 | } |
350 | #endif |
351 | |
352 | myEEIntersector.SetFaces(face1,face2); |
353 | |
354 | TopAbs_ShapeEnum tscann = TopAbs_EDGE; |
355 | TopAbs_ShapeEnum texplo = TopAbs_EDGE; |
356 | myEdgeScanner.Clear(); |
357 | myEdgeScanner.AddBoxesMakeCOB(face1,tscann); |
358 | myEdgeExplorer.Init(face2,texplo); |
359 | myEdgeScanner.Init(myEdgeExplorer); |
360 | |
361 | myEEFFInit = Standard_True; |
362 | } |
363 | |
364 | |
365 | //======================================================================= |
366 | //function : FindEEFFIntersection |
367 | //purpose : |
368 | //======================================================================= |
369 | |
370 | void TopOpeBRep_ShapeIntersector2d::FindEEFFIntersection() |
371 | { |
372 | myEEFFDone = Standard_False; |
373 | while ( MoreEEFFCouple() ) { |
374 | const TopoDS_Shape& GS1 = myEdgeScanner.Current(); |
375 | const TopoDS_Shape& GS2 = myEdgeExplorer.Current(); |
376 | myEEIntersector.Perform(GS1,GS2); |
377 | |
378 | #ifdef DEB |
7fd59977 |
379 | if (TopOpeBRep_GettraceSI() && myEEIntersector.IsEmpty()) { |
380 | cout<<" EE : "; |
381 | myEdgeScanner.DumpCurrent(cout); |
382 | myEdgeExplorer.DumpCurrent(cout); |
383 | cout<<"(EE of FF SameDomain)"; |
384 | cout<<" : EMPTY INTERSECTION"; |
385 | cout<<endl; |
386 | } |
387 | #endif |
388 | |
389 | myEEFFDone = ! (myEEIntersector.IsEmpty()); |
390 | if (myEEFFDone) break; |
391 | else NextEEFFCouple(); |
392 | } |
393 | SetIntersectionDone(); |
394 | } |
395 | |
396 | |
397 | //======================================================================= |
398 | //function : MoreEEFFCouple |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreEEFFCouple() const |
403 | { |
404 | Standard_Boolean more1 = myEdgeScanner.More(); |
405 | Standard_Boolean more2 = myEdgeExplorer.More(); |
406 | return (more1 && more2); |
407 | } |
408 | |
409 | |
410 | //======================================================================= |
411 | //function : NextEEFFCouple |
412 | //purpose : |
413 | //======================================================================= |
414 | |
415 | void TopOpeBRep_ShapeIntersector2d::NextEEFFCouple() |
416 | { |
417 | myEdgeScanner.Next(); |
418 | while ( ! myEdgeScanner.More() && myEdgeExplorer.More() ) { |
419 | myEdgeExplorer.Next(); |
420 | myEdgeScanner.Init(myEdgeExplorer); |
421 | } |
422 | } |
423 | |
424 | |
425 | //======================================================================= |
426 | //function : Shape |
427 | //purpose : |
428 | //======================================================================= |
429 | |
430 | const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::Shape |
431 | ( const Standard_Integer Index )const |
432 | { |
433 | if ( Index == 1 ) return myShape1; |
434 | else if ( Index == 2 ) return myShape2; |
435 | |
436 | Standard_ProgramError::Raise("ShapeIntersector : no shape"); |
437 | TopoDS_Shape* bid = new TopoDS_Shape(); |
438 | return *bid; |
439 | } |
440 | |
441 | //======================================================================= |
442 | //function : ChangeEdgesIntersector |
443 | //purpose : |
444 | //======================================================================= |
445 | |
446 | TopOpeBRep_EdgesIntersector& |
447 | TopOpeBRep_ShapeIntersector2d::ChangeEdgesIntersector() |
448 | { return myEEIntersector; } |
449 | |