7fd59977 |
1 | // File: LocOpe_CSIntersector.lxx |
2 | // Created: Tue Jun 11 09:11:57 1996 |
3 | // Author: Jacques GOUSSARD |
4 | // <jag@bravox> |
5 | |
6 | |
7 | #include <LocOpe_CSIntersector.ixx> |
8 | |
9 | #include <LocOpe_PntFace.hxx> |
10 | #include <LocOpe_SequenceOfPntFace.hxx> |
11 | #include <TopExp_Explorer.hxx> |
12 | |
13 | #include <IntCurvesFace_Intersector.hxx> |
14 | #include <GeomAdaptor_HCurve.hxx> |
15 | #include <Geom_Circle.hxx> |
16 | |
17 | |
18 | #include <Standard_ConstructionError.hxx> |
19 | |
20 | #include <TopoDS.hxx> |
21 | #include <Precision.hxx> |
22 | |
23 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&, |
24 | const Standard_Real, |
25 | const Standard_Real, |
26 | TopAbs_Orientation&, |
27 | Standard_Integer&, |
28 | Standard_Integer&); |
29 | |
30 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&, |
31 | const Standard_Real, |
32 | const Standard_Real, |
33 | TopAbs_Orientation&, |
34 | Standard_Integer&, |
35 | Standard_Integer&); |
36 | |
37 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&, |
38 | const Standard_Integer, |
39 | const Standard_Real, |
40 | TopAbs_Orientation&, |
41 | Standard_Integer&, |
42 | Standard_Integer&); |
43 | |
44 | #ifdef DEB |
45 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&, |
46 | const Standard_Integer, |
47 | Standard_Integer&, |
48 | Standard_Integer&); |
49 | #endif |
50 | |
51 | |
52 | static void AddPoints(IntCurvesFace_Intersector&, |
53 | LocOpe_SequenceOfPntFace&, |
54 | const TopoDS_Face&); |
55 | |
56 | |
57 | |
58 | |
59 | //======================================================================= |
60 | //function : Init |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | void LocOpe_CSIntersector::Init(const TopoDS_Shape& S) |
65 | { |
66 | myDone = Standard_False; |
67 | myShape = S; |
68 | if (myPoints != NULL) { |
69 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
70 | myPoints = NULL; |
71 | } |
72 | myNbelem = 0; |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : Perform |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfLin& Slin) |
82 | { |
83 | if (myShape.IsNull() || Slin.Length() <= 0) { |
84 | Standard_ConstructionError::Raise(); |
85 | } |
86 | myDone = Standard_False; |
87 | |
88 | myNbelem = Slin.Length(); |
89 | if (myPoints != NULL) { |
90 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
91 | } |
92 | myPoints = |
93 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
94 | |
95 | Standard_Real binf = RealFirst(); |
96 | Standard_Real bsup = RealLast(); |
97 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
98 | for (; exp.More(); exp.Next()) { |
99 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
100 | IntCurvesFace_Intersector theInt(theface,Precision::PConfusion()); |
101 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
102 | theInt.Perform(Slin(i),binf,bsup); |
103 | if (theInt.IsDone()) { |
104 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
105 | } |
106 | } |
107 | } |
108 | myDone = Standard_True; |
109 | } |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : Perform |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfCirc& Scir) |
118 | { |
119 | if (myShape.IsNull() || Scir.Length() <= 0) { |
120 | Standard_ConstructionError::Raise(); |
121 | } |
122 | myDone = Standard_False; |
123 | |
124 | myNbelem = Scir.Length(); |
125 | if (myPoints != NULL) { |
126 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
127 | } |
128 | myPoints = |
129 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
130 | |
131 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
132 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve (); |
133 | Standard_Real binf = 0.; |
c6541a0c |
134 | Standard_Real bsup = 2.*M_PI; |
7fd59977 |
135 | |
136 | |
137 | for (; exp.More(); exp.Next()) { |
138 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
139 | IntCurvesFace_Intersector theInt(theface,0.); |
140 | #ifdef DEB |
141 | TopAbs_Orientation orface = |
142 | #endif |
143 | theface.Orientation(); |
144 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
145 | |
146 | HC->ChangeCurve().Load(new Geom_Circle(Scir(i))); |
147 | theInt.Perform(HC,binf,bsup); |
148 | if (theInt.IsDone()) { |
149 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
150 | } |
151 | } |
152 | } |
153 | myDone = Standard_True; |
154 | } |
155 | |
156 | |
157 | |
158 | //======================================================================= |
159 | //function : Perform |
160 | //purpose : |
161 | //======================================================================= |
162 | |
163 | void LocOpe_CSIntersector::Perform(const TColGeom_SequenceOfCurve& Scur) |
164 | { |
165 | if (myShape.IsNull() || Scur.Length() <= 0) { |
166 | Standard_ConstructionError::Raise(); |
167 | } |
168 | myDone = Standard_False; |
169 | |
170 | myNbelem = Scur.Length(); |
171 | if (myPoints != NULL) { |
172 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
173 | } |
174 | myPoints = |
175 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
176 | |
177 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
178 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve (); |
179 | for (; exp.More(); exp.Next()) { |
180 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
181 | IntCurvesFace_Intersector theInt(theface,0.); |
182 | #ifdef DEB |
183 | TopAbs_Orientation orface = |
184 | #endif |
185 | theface.Orientation(); |
186 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
187 | if (Scur(i).IsNull()) { |
188 | continue; |
189 | } |
190 | HC->ChangeCurve().Load(Scur(i)); |
191 | Standard_Real binf = HC->FirstParameter(); |
192 | Standard_Real bsup = HC->LastParameter(); |
193 | theInt.Perform(HC,binf,bsup); |
194 | if (theInt.IsDone()) { |
195 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
196 | } |
197 | } |
198 | } |
199 | myDone = Standard_True; |
200 | } |
201 | |
202 | |
203 | |
204 | //======================================================================= |
205 | //function : NbPoints |
206 | //purpose : |
207 | //======================================================================= |
208 | |
209 | Standard_Integer LocOpe_CSIntersector::NbPoints |
210 | (const Standard_Integer I) const |
211 | { |
212 | if (!myDone) {StdFail_NotDone::Raise();} |
213 | if (I <= 0 || I > myNbelem) { |
214 | Standard_OutOfRange::Raise(); |
215 | } |
216 | return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1].Length(); |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : Point |
221 | //purpose : |
222 | //======================================================================= |
223 | |
224 | const LocOpe_PntFace& LocOpe_CSIntersector:: |
225 | Point(const Standard_Integer I, |
226 | const Standard_Integer Index) const |
227 | { |
228 | if (!myDone) {StdFail_NotDone::Raise();} |
229 | if (I <= 0 || I > myNbelem) { |
230 | Standard_OutOfRange::Raise(); |
231 | } |
232 | return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1](Index); |
233 | } |
234 | |
235 | //======================================================================= |
236 | //function : Destroy |
237 | //purpose : |
238 | //======================================================================= |
239 | |
240 | void LocOpe_CSIntersector::Destroy() |
241 | { |
242 | if (myPoints != NULL) { |
243 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
244 | myPoints = NULL; |
245 | } |
246 | } |
247 | |
248 | |
249 | //======================================================================= |
250 | //function : LocalizeAfter |
251 | //purpose : |
252 | //======================================================================= |
253 | |
254 | Standard_Boolean LocOpe_CSIntersector::LocalizeAfter |
255 | (const Standard_Integer I, |
256 | const Standard_Real From, |
257 | const Standard_Real Tol, |
258 | TopAbs_Orientation& Or, |
259 | Standard_Integer& IndFrom, |
260 | Standard_Integer& IndTo) const |
261 | { |
262 | if (!myDone) { |
263 | StdFail_NotDone::Raise(); |
264 | } |
265 | if (I <= 0 || I > myNbelem) { |
266 | Standard_OutOfRange::Raise(); |
267 | } |
268 | return LocAfter((((LocOpe_SequenceOfPntFace*)myPoints)[I-1]), |
269 | From,Tol,Or,IndFrom,IndTo); |
270 | } |
271 | |
272 | |
273 | //======================================================================= |
274 | //function : LocalizeBefore |
275 | //purpose : |
276 | //======================================================================= |
277 | |
278 | Standard_Boolean LocOpe_CSIntersector::LocalizeBefore |
279 | (const Standard_Integer I, |
280 | const Standard_Real From, |
281 | const Standard_Real Tol, |
282 | TopAbs_Orientation& Or, |
283 | Standard_Integer& IndFrom, |
284 | Standard_Integer& IndTo) const |
285 | { |
286 | if (!myDone) { |
287 | StdFail_NotDone::Raise(); |
288 | } |
289 | if (I <= 0 || I > myNbelem) { |
290 | Standard_OutOfRange::Raise(); |
291 | } |
292 | return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
293 | From,Tol,Or,IndFrom,IndTo); |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : LocalizeAfter |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | Standard_Boolean LocOpe_CSIntersector::LocalizeAfter |
302 | (const Standard_Integer I, |
303 | const Standard_Integer FromInd, |
304 | const Standard_Real Tol, |
305 | TopAbs_Orientation& Or, |
306 | Standard_Integer& IndFrom, |
307 | Standard_Integer& IndTo) const |
308 | { |
309 | if (!myDone) { |
310 | StdFail_NotDone::Raise(); |
311 | } |
312 | if (I <= 0 || I > myNbelem) { |
313 | Standard_OutOfRange::Raise(); |
314 | } |
315 | return LocAfter(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
316 | FromInd,Tol,Or,IndFrom,IndTo); |
317 | |
318 | } |
319 | |
320 | //======================================================================= |
321 | //function : LocalizeBefore |
322 | //purpose : |
323 | //======================================================================= |
324 | |
325 | Standard_Boolean LocOpe_CSIntersector::LocalizeBefore |
326 | (const Standard_Integer I, |
327 | const Standard_Integer FromInd, |
328 | const Standard_Real Tol, |
329 | TopAbs_Orientation& Or, |
330 | Standard_Integer& IndFrom, |
331 | Standard_Integer& IndTo) const |
332 | { |
333 | if (!myDone) { |
334 | StdFail_NotDone::Raise(); |
335 | } |
336 | if (I <= 0 || I > myNbelem) { |
337 | Standard_OutOfRange::Raise(); |
338 | } |
339 | return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
340 | FromInd,Tol,Or,IndFrom,IndTo); |
341 | |
342 | } |
343 | |
344 | |
345 | |
346 | |
347 | //======================================================================= |
348 | //function : LocAfter |
349 | //purpose : |
350 | //======================================================================= |
351 | |
352 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt, |
353 | const Standard_Real From, |
354 | const Standard_Real Tol, |
355 | TopAbs_Orientation& Or, |
356 | Standard_Integer& IndFrom, |
357 | Standard_Integer& IndTo) |
358 | { |
359 | |
360 | Standard_Real param,FMEPS = From - Tol; |
361 | Standard_Integer i,ifirst,nbpoints = Spt.Length(); |
362 | for (ifirst=1; ifirst<=nbpoints; ifirst++) { |
363 | if (Spt(ifirst).Parameter() >= FMEPS) { |
364 | break; |
365 | } |
366 | } |
367 | Standard_Boolean RetVal = Standard_False; |
368 | if (ifirst <= nbpoints) { |
369 | i = ifirst; |
370 | IndFrom = ifirst; |
371 | Standard_Boolean found = Standard_False; |
372 | while (!found) { |
373 | Or = Spt(i).Orientation(); |
374 | param = Spt(i).Parameter(); |
375 | i = i+1; |
376 | while (i<=nbpoints) { |
377 | if (Spt(i).Parameter()-param <= Tol) { |
378 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
379 | Or = TopAbs_EXTERNAL; |
380 | } |
381 | i++; |
382 | } |
383 | else { |
384 | break; |
385 | } |
386 | } |
387 | if (Or == TopAbs_EXTERNAL) { |
388 | found = (i > nbpoints); |
389 | IndFrom = i; |
390 | } |
391 | else { // on a une intersection franche |
392 | IndTo = i-1; |
393 | found = Standard_True; |
394 | RetVal = Standard_True; |
395 | } |
396 | } |
397 | } |
398 | |
399 | return RetVal; |
400 | } |
401 | |
402 | //======================================================================= |
403 | //function : LocBefore |
404 | //purpose : |
405 | //======================================================================= |
406 | |
407 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace& Spt, |
408 | const Standard_Real From, |
409 | const Standard_Real Tol, |
410 | TopAbs_Orientation& Or, |
411 | Standard_Integer& IndFrom, |
412 | Standard_Integer& IndTo) |
413 | { |
414 | Standard_Real param,FPEPS = From + Tol; |
415 | Standard_Integer i,ifirst,nbpoints = Spt.Length(); |
416 | for (ifirst=nbpoints; ifirst>=1; ifirst--) { |
417 | if (Spt(ifirst).Parameter() <= FPEPS) { |
418 | break; |
419 | } |
420 | } |
421 | Standard_Boolean RetVal = Standard_False; |
422 | if (ifirst >= 1) { |
423 | i = ifirst; |
424 | IndTo = ifirst; |
425 | Standard_Boolean found = Standard_False; |
426 | while (!found) { |
427 | Or = Spt(i).Orientation(); |
428 | param = Spt(i).Parameter(); |
429 | i = i-1; |
430 | while (i>=1) { |
431 | if (param - Spt(i).Parameter() <= Tol) { |
432 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
433 | Or = TopAbs_EXTERNAL; |
434 | } |
435 | i--; |
436 | } |
437 | else { |
438 | break; |
439 | } |
440 | } |
441 | if (Or == TopAbs_EXTERNAL) { |
442 | found = (i < 1); |
443 | IndTo = i; |
444 | } |
445 | else { // on a une intersection franche |
446 | IndFrom = i+1; |
447 | found = Standard_True; |
448 | RetVal = Standard_True; |
449 | } |
450 | } |
451 | } |
452 | |
453 | return RetVal; |
454 | } |
455 | |
456 | //======================================================================= |
457 | //function : LocAfter |
458 | //purpose : |
459 | //======================================================================= |
460 | |
461 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt, |
462 | const Standard_Integer FromInd, |
463 | const Standard_Real Tol, |
464 | TopAbs_Orientation& Or, |
465 | Standard_Integer& IndFrom, |
466 | Standard_Integer& IndTo) |
467 | { |
468 | Standard_Integer nbpoints = Spt.Length(); |
469 | if (FromInd >= nbpoints) { |
470 | return Standard_False; |
471 | } |
472 | |
473 | Standard_Real param,FMEPS; |
474 | Standard_Integer i,ifirst; |
475 | if (FromInd >= 1) { |
476 | FMEPS = Spt(FromInd).Parameter() - Tol; |
477 | for (ifirst=FromInd+1; ifirst<=nbpoints; ifirst++) { |
478 | if (Spt(ifirst).Parameter() >= FMEPS) { |
479 | break; |
480 | } |
481 | } |
482 | } |
483 | else { |
484 | ifirst = 1; |
485 | } |
486 | |
487 | Standard_Boolean RetVal = Standard_False; |
488 | if (ifirst <= nbpoints) { |
489 | i = ifirst; |
490 | IndFrom = ifirst; |
491 | Standard_Boolean found = Standard_False; |
492 | while (!found) { |
493 | Or = Spt(i).Orientation(); |
494 | param = Spt(i).Parameter(); |
495 | i = i+1; |
496 | while (i<=nbpoints) { |
497 | if (Spt(i).Parameter()-param <= Tol) { |
498 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
499 | Or = TopAbs_EXTERNAL; |
500 | } |
501 | i++; |
502 | } |
503 | else { |
504 | break; |
505 | } |
506 | } |
507 | if (Or == TopAbs_EXTERNAL) { |
508 | found = (i > nbpoints); |
509 | IndFrom = i; |
510 | } |
511 | else { // on a une intersection franche |
512 | IndTo = i-1; |
513 | found = Standard_True; |
514 | RetVal = Standard_True; |
515 | } |
516 | } |
517 | } |
518 | return RetVal; |
519 | } |
520 | |
521 | |
522 | //======================================================================= |
523 | //function : LocBefore |
524 | //purpose : |
525 | //======================================================================= |
526 | |
527 | #ifdef DEB |
528 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace& Spt, |
529 | const Standard_Integer FromInd, |
530 | const Standard_Real Tol, |
531 | TopAbs_Orientation& Or, |
532 | Standard_Integer& IndFrom, |
533 | Standard_Integer& IndTo) |
534 | { |
535 | Standard_Integer nbpoints = Spt.Length(); |
536 | if (FromInd <= 1) { |
537 | return Standard_False; |
538 | } |
539 | |
540 | Standard_Real param,FPEPS; |
541 | Standard_Integer i,ifirst; |
542 | if (FromInd <= nbpoints) { |
543 | FPEPS = Spt(FromInd).Parameter() + Tol; |
544 | for (ifirst=FromInd-1; ifirst>=1; ifirst--) { |
545 | if (Spt(ifirst).Parameter() <= FPEPS) { |
546 | break; |
547 | } |
548 | } |
549 | } |
550 | else { |
551 | ifirst = nbpoints; |
552 | } |
553 | |
554 | Standard_Boolean RetVal = Standard_False; |
555 | if (ifirst >= 1) { |
556 | i = ifirst; |
557 | IndTo = ifirst; |
558 | Standard_Boolean found = Standard_False; |
559 | while (!found) { |
560 | Or = Spt(i).Orientation(); |
561 | param = Spt(i).Parameter(); |
562 | i = i-1; |
563 | while (i>=1) { |
564 | if (param - Spt(i).Parameter() <= Tol) { |
565 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
566 | Or = TopAbs_EXTERNAL; |
567 | } |
568 | i--; |
569 | } |
570 | else { |
571 | break; |
572 | } |
573 | } |
574 | if (Or == TopAbs_EXTERNAL) { |
575 | found = (i < 1); |
576 | IndTo = i; |
577 | } |
578 | else { // on a une intersection franche |
579 | IndFrom = i+1; |
580 | found = Standard_True; |
581 | RetVal = Standard_True; |
582 | } |
583 | } |
584 | } |
585 | return RetVal; |
586 | } |
587 | #endif |
588 | |
589 | |
590 | //======================================================================= |
591 | //function : AddPoints |
592 | //purpose : |
593 | //======================================================================= |
594 | |
595 | static void AddPoints(IntCurvesFace_Intersector& theInt, |
596 | LocOpe_SequenceOfPntFace& theSeq, |
597 | const TopoDS_Face& theface) |
598 | { |
599 | Standard_Integer nbpoints = theSeq.Length(); |
600 | Standard_Integer newpnt = theInt.NbPnt(); |
601 | Standard_Real param,paramu,paramv; |
602 | #ifdef DEB |
603 | TopAbs_Orientation orface = |
604 | #endif |
605 | theface.Orientation(); |
606 | for (Standard_Integer j = 1; j<=newpnt; j++) { |
607 | const gp_Pnt& thept = theInt.Pnt(j); |
608 | param = theInt.WParameter(j); |
609 | paramu = theInt.UParameter(j); |
610 | paramv = theInt.VParameter(j); |
611 | #ifdef DEB |
612 | TopAbs_Orientation theor; |
613 | #else |
614 | TopAbs_Orientation theor=TopAbs_FORWARD; |
615 | #endif |
616 | switch (theInt.Transition(j)) { |
617 | case IntCurveSurface_In: |
618 | /* JAG 13.09.96 |
619 | if ( orface == TopAbs_FORWARD) { |
620 | theor = TopAbs_FORWARD; |
621 | } |
622 | else if (orface == TopAbs_REVERSED) { |
623 | theor = TopAbs_REVERSED; |
624 | } |
625 | else { |
626 | theor = TopAbs_EXTERNAL; |
627 | } |
628 | */ |
629 | theor = TopAbs_FORWARD; |
630 | |
631 | break; |
632 | case IntCurveSurface_Out: |
633 | /* JAG 13.09.96 |
634 | if ( orface == TopAbs_FORWARD) { |
635 | theor = TopAbs_REVERSED; |
636 | } |
637 | else if (orface == TopAbs_REVERSED) { |
638 | theor = TopAbs_FORWARD; |
639 | } |
640 | else { |
641 | theor = TopAbs_EXTERNAL; |
642 | } |
643 | */ |
644 | theor = TopAbs_REVERSED; |
645 | break; |
646 | case IntCurveSurface_Tangent: |
647 | theor = TopAbs_EXTERNAL; |
648 | break; |
649 | |
650 | } |
651 | LocOpe_PntFace newpt(thept,theface,theor,param,paramu,paramv); |
652 | // for (Standard_Integer k=1; k <= nbpoints; k++) { |
653 | Standard_Integer k; |
654 | for ( k=1; k <= nbpoints; k++) { |
655 | if (theSeq(k).Parameter() - param > 0.) { |
656 | break; |
657 | } |
658 | } |
659 | if (k <= nbpoints) { |
660 | theSeq.InsertBefore(k,newpt); |
661 | } |
662 | else { |
663 | theSeq.Append(newpt); |
664 | } |
665 | nbpoints++; |
666 | } |
667 | } |