1 //-----------------------------
2 //-- IntWalk_PWalking_1.gxx
5 #include <Precision.hxx>
6 #include <math_FunctionSetRoot.hxx>
10 //==================================================================================
11 // function : IntWalk_PWalking::IntWalk_PWalking
13 // estimation des max pas : Pour eviter des changenets
14 // trop brusques lors des changements d isos
15 //==================================================================================
16 void ComputePasInit(Standard_Real *pasuv,
17 Standard_Real Um1,Standard_Real UM1,
18 Standard_Real Vm1,Standard_Real VM1,
19 Standard_Real Um2,Standard_Real UM2,
20 Standard_Real Vm2,Standard_Real VM2,
21 Standard_Real _Um1,Standard_Real _UM1,
22 Standard_Real _Vm1,Standard_Real _VM1,
23 Standard_Real _Um2,Standard_Real _UM2,
24 Standard_Real _Vm2,Standard_Real _VM2,
27 const Standard_Real Increment)
29 Standard_Real du1=Abs(UM1-Um1);
30 Standard_Real dv1=Abs(VM1-Vm1);
31 Standard_Real du2=Abs(UM2-Um2);
32 Standard_Real dv2=Abs(VM2-Vm2);
34 Standard_Real _du1=Abs(_UM1-_Um1);
35 Standard_Real _dv1=Abs(_VM1-_Vm1);
36 Standard_Real _du2=Abs(_UM2-_Um2);
37 Standard_Real _dv2=Abs(_VM2-_Vm2);
39 //-- On limite la reduction de l estimation de la boite uv a 0.01 la boite naturelle
40 //-- du1 : Sur boite des Inter
41 //-- _du1 : Sur espace parametrique
42 if(_du1<1e50 && du1<0.01*_du1) du1=0.01*_du1;
43 if(_dv1<1e50 && dv1<0.01*_dv1) dv1=0.01*_dv1;
44 if(_du2<1e50 && du2<0.01*_du2) du2=0.01*_du2;
45 if(_dv2<1e50 && dv2<0.01*_dv2) dv2=0.01*_dv2;
47 pasuv[0]=Increment*du1;
48 pasuv[1]=Increment*dv1;
49 pasuv[2]=Increment*du2;
50 pasuv[3]=Increment*dv2;
52 //==================================================================================
53 // function : IntWalk_PWalking::IntWalk_PWalking
55 //==================================================================================
56 IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
57 const ThePSurface& Caro2,
58 const Standard_Real TolTangency,
59 const Standard_Real Epsilon,
60 const Standard_Real Deflection,
61 const Standard_Real Increment )
65 close(Standard_False),
69 myIntersectionOn2S(Caro1,Caro2,TolTangency)
71 Standard_Real KELARG=20.;
73 pasMax=Increment*0.2; //-- le 25 juin 99 suite a des pbs de precision
74 Um1 = ThePSurfaceTool::FirstUParameter(Caro1);
75 Vm1 = ThePSurfaceTool::FirstVParameter(Caro1);
76 UM1 = ThePSurfaceTool::LastUParameter(Caro1);
77 VM1 = ThePSurfaceTool::LastVParameter(Caro1);
79 Um2 = ThePSurfaceTool::FirstUParameter(Caro2);
80 Vm2 = ThePSurfaceTool::FirstVParameter(Caro2);
81 UM2 = ThePSurfaceTool::LastUParameter(Caro2);
82 VM2 = ThePSurfaceTool::LastVParameter(Caro2);
84 ResoU1 = ThePSurfaceTool::UResolution(Caro1,Precision::Confusion());
85 ResoV1 = ThePSurfaceTool::VResolution(Caro1,Precision::Confusion());
87 ResoU2 = ThePSurfaceTool::UResolution(Caro2,Precision::Confusion());
88 ResoV2 = ThePSurfaceTool::VResolution(Caro2,Precision::Confusion());
90 Standard_Real NEWRESO;
92 Standard_Real MAXVAL2;
94 MAXVAL = Abs(Um1); MAXVAL2 = Abs(UM1);
95 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
96 NEWRESO = ResoU1 * MAXVAL ;
97 if(NEWRESO > ResoU1 &&NEWRESO<10) { ResoU1 = NEWRESO; }
100 MAXVAL = Abs(Um2); MAXVAL2 = Abs(UM2);
101 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
102 NEWRESO = ResoU2 * MAXVAL ;
103 if(NEWRESO > ResoU2 && NEWRESO<10) { ResoU2 = NEWRESO; }
106 MAXVAL = Abs(Vm1); MAXVAL2 = Abs(VM1);
107 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
108 NEWRESO = ResoV1 * MAXVAL ;
109 if(NEWRESO > ResoV1 && NEWRESO<10) { ResoV1 = NEWRESO; }
112 MAXVAL = Abs(Vm2); MAXVAL2 = Abs(VM2);
113 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
114 NEWRESO = ResoV2 * MAXVAL ;
115 if(NEWRESO > ResoV2 && NEWRESO<10) { ResoV2 = NEWRESO; }
117 pasuv[0]=pasMax*Abs(UM1-Um1);
118 pasuv[1]=pasMax*Abs(VM1-Vm1);
119 pasuv[2]=pasMax*Abs(UM2-Um2);
120 pasuv[3]=pasMax*Abs(VM2-Vm2);
122 if(ResoU1>0.0001*pasuv[0]) ResoU1=0.00001*pasuv[0];
123 if(ResoV1>0.0001*pasuv[1]) ResoV1=0.00001*pasuv[1];
124 if(ResoU2>0.0001*pasuv[2]) ResoU2=0.00001*pasuv[2];
125 if(ResoV2>0.0001*pasuv[3]) ResoV2=0.00001*pasuv[3];
128 if(ThePSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
129 UM1+=KELARG*pasuv[0]; Um1-=KELARG*pasuv[0];
132 Standard_Real t = UM1-Um1;
133 if(t<ThePSurfaceTool::UPeriod(Caro1)) {
134 t=0.5*(ThePSurfaceTool::UPeriod(Caro1)-t);
135 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
140 if(ThePSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
141 VM1+=KELARG*pasuv[1]; Vm1-=KELARG*pasuv[1];
144 Standard_Real t = VM1-Vm1;
145 if(t<ThePSurfaceTool::VPeriod(Caro1)) {
146 t=0.5*(ThePSurfaceTool::VPeriod(Caro1)-t);
147 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
152 if(ThePSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
153 UM2+=KELARG*pasuv[2]; Um2-=KELARG*pasuv[2];
156 Standard_Real t = UM2-Um2;
157 if(t<ThePSurfaceTool::UPeriod(Caro2)) {
158 t=0.5*(ThePSurfaceTool::UPeriod(Caro2)-t);
159 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
164 if(ThePSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
165 VM2+=KELARG*pasuv[3]; Vm2-=KELARG*pasuv[3];
168 Standard_Real t = VM2-Vm2;
169 if(t<ThePSurfaceTool::VPeriod(Caro2)) {
170 t=0.5*(ThePSurfaceTool::VPeriod(Caro2)-t);
171 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
176 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
178 for (Standard_Integer i = 0; i<=3;i++) {
181 pasInit[i] = pasSav[i] = pasuv[i];
186 //==================================================================================
187 // function : IntWalk_PWalking
189 //==================================================================================
190 IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
191 const ThePSurface& Caro2,
192 const Standard_Real TolTangency,
193 const Standard_Real Epsilon,
194 const Standard_Real Deflection,
195 const Standard_Real Increment,
196 const Standard_Real U1,
197 const Standard_Real V1,
198 const Standard_Real U2,
199 const Standard_Real V2)
203 close(Standard_False),
207 myIntersectionOn2S(Caro1,Caro2,TolTangency)
209 Standard_Real KELARG=20.;
211 pasMax=Increment*0.2; //-- le 25 juin 99 suite a des pbs de precision
213 Um1 = ThePSurfaceTool::FirstUParameter(Caro1);
214 Vm1 = ThePSurfaceTool::FirstVParameter(Caro1);
215 UM1 = ThePSurfaceTool::LastUParameter(Caro1);
216 VM1 = ThePSurfaceTool::LastVParameter(Caro1);
218 Um2 = ThePSurfaceTool::FirstUParameter(Caro2);
219 Vm2 = ThePSurfaceTool::FirstVParameter(Caro2);
220 UM2 = ThePSurfaceTool::LastUParameter(Caro2);
221 VM2 = ThePSurfaceTool::LastVParameter(Caro2);
223 ResoU1 = ThePSurfaceTool::UResolution(Caro1,Precision::Confusion());
224 ResoV1 = ThePSurfaceTool::VResolution(Caro1,Precision::Confusion());
226 ResoU2 = ThePSurfaceTool::UResolution(Caro2,Precision::Confusion());
227 ResoV2 = ThePSurfaceTool::VResolution(Caro2,Precision::Confusion());
229 Standard_Real NEWRESO, MAXVAL, MAXVAL2;
233 if(MAXVAL2 > MAXVAL) {
236 NEWRESO = ResoU1 * MAXVAL ;
237 if(NEWRESO > ResoU1) {
243 if(MAXVAL2 > MAXVAL){
246 NEWRESO = ResoU2 * MAXVAL ;
247 if(NEWRESO > ResoU2) {
253 if(MAXVAL2 > MAXVAL) {
256 NEWRESO = ResoV1 * MAXVAL ;
257 if(NEWRESO > ResoV1) {
263 if(MAXVAL2 > MAXVAL){
266 NEWRESO = ResoV2 * MAXVAL ;
267 if(NEWRESO > ResoV2) {
271 pasuv[0]=pasMax*Abs(UM1-Um1);
272 pasuv[1]=pasMax*Abs(VM1-Vm1);
273 pasuv[2]=pasMax*Abs(UM2-Um2);
274 pasuv[3]=pasMax*Abs(VM2-Vm2);
276 if(ThePSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
277 UM1+=KELARG*pasuv[0];
278 Um1-=KELARG*pasuv[0];
281 Standard_Real t = UM1-Um1;
282 if(t<ThePSurfaceTool::UPeriod(Caro1)) {
283 t=0.5*(ThePSurfaceTool::UPeriod(Caro1)-t);
284 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
290 if(ThePSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
291 VM1+=KELARG*pasuv[1];
292 Vm1-=KELARG*pasuv[1];
295 Standard_Real t = VM1-Vm1;
296 if(t<ThePSurfaceTool::VPeriod(Caro1)) {
297 t=0.5*(ThePSurfaceTool::VPeriod(Caro1)-t);
298 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
303 if(ThePSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
304 UM2+=KELARG*pasuv[2];
305 Um2-=KELARG*pasuv[2];
308 Standard_Real t = UM2-Um2;
309 if(t<ThePSurfaceTool::UPeriod(Caro2)) {
310 t=0.5*(ThePSurfaceTool::UPeriod(Caro2)-t);
311 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
317 if(ThePSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
318 VM2+=KELARG*pasuv[3];
319 Vm2-=KELARG*pasuv[3];
322 Standard_Real t = VM2-Vm2;
323 if(t<ThePSurfaceTool::UPeriod(Caro2)) {
324 t=0.5*(ThePSurfaceTool::VPeriod(Caro2)-t);
325 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
330 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
332 for (Standard_Integer i = 0; i<=3;i++) {
333 pasInit[i] = pasSav[i] = pasuv[i];
336 if(ResoU1>0.0001*pasuv[0]) ResoU1=0.00001*pasuv[0];
337 if(ResoV1>0.0001*pasuv[1]) ResoV1=0.00001*pasuv[1];
338 if(ResoU2>0.0001*pasuv[2]) ResoU2=0.00001*pasuv[2];
339 if(ResoV2>0.0001*pasuv[3]) ResoV2=0.00001*pasuv[3];
341 TColStd_Array1OfReal Par(1,4);
349 //==================================================================================
350 // function : PerformFirstPoint
352 //==================================================================================
353 Standard_Boolean IntWalk_PWalking::PerformFirstPoint (const TColStd_Array1OfReal& ParDep,
354 IntSurf_PntOn2S& FirstPoint)
357 close = Standard_False;
361 TColStd_Array1OfReal Param(1,4);
363 for (i=1; i<=4; ++i) {
365 Param(i) = ParDep(i);
367 //-- calcul du premier point solution
368 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
370 myIntersectionOn2S.Perform(Param,Rsnld);
371 if (!myIntersectionOn2S.IsDone()) {
372 return Standard_False;
374 if (myIntersectionOn2S.IsEmpty()) {
375 return Standard_False;
377 FirstPoint = myIntersectionOn2S.Point();
378 return Standard_True;
380 //==================================================================================
381 // function : Perform
383 //==================================================================================
384 void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep)
386 Perform(ParDep,Um1,Vm1,Um2,Vm2,UM1,VM1,UM2,VM2);
388 //==================================================================================
389 // function : Perform
391 //==================================================================================
392 void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
393 const Standard_Real u1min,
394 const Standard_Real v1min,
395 const Standard_Real u2min,
396 const Standard_Real v2min,
397 const Standard_Real u1max,
398 const Standard_Real v1max,
399 const Standard_Real u2max,
400 const Standard_Real v2max)
403 Standard_Integer i, NbPasOKConseq;
404 Standard_Real UFirst1, VFirst1, ULast1, VLast1, UFirst2, VFirst2, ULast2, VLast2;
405 Standard_Real pasMaxSV[4], aTmp;
406 TColStd_Array1OfReal Param(1,4);
407 IntImp_ConstIsoparametric ChoixIso;
410 done = Standard_False;
414 const ThePSurface& Caro1 =myIntersectionOn2S.Function().AuxillarSurface1();
415 const ThePSurface& Caro2 =myIntersectionOn2S.Function().AuxillarSurface2();
417 UFirst1 = ThePSurfaceTool::FirstUParameter(Caro1);
418 VFirst1 = ThePSurfaceTool::FirstVParameter(Caro1);
419 ULast1 = ThePSurfaceTool::LastUParameter (Caro1);
420 VLast1 = ThePSurfaceTool::LastVParameter (Caro1);
422 UFirst2 = ThePSurfaceTool::FirstUParameter(Caro2);
423 VFirst2 = ThePSurfaceTool::FirstVParameter(Caro2);
424 ULast2 = ThePSurfaceTool::LastUParameter (Caro2);
425 VLast2 = ThePSurfaceTool::LastVParameter (Caro2);
427 ComputePasInit(pasuv,u1min,u1max,v1min,v1max,u2min,u2max,v2min,v2max,
428 Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2,pasMax+pasMax);
430 if(pasuv[0]<100*ResoU1) {
433 if(pasuv[1]<100*ResoV1) {
436 if(pasuv[2]<100*ResoU2) {
439 if(pasuv[3]<100*ResoV2) {
443 for (i=0; i<4; ++i) {
447 pasInit[i] = pasSav[i] = pasuv[i];
450 line = new IntSurf_LineOn2S ();
452 for (i=1; i<=4; ++i) {
456 //-- reprise des pas uv lies aux surfaces Caro1 et Caro2
457 //-- pasuv[] et pasSav[] sont modifies lors du cheminement
458 for(i = 0; i < 4; ++i) {
459 pasMaxSV[i] = pasSav[i] = pasuv[i] = pasInit[i];
462 //-- calcul du premier point solution
463 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
465 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld);
466 if (!myIntersectionOn2S.IsDone()) {
470 if (myIntersectionOn2S.IsEmpty()) {
474 if(myIntersectionOn2S.IsTangent()) {
478 Standard_Boolean Arrive, DejaReparti;
479 Standard_Integer IncKey, RejectIndex;
482 DejaReparti = Standard_False;
486 previousPoint = myIntersectionOn2S.Point();
487 previoustg = Standard_False;
488 previousd = myIntersectionOn2S.Direction();
489 previousd1 = myIntersectionOn2S.DirectionOnS1();
490 previousd2 = myIntersectionOn2S.DirectionOnS2();
493 firstd1 = previousd1;
494 firstd2 = previousd2;
495 tgfirst = tglast = Standard_False;
496 choixIsoSav = ChoixIso;
497 //------------------------------------------------------------
498 //-- On Teste si le premier point de cheminement correspond
499 //-- a un point sur frontiere.
500 //-- Dans ce cas, DejaReparti est initialise a True
502 pf = previousPoint.Value();
503 Standard_Boolean bTestFirstPoint = Standard_True;
505 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
506 AddAPoint(line,previousPoint);
508 IntWalk_StatusDeflection Status = IntWalk_OK;
509 Standard_Boolean NoTestDeflection = Standard_False;
510 Standard_Real SvParam[4], f;
511 Standard_Integer LevelOfEmptyInmyIntersectionOn2S=0;
512 Standard_Integer LevelOfPointConfondu = 0;
513 Standard_Integer LevelOfIterWithoutAppend = -1;
515 Arrive = Standard_False;
516 while(!Arrive) {//010
517 LevelOfIterWithoutAppend++;
518 if(LevelOfIterWithoutAppend>20) {
519 Arrive = Standard_True;
523 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
524 LevelOfIterWithoutAppend = 0;
530 case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
531 case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
532 case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
533 case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
541 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
544 Standard_Real aIncKey, aEps, dP1, dP2, dP3, dP4;
546 dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
547 dP2 = sensCheminement * pasuv[1] * previousd1.Y() /f;
548 dP3 = sensCheminement * pasuv[2] * previousd2.X() /f;
549 dP4 = sensCheminement * pasuv[3] * previousd2.Y() /f;
551 aIncKey=5.*(Standard_Real)IncKey;
553 if(ChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < aEps) {
556 if(ChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < aEps) {
559 if(ChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < aEps) {
562 if(ChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < aEps) {
571 //==========================
577 ChoixIso= myIntersectionOn2S.Perform(Param, Rsnld, ChoixIso);
579 if (!myIntersectionOn2S.IsDone()) {
580 //arret de la ligne,division
581 Arrive = Standard_False;
586 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
589 //== Le calcul du point exact a partir de Param(.) est possible
590 if (myIntersectionOn2S.IsEmpty()) {
591 Standard_Real u1,v1,u2,v2;
592 previousPoint.Parameters(u1,v1,u2,v2);
594 Arrive = Standard_False;
595 if(u1<UFirst1 || u1>ULast1) {
596 Arrive=Standard_True;
598 if(u2<UFirst2 || u2>ULast2) {
599 Arrive=Standard_True;
601 if(v1<VFirst1 || v1>VLast1) {
602 Arrive=Standard_True;
604 if(v2<VFirst2 || v2>VLast2) {
605 Arrive=Standard_True;
607 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
608 LevelOfEmptyInmyIntersectionOn2S++;
610 if(LevelOfEmptyInmyIntersectionOn2S>10) {
618 //============================================================
619 //== Un point a ete trouve : T E S T D E F L E C T I O N
620 //============================================================
621 if(NoTestDeflection) {
622 NoTestDeflection = Standard_False;
625 if(--LevelOfEmptyInmyIntersectionOn2S<=0) {
626 LevelOfEmptyInmyIntersectionOn2S=0;
627 if(LevelOfIterWithoutAppend < 10) {
628 Status = TestDeflection();
638 //============================================================
639 //== T r a i t e m e n t s u r S t a t u s ==
640 //============================================================
641 if(LevelOfPointConfondu > 5) {
642 Status = IntWalk_ArretSurPoint;
643 LevelOfPointConfondu = 0;
646 if(Status==IntWalk_OK) {
648 if(NbPasOKConseq >= 5) {
650 Standard_Boolean pastroppetit;
654 pastroppetit=Standard_True;
656 if(pasuv[0]<pasInit[0]) {
657 t = (pasInit[0]-pasuv[0])*0.25;
658 if(t>0.1*pasInit[0]) {
662 pastroppetit=Standard_False;
664 if(pasuv[1]<pasInit[1]) {
665 t = (pasInit[1]-pasuv[1])*0.25;
666 if(t>0.1*pasInit[1]) {
670 pastroppetit=Standard_False;
672 if(pasuv[2]<pasInit[2]){
673 t = (pasInit[2]-pasuv[2])*0.25;
674 if(t>0.1*pasInit[2]) {
678 pastroppetit=Standard_False;
680 if(pasuv[3]<pasInit[3]) {
681 t = (pasInit[3]-pasuv[3])*0.25;
682 if(t>0.1*pasInit[3]) {
686 pastroppetit=Standard_False;
697 pastroppetit=Standard_False;
700 } while(pastroppetit);
702 }//Status==IntWalk_OK
703 else NbPasOKConseq=0;
705 switch(Status) {//007
706 case IntWalk_ArretSurPointPrecedent: {
707 Arrive = Standard_False;
708 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
711 case IntWalk_PasTropGrand: {
716 if(LevelOfIterWithoutAppend > 5) {
717 if(pasSav[0]<pasInit[0]) {
718 pasInit[0]-=(pasInit[0]-pasSav[0])*0.25;
719 LevelOfIterWithoutAppend=0;
721 if(pasSav[1]<pasInit[1]) {
722 pasInit[1]-=(pasInit[1]-pasSav[1])*0.25;
723 LevelOfIterWithoutAppend=0;
725 if(pasSav[2]<pasInit[2]) {
726 pasInit[2]-=(pasInit[2]-pasSav[2])*0.25;
727 LevelOfIterWithoutAppend=0;
729 if(pasSav[3]<pasInit[3]) {
730 pasInit[3]-=(pasInit[3]-pasSav[3])*0.25;
731 LevelOfIterWithoutAppend=0;
736 case IntWalk_PointConfondu: {
737 LevelOfPointConfondu++;
738 if(LevelOfPointConfondu>5) {
739 Standard_Boolean pastroppetit;
742 pastroppetit=Standard_True;
743 if(pasuv[0]<pasInit[0]) {
744 pasuv[0]+=(pasInit[0]-pasuv[0])*0.25;
745 pastroppetit=Standard_False;
747 if(pasuv[1]<pasInit[1]) {
748 pasuv[1]+=(pasInit[1]-pasuv[1])*0.25;
749 pastroppetit=Standard_False;
751 if(pasuv[2]<pasInit[2]) {
752 pasuv[2]+=(pasInit[2]-pasuv[2])*0.25;
753 pastroppetit=Standard_False;
755 if(pasuv[3]<pasInit[3]) {
756 pasuv[3]+=(pasInit[3]-pasuv[3])*0.25;
757 pastroppetit=Standard_False;
768 pastroppetit=Standard_False;
771 } while(pastroppetit);
776 case IntWalk_ArretSurPoint: {//006
777 //=======================================================
778 //== T e s t A r r e t : Cadrage sur Param(.) ==
779 //=======================================================
781 Arrive = TestArret(DejaReparti,Param,ChoixIso);
782 // JMB 30th December 1999.
783 // Some statement below should not be put in comment because they are useful.
784 // See grid CTO 909 A1 which infinitely loops
785 if(Arrive==Standard_False && Status==IntWalk_ArretSurPoint) {
786 Arrive=Standard_True;
788 cout << "Compile avec option DEB :Si Pb d intersection : ";
789 cout << "IntWalk_PWalking_1.gxx (lbr le 1erdec98)"<<endl;
796 //=====================================================
797 //== Param(.) est dans les bornes ==
798 //== et ne finit pas une ligne fermee ==
799 //=====================================================
800 //== Verification sur Le Point Courant de myInters
801 Standard_Boolean pointisvalid = Standard_False;
803 Standard_Real u1,v1,u2,v2;
804 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
806 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
807 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
808 v1 >= Vm1 && v2 >= Vm2) {
809 pointisvalid=Standard_True;
814 previousPoint = myIntersectionOn2S.Point();
815 previoustg = myIntersectionOn2S.IsTangent();
817 previousd = myIntersectionOn2S.Direction();
818 previousd1 = myIntersectionOn2S.DirectionOnS1();
819 previousd2 = myIntersectionOn2S.DirectionOnS2();
821 //=====================================================
822 //== Verification sur Previous Point
824 Standard_Real u1,v1,u2,v2;
825 previousPoint.Parameters(u1,v1,u2,v2);
826 if( u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
827 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
828 v1 >= Vm1 && v2 >= Vm2) {
829 pl = previousPoint.Value();
830 if(bTestFirstPoint) {
831 if(pf.Distance(pl) < 1.e-7){
839 bTestFirstPoint = Standard_False;
843 AddAPoint(line,previousPoint);
845 if(RejectIndex >= 250000) {
849 LevelOfIterWithoutAppend = 0;
853 //====================================================
854 if(Status == IntWalk_ArretSurPoint) {
855 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
858 if (line->NbPoints() == 2) {
859 pasSav[0] = pasuv[0];
860 pasSav[1] = pasuv[1];
861 pasSav[2] = pasuv[2];
862 pasSav[3] = pasuv[3];
869 //================= la ligne est fermee ===============
870 AddAPoint(line,line->Value(1)); //ligne fermee
871 LevelOfIterWithoutAppend=0;
874 //====================================================
875 //== Param n etait pas dans les bornes (a ete recadre)
876 //====================================================
877 Standard_Boolean bPrevNotTangent = !previoustg || !myIntersectionOn2S.IsTangent();
879 IntImp_ConstIsoparametric SauvChoixIso = ChoixIso;
880 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
882 if(!myIntersectionOn2S.IsEmpty()) { //002
883 // debordement sur le carreau reciproque ou intersection en coin
884 if(TestArret(Standard_True,Param,ChoixIso)) {
886 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
887 if(!myIntersectionOn2S.IsEmpty()) {
888 previousPoint = myIntersectionOn2S.Point();
889 previoustg = myIntersectionOn2S.IsTangent();
891 previousd = myIntersectionOn2S.Direction();
892 previousd1 = myIntersectionOn2S.DirectionOnS1();
893 previousd2 = myIntersectionOn2S.DirectionOnS2();
895 pl = previousPoint.Value();
896 if(bTestFirstPoint) {
897 if(pf.Distance(pl) < 1.e-7){
905 bTestFirstPoint = Standard_False;
909 AddAPoint(line,previousPoint);
911 if(RejectIndex >= 250000) {
915 LevelOfIterWithoutAppend=0;
916 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
919 //echec cadrage diviser le pas
920 Arrive = Standard_False;
921 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
922 NoTestDeflection = Standard_True;
923 ChoixIso = SauvChoixIso;
927 // save the last point
928 // to revert to it if the current point is out of bounds
929 IntSurf_PntOn2S previousPointSave = previousPoint;
930 Standard_Boolean previoustgSave = previoustg;
931 gp_Dir previousdSave = previousd;
932 gp_Dir2d previousd1Save = previousd1;
933 gp_Dir2d previousd2Save = previousd2;
935 previousPoint = myIntersectionOn2S.Point();
936 previoustg = myIntersectionOn2S.IsTangent();
937 Arrive = Standard_False;
939 previousd = myIntersectionOn2S.Direction();
940 previousd1 = myIntersectionOn2S.DirectionOnS1();
941 previousd2 = myIntersectionOn2S.DirectionOnS2();
943 //========================================
944 //== Verification sur PreviousPoint @@
946 Standard_Real u1,v1,u2,v2;
947 previousPoint.Parameters(u1,v1,u2,v2);
954 Standard_Boolean bFlag1, bFlag2;
955 Standard_Real aTol2D=1.e-11;
957 bFlag1=u1 >= Um1-aTol2D && v1 >= Vm1-aTol2D && u1 <= UM1+aTol2D && v1 <= VM1+aTol2D;
958 bFlag2=u2 >= Um2-aTol2D && v2 >= Vm2-aTol2D && u2 <= UM2+aTol2D && v2 <= VM2+aTol2D;
959 if (bFlag1 && bFlag2) {
961 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
962 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
963 v1 >= Vm1 && v2 >= Vm2) {
966 pl = previousPoint.Value();
967 if(bTestFirstPoint) {
968 if(pf.Distance(pl) < 1.e-7) {
976 bTestFirstPoint = Standard_False;
979 AddAPoint(line,previousPoint);
981 if(RejectIndex >= 250000) {
985 LevelOfIterWithoutAppend=0;
986 Arrive = Standard_True;
989 // revert to the last correctly calculated point
990 previousPoint = previousPointSave;
991 previoustg = previoustgSave;
992 previousd = previousdSave;
993 previousd1 = previousd1Save;
994 previousd2 = previousd2Save;
998 Standard_Boolean wasExtended = Standard_False;
1000 if(Arrive && myIntersectionOn2S.IsTangent() && bPrevNotTangent) {
1001 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti)) {
1002 wasExtended = Standard_True;
1003 Arrive = Standard_False;
1004 ChoixIso = SauvChoixIso;
1008 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1010 myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty() &&
1011 myIntersectionOn2S.IsTangent() && bPrevNotTangent &&
1014 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti)) {
1015 wasExtended = Standard_True;
1016 Arrive = Standard_False;
1017 ChoixIso = SauvChoixIso;
1020 }//else !TestArret() $
1021 } //$$ fin succes cadrage sur frontiere (!myIntersectionOn2S.IsEmpty())
1023 //echec cadrage sur frontiere;division du pas
1024 Arrive = Standard_False;
1025 NoTestDeflection = Standard_True;
1026 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1028 }//$$$ fin cadrage sur frontiere (!close)
1029 } //004 fin TestArret retourne Arrive = True
1030 } // 006case IntWalk_ArretSurPoint: fin Traitement Status = OK ou ArretSurPoint
1031 } //007 switch(Status)
1032 } //008 fin traitement point en court (TEST DEFLECTION)
1033 } //009 fin traitement ligne (else if myIntersectionOn2S.IsDone())
1034 } //010 fin si premier point de depart a permis un cheminement while(!Arrive)
1035 done = Standard_True;
1037 // ===========================================================================================================
1038 // function: ExtendLineInCommonZone
1039 // purpose: Extends already computed line inside tangent zone in the direction given by theChoixIso.
1040 // Returns Standard_True if the line was extended through tangent zone and the last computed point
1041 // is outside the tangent zone (but it is not put into the line). Otherwise returns Standard_False.
1042 // ===========================================================================================================
1043 Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsoparametric theChoixIso,
1044 const Standard_Boolean theDirectionFlag)
1046 Standard_Boolean bOutOfTangentZone = Standard_False;
1047 Standard_Boolean bStop = !myIntersectionOn2S.IsTangent();
1048 Standard_Integer dIncKey = 1;
1049 TColStd_Array1OfReal Param(1,4);
1050 IntWalk_StatusDeflection Status = IntWalk_OK;
1051 Standard_Integer nbIterWithoutAppend = 0;
1052 Standard_Integer nbEqualPoints = 0;
1053 Standard_Integer parit = 0;
1054 Standard_Integer uvit = 0;
1055 IntSurf_SequenceOfPntOn2S aSeqOfNewPoint;
1058 nbIterWithoutAppend++;
1060 if((nbIterWithoutAppend > 20) || (nbEqualPoints > 20)) {
1062 cout<<"Compile with option DEB:";
1063 cout<<"Infinite loop has detected. Stop iterations (IntWalk_PWalking_1.gxx)" << endl;
1065 bStop = Standard_True;
1068 Standard_Real f = 0.;
1070 switch (theChoixIso)
1072 case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
1073 case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
1074 case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
1075 case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
1080 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
1082 Standard_Real dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
1083 Standard_Real dP2 = sensCheminement * pasuv[1] * previousd1.Y() /f;
1084 Standard_Real dP3 = sensCheminement * pasuv[2] * previousd2.X() /f;
1085 Standard_Real dP4 = sensCheminement * pasuv[3] * previousd2.Y() /f;
1087 if(theChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < 1.e-7) dP1 *= (5. * (Standard_Real)dIncKey);
1088 if(theChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < 1.e-7) dP2 *= (5. * (Standard_Real)dIncKey);
1089 if(theChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < 1.e-7) dP3 *= (5. * (Standard_Real)dIncKey);
1090 if(theChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < 1.e-7) dP4 *= (5. * (Standard_Real)dIncKey);
1096 Standard_Real SvParam[4];
1097 IntImp_ConstIsoparametric ChoixIso = theChoixIso;
1099 for(parit = 0; parit < 4; parit++) {
1100 SvParam[parit] = Param(parit+1);
1102 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
1103 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld, theChoixIso);
1105 if (!myIntersectionOn2S.IsDone()) {
1106 return bOutOfTangentZone;
1109 if (myIntersectionOn2S.IsEmpty()) {
1110 return bOutOfTangentZone;
1113 Status = TestDeflection();
1115 if(Status == IntWalk_OK) {
1117 for(uvit = 0; uvit < 4; uvit++) {
1118 if(pasuv[uvit] < pasInit[uvit]) {
1119 pasuv[uvit] = pasInit[uvit];
1125 case IntWalk_ArretSurPointPrecedent:
1127 bStop = Standard_True;
1128 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1131 case IntWalk_PasTropGrand:
1133 for(parit = 0; parit < 4; parit++) {
1134 Param(parit+1) = SvParam[parit];
1136 Standard_Boolean bDecrease = Standard_False;
1138 for(uvit = 0; uvit < 4; uvit++) {
1139 if(pasSav[uvit] < pasInit[uvit]) {
1140 pasInit[uvit] -= (pasInit[uvit] - pasSav[uvit]) * 0.1;
1141 bDecrease = Standard_True;
1145 if(bDecrease) nbIterWithoutAppend--;
1148 case IntWalk_PointConfondu:
1150 for(uvit = 0; uvit < 4; uvit++) {
1151 if(pasuv[uvit] < pasInit[uvit]) {
1152 pasuv[uvit] += (pasInit[uvit] - pasuv[uvit]) * 0.1;
1158 case IntWalk_ArretSurPoint:
1161 bStop = TestArret(theDirectionFlag, Param, ChoixIso);
1166 Standard_Real u11,v11,u12,v12;
1167 myIntersectionOn2S.Point().Parameters(u11,v11,u12,v12);
1168 Standard_Real u21,v21,u22,v22;
1169 previousPoint.Parameters(u21,v21,u22,v22);
1171 if(((fabs(u11-u21) < ResoU1) && (fabs(v11-v21) < ResoV1)) ||
1172 ((fabs(u12-u22) < ResoU2) && (fabs(v12-v22) < ResoV2))) {
1181 bStop = bStop || !myIntersectionOn2S.IsTangent();
1182 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1185 Standard_Boolean pointisvalid = Standard_False;
1186 Standard_Real u1,v1,u2,v2;
1187 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
1189 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1190 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1191 v1 >= Vm1 && v2 >= Vm2)
1192 pointisvalid = Standard_True;
1195 previousPoint = myIntersectionOn2S.Point();
1196 previoustg = myIntersectionOn2S.IsTangent();
1199 previousd = myIntersectionOn2S.Direction();
1200 previousd1 = myIntersectionOn2S.DirectionOnS1();
1201 previousd2 = myIntersectionOn2S.DirectionOnS2();
1203 Standard_Boolean bAddPoint = Standard_True;
1205 if(line->NbPoints() >= 1) {
1206 gp_Pnt pf = line->Value(1).Value();
1207 gp_Pnt pl = previousPoint.Value();
1209 if(pf.Distance(pl) < Precision::Confusion()) {
1211 if(dIncKey == 5000) return bOutOfTangentZone;
1212 else bAddPoint = Standard_False;
1217 aSeqOfNewPoint.Append(previousPoint);
1218 nbIterWithoutAppend = 0;
1222 if (line->NbPoints() == 2) {
1223 for(uvit = 0; uvit < 4; uvit++) {
1224 pasSav[uvit] = pasuv[uvit];
1228 if ( !pointisvalid ) {
1229 // decrease step if out of bounds
1230 // otherwise the same calculations will be
1231 // repeated several times
1232 if ( ( u1 > UM1 ) || ( u1 < Um1 ) )
1235 if ( ( v1 > VM1 ) || ( v1 < Vm1 ) )
1238 if ( ( u2 > UM2 ) || ( u2 < Um2 ) )
1241 if ( ( v2 > VM2 ) || ( v2 < Vm2 ) )
1246 if(close && (line->NbPoints() >= 1)) {
1248 if(!bOutOfTangentZone) {
1249 aSeqOfNewPoint.Append(line->Value(1)); // line end
1251 nbIterWithoutAppend = 0;
1254 ChoixIso = myIntersectionOn2S.Perform(Param, Rsnld, theChoixIso);
1256 if(myIntersectionOn2S.IsEmpty()) {
1257 bStop = !myIntersectionOn2S.IsTangent();
1258 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1261 Standard_Boolean bAddPoint = Standard_True;
1262 Standard_Boolean pointisvalid = Standard_False;
1264 previousPoint = myIntersectionOn2S.Point();
1265 Standard_Real u1,v1,u2,v2;
1266 previousPoint.Parameters(u1,v1,u2,v2);
1268 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1269 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1270 v1 >= Vm1 && v2 >= Vm2)
1271 pointisvalid = Standard_True;
1275 if(line->NbPoints() >= 1) {
1276 gp_Pnt pf = line->Value(1).Value();
1277 gp_Pnt pl = previousPoint.Value();
1279 if(pf.Distance(pl) < Precision::Confusion()) {
1281 if(dIncKey == 5000) return bOutOfTangentZone;
1282 else bAddPoint = Standard_False;
1286 if(bAddPoint && !bOutOfTangentZone) {
1287 aSeqOfNewPoint.Append(previousPoint);
1288 nbIterWithoutAppend = 0;
1303 Standard_Boolean bExtendLine = Standard_False;
1304 Standard_Real u1 = 0., v1 = 0., u2 = 0., v2 = 0.;
1306 Standard_Integer pit = 0;
1308 for(pit = 0; !bExtendLine && (pit < 2); pit++) {
1310 previousPoint.Parameters(u1,v1,u2,v2);
1312 if(aSeqOfNewPoint.Length() > 0)
1313 aSeqOfNewPoint.Value(aSeqOfNewPoint.Length()).Parameters(u1,v1,u2,v2);
1318 if(((u1 - Um1) < ResoU1) ||
1319 ((UM1 - u1) < ResoU1) ||
1320 ((u2 - Um2) < ResoU2) ||
1321 ((UM2 - u2) < ResoU2) ||
1322 ((v1 - Vm1) < ResoV1) ||
1323 ((VM1 - v1) < ResoV1) ||
1324 ((v2 - Vm2) < ResoV2) ||
1325 ((VM2 - v2) < ResoV2))
1326 bExtendLine = Standard_True;
1330 // if(Status == IntWalk_OK || Status == IntWalk_ArretSurPoint) {
1331 if(Status == IntWalk_OK) {
1332 bExtendLine = Standard_True;
1334 if(aSeqOfNewPoint.Length() > 1) {
1335 TColStd_Array1OfReal FirstParams(0, 3), LastParams(0, 3), Resolutions(0, 3);
1336 Resolutions(0) = ResoU1; Resolutions(1) = ResoV1; Resolutions(2) = ResoU2; Resolutions(3) = ResoV2;
1338 aSeqOfNewPoint(1).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1339 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1340 aSeqOfNewPoint(aSeqOfNewPoint.Length()).Parameters(LastParams.ChangeValue(0),
1341 LastParams.ChangeValue(1),
1342 LastParams.ChangeValue(2),
1343 LastParams.ChangeValue(3));
1344 Standard_Integer indexofiso = 0;
1346 if(theChoixIso == IntImp_UIsoparametricOnCaro1) indexofiso = 0;
1347 if(theChoixIso == IntImp_VIsoparametricOnCaro1) indexofiso = 1;
1348 if(theChoixIso == IntImp_UIsoparametricOnCaro2) indexofiso = 2;
1349 if(theChoixIso == IntImp_VIsoparametricOnCaro2) indexofiso = 3;
1351 Standard_Integer afirstindex = (indexofiso < 2) ? 0 : 2;
1352 gp_Vec2d aTangentZoneDir(gp_Pnt2d(FirstParams.Value(afirstindex), FirstParams.Value(afirstindex + 1)),
1353 gp_Pnt2d(LastParams.Value(afirstindex), LastParams.Value(afirstindex + 1)));
1355 gp_Dir2d anIsoDir(0, 1);
1357 if((indexofiso == 1) || (indexofiso == 3))
1358 anIsoDir = gp_Dir2d(1, 0);
1360 if(aTangentZoneDir.SquareMagnitude() > gp::Resolution()) {
1361 Standard_Real piquota = M_PI*0.25;
1363 if(fabs(aTangentZoneDir.Angle(anIsoDir)) > piquota) {
1364 Standard_Integer ii = 1, nextii = 2;
1366 Standard_Real asqresol = gp::Resolution();
1367 asqresol *= asqresol;
1370 aSeqOfNewPoint(ii).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1371 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1372 aSeqOfNewPoint(ii + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1373 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1374 d1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1375 FirstParams.Value(afirstindex + 1)),
1376 gp_Pnt2d(LastParams.Value(afirstindex),
1377 LastParams.Value(afirstindex + 1)));
1380 while((d1.SquareMagnitude() < asqresol) &&
1381 (ii < aSeqOfNewPoint.Length()));
1385 while(nextii < aSeqOfNewPoint.Length()) {
1387 gp_Vec2d nextd1(0, 0);
1388 Standard_Integer jj = nextii;
1391 aSeqOfNewPoint(jj).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1392 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1393 aSeqOfNewPoint(jj + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1394 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1395 nextd1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1396 FirstParams.Value(afirstindex + 1)),
1397 gp_Pnt2d(LastParams.Value(afirstindex),
1398 LastParams.Value(afirstindex + 1)));
1402 while((nextd1.SquareMagnitude() < asqresol) &&
1403 (jj < aSeqOfNewPoint.Length()));
1406 if(fabs(d1.Angle(nextd1)) > piquota) {
1407 bExtendLine = Standard_False;
1413 // end if(fabs(aTangentZoneDir.Angle(anIsoDir)
1420 return Standard_False;
1422 Standard_Integer i = 0;
1424 for(i = 1; i <= aSeqOfNewPoint.Length(); i++) {
1425 AddAPoint(line, aSeqOfNewPoint.Value(i));
1428 return bOutOfTangentZone;