1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <IntWalk_PWalking.ixx>
17 #include <IntWalk_StatusDeflection.hxx>
19 #include <TColgp_Array1OfPnt.hxx>
20 #include <TColStd_Array1OfReal.hxx>
22 #include <IntImp_ComputeTangence.hxx>
24 #include <Adaptor3d_HSurface.hxx>
25 #include <Adaptor3d_HSurfaceTool.hxx>
27 #include <Precision.hxx>
29 #include <math_FunctionSetRoot.hxx>
30 #include <Geom_Surface.hxx>
32 #include <Standard_Failure.hxx>
33 #include <gp_Pnt2d.hxx>
35 //==================================================================================
36 // function : IntWalk_PWalking::IntWalk_PWalking
38 // estimate of max step : To avoid abrupt changes
39 // during change of isos
40 //==================================================================================
41 void ComputePasInit(Standard_Real *pasuv,
42 Standard_Real Um1,Standard_Real UM1,
43 Standard_Real Vm1,Standard_Real VM1,
44 Standard_Real Um2,Standard_Real UM2,
45 Standard_Real Vm2,Standard_Real VM2,
46 Standard_Real _Um1,Standard_Real _UM1,
47 Standard_Real _Vm1,Standard_Real _VM1,
48 Standard_Real _Um2,Standard_Real _UM2,
49 Standard_Real _Vm2,Standard_Real _VM2,
50 const Handle(Adaptor3d_HSurface)& ,
51 const Handle(Adaptor3d_HSurface)& ,
52 const Standard_Real Increment)
54 Standard_Real du1=Abs(UM1-Um1);
55 Standard_Real dv1=Abs(VM1-Vm1);
56 Standard_Real du2=Abs(UM2-Um2);
57 Standard_Real dv2=Abs(VM2-Vm2);
59 Standard_Real _du1=Abs(_UM1-_Um1);
60 Standard_Real _dv1=Abs(_VM1-_Vm1);
61 Standard_Real _du2=Abs(_UM2-_Um2);
62 Standard_Real _dv2=Abs(_VM2-_Vm2);
64 //-- limit the reduction of uv box estimate to 0.01 natural box
65 //-- du1 : On box of Inter
66 //-- _du1 : On parametric space
67 if(_du1<1e50 && du1<0.01*_du1) du1=0.01*_du1;
68 if(_dv1<1e50 && dv1<0.01*_dv1) dv1=0.01*_dv1;
69 if(_du2<1e50 && du2<0.01*_du2) du2=0.01*_du2;
70 if(_dv2<1e50 && dv2<0.01*_dv2) dv2=0.01*_dv2;
72 pasuv[0]=Increment*du1;
73 pasuv[1]=Increment*dv1;
74 pasuv[2]=Increment*du2;
75 pasuv[3]=Increment*dv2;
78 //=======================================================================
79 //function : IsParallel
80 //purpose : Checks if theLine is parallel of some boundary of given
81 // surface (it is determined by theCheckSurf1 flag).
82 // Parallelism assumes small oscillations (swing is less or
83 // equal than theToler).
84 // Small lines (if first and last parameters in the Surface
85 // are almost equal) are classified as parallel (as same as
86 // any point can be considered as parallel of any line).
87 //=======================================================================
88 static void IsParallel(const Handle(IntSurf_LineOn2S)& theLine,
89 const Standard_Boolean theCheckSurf1,
90 const Standard_Real theToler,
91 Standard_Boolean& theIsUparallel,
92 Standard_Boolean& theIsVparallel)
94 const Standard_Integer aNbPointsMAX = 23;
96 theIsUparallel = theIsVparallel = Standard_True;
98 Standard_Integer aNbPoints = theLine->NbPoints();
99 if(aNbPoints > aNbPointsMAX)
101 aNbPoints = aNbPointsMAX;
103 else if(aNbPoints < 3)
105 //Here we cannot estimate parallelism.
106 //Do all same as for small lines
110 Standard_Real aStep = IntToReal(theLine->NbPoints()) / aNbPoints;
111 Standard_Real aNPoint = 1.0;
113 Standard_Real aUmin = RealLast(), aUmax = RealFirst(), aVmin = RealLast(), aVmax = RealFirst();
114 for(Standard_Integer aNum = 1; aNum <= aNbPoints; aNum++, aNPoint += aStep)
116 if(aNPoint > aNbPoints)
123 theLine->Value(RealToInt(aNPoint)).ParametersOnS1(u, v);
125 theLine->Value(RealToInt(aNPoint)).ParametersOnS2(u, v);
140 theIsVparallel = ((aUmax - aUmin) < theToler);
141 theIsUparallel = ((aVmax - aVmin) < theToler);
144 //=======================================================================
145 //function : Checking
146 //purpose : Check, if given point is in surface's boundaries.
147 // If "yes" then theFactTol = 0.0, else theFactTol is
148 // equal maximal deviation.
149 //=======================================================================
150 static Standard_Boolean Checking( const Handle(Adaptor3d_HSurface)& theASurf1,
151 const Handle(Adaptor3d_HSurface)& theASurf2,
152 Standard_Real& theU1,
153 Standard_Real& theV1,
154 Standard_Real& theU2,
155 Standard_Real& theV2,
156 Standard_Real& theFactTol)
158 const Standard_Real aTol = Precision::PConfusion();
159 const Standard_Real aU1bFirst = theASurf1->FirstUParameter();
160 const Standard_Real aU1bLast = theASurf1->LastUParameter();
161 const Standard_Real aU2bFirst = theASurf2->FirstUParameter();
162 const Standard_Real aU2bLast = theASurf2->LastUParameter();
163 const Standard_Real aV1bFirst = theASurf1->FirstVParameter();
164 const Standard_Real aV1bLast = theASurf1->LastVParameter();
165 const Standard_Real aV2bFirst = theASurf2->FirstVParameter();
166 const Standard_Real aV2bLast = theASurf2->LastVParameter();
168 Standard_Boolean isOnOrIn = Standard_True;
171 Standard_Real aDelta = aU1bFirst - theU1;
175 theFactTol = Max(theFactTol, aDelta);
176 isOnOrIn = Standard_False;
179 aDelta = theU1 - aU1bLast;
183 theFactTol = Max(theFactTol, aDelta);
184 isOnOrIn = Standard_False;
187 aDelta = aV1bFirst - theV1;
191 theFactTol = Max(theFactTol, aDelta);
192 isOnOrIn = Standard_False;
195 aDelta = theV1 - aV1bLast;
199 theFactTol = Max(theFactTol, aDelta);
200 isOnOrIn = Standard_False;
203 aDelta = aU2bFirst - theU2;
207 theFactTol = Max(theFactTol, aDelta);
208 isOnOrIn = Standard_False;
211 aDelta = theU2 - aU2bLast;
215 theFactTol = Max(theFactTol, aDelta);
216 isOnOrIn = Standard_False;
219 aDelta = aV2bFirst - theV2;
223 theFactTol = Max(theFactTol, aDelta);
224 isOnOrIn = Standard_False;
227 aDelta = theV2 - aV2bLast;
231 theFactTol = Max(theFactTol, aDelta);
232 isOnOrIn = Standard_False;
238 //==================================================================================
239 // function : IntWalk_PWalking::IntWalk_PWalking
241 //==================================================================================
242 IntWalk_PWalking::IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1,
243 const Handle(Adaptor3d_HSurface)& Caro2,
244 const Standard_Real TolTangency,
245 const Standard_Real Epsilon,
246 const Standard_Real Deflection,
247 const Standard_Real Increment )
251 close(Standard_False),
255 myIntersectionOn2S(Caro1,Caro2,TolTangency),
256 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
257 STATIC_PRECEDENT_INFLEXION(0)
259 Standard_Real KELARG=20.;
261 pasMax=Increment*0.2; //-- June 25 99 after problems with precision
262 Um1 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro1);
263 Vm1 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro1);
264 UM1 = Adaptor3d_HSurfaceTool::LastUParameter(Caro1);
265 VM1 = Adaptor3d_HSurfaceTool::LastVParameter(Caro1);
267 Um2 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro2);
268 Vm2 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro2);
269 UM2 = Adaptor3d_HSurfaceTool::LastUParameter(Caro2);
270 VM2 = Adaptor3d_HSurfaceTool::LastVParameter(Caro2);
272 ResoU1 = Adaptor3d_HSurfaceTool::UResolution(Caro1,Precision::Confusion());
273 ResoV1 = Adaptor3d_HSurfaceTool::VResolution(Caro1,Precision::Confusion());
275 ResoU2 = Adaptor3d_HSurfaceTool::UResolution(Caro2,Precision::Confusion());
276 ResoV2 = Adaptor3d_HSurfaceTool::VResolution(Caro2,Precision::Confusion());
278 Standard_Real NEWRESO;
279 Standard_Real MAXVAL;
280 Standard_Real MAXVAL2;
282 MAXVAL = Abs(Um1); MAXVAL2 = Abs(UM1);
283 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
284 NEWRESO = ResoU1 * MAXVAL ;
285 if(NEWRESO > ResoU1 &&NEWRESO<10) { ResoU1 = NEWRESO; }
288 MAXVAL = Abs(Um2); MAXVAL2 = Abs(UM2);
289 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
290 NEWRESO = ResoU2 * MAXVAL ;
291 if(NEWRESO > ResoU2 && NEWRESO<10) { ResoU2 = NEWRESO; }
294 MAXVAL = Abs(Vm1); MAXVAL2 = Abs(VM1);
295 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
296 NEWRESO = ResoV1 * MAXVAL ;
297 if(NEWRESO > ResoV1 && NEWRESO<10) { ResoV1 = NEWRESO; }
300 MAXVAL = Abs(Vm2); MAXVAL2 = Abs(VM2);
301 if(MAXVAL2 > MAXVAL) MAXVAL = MAXVAL2;
302 NEWRESO = ResoV2 * MAXVAL ;
303 if(NEWRESO > ResoV2 && NEWRESO<10) { ResoV2 = NEWRESO; }
305 pasuv[0]=pasMax*Abs(UM1-Um1);
306 pasuv[1]=pasMax*Abs(VM1-Vm1);
307 pasuv[2]=pasMax*Abs(UM2-Um2);
308 pasuv[3]=pasMax*Abs(VM2-Vm2);
310 if(ResoU1>0.0001*pasuv[0]) ResoU1=0.00001*pasuv[0];
311 if(ResoV1>0.0001*pasuv[1]) ResoV1=0.00001*pasuv[1];
312 if(ResoU2>0.0001*pasuv[2]) ResoU2=0.00001*pasuv[2];
313 if(ResoV2>0.0001*pasuv[3]) ResoV2=0.00001*pasuv[3];
316 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
317 //UM1+=KELARG*pasuv[0]; Um1-=KELARG*pasuv[0];
320 Standard_Real t = UM1-Um1;
321 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro1)) {
322 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro1)-t);
323 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
328 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
329 //VM1+=KELARG*pasuv[1]; Vm1-=KELARG*pasuv[1];
332 Standard_Real t = VM1-Vm1;
333 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro1)) {
334 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro1)-t);
335 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
340 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
341 //UM2+=KELARG*pasuv[2]; Um2-=KELARG*pasuv[2];
344 Standard_Real t = UM2-Um2;
345 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro2)) {
346 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro2)-t);
347 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
352 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
353 //VM2+=KELARG*pasuv[3]; Vm2-=KELARG*pasuv[3];
356 Standard_Real t = VM2-Vm2;
357 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro2)) {
358 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro2)-t);
359 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
364 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
366 for (Standard_Integer i = 0; i<=3;i++) {
369 pasInit[i] = pasSav[i] = pasuv[i];
374 //==================================================================================
375 // function : IntWalk_PWalking
377 //==================================================================================
378 IntWalk_PWalking::IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1,
379 const Handle(Adaptor3d_HSurface)& Caro2,
380 const Standard_Real TolTangency,
381 const Standard_Real Epsilon,
382 const Standard_Real Deflection,
383 const Standard_Real Increment,
384 const Standard_Real U1,
385 const Standard_Real V1,
386 const Standard_Real U2,
387 const Standard_Real V2)
391 close(Standard_False),
395 myIntersectionOn2S(Caro1,Caro2,TolTangency),
396 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
397 STATIC_PRECEDENT_INFLEXION(0)
399 Standard_Real KELARG=20.;
401 pasMax=Increment*0.2; //-- June 25 99 after problems with precision
403 Um1 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro1);
404 Vm1 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro1);
405 UM1 = Adaptor3d_HSurfaceTool::LastUParameter(Caro1);
406 VM1 = Adaptor3d_HSurfaceTool::LastVParameter(Caro1);
408 Um2 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro2);
409 Vm2 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro2);
410 UM2 = Adaptor3d_HSurfaceTool::LastUParameter(Caro2);
411 VM2 = Adaptor3d_HSurfaceTool::LastVParameter(Caro2);
413 ResoU1 = Adaptor3d_HSurfaceTool::UResolution(Caro1,Precision::Confusion());
414 ResoV1 = Adaptor3d_HSurfaceTool::VResolution(Caro1,Precision::Confusion());
416 ResoU2 = Adaptor3d_HSurfaceTool::UResolution(Caro2,Precision::Confusion());
417 ResoV2 = Adaptor3d_HSurfaceTool::VResolution(Caro2,Precision::Confusion());
419 Standard_Real NEWRESO, MAXVAL, MAXVAL2;
423 if(MAXVAL2 > MAXVAL) {
426 NEWRESO = ResoU1 * MAXVAL ;
427 if(NEWRESO > ResoU1) {
433 if(MAXVAL2 > MAXVAL){
436 NEWRESO = ResoU2 * MAXVAL ;
437 if(NEWRESO > ResoU2) {
443 if(MAXVAL2 > MAXVAL) {
446 NEWRESO = ResoV1 * MAXVAL ;
447 if(NEWRESO > ResoV1) {
453 if(MAXVAL2 > MAXVAL){
456 NEWRESO = ResoV2 * MAXVAL ;
457 if(NEWRESO > ResoV2) {
461 pasuv[0]=pasMax*Abs(UM1-Um1);
462 pasuv[1]=pasMax*Abs(VM1-Vm1);
463 pasuv[2]=pasMax*Abs(UM2-Um2);
464 pasuv[3]=pasMax*Abs(VM2-Vm2);
466 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
467 UM1+=KELARG*pasuv[0];
468 Um1-=KELARG*pasuv[0];
471 Standard_Real t = UM1-Um1;
472 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro1)) {
473 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro1)-t);
474 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
480 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
481 VM1+=KELARG*pasuv[1];
482 Vm1-=KELARG*pasuv[1];
485 Standard_Real t = VM1-Vm1;
486 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro1)) {
487 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro1)-t);
488 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
493 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
494 UM2+=KELARG*pasuv[2];
495 Um2-=KELARG*pasuv[2];
498 Standard_Real t = UM2-Um2;
499 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro2)) {
500 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro2)-t);
501 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
507 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
508 VM2+=KELARG*pasuv[3];
509 Vm2-=KELARG*pasuv[3];
512 Standard_Real t = VM2-Vm2;
513 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro2)) {
514 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro2)-t);
515 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
520 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
522 for (Standard_Integer i = 0; i<=3;i++) {
523 pasInit[i] = pasSav[i] = pasuv[i];
526 if(ResoU1>0.0001*pasuv[0]) ResoU1=0.00001*pasuv[0];
527 if(ResoV1>0.0001*pasuv[1]) ResoV1=0.00001*pasuv[1];
528 if(ResoU2>0.0001*pasuv[2]) ResoU2=0.00001*pasuv[2];
529 if(ResoV2>0.0001*pasuv[3]) ResoV2=0.00001*pasuv[3];
531 TColStd_Array1OfReal Par(1,4);
539 //==================================================================================
540 // function : PerformFirstPoint
542 //==================================================================================
543 Standard_Boolean IntWalk_PWalking::PerformFirstPoint (const TColStd_Array1OfReal& ParDep,
544 IntSurf_PntOn2S& FirstPoint)
547 close = Standard_False;
550 TColStd_Array1OfReal Param(1,4);
552 for (i=1; i<=4; ++i) {
553 Param(i) = ParDep(i);
555 //-- calculate the first solution point
556 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
558 myIntersectionOn2S.Perform(Param,Rsnld);
559 if (!myIntersectionOn2S.IsDone()) {
560 return Standard_False;
563 if (myIntersectionOn2S.IsEmpty()) {
564 return Standard_False;
567 FirstPoint = myIntersectionOn2S.Point();
568 return Standard_True;
570 //==================================================================================
571 // function : Perform
573 //==================================================================================
574 void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep)
576 Perform(ParDep,Um1,Vm1,Um2,Vm2,UM1,VM1,UM2,VM2);
578 //==================================================================================
579 // function : Perform
581 //==================================================================================
582 void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
583 const Standard_Real u1min,
584 const Standard_Real v1min,
585 const Standard_Real u2min,
586 const Standard_Real v2min,
587 const Standard_Real u1max,
588 const Standard_Real v1max,
589 const Standard_Real u2max,
590 const Standard_Real v2max)
592 const Standard_Real aSQDistMax = 1.0e-14;
595 Standard_Integer NbPasOKConseq=0;
596 Standard_Real pasMaxSV[4], aTmp;
597 TColStd_Array1OfReal Param(1,4);
598 IntImp_ConstIsoparametric ChoixIso;
601 done = Standard_False;
604 const Handle(Adaptor3d_HSurface)& Caro1 =myIntersectionOn2S.Function().AuxillarSurface1();
605 const Handle(Adaptor3d_HSurface)& Caro2 =myIntersectionOn2S.Function().AuxillarSurface2();
607 const Standard_Real UFirst1 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro1);
608 const Standard_Real VFirst1 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro1);
609 const Standard_Real ULast1 = Adaptor3d_HSurfaceTool::LastUParameter (Caro1);
610 const Standard_Real VLast1 = Adaptor3d_HSurfaceTool::LastVParameter (Caro1);
612 const Standard_Real UFirst2 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro2);
613 const Standard_Real VFirst2 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro2);
614 const Standard_Real ULast2 = Adaptor3d_HSurfaceTool::LastUParameter (Caro2);
615 const Standard_Real VLast2 = Adaptor3d_HSurfaceTool::LastVParameter (Caro2);
617 ComputePasInit(pasuv,u1min,u1max,v1min,v1max,u2min,u2max,v2min,v2max,
618 Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2,pasMax+pasMax);
620 if(pasuv[0]<100.0*ResoU1) {
621 pasuv[0]=100.0*ResoU1;
623 if(pasuv[1]<100.0*ResoV1) {
624 pasuv[1]=100.0*ResoV1;
626 if(pasuv[2]<100.0*ResoU2) {
627 pasuv[2]=100.0*ResoU2;
629 if(pasuv[3]<100.0*ResoV2) {
630 pasuv[3]=100.0*ResoV2;
633 for (Standard_Integer i=0; i<4; ++i)
640 pasInit[i] = pasSav[i] = pasuv[i];
643 line = new IntSurf_LineOn2S ();
645 for (Standard_Integer i=1; i<=4; ++i)
650 //-- reproduce steps uv connected to surfaces Caro1 and Caro2
651 //-- pasuv[] and pasSav[] are modified during the marching
652 for(Standard_Integer i = 0; i < 4; ++i)
654 pasMaxSV[i] = pasSav[i] = pasuv[i] = pasInit[i];
657 //-- calculate the first solution point
658 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
660 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld);
661 if (!myIntersectionOn2S.IsDone())
667 if (myIntersectionOn2S.IsEmpty())
672 if(myIntersectionOn2S.IsTangent())
677 Standard_Boolean Arrive, DejaReparti;
678 const Standard_Integer RejectIndexMAX = 250000;
679 Standard_Integer IncKey, RejectIndex;
682 DejaReparti = Standard_False;
686 previousPoint = myIntersectionOn2S.Point();
687 previoustg = Standard_False;
688 previousd = myIntersectionOn2S.Direction();
689 previousd1 = myIntersectionOn2S.DirectionOnS1();
690 previousd2 = myIntersectionOn2S.DirectionOnS2();
693 firstd1 = previousd1;
694 firstd2 = previousd2;
695 tgfirst = tglast = Standard_False;
696 choixIsoSav = ChoixIso;
697 //------------------------------------------------------------
698 //-- Test if the first point of marching corresponds
699 //-- to a point on borders.
700 //-- In this case, DejaReparti is initialized as True
702 pf = previousPoint.Value();
703 Standard_Boolean bTestFirstPoint = Standard_True;
705 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
706 AddAPoint(line,previousPoint);
708 IntWalk_StatusDeflection Status = IntWalk_OK;
709 Standard_Boolean NoTestDeflection = Standard_False;
710 Standard_Real SvParam[4], f;
711 Standard_Integer LevelOfEmptyInmyIntersectionOn2S=0;
712 Standard_Integer LevelOfPointConfondu = 0;
713 Standard_Integer LevelOfIterWithoutAppend = -1;
715 Arrive = Standard_False;
718 LevelOfIterWithoutAppend++;
719 if(LevelOfIterWithoutAppend>20)
721 Arrive = Standard_True;
725 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
726 LevelOfIterWithoutAppend = 0;
732 case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
733 case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
734 case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
735 case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
743 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
746 Standard_Real aIncKey, aEps, dP1, dP2, dP3, dP4;
748 dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
749 dP2 = sensCheminement * pasuv[1] * previousd1.Y() /f;
750 dP3 = sensCheminement * pasuv[2] * previousd2.X() /f;
751 dP4 = sensCheminement * pasuv[3] * previousd2.Y() /f;
753 aIncKey=5.*(Standard_Real)IncKey;
755 if(ChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < aEps)
760 if(ChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < aEps)
765 if(ChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < aEps)
770 if(ChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < aEps)
780 //==========================
786 ChoixIso= myIntersectionOn2S.Perform(Param, Rsnld, ChoixIso);
788 if (!myIntersectionOn2S.IsDone())
790 //end of line, division
791 Arrive = Standard_False;
796 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
800 //== Calculation of exact point from Param(.) is possible
801 if (myIntersectionOn2S.IsEmpty())
803 Standard_Real u1,v1,u2,v2;
804 previousPoint.Parameters(u1,v1,u2,v2);
806 Arrive = Standard_False;
807 if(u1<UFirst1 || u1>ULast1)
809 Arrive=Standard_True;
812 if(u2<UFirst2 || u2>ULast2)
814 Arrive=Standard_True;
817 if(v1<VFirst1 || v1>VLast1)
819 Arrive=Standard_True;
822 if(v2<VFirst2 || v2>VLast2)
824 Arrive=Standard_True;
827 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
828 LevelOfEmptyInmyIntersectionOn2S++;
830 if(LevelOfEmptyInmyIntersectionOn2S>10)
840 //============================================================
841 //== A point has been found : T E S T D E F L E C T I O N
842 //============================================================
845 NoTestDeflection = Standard_False;
849 if(--LevelOfEmptyInmyIntersectionOn2S<=0)
851 LevelOfEmptyInmyIntersectionOn2S=0;
852 if(LevelOfIterWithoutAppend < 10)
854 Status = TestDeflection();
866 //============================================================
867 //== T r a i t e m e n t s u r S t a t u s ==
868 //============================================================
869 if(LevelOfPointConfondu > 5)
871 Status = IntWalk_ArretSurPoint;
872 LevelOfPointConfondu = 0;
875 if(Status==IntWalk_OK)
878 if(NbPasOKConseq >= 5)
881 Standard_Boolean pastroppetit;
886 pastroppetit=Standard_True;
888 if(pasuv[0]<pasInit[0])
890 t = (pasInit[0]-pasuv[0])*0.25;
897 pastroppetit=Standard_False;
900 if(pasuv[1]<pasInit[1])
902 t = (pasInit[1]-pasuv[1])*0.25;
903 if(t>0.1*pasInit[1]) {
908 pastroppetit=Standard_False;
911 if(pasuv[2]<pasInit[2])
913 t = (pasInit[2]-pasuv[2])*0.25;
920 pastroppetit=Standard_False;
923 if(pasuv[3]<pasInit[3])
925 t = (pasInit[3]-pasuv[3])*0.25;
926 if(t>0.1*pasInit[3]) {
930 pastroppetit=Standard_False;
944 pastroppetit=Standard_False;
950 }//Status==IntWalk_OK
957 case IntWalk_ArretSurPointPrecedent:
959 Arrive = Standard_False;
960 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
963 case IntWalk_PasTropGrand:
970 if(LevelOfIterWithoutAppend > 5)
972 if(pasSav[0]<pasInit[0])
974 pasInit[0]-=(pasInit[0]-pasSav[0])*0.25;
975 LevelOfIterWithoutAppend=0;
978 if(pasSav[1]<pasInit[1])
980 pasInit[1]-=(pasInit[1]-pasSav[1])*0.25;
981 LevelOfIterWithoutAppend=0;
984 if(pasSav[2]<pasInit[2])
986 pasInit[2]-=(pasInit[2]-pasSav[2])*0.25;
987 LevelOfIterWithoutAppend=0;
990 if(pasSav[3]<pasInit[3])
992 pasInit[3]-=(pasInit[3]-pasSav[3])*0.25;
993 LevelOfIterWithoutAppend=0;
999 case IntWalk_PointConfondu:
1001 LevelOfPointConfondu++;
1003 if(LevelOfPointConfondu>5)
1005 Standard_Boolean pastroppetit;
1009 pastroppetit=Standard_True;
1011 if(pasuv[0]<pasInit[0])
1013 pasuv[0]+=(pasInit[0]-pasuv[0])*0.25;
1014 pastroppetit=Standard_False;
1017 if(pasuv[1]<pasInit[1])
1019 pasuv[1]+=(pasInit[1]-pasuv[1])*0.25;
1020 pastroppetit=Standard_False;
1023 if(pasuv[2]<pasInit[2])
1025 pasuv[2]+=(pasInit[2]-pasuv[2])*0.25;
1026 pastroppetit=Standard_False;
1029 if(pasuv[3]<pasInit[3])
1031 pasuv[3]+=(pasInit[3]-pasuv[3])*0.25;
1032 pastroppetit=Standard_False;
1047 pastroppetit=Standard_False;
1051 while(pastroppetit);
1057 case IntWalk_ArretSurPoint://006
1059 //=======================================================
1060 //== Stop Test t : Frame on Param(.) ==
1061 //=======================================================
1063 Arrive = TestArret(DejaReparti,Param,ChoixIso);
1064 // JMB 30th December 1999.
1065 // Some statement below should not be put in comment because they are useful.
1066 // See grid CTO 909 A1 which infinitely loops
1067 if(Arrive==Standard_False && Status==IntWalk_ArretSurPoint)
1069 Arrive=Standard_True;
1071 cout << "Compile with option DEB : if problems with intersection : ";
1072 cout << "IntWalk_PWalking_1.gxx (lbr le 1erdec98)"<<endl;
1078 NbPasOKConseq = -10;
1083 //=====================================================
1084 //== Param(.) is in the limits ==
1085 //== and does not end a closed line ==
1086 //=====================================================
1087 //== Check on the current point of myInters
1088 Standard_Boolean pointisvalid = Standard_False;
1090 Standard_Real u1,v1,u2,v2;
1091 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
1094 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1095 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1096 v1 >= Vm1 && v2 >= Vm2)
1098 pointisvalid=Standard_True;
1105 previousPoint = myIntersectionOn2S.Point();
1106 previoustg = myIntersectionOn2S.IsTangent();
1110 previousd = myIntersectionOn2S.Direction();
1111 previousd1 = myIntersectionOn2S.DirectionOnS1();
1112 previousd2 = myIntersectionOn2S.DirectionOnS2();
1114 //=====================================================
1115 //== Check on the previous Point
1117 Standard_Real u1,v1,u2,v2;
1118 previousPoint.Parameters(u1,v1,u2,v2);
1119 if( u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1120 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1121 v1 >= Vm1 && v2 >= Vm2)
1123 pl = previousPoint.Value();
1126 if(pf.SquareDistance(pl) < aSQDistMax)
1136 bTestFirstPoint = Standard_False;
1140 AddAPoint(line,previousPoint);
1143 if(RejectIndex >= RejectIndexMAX)
1149 LevelOfIterWithoutAppend = 0;
1153 //====================================================
1155 if(Status == IntWalk_ArretSurPoint)
1157 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1161 if (line->NbPoints() == 2)
1163 pasSav[0] = pasuv[0];
1164 pasSav[1] = pasuv[1];
1165 pasSav[2] = pasuv[2];
1166 pasSav[3] = pasuv[3];
1174 //================= la ligne est fermee ===============
1175 AddAPoint(line,line->Value(1)); //ligne fermee
1176 LevelOfIterWithoutAppend=0;
1180 //====================================================
1181 //== Param was not in the limits (was reframed)
1182 //====================================================
1183 Standard_Boolean bPrevNotTangent = !previoustg || !myIntersectionOn2S.IsTangent();
1185 IntImp_ConstIsoparametric SauvChoixIso = ChoixIso;
1186 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
1188 if(!myIntersectionOn2S.IsEmpty()) //002
1190 // mutially outpasses in the square or intersection in corner
1192 if(TestArret(Standard_True,Param,ChoixIso))
1194 NbPasOKConseq = -10;
1195 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
1197 if(!myIntersectionOn2S.IsEmpty())
1199 previousPoint = myIntersectionOn2S.Point();
1200 previoustg = myIntersectionOn2S.IsTangent();
1204 previousd = myIntersectionOn2S.Direction();
1205 previousd1 = myIntersectionOn2S.DirectionOnS1();
1206 previousd2 = myIntersectionOn2S.DirectionOnS2();
1209 pl = previousPoint.Value();
1213 if(pf.SquareDistance(pl) < aSQDistMax)
1223 bTestFirstPoint = Standard_False;
1227 AddAPoint(line,previousPoint);
1230 if(RejectIndex >= RejectIndexMAX)
1236 LevelOfIterWithoutAppend=0;
1237 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1241 //fail framing divides the step
1242 Arrive = Standard_False;
1243 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1244 NoTestDeflection = Standard_True;
1245 ChoixIso = SauvChoixIso;
1250 // save the last point
1251 // to revert to it if the current point is out of bounds
1253 IntSurf_PntOn2S previousPointSave = previousPoint;
1254 Standard_Boolean previoustgSave = previoustg;
1255 gp_Dir previousdSave = previousd;
1256 gp_Dir2d previousd1Save = previousd1;
1257 gp_Dir2d previousd2Save = previousd2;
1259 previousPoint = myIntersectionOn2S.Point();
1260 previoustg = myIntersectionOn2S.IsTangent();
1261 Arrive = Standard_False;
1265 previousd = myIntersectionOn2S.Direction();
1266 previousd1 = myIntersectionOn2S.DirectionOnS1();
1267 previousd2 = myIntersectionOn2S.DirectionOnS2();
1270 //========================================
1271 //== Check on PreviousPoint @@
1274 Standard_Real u1,v1,u2,v2;
1275 previousPoint.Parameters(u1,v1,u2,v2);
1277 //To save initial 2d points
1278 gp_Pnt2d ParamPntOnS1(Param(1), Param(2));
1279 gp_Pnt2d ParamPntOnS2(Param(3), Param(4));
1281 ///////////////////////////
1289 Standard_Boolean bFlag1, bFlag2;
1290 Standard_Real aTol2D=1.e-11;
1292 bFlag1=u1 >= Um1-aTol2D && v1 >= Vm1-aTol2D && u1 <= UM1+aTol2D && v1 <= VM1+aTol2D;
1293 bFlag2=u2 >= Um2-aTol2D && v2 >= Vm2-aTol2D && u2 <= UM2+aTol2D && v2 <= VM2+aTol2D;
1294 if (bFlag1 && bFlag2)
1297 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1298 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1299 v1 >= Vm1 && v2 >= Vm2) {
1302 pl = previousPoint.Value();
1306 if(pf.SquareDistance(pl) < aSQDistMax)
1317 bTestFirstPoint = Standard_False;
1321 //To avoid walking around the same point
1322 //in the tangent zone near a border
1326 Standard_Real prevU1, prevV1, prevU2, prevV2;
1327 previousPointSave.Parameters(prevU1, prevV1, prevU2, prevV2);
1328 gp_Pnt2d prevPntOnS1(prevU1, prevV1), prevPntOnS2(prevU2, prevV2);
1329 gp_Pnt2d curPntOnS1(u1, v1), curPntOnS2(u2, v2);
1330 gp_Vec2d PrevToParamOnS1(prevPntOnS1, ParamPntOnS1);
1331 gp_Vec2d PrevToCurOnS1(prevPntOnS1, curPntOnS1);
1332 gp_Vec2d PrevToParamOnS2(prevPntOnS2, ParamPntOnS2);
1333 gp_Vec2d PrevToCurOnS2(prevPntOnS2, curPntOnS2);
1334 Standard_Real MaxAngle = 3*M_PI/4;
1336 if (Abs(PrevToParamOnS1.Angle(PrevToCurOnS1)) > MaxAngle &&
1337 Abs(PrevToParamOnS2.Angle(PrevToCurOnS2)) > MaxAngle)
1339 Arrive = Standard_True;
1344 ////////////////////////////////////////
1345 AddAPoint(line,previousPoint);
1348 if(RejectIndex >= RejectIndexMAX)
1355 LevelOfIterWithoutAppend=0;
1356 Arrive = Standard_True;
1360 // revert to the last correctly calculated point
1361 previousPoint = previousPointSave;
1362 previoustg = previoustgSave;
1363 previousd = previousdSave;
1364 previousd1 = previousd1Save;
1365 previousd2 = previousd2Save;
1370 Standard_Boolean wasExtended = Standard_False;
1372 if(Arrive && myIntersectionOn2S.IsTangent() && bPrevNotTangent)
1374 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
1376 wasExtended = Standard_True;
1377 Arrive = Standard_False;
1378 ChoixIso = SauvChoixIso;
1382 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1385 myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty() &&
1386 myIntersectionOn2S.IsTangent() && bPrevNotTangent &&
1389 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
1391 wasExtended = Standard_True;
1392 Arrive = Standard_False;
1393 ChoixIso = SauvChoixIso;
1396 }//else !TestArret() $
1397 }//$$ end successful framing on border (!myIntersectionOn2S.IsEmpty())
1400 //echec framing on border; division of step
1401 Arrive = Standard_False;
1402 NoTestDeflection = Standard_True;
1403 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1405 }//$$$ end framing on border (!close)
1406 }//004 fin TestArret return Arrive = True
1407 } // 006case IntWalk_ArretSurPoint: end Processing Status = OK or ArretSurPoint
1408 } //007 switch(Status)
1409 } //008 end processing point (TEST DEFLECTION)
1410 } //009 end processing line (else if myIntersectionOn2S.IsDone())
1411 } //010 end if first departure point allows marching while (!Arrive)
1413 done = Standard_True;
1415 // ===========================================================================================================
1416 // function: ExtendLineInCommonZone
1417 // purpose: Extends already computed line inside tangent zone in the direction given by theChoixIso.
1418 // Returns Standard_True if the line was extended through tangent zone and the last computed point
1419 // is outside the tangent zone (but it is not put into the line). Otherwise returns Standard_False.
1420 // ===========================================================================================================
1421 Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsoparametric theChoixIso,
1422 const Standard_Boolean theDirectionFlag)
1424 Standard_Boolean bOutOfTangentZone = Standard_False;
1425 Standard_Boolean bStop = !myIntersectionOn2S.IsTangent();
1426 Standard_Integer dIncKey = 1;
1427 TColStd_Array1OfReal Param(1,4);
1428 IntWalk_StatusDeflection Status = IntWalk_OK;
1429 Standard_Integer nbIterWithoutAppend = 0;
1430 Standard_Integer nbEqualPoints = 0;
1431 Standard_Integer parit = 0;
1432 Standard_Integer uvit = 0;
1433 IntSurf_SequenceOfPntOn2S aSeqOfNewPoint;
1436 nbIterWithoutAppend++;
1438 if((nbIterWithoutAppend > 20) || (nbEqualPoints > 20)) {
1440 cout<<"Compile with option DEB:";
1441 cout<<"Infinite loop has detected. Stop iterations (IntWalk_PWalking_1.gxx)" << endl;
1443 bStop = Standard_True;
1446 Standard_Real f = 0.;
1448 switch (theChoixIso)
1450 case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
1451 case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
1452 case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
1453 case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
1458 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
1460 Standard_Real dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
1461 Standard_Real dP2 = sensCheminement * pasuv[1] * previousd1.Y() /f;
1462 Standard_Real dP3 = sensCheminement * pasuv[2] * previousd2.X() /f;
1463 Standard_Real dP4 = sensCheminement * pasuv[3] * previousd2.Y() /f;
1465 if(theChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < 1.e-7) dP1 *= (5. * (Standard_Real)dIncKey);
1466 if(theChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < 1.e-7) dP2 *= (5. * (Standard_Real)dIncKey);
1467 if(theChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < 1.e-7) dP3 *= (5. * (Standard_Real)dIncKey);
1468 if(theChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < 1.e-7) dP4 *= (5. * (Standard_Real)dIncKey);
1474 Standard_Real SvParam[4];
1475 IntImp_ConstIsoparametric ChoixIso = theChoixIso;
1477 for(parit = 0; parit < 4; parit++) {
1478 SvParam[parit] = Param(parit+1);
1480 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
1481 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld, theChoixIso);
1483 if (!myIntersectionOn2S.IsDone()) {
1484 return bOutOfTangentZone;
1487 if (myIntersectionOn2S.IsEmpty()) {
1488 return bOutOfTangentZone;
1491 Status = TestDeflection();
1493 if(Status == IntWalk_OK) {
1495 for(uvit = 0; uvit < 4; uvit++) {
1496 if(pasuv[uvit] < pasInit[uvit]) {
1497 pasuv[uvit] = pasInit[uvit];
1503 case IntWalk_ArretSurPointPrecedent:
1505 bStop = Standard_True;
1506 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1509 case IntWalk_PasTropGrand:
1511 for(parit = 0; parit < 4; parit++) {
1512 Param(parit+1) = SvParam[parit];
1514 Standard_Boolean bDecrease = Standard_False;
1516 for(uvit = 0; uvit < 4; uvit++) {
1517 if(pasSav[uvit] < pasInit[uvit]) {
1518 pasInit[uvit] -= (pasInit[uvit] - pasSav[uvit]) * 0.1;
1519 bDecrease = Standard_True;
1523 if(bDecrease) nbIterWithoutAppend--;
1526 case IntWalk_PointConfondu:
1528 for(uvit = 0; uvit < 4; uvit++) {
1529 if(pasuv[uvit] < pasInit[uvit]) {
1530 pasuv[uvit] += (pasInit[uvit] - pasuv[uvit]) * 0.1;
1536 case IntWalk_ArretSurPoint:
1539 bStop = TestArret(theDirectionFlag, Param, ChoixIso);
1544 Standard_Real u11,v11,u12,v12;
1545 myIntersectionOn2S.Point().Parameters(u11,v11,u12,v12);
1546 Standard_Real u21,v21,u22,v22;
1547 previousPoint.Parameters(u21,v21,u22,v22);
1549 if(((fabs(u11-u21) < ResoU1) && (fabs(v11-v21) < ResoV1)) ||
1550 ((fabs(u12-u22) < ResoU2) && (fabs(v12-v22) < ResoV2))) {
1559 bStop = bStop || !myIntersectionOn2S.IsTangent();
1560 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1563 Standard_Boolean pointisvalid = Standard_False;
1564 Standard_Real u1,v1,u2,v2;
1565 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
1567 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1568 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1569 v1 >= Vm1 && v2 >= Vm2)
1570 pointisvalid = Standard_True;
1573 previousPoint = myIntersectionOn2S.Point();
1574 previoustg = myIntersectionOn2S.IsTangent();
1577 previousd = myIntersectionOn2S.Direction();
1578 previousd1 = myIntersectionOn2S.DirectionOnS1();
1579 previousd2 = myIntersectionOn2S.DirectionOnS2();
1581 Standard_Boolean bAddPoint = Standard_True;
1583 if(line->NbPoints() >= 1) {
1584 gp_Pnt pf = line->Value(1).Value();
1585 gp_Pnt pl = previousPoint.Value();
1587 if(pf.Distance(pl) < Precision::Confusion()) {
1589 if(dIncKey == 5000) return bOutOfTangentZone;
1590 else bAddPoint = Standard_False;
1595 aSeqOfNewPoint.Append(previousPoint);
1596 nbIterWithoutAppend = 0;
1600 if (line->NbPoints() == 2) {
1601 for(uvit = 0; uvit < 4; uvit++) {
1602 pasSav[uvit] = pasuv[uvit];
1606 if ( !pointisvalid ) {
1607 // decrease step if out of bounds
1608 // otherwise the same calculations will be
1609 // repeated several times
1610 if ( ( u1 > UM1 ) || ( u1 < Um1 ) )
1613 if ( ( v1 > VM1 ) || ( v1 < Vm1 ) )
1616 if ( ( u2 > UM2 ) || ( u2 < Um2 ) )
1619 if ( ( v2 > VM2 ) || ( v2 < Vm2 ) )
1624 if(close && (line->NbPoints() >= 1)) {
1626 if(!bOutOfTangentZone) {
1627 aSeqOfNewPoint.Append(line->Value(1)); // line end
1629 nbIterWithoutAppend = 0;
1632 ChoixIso = myIntersectionOn2S.Perform(Param, Rsnld, theChoixIso);
1634 if(myIntersectionOn2S.IsEmpty()) {
1635 bStop = !myIntersectionOn2S.IsTangent();
1636 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1639 Standard_Boolean bAddPoint = Standard_True;
1640 Standard_Boolean pointisvalid = Standard_False;
1642 previousPoint = myIntersectionOn2S.Point();
1643 Standard_Real u1,v1,u2,v2;
1644 previousPoint.Parameters(u1,v1,u2,v2);
1646 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1647 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1648 v1 >= Vm1 && v2 >= Vm2)
1649 pointisvalid = Standard_True;
1653 if(line->NbPoints() >= 1) {
1654 gp_Pnt pf = line->Value(1).Value();
1655 gp_Pnt pl = previousPoint.Value();
1657 if(pf.Distance(pl) < Precision::Confusion()) {
1659 if(dIncKey == 5000) return bOutOfTangentZone;
1660 else bAddPoint = Standard_False;
1664 if(bAddPoint && !bOutOfTangentZone) {
1665 aSeqOfNewPoint.Append(previousPoint);
1666 nbIterWithoutAppend = 0;
1681 Standard_Boolean bExtendLine = Standard_False;
1682 Standard_Real u1 = 0., v1 = 0., u2 = 0., v2 = 0.;
1684 Standard_Integer pit = 0;
1686 for(pit = 0; !bExtendLine && (pit < 2); pit++) {
1688 previousPoint.Parameters(u1,v1,u2,v2);
1690 if(aSeqOfNewPoint.Length() > 0)
1691 aSeqOfNewPoint.Value(aSeqOfNewPoint.Length()).Parameters(u1,v1,u2,v2);
1696 if(((u1 - Um1) < ResoU1) ||
1697 ((UM1 - u1) < ResoU1) ||
1698 ((u2 - Um2) < ResoU2) ||
1699 ((UM2 - u2) < ResoU2) ||
1700 ((v1 - Vm1) < ResoV1) ||
1701 ((VM1 - v1) < ResoV1) ||
1702 ((v2 - Vm2) < ResoV2) ||
1703 ((VM2 - v2) < ResoV2))
1704 bExtendLine = Standard_True;
1708 // if(Status == IntWalk_OK || Status == IntWalk_ArretSurPoint) {
1709 if(Status == IntWalk_OK) {
1710 bExtendLine = Standard_True;
1712 if(aSeqOfNewPoint.Length() > 1) {
1713 TColStd_Array1OfReal FirstParams(0, 3), LastParams(0, 3), Resolutions(0, 3);
1714 Resolutions(0) = ResoU1; Resolutions(1) = ResoV1; Resolutions(2) = ResoU2; Resolutions(3) = ResoV2;
1716 aSeqOfNewPoint(1).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1717 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1718 aSeqOfNewPoint(aSeqOfNewPoint.Length()).Parameters(LastParams.ChangeValue(0),
1719 LastParams.ChangeValue(1),
1720 LastParams.ChangeValue(2),
1721 LastParams.ChangeValue(3));
1722 Standard_Integer indexofiso = 0;
1724 if(theChoixIso == IntImp_UIsoparametricOnCaro1) indexofiso = 0;
1725 if(theChoixIso == IntImp_VIsoparametricOnCaro1) indexofiso = 1;
1726 if(theChoixIso == IntImp_UIsoparametricOnCaro2) indexofiso = 2;
1727 if(theChoixIso == IntImp_VIsoparametricOnCaro2) indexofiso = 3;
1729 Standard_Integer afirstindex = (indexofiso < 2) ? 0 : 2;
1730 gp_Vec2d aTangentZoneDir(gp_Pnt2d(FirstParams.Value(afirstindex), FirstParams.Value(afirstindex + 1)),
1731 gp_Pnt2d(LastParams.Value(afirstindex), LastParams.Value(afirstindex + 1)));
1733 gp_Dir2d anIsoDir(0, 1);
1735 if((indexofiso == 1) || (indexofiso == 3))
1736 anIsoDir = gp_Dir2d(1, 0);
1738 if(aTangentZoneDir.SquareMagnitude() > gp::Resolution()) {
1739 Standard_Real piquota = M_PI*0.25;
1741 if(fabs(aTangentZoneDir.Angle(anIsoDir)) > piquota) {
1742 Standard_Integer ii = 1, nextii = 2;
1744 Standard_Real asqresol = gp::Resolution();
1745 asqresol *= asqresol;
1748 aSeqOfNewPoint(ii).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1749 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1750 aSeqOfNewPoint(ii + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1751 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1752 d1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1753 FirstParams.Value(afirstindex + 1)),
1754 gp_Pnt2d(LastParams.Value(afirstindex),
1755 LastParams.Value(afirstindex + 1)));
1758 while((d1.SquareMagnitude() < asqresol) &&
1759 (ii < aSeqOfNewPoint.Length()));
1763 while(nextii < aSeqOfNewPoint.Length()) {
1765 gp_Vec2d nextd1(0, 0);
1766 Standard_Integer jj = nextii;
1769 aSeqOfNewPoint(jj).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1770 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1771 aSeqOfNewPoint(jj + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1772 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1773 nextd1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1774 FirstParams.Value(afirstindex + 1)),
1775 gp_Pnt2d(LastParams.Value(afirstindex),
1776 LastParams.Value(afirstindex + 1)));
1780 while((nextd1.SquareMagnitude() < asqresol) &&
1781 (jj < aSeqOfNewPoint.Length()));
1784 if(fabs(d1.Angle(nextd1)) > piquota) {
1785 bExtendLine = Standard_False;
1791 // end if(fabs(aTangentZoneDir.Angle(anIsoDir)
1798 return Standard_False;
1800 Standard_Integer i = 0;
1802 for(i = 1; i <= aSeqOfNewPoint.Length(); i++) {
1803 AddAPoint(line, aSeqOfNewPoint.Value(i));
1806 return bOutOfTangentZone;
1809 //=======================================================================
1810 //function : DistanceMinimizeByGradient
1812 //=======================================================================
1813 Standard_Boolean IntWalk_PWalking::
1814 DistanceMinimizeByGradient( const Handle(Adaptor3d_HSurface)& theASurf1,
1815 const Handle(Adaptor3d_HSurface)& theASurf2,
1816 Standard_Real& theU1,
1817 Standard_Real& theV1,
1818 Standard_Real& theU2,
1819 Standard_Real& theV2,
1820 const Standard_Real theStep0U1V1,
1821 const Standard_Real theStep0U2V2)
1823 const Standard_Integer aNbIterMAX = 60;
1824 const Standard_Real aTol = 1.0e-14;
1825 Handle(Geom_Surface) aS1, aS2;
1827 switch(theASurf1->GetType())
1829 case GeomAbs_BezierSurface:
1830 aS1 = theASurf1->Surface().Bezier();
1832 case GeomAbs_BSplineSurface:
1833 aS1 = theASurf1->Surface().BSpline();
1836 return Standard_True;
1839 switch(theASurf2->GetType())
1841 case GeomAbs_BezierSurface:
1842 aS2 = theASurf2->Surface().Bezier();
1844 case GeomAbs_BSplineSurface:
1845 aS2 = theASurf2->Surface().BSpline();
1848 return Standard_True;
1851 Standard_Boolean aStatus = Standard_False;
1854 gp_Vec aD1u, aD1v, aD2U, aD2V;
1856 aS1->D1(theU1, theV1, aP1, aD1u, aD1v);
1857 aS2->D1(theU2, theV2, aP2, aD2U, aD2V);
1859 Standard_Real aSQDistPrev = aP1.SquareDistance(aP2);
1861 gp_Vec aP12(aP1, aP2);
1863 Standard_Real aGradFu(-aP12.Dot(aD1u));
1864 Standard_Real aGradFv(-aP12.Dot(aD1v));
1865 Standard_Real aGradFU( aP12.Dot(aD2U));
1866 Standard_Real aGradFV( aP12.Dot(aD2V));
1868 Standard_Real aSTEPuv = theStep0U1V1, aStepUV = theStep0U2V2;
1870 Standard_Boolean flRepeat = Standard_True;
1871 Standard_Integer aNbIter = aNbIterMAX;
1875 Standard_Real anAdd = aGradFu*aSTEPuv;
1876 Standard_Real aPARu = (anAdd >= 0.0)?
1877 (theU1 - Max(anAdd, Epsilon(theU1))) :
1878 (theU1 + Max(-anAdd, Epsilon(theU1)));
1879 anAdd = aGradFv*aSTEPuv;
1880 Standard_Real aPARv = (anAdd >= 0.0)?
1881 (theV1 - Max(anAdd, Epsilon(theV1))) :
1882 (theV1 + Max(-anAdd, Epsilon(theV1)));
1883 anAdd = aGradFU*aStepUV;
1884 Standard_Real aParU = (anAdd >= 0.0)?
1885 (theU2 - Max(anAdd, Epsilon(theU2))) :
1886 (theU2 + Max(-anAdd, Epsilon(theU2)));
1887 anAdd = aGradFV*aStepUV;
1888 Standard_Real aParV = (anAdd >= 0.0)?
1889 (theV2 - Max(anAdd, Epsilon(theV2))) :
1890 (theV2 + Max(-anAdd, Epsilon(theV2)));
1894 aS1->D1(aPARu, aPARv, aPt1, aD1u, aD1v);
1895 aS2->D1(aParU, aParV, aPt2, aD2U, aD2V);
1897 Standard_Real aSQDist = aPt1.SquareDistance(aPt2);
1899 if(aSQDist < aSQDistPrev)
1901 aSQDistPrev = aSQDist;
1907 aStatus = aSQDistPrev < aTol;
1915 flRepeat = Standard_False;
1919 aS1->D1(theU1, theV1, aPt1, aD1u, aD1v);
1920 aS2->D1(theU2, theV2, aPt2, aD2U, aD2V);
1922 gp_Vec aP12(aPt1, aPt2);
1923 aGradFu = -aP12.Dot(aD1u);
1924 aGradFv = -aP12.Dot(aD1v);
1925 aGradFU = aP12.Dot(aD2U);
1926 aGradFV = aP12.Dot(aD2V);
1927 aSTEPuv = theStep0U1V1;
1928 aStepUV = theStep0U2V2;
1936 //=======================================================================
1937 //function : DistanceMinimizeByExtrema
1939 //=======================================================================
1940 Standard_Boolean IntWalk_PWalking::
1941 DistanceMinimizeByExtrema(const Handle(Adaptor3d_HSurface)& theASurf,
1942 const gp_Pnt& theP0,
1943 Standard_Real& theU0,
1944 Standard_Real& theV0,
1945 const Standard_Real theStep0U,
1946 const Standard_Real theStep0V)
1948 const Standard_Real aTol = 1.0e-14;
1950 gp_Vec aD1Su, aD1Sv, aD2Su, aD2Sv, aD2SuvTemp;
1951 Standard_Real aSQDistPrev = RealLast();
1952 Standard_Real aU = theU0, aV = theV0;
1954 Standard_Integer aNbIter = 10;
1957 theASurf->D2(aU, aV, aPS, aD1Su, aD1Sv, aD2Su, aD2Sv, aD2SuvTemp);
1959 gp_Vec aVec(theP0, aPS);
1961 Standard_Real aSQDist = aVec.SquareMagnitude();
1963 if(aSQDist >= aSQDistPrev)
1966 aSQDistPrev = aSQDist;
1971 if(aSQDistPrev < aTol)
1975 const Standard_Real aF1 = aD1Su.Dot(aVec), aF2 = aD1Sv.Dot(aVec);
1978 const Standard_Real aDf1u = aD2Su.Dot(aVec) + aD1Su.Dot(aD1Su),
1979 aDf1v = aD2Su.Dot(aD1Sv),
1981 aDf2v = aD2Sv.Dot(aVec) + aD1Sv.Dot(aD1Sv);
1983 const Standard_Real aDet = aDf1u*aDf2v - aDf1v*aDf2u;
1984 aU -= theStep0U*(aDf2v*aF1 - aDf1v*aF2)/aDet;
1985 aV += theStep0V*(aDf2u*aF1 - aDf1u*aF2)/aDet;
1989 return (aSQDistPrev < aTol);
1992 //=======================================================================
1993 //function : SeekPointOnBoundary
1995 //=======================================================================
1996 Standard_Boolean IntWalk_PWalking::
1997 SeekPointOnBoundary(const Handle(Adaptor3d_HSurface)& theASurf1,
1998 const Handle(Adaptor3d_HSurface)& theASurf2,
1999 const Standard_Real theU1,
2000 const Standard_Real theV1,
2001 const Standard_Real theU2,
2002 const Standard_Real theV2,
2003 const Standard_Boolean isTheFirst)
2005 const Standard_Real aTol = 1.0e-14;
2006 Standard_Boolean isOK = Standard_False;
2007 Standard_Real U1prec = theU1, V1prec = theV1, U2prec = theU2, V2prec = theV2;
2009 Standard_Boolean flFinish = Standard_False;
2011 Standard_Integer aNbIter = 20;
2014 flFinish = Standard_False;
2015 Standard_Boolean aStatus = Standard_False;
2020 aStatus = DistanceMinimizeByGradient(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec);
2026 aStatus = DistanceMinimizeByExtrema(theASurf1, theASurf2->Value(U2prec, V2prec), U1prec, V1prec);
2032 aStatus = DistanceMinimizeByExtrema(theASurf2, theASurf1->Value(U1prec, V1prec), U2prec, V2prec);
2038 while(!aStatus && (aNbIter > 0));
2042 const Standard_Real aTolMax = 1.0e-8;
2043 Standard_Real aTolF = 0.0;
2045 Standard_Real u1 = U1prec, v1 = V1prec, u2 = U2prec, v2 = V2prec;
2047 flFinish = Checking(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec, aTolF);
2049 if(aTolF <= aTolMax)
2051 gp_Pnt aP1 = theASurf1->Value(u1, v1),
2052 aP2 = theASurf2->Value(u2, v2);
2053 gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
2055 const Standard_Real aSQDist1 = aPInt.SquareDistance(aP1),
2056 aSQDist2 = aPInt.SquareDistance(aP2);
2057 if((aSQDist1 < aTol) && (aSQDist2 < aTol))
2059 IntSurf_PntOn2S anIP;
2060 anIP.SetValue(aPInt, u1, v1, u2, v2);
2063 line->InsertBefore(1,anIP);
2067 isOK = Standard_True;
2083 //=======================================================================
2084 //function : PutToBoundary
2086 //=======================================================================
2087 Standard_Boolean IntWalk_PWalking::
2088 PutToBoundary(const Handle(Adaptor3d_HSurface)& theASurf1,
2089 const Handle(Adaptor3d_HSurface)& theASurf2)
2091 const Standard_Real aTolMin = Precision::Confusion();
2093 Standard_Boolean hasBeenAdded = Standard_False;
2095 const Standard_Real aU1bFirst = theASurf1->FirstUParameter();
2096 const Standard_Real aU1bLast = theASurf1->LastUParameter();
2097 const Standard_Real aU2bFirst = theASurf2->FirstUParameter();
2098 const Standard_Real aU2bLast = theASurf2->LastUParameter();
2099 const Standard_Real aV1bFirst = theASurf1->FirstVParameter();
2100 const Standard_Real aV1bLast = theASurf1->LastVParameter();
2101 const Standard_Real aV2bFirst = theASurf2->FirstVParameter();
2102 const Standard_Real aV2bLast = theASurf2->LastVParameter();
2104 Standard_Real aTol = 1.0;
2105 aTol = Min(aTol, aU1bLast - aU1bFirst);
2106 aTol = Min(aTol, aU2bLast - aU2bFirst);
2107 aTol = Min(aTol, aV1bLast - aV1bFirst);
2108 aTol = Min(aTol, aV2bLast - aV2bFirst)*1.0e-3;
2110 if(aTol <= 2.0*aTolMin)
2111 return hasBeenAdded;
2113 Standard_Boolean isNeedAdding = Standard_False;
2114 Standard_Boolean isU1parallel = Standard_False, isV1parallel = Standard_False;
2115 Standard_Boolean isU2parallel = Standard_False, isV2parallel = Standard_False;
2116 IsParallel(line, Standard_True, aTol, isU1parallel, isV1parallel);
2117 IsParallel(line, Standard_False, aTol, isU2parallel, isV2parallel);
2119 const Standard_Integer aNbPnts = line->NbPoints();
2120 Standard_Real u1, v1, u2, v2;
2121 line->Value(1).Parameters(u1, v1, u2, v2);
2122 Standard_Real aDelta = 0.0;
2126 aDelta = u1 - aU1bFirst;
2127 if((aTolMin < aDelta) && (aDelta < aTol))
2129 u1 = aU1bFirst - aDelta;
2130 isNeedAdding = Standard_True;
2134 aDelta = aU1bLast - u1;
2135 if((aTolMin < aDelta) && (aDelta < aTol))
2137 u1 = aU1bLast + aDelta;
2138 isNeedAdding = Standard_True;
2145 aDelta = u2 - aU2bFirst;
2146 if((aTolMin < aDelta) && (aDelta < aTol))
2148 u2 = aU2bFirst - aDelta;
2149 isNeedAdding = Standard_True;
2153 aDelta = aU2bLast - u2;
2154 if((aTolMin < aDelta) && (aDelta < aTol))
2156 u2 = aU2bLast + aDelta;
2157 isNeedAdding = Standard_True;
2164 aDelta = v1 - aV1bFirst;
2165 if((aTolMin < aDelta) && (aDelta < aTol))
2167 v1 = aV1bFirst - aDelta;
2168 isNeedAdding = Standard_True;
2172 aDelta = aV1bLast - v1;
2173 if((aTolMin < aDelta) && (aDelta < aTol))
2175 v1 = aV1bLast + aDelta;
2176 isNeedAdding = Standard_True;
2183 aDelta = v2 - aV2bFirst;
2184 if((aTolMin < aDelta) && (aDelta < aTol))
2186 v2 = aV2bFirst - aDelta;
2187 isNeedAdding = Standard_True;
2191 aDelta = aV2bLast - v2;
2192 if((aTolMin < aDelta) && (aDelta < aTol))
2194 v2 = aV2bLast + aDelta;
2195 isNeedAdding = Standard_True;
2203 SeekPointOnBoundary(theASurf1, theASurf2, u1,
2204 v1, u2, v2, Standard_True);
2207 isNeedAdding = Standard_False;
2208 line->Value(aNbPnts).Parameters(u1, v1, u2, v2);
2212 aDelta = u1 - aU1bFirst;
2213 if((aTolMin < aDelta) && (aDelta < aTol))
2215 u1 = aU1bFirst - aDelta;
2216 isNeedAdding = Standard_True;
2220 aDelta = aU1bLast - u1;
2221 if((aTolMin < aDelta) && (aDelta < aTol))
2223 u1 = aU1bLast + aDelta;
2224 isNeedAdding = Standard_True;
2231 aDelta = u2 - aU2bFirst;
2232 if((aTolMin < aDelta) && (aDelta < aTol))
2234 u2 = aU2bFirst - aDelta;
2235 isNeedAdding = Standard_True;
2239 aDelta = aU2bLast - u2;
2240 if((aTolMin < aDelta) && (aDelta < aTol))
2242 u2 = aU2bLast + aDelta;
2243 isNeedAdding = Standard_True;
2250 aDelta = v1 - aV1bFirst;
2251 if((aTolMin < aDelta) && (aDelta < aTol))
2253 v1 = aV1bFirst - aDelta;
2254 isNeedAdding = Standard_True;
2258 aDelta = aV1bLast - v1;
2259 if((aTolMin < aDelta) && (aDelta < aTol))
2261 v1 = aV1bLast + aDelta;
2262 isNeedAdding = Standard_True;
2269 aDelta = v2 - aV2bFirst;
2270 if((aTolMin < aDelta) && (aDelta < aTol))
2272 v2 = aV2bFirst - aDelta;
2273 isNeedAdding = Standard_True;
2277 aDelta = aV2bLast - v2;
2278 if((aTolMin < aDelta) && (aDelta < aTol))
2280 v2 = aV2bLast + aDelta;
2281 isNeedAdding = Standard_True;
2289 SeekPointOnBoundary(theASurf1, theASurf2, u1,
2290 v1, u2, v2, Standard_False);
2293 return hasBeenAdded;
2296 //=======================================================================
2297 //function : SeekAdditionalPoints
2299 //=======================================================================
2300 Standard_Boolean IntWalk_PWalking::
2301 SeekAdditionalPoints( const Handle(Adaptor3d_HSurface)& theASurf1,
2302 const Handle(Adaptor3d_HSurface)& theASurf2,
2303 const Standard_Integer theMinNbPoints)
2305 const Standard_Real aTol = 1.0e-14;
2306 Standard_Integer aNbPoints = line->NbPoints();
2307 if(aNbPoints > theMinNbPoints)
2308 return Standard_True;
2310 const Standard_Real aU1bFirst = theASurf1->FirstUParameter();
2311 const Standard_Real aU1bLast = theASurf1->LastUParameter();
2312 const Standard_Real aU2bFirst = theASurf2->FirstUParameter();
2313 const Standard_Real aU2bLast = theASurf2->LastUParameter();
2314 const Standard_Real aV1bFirst = theASurf1->FirstVParameter();
2315 const Standard_Real aV1bLast = theASurf1->LastVParameter();
2316 const Standard_Real aV2bFirst = theASurf2->FirstVParameter();
2317 const Standard_Real aV2bLast = theASurf2->LastVParameter();
2320 Standard_Boolean isPrecise = Standard_False;
2322 Standard_Real U1prec = 0.0, V1prec = 0.0, U2prec = 0.0, V2prec = 0.0;
2324 Standard_Integer aNbPointsPrev = 0;
2325 while(aNbPoints < theMinNbPoints && (aNbPoints != aNbPointsPrev))
2327 aNbPointsPrev = aNbPoints;
2328 for(Standard_Integer fp = 1, lp = 2; fp < aNbPoints; fp = lp + 1)
2330 Standard_Real U1f, V1f, U2f, V2f; //first point in 1st and 2nd surafaces
2331 Standard_Real U1l, V1l, U2l, V2l; //last point in 1st and 2nd surafaces
2334 line->Value(fp).Parameters(U1f, V1f, U2f, V2f);
2335 line->Value(lp).Parameters(U1l, V1l, U2l, V2l);
2337 U1prec = 0.5*(U1f+U1l);
2338 if(U1prec < aU1bFirst)
2340 if(U1prec > aU1bLast)
2343 V1prec = 0.5*(V1f+V1l);
2344 if(V1prec < aV1bFirst)
2346 if(V1prec > aV1bLast)
2349 U2prec = 0.5*(U2f+U2l);
2350 if(U2prec < aU2bFirst)
2352 if(U2prec > aU2bLast)
2355 V2prec = 0.5*(V2f+V2l);
2356 if(V2prec < aV2bFirst)
2358 if(V2prec > aV2bLast)
2361 Standard_Boolean aStatus = Standard_False;
2362 Standard_Integer aNbIter = 5;
2365 aStatus = DistanceMinimizeByGradient(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec);
2371 aStatus = DistanceMinimizeByExtrema(theASurf1, theASurf2->Value(U2prec, V2prec), U1prec, V1prec);
2377 aStatus = DistanceMinimizeByExtrema(theASurf2, theASurf1->Value(U1prec, V1prec), U2prec, V2prec);
2383 while(!aStatus && (--aNbIter > 0));
2387 gp_Pnt aP1 = theASurf1->Value(U1prec, V1prec),
2388 aP2 = theASurf2->Value(U2prec, V2prec);
2389 gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
2391 const Standard_Real aSQDist1 = aPInt.SquareDistance(aP1),
2392 aSQDist2 = aPInt.SquareDistance(aP2);
2394 if((aSQDist1 < aTol) && (aSQDist2 < aTol))
2396 IntSurf_PntOn2S anIP;
2397 anIP.SetValue(aPInt, U1prec, V1prec, U2prec, V2prec);
2398 line->InsertBefore(lp, anIP);
2400 isPrecise = Standard_True;
2402 if(++aNbPoints >= theMinNbPoints)
2416 void IntWalk_PWalking::
2417 RepartirOuDiviser(Standard_Boolean& DejaReparti,
2418 IntImp_ConstIsoparametric& ChoixIso,
2419 Standard_Boolean& Arrive)
2421 // at the neighborhood of a point, there is a fail of marching
2422 // it is required to divide the steps to try to continue
2423 // if the step is too small if we are on border
2424 // restart in another direction if it was not done, otherwise stop
2427 // Standard_Integer i;
2428 if (Arrive) { //restart in the other direction
2429 if (!DejaReparti ) {
2430 Arrive = Standard_False;
2431 DejaReparti = Standard_True;
2432 previousPoint = line->Value(1);
2433 previoustg = Standard_False;
2434 previousd1 = firstd1;
2435 previousd2 = firstd2;
2437 indextg = line->NbPoints();
2441 //-- printf("\nIntWalk_PWalking_2.gxx Reverse %3d\n",indextg);
2442 sensCheminement = -1;
2444 tglast = Standard_False;
2445 ChoixIso = choixIsoSav;
2452 Standard_Real u1,v1,u2,v2;
2453 Standard_Real U1,V1,U2,V2;
2454 Standard_Integer nn=line->NbPoints();
2456 line->Value(nn).Parameters(u1,v1,u2,v2);
2457 line->Value(nn-1).Parameters(U1,V1,U2,V2);
2458 pasuv[0]=Abs(u1-U1);
2459 pasuv[1]=Abs(v1-V1);
2460 pasuv[2]=Abs(u2-U2);
2461 pasuv[3]=Abs(v2-V2);
2468 if ( pasuv[0]*0.5 < ResoU1
2469 && pasuv[1]*0.5 < ResoV1
2470 && pasuv[2]*0.5 < ResoU2
2471 && pasuv[3]*0.5 < ResoV2
2474 tglast = Standard_True; // IS IT ENOUGH ????
2477 if (!DejaReparti) { //restart in the other direction
2478 DejaReparti = Standard_True;
2479 previousPoint = line->Value(1);
2480 previoustg = Standard_False;
2481 previousd1 = firstd1;
2482 previousd2 = firstd2;
2484 indextg = line->NbPoints();
2488 //-- printf("\nIntWalk_PWalking_2.gxx Reverse %3d\n",indextg);
2490 sensCheminement = -1;
2492 tglast = Standard_False;
2493 ChoixIso = choixIsoSav;
2501 Standard_Real u1,v1,u2,v2;
2502 Standard_Real U1,V1,U2,V2;
2503 Standard_Integer nn=line->NbPoints();
2505 line->Value(nn).Parameters(u1,v1,u2,v2);
2506 line->Value(nn-1).Parameters(U1,V1,U2,V2);
2507 pasuv[0]=Abs(u1-U1);
2508 pasuv[1]=Abs(v1-V1);
2509 pasuv[2]=Abs(u2-U2);
2510 pasuv[3]=Abs(v2-V2);
2514 else Arrive = Standard_True;
2526 //OCC431(apo): modified ->
2527 static const Standard_Real CosRef2D = Cos(M_PI/9.0), AngRef2D = M_PI/2.0;
2529 static const Standard_Real d = 7.0;
2532 IntWalk_StatusDeflection IntWalk_PWalking::TestDeflection()
2534 // test if vector is observed by calculating an increase of vector
2535 // or the previous point and its tangent, the new calculated point and its
2536 // tangent; it is possible to find a cube passing by the 2 points and having as a
2537 // derivative the tangents of the intersection
2538 // calculate the point with parameter 0.5 on cube=p1
2539 // calculate the medium point of 2 points of intersection=p2
2540 // if arrow/2<=||p1p2||<= arrow consider that the vector is observed
2541 // otherwise adjust the step depending on the ratio ||p1p2||/vector
2542 // and the previous step
2543 // test if in 2 tangent planes of surfaces there is no too great angle2d
2544 // grand : if yes divide the step
2545 // test if there is no change of side
2548 if(line->NbPoints() ==1 ) {
2549 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=STATIC_PRECEDENT_INFLEXION=0;
2552 IntWalk_StatusDeflection Status = IntWalk_OK;
2553 Standard_Real FlecheCourante ,Ratio;
2556 const IntSurf_PntOn2S& CurrentPoint = myIntersectionOn2S.Point();
2557 //==================================================================================
2558 //========= S t o p o n p o i n t ============
2559 //==================================================================================
2560 if (myIntersectionOn2S.IsTangent()) {
2561 return IntWalk_ArretSurPoint;
2564 const gp_Dir& TgCourante = myIntersectionOn2S.Direction();
2566 //==================================================================================
2567 //========= R i s k o f i n f l e x i o n p o i n t ============
2568 //==================================================================================
2569 if (TgCourante.Dot(previousd)<0) {
2570 //------------------------------------------------------------
2571 //-- Risk of inflexion point : Divide the step by 2
2572 //-- Initialize STATIC_PRECEDENT_INFLEXION so that
2573 //-- at the next call to return Pas_OK if there is no
2574 //-- more risk of the point of inflexion
2575 //------------------------------------------------------------
2581 STATIC_PRECEDENT_INFLEXION+=3;
2582 if (pasuv[0] < ResoU1 && pasuv[1] <ResoV1 && pasuv[2] <ResoU2 && pasuv[3] < ResoV2)
2583 return IntWalk_ArretSurPointPrecedent;
2585 return IntWalk_PasTropGrand;
2589 if(STATIC_PRECEDENT_INFLEXION > 0) {
2590 STATIC_PRECEDENT_INFLEXION -- ;
2595 //==================================================================================
2596 //========= D e t e c t c o n f u s e d P o in t s ===========
2597 //==================================================================================
2599 Standard_Real Dist = previousPoint.Value().
2600 SquareDistance(CurrentPoint.Value());
2603 if (Dist < tolconf*tolconf ) {
2604 pasuv[0] = Max(5.*ResoU1,Min(1.5*pasuv[0],pasInit[0]));
2605 pasuv[1] = Max(5.*ResoV1,Min(1.5*pasuv[1],pasInit[1]));
2606 pasuv[2] = Max(5.*ResoU2,Min(1.5*pasuv[2],pasInit[2]));
2607 pasuv[3] = Max(5.*ResoV2,Min(1.5*pasuv[3],pasInit[3]));
2608 Status = IntWalk_PointConfondu;
2611 //==================================================================================
2612 Standard_Real Up1,Vp1,Uc1,Vc1,Du1,Dv1,AbsDu1,AbsDu2,AbsDv1,AbsDv2;
2613 Standard_Real Up2,Vp2,Uc2,Vc2,Du2,Dv2;
2615 previousPoint.Parameters(Up1,Vp1,Up2,Vp2);
2616 CurrentPoint.Parameters(Uc1,Vc1,Uc2,Vc2);
2618 Du1 = Uc1 - Up1; Dv1 = Vc1 - Vp1;
2619 Du2 = Uc2 - Up2; Dv2 = Vc2 - Vp2;
2625 //=================================================================================
2626 //==== S t e p o f p r o g r e s s i o n (between previous and Current) =======
2627 //=================================================================================
2628 if ( AbsDu1 < ResoU1 && AbsDv1 < ResoV1
2629 && AbsDu2 < ResoU2 && AbsDv2 < ResoV2) {
2630 pasuv[0] = ResoU1; pasuv[1] = ResoV1; pasuv[2] = ResoU2; pasuv[3] = ResoV2;
2631 return(IntWalk_ArretSurPointPrecedent);
2633 //==================================================================================
2635 Standard_Real tolArea = 100.0;
2636 if (ResoU1 < Precision::PConfusion() ||
2637 ResoV1 < Precision::PConfusion() ||
2638 ResoU2 < Precision::PConfusion() ||
2639 ResoV2 < Precision::PConfusion() )
2640 tolArea = tolArea*2.0;
2642 Standard_Real Cosi1, CosRef1, Ang1, AngRef1, ResoUV1, Duv1, d1, tolCoeff1;
2643 Standard_Real Cosi2, CosRef2, Ang2, AngRef2, ResoUV2, Duv2, d2, tolCoeff2;
2644 Cosi1 = Du1*previousd1.X() + Dv1*previousd1.Y();
2645 Cosi2 = Du2*previousd2.X() + Dv2*previousd2.Y();
2646 Duv1 = Du1*Du1 + Dv1*Dv1;
2647 Duv2 = Du2*Du2 + Dv2*Dv2;
2648 ResoUV1 = ResoU1*ResoU1 + ResoV1*ResoV1;
2649 ResoUV2 = ResoU2*ResoU2 + ResoV2*ResoV2;
2651 //modified by NIZNHY-PKV Wed Nov 13 12:25:44 2002 f
2653 Standard_Real aMinDiv2=Precision::Confusion();
2654 aMinDiv2=aMinDiv2*aMinDiv2;
2657 if (Duv1>aMinDiv2) {
2658 d1 = Abs(ResoUV1/Duv1);
2659 d1 = Min(Sqrt(d1)*tolArea, d);
2661 //d1 = Abs(ResoUV1/Duv1);
2662 //d1 = Min(Sqrt(d1)*tolArea,d);
2663 //modified by NIZNHY-PKV Wed Nov 13 12:34:30 2002 t
2664 tolCoeff1 = Exp(d1);
2666 //modified by NIZNHY-PKV Wed Nov 13 12:34:43 2002 f
2668 if (Duv2>aMinDiv2) {
2669 d2 = Abs(ResoUV2/Duv2);
2670 d2 = Min(Sqrt(d2)*tolArea,d);
2672 //d2 = Abs(ResoUV2/Duv2);
2673 //d2 = Min(Sqrt(d2)*tolArea,d);
2674 //modified by NIZNHY-PKV Wed Nov 13 12:34:53 2002 t
2675 tolCoeff2 = Exp(d2);
2676 CosRef1 = CosRef2D/tolCoeff1;
2677 CosRef2 = CosRef2D/tolCoeff2;
2679 //==================================================================================
2680 //== The points are not confused : ==
2681 //== D e t e c t t h e S t o p a t p r e v i o u s p o i n t ==
2682 //== N o t T o o G r e a t (angle in space UV) ==
2683 //== C h a n g e o f s i d e ==
2684 //==================================================================================
2685 if (Status != IntWalk_PointConfondu) {
2686 if(Cosi1*Cosi1 < CosRef1*Duv1 || Cosi2*Cosi2 < CosRef2*Duv2) {
2687 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2688 if (pasuv[0]<ResoU1 && pasuv[1]<ResoV1 && pasuv[2]<ResoU2 && pasuv[3]<ResoV2) {
2689 return(IntWalk_ArretSurPointPrecedent);
2692 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2693 return(IntWalk_PasTropGrand);
2696 const gp_Dir2d& Tg2dcourante1 = myIntersectionOn2S.DirectionOnS1();
2697 const gp_Dir2d& Tg2dcourante2 = myIntersectionOn2S.DirectionOnS2();
2698 Cosi1 = Du1*Tg2dcourante1.X() + Dv1*Tg2dcourante1.Y();
2699 Cosi2 = Du2*Tg2dcourante2.X() + Dv2*Tg2dcourante2.Y();
2700 Ang1 = Abs(previousd1.Angle(Tg2dcourante1));
2701 Ang2 = Abs(previousd2.Angle(Tg2dcourante2));
2702 AngRef1 = AngRef2D*tolCoeff1;
2703 AngRef2 = AngRef2D*tolCoeff2;
2704 //-------------------------------------------------------
2705 //-- Test : Angle too great in space UV -----
2706 //-- Change of side -----
2707 //-------------------------------------------------------
2708 if(Cosi1*Cosi1 < CosRef1*Duv1 || Cosi2*Cosi2 < CosRef2*Duv2 || Ang1 > AngRef1 || Ang2 > AngRef2) {
2709 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2710 if (pasuv[0]<ResoU1 && pasuv[1]<ResoV1 && pasuv[2]<ResoU2 && pasuv[3]<ResoV2)
2711 return(IntWalk_ArretSurPoint);
2713 return(IntWalk_PasTropGrand);
2717 //==================================================================================
2718 //== D e t e c t i o n o f : Step Too Small
2720 //==================================================================================
2722 //---------------------------------------
2723 //-- Estimate of the vector --
2724 //---------------------------------------
2726 Sqrt(Abs((previousd.XYZ()-TgCourante.XYZ()).SquareModulus()*Dist))/8.;
2728 if ( FlecheCourante<= fleche*0.5) { //-- Current step too small
2729 if(FlecheCourante>1e-16) {
2730 Ratio = 0.5*(fleche/FlecheCourante);
2735 Standard_Real pasSu1 = pasuv[0];
2736 Standard_Real pasSv1 = pasuv[1];
2737 Standard_Real pasSu2 = pasuv[2];
2738 Standard_Real pasSv2 = pasuv[3];
2741 //-- a point at U+DeltaU is required, ....
2742 //-- return a point at U + Epsilon
2743 //-- Epsilon << DeltaU.
2745 if(pasuv[0]< AbsDu1) pasuv[0] = AbsDu1;
2746 if(pasuv[1]< AbsDv1) pasuv[1] = AbsDv1;
2747 if(pasuv[2]< AbsDu2) pasuv[2] = AbsDu2;
2748 if(pasuv[3]< AbsDv2) pasuv[3] = AbsDv2;
2750 if(pasuv[0]<ResoU1) pasuv[0]=ResoU1;
2751 if(pasuv[1]<ResoV1) pasuv[1]=ResoV1;
2752 if(pasuv[2]<ResoU2) pasuv[2]=ResoU2;
2753 if(pasuv[3]<ResoV2) pasuv[3]=ResoV2;
2754 //-- if(Ratio>10.0 ) { Ratio=10.0; }
2755 Standard_Real R1,R = pasInit[0]/pasuv[0];
2756 R1= pasInit[1]/pasuv[1]; if(R1<R) R=R1;
2757 R1= pasInit[2]/pasuv[2]; if(R1<R) R=R1;
2758 R1= pasInit[3]/pasuv[3]; if(R1<R) R=R1;
2759 if(Ratio > R) Ratio=R;
2760 pasuv[0] = Min(Ratio*pasuv[0],pasInit[0]);
2761 pasuv[1] = Min(Ratio*pasuv[1],pasInit[1]);
2762 pasuv[2] = Min(Ratio*pasuv[2],pasInit[2]);
2763 pasuv[3] = Min(Ratio*pasuv[3],pasInit[3]);
2764 if (pasuv[0] != pasSu1 || pasuv[2] != pasSu2||
2765 pasuv[1] != pasSv1 || pasuv[3] != pasSv2) {
2766 if(++STATIC_BLOCAGE_SUR_PAS_TROP_GRAND > 5) {
2767 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND = 0;
2768 return IntWalk_PasTropGrand;
2771 if(Status == IntWalk_OK) {
2772 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=0;
2773 //-- Try to increase the step
2777 else { //-- CurrentVector > vector*0.5
2778 if (FlecheCourante > fleche) { //-- Current step too Great
2779 Ratio = fleche/FlecheCourante;
2780 pasuv[0] = Ratio*pasuv[0];
2781 pasuv[1] = Ratio*pasuv[1];
2782 pasuv[2] = Ratio*pasuv[2];
2783 pasuv[3] = Ratio*pasuv[3];
2784 //if(++STATIC_BLOCAGE_SUR_PAS_TROP_GRAND > 5) {
2785 // STATIC_BLOCAGE_SUR_PAS_TROP_GRAND = 0;
2786 return IntWalk_PasTropGrand;
2789 else { //-- vector/2 < CurrentVector <= vector
2790 Ratio = 0.75 * (fleche / FlecheCourante);
2793 pasuv[0] = Max(5.*ResoU1,Min(Min(Ratio*AbsDu1,pasuv[0]),pasInit[0]));
2794 pasuv[1] = Max(5.*ResoV1,Min(Min(Ratio*AbsDv1,pasuv[1]),pasInit[1]));
2795 pasuv[2] = Max(5.*ResoU2,Min(Min(Ratio*AbsDu2,pasuv[2]),pasInit[2]));
2796 pasuv[3] = Max(5.*ResoV2,Min(Min(Ratio*AbsDv2,pasuv[3]),pasInit[3]));
2797 if(Status == IntWalk_OK) STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=0;
2801 Standard_Boolean IntWalk_PWalking::
2802 TestArret(const Standard_Boolean DejaReparti,
2803 TColStd_Array1OfReal& Param,
2804 IntImp_ConstIsoparametric& ChoixIso)
2807 // test if the point of intersection set by these parameters remains in the
2808 // natural domain of each square.
2809 // if the point outpasses reframe to find the best iso (border)
2810 // that intersects easiest the other square
2811 // otherwise test if closed line is present
2814 Standard_Real Uvd[4],Uvf[4],Epsuv[4],Duv[4],Uvp[4],dv,dv2,ParC[4];
2815 Standard_Real DPc,DPb;
2816 Standard_Integer i = 0, k = 0;
2821 previousPoint.Parameters(Uvp[0],Uvp[1],Uvp[2],Uvp[3]);
2823 Standard_Real SolParam[4];
2824 myIntersectionOn2S.Point().Parameters(SolParam[0],SolParam[1],SolParam[2],SolParam[3]);
2826 Standard_Boolean Trouve = Standard_False;
2828 Uvd[0]=Um1; Uvf[0]=UM1; Uvd[1]=Vm1; Uvf[1]=VM1;
2829 Uvd[2]=Um2; Uvf[2]=UM2; Uvd[3]=Vm2; Uvf[3]=VM2;
2831 Standard_Integer im1;
2832 for ( i = 1,im1 = 0;i<=4;i++,im1++) {
2839 if (Param(i) < (Uvd[im1]-Epsuv[im1]) ||
2840 SolParam[im1] < (Uvd[im1]-Epsuv[im1])) //-- Current ----- Bound Inf ----- Previous
2842 Trouve = Standard_True; //--
2843 DPc = Uvp[im1]-Param(i); //-- Previous - Current
2844 DPb = Uvp[im1]-Uvd[im1]; //-- Previous - Bound Inf
2845 ParC[im1] = Uvd[im1]; //-- ParamCorrige
2846 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction)
2848 if(dv2>RealEpsilon()) { //-- Progress at the other Direction ?
2849 Duv[im1] = DPc*DPb + dv2;
2850 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
2853 Duv[im1]=-1.0; //-- If no progress, do not change
2854 } //-- the choice of iso
2856 else if (Param(i) > (Uvf[im1] + Epsuv[im1]) ||
2857 SolParam[im1] > (Uvf[im1] + Epsuv[im1]))//-- Previous ----- Bound Sup ----- Current
2859 Trouve = Standard_True; //--
2860 DPc = Param(i)-Uvp[im1]; //-- Current - Previous
2861 DPb = Uvf[im1]-Uvp[im1]; //-- Bound Sup - Previous
2862 ParC[im1] = Uvf[im1]; //-- Param Corrige
2863 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction)
2865 if(dv2>RealEpsilon()) { //-- Progress in other Direction ?
2866 Duv[im1] = DPc*DPb + dv2;
2867 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
2870 Duv[im1]=-1.0; //-- If no progress, do not change
2871 } //-- the choice of iso
2880 //--------------------------------------------------
2881 //-- One of Parameters u1,v1,u2,v2 is outside of --
2882 //-- the natural limits. --
2883 //-- Find the best direction of --
2884 //-- progress and reframe the parameters. --
2885 //--------------------------------------------------
2886 Standard_Real ddv = -1.0;
2888 for (i=0;i<=3;i++) {
2889 Param(i+1) = ParC[i];
2896 ChoixIso = ChoixRef[k];
2899 if((ParC[0]<=Uvd[0]+Epsuv[0]) || (ParC[0]>=Uvf[0]-Epsuv[0])) {
2900 ChoixIso = IntImp_UIsoparametricOnCaro1;
2902 else if((ParC[1]<=Uvd[1]+Epsuv[1]) || (ParC[1]>=Uvf[1]-Epsuv[1])) {
2903 ChoixIso = IntImp_VIsoparametricOnCaro1;
2905 else if((ParC[2]<=Uvd[2]+Epsuv[2]) || (ParC[2]>=Uvf[2]-Epsuv[2])) {
2906 ChoixIso = IntImp_UIsoparametricOnCaro2;
2908 else if((ParC[3]<=Uvd[3]+Epsuv[3]) || (ParC[3]>=Uvf[3]-Epsuv[3])) {
2909 ChoixIso = IntImp_VIsoparametricOnCaro2;
2912 close = Standard_False;
2913 return Standard_True;
2917 if (!DejaReparti) { // find if line closed
2920 const IntSurf_PntOn2S& POn2S1=line->Value(1);
2922 POn2S1.ParametersOnS1(u,v);
2923 gp_Pnt2d P1uvS1(u,v);
2924 previousPoint.ParametersOnS1(u,v);
2925 gp_Pnt2d PrevuvS1(u,v);
2926 myIntersectionOn2S.Point().ParametersOnS1(u,v);
2927 gp_Pnt2d myIntersuvS1(u,v);
2928 Standard_Boolean close2dS1 = (P1uvS1.XY()-PrevuvS1.XY())*
2929 (P1uvS1.XY()-myIntersuvS1.XY()) < 0.0;
2931 POn2S1.ParametersOnS2(u,v);
2932 gp_Pnt2d P1uvS2(u,v);
2933 previousPoint.ParametersOnS2(u,v);
2934 gp_Pnt2d PrevuvS2(u,v);
2935 myIntersectionOn2S.Point().ParametersOnS2(u,v);
2936 gp_Pnt2d myIntersuvS2(u,v);
2937 Standard_Boolean close2dS2 = (P1uvS2.XY()-PrevuvS2.XY())*
2938 (P1uvS2.XY()-myIntersuvS2.XY()) < 0.0;
2940 close = close2dS1 && close2dS2;
2943 else return Standard_False;