0025418: Debug output to be limited to OCC development environment
[occt.git] / src / IntWalk / IntWalk_PWalking.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
47cbf134 15#include <IntWalk_PWalking.ixx>
16
17#include <IntWalk_StatusDeflection.hxx>
18
19#include <TColgp_Array1OfPnt.hxx>
20#include <TColStd_Array1OfReal.hxx>
21
22#include <IntImp_ComputeTangence.hxx>
23
24#include <Adaptor3d_HSurface.hxx>
25#include <Adaptor3d_HSurfaceTool.hxx>
7fd59977 26
27#include <Precision.hxx>
7fd59977 28
47cbf134 29#include <math_FunctionSetRoot.hxx>
00302ba4 30#include <Geom_Surface.hxx>
31
47cbf134 32#include <Standard_Failure.hxx>
33#include <gp_Pnt2d.hxx>
7fd59977 34
35//==================================================================================
36// function : IntWalk_PWalking::IntWalk_PWalking
37// purpose :
b1c5c4e6 38// estimate of max step : To avoid abrupt changes
39// during change of isos
7fd59977 40//==================================================================================
41void ComputePasInit(Standard_Real *pasuv,
00302ba4 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,
47cbf134 50 const Handle(Adaptor3d_HSurface)& ,
51 const Handle(Adaptor3d_HSurface)& ,
00302ba4 52 const Standard_Real Increment)
7fd59977 53{
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);
00302ba4 58
7fd59977 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);
00302ba4 63
b1c5c4e6 64 //-- limit the reduction of uv box estimate to 0.01 natural box
65 //-- du1 : On box of Inter
66 //-- _du1 : On parametric space
7fd59977 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;
00302ba4 71
7fd59977 72 pasuv[0]=Increment*du1;
73 pasuv[1]=Increment*dv1;
74 pasuv[2]=Increment*du2;
75 pasuv[3]=Increment*dv2;
76}
c2c2f2b6 77
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//=======================================================================
88static void IsParallel(const Handle(IntSurf_LineOn2S)& theLine,
47cbf134 89 const Standard_Boolean theCheckSurf1,
90 const Standard_Real theToler,
91 Standard_Boolean& theIsUparallel,
92 Standard_Boolean& theIsVparallel)
c2c2f2b6 93{
94 const Standard_Integer aNbPointsMAX = 23;
95
96 theIsUparallel = theIsVparallel = Standard_True;
97
98 Standard_Integer aNbPoints = theLine->NbPoints();
99 if(aNbPoints > aNbPointsMAX)
100 {
101 aNbPoints = aNbPointsMAX;
102 }
103 else if(aNbPoints < 3)
104 {
105 //Here we cannot estimate parallelism.
106 //Do all same as for small lines
107 return;
108 }
109
110 Standard_Real aStep = IntToReal(theLine->NbPoints()) / aNbPoints;
111 Standard_Real aNPoint = 1.0;
112
113 Standard_Real aUmin = RealLast(), aUmax = RealFirst(), aVmin = RealLast(), aVmax = RealFirst();
114 for(Standard_Integer aNum = 1; aNum <= aNbPoints; aNum++, aNPoint += aStep)
115 {
116 if(aNPoint > aNbPoints)
117 {
118 aNPoint = aNbPoints;
119 }
120
121 Standard_Real u, v;
122 if(theCheckSurf1)
123 theLine->Value(RealToInt(aNPoint)).ParametersOnS1(u, v);
124 else
125 theLine->Value(RealToInt(aNPoint)).ParametersOnS2(u, v);
126
127 if(u < aUmin)
128 aUmin = u;
129
130 if(u > aUmax)
131 aUmax = u;
132
133 if(v < aVmin)
134 aVmin = v;
135
136 if(v > aVmax)
137 aVmax = v;
138 }
139
140 theIsVparallel = ((aUmax - aUmin) < theToler);
141 theIsUparallel = ((aVmax - aVmin) < theToler);
142}
143
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//=======================================================================
150static Standard_Boolean Checking( const Handle(Adaptor3d_HSurface)& theASurf1,
47cbf134 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)
c2c2f2b6 157{
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();
167
168 Standard_Boolean isOnOrIn = Standard_True;
169 theFactTol = 0.0;
170
171 Standard_Real aDelta = aU1bFirst - theU1;
172 if(aDelta > aTol)
173 {
174 theU1 = aU1bFirst;
175 theFactTol = Max(theFactTol, aDelta);
176 isOnOrIn = Standard_False;
177 }
47cbf134 178
c2c2f2b6 179 aDelta = theU1 - aU1bLast;
180 if(aDelta > aTol)
181 {
182 theU1 = aU1bLast;
183 theFactTol = Max(theFactTol, aDelta);
184 isOnOrIn = Standard_False;
185 }
186
187 aDelta = aV1bFirst - theV1;
188 if(aDelta > aTol)
189 {
190 theV1 = aV1bFirst;
191 theFactTol = Max(theFactTol, aDelta);
192 isOnOrIn = Standard_False;
193 }
47cbf134 194
c2c2f2b6 195 aDelta = theV1 - aV1bLast;
196 if(aDelta > aTol)
197 {
198 theV1 = aV1bLast;
199 theFactTol = Max(theFactTol, aDelta);
200 isOnOrIn = Standard_False;
201 }
202
203 aDelta = aU2bFirst - theU2;
204 if(aDelta > aTol)
205 {
206 theU2 = aU2bFirst;
207 theFactTol = Max(theFactTol, aDelta);
208 isOnOrIn = Standard_False;
209 }
47cbf134 210
c2c2f2b6 211 aDelta = theU2 - aU2bLast;
212 if(aDelta > aTol)
213 {
214 theU2 = aU2bLast;
215 theFactTol = Max(theFactTol, aDelta);
216 isOnOrIn = Standard_False;
217 }
218
219 aDelta = aV2bFirst - theV2;
220 if(aDelta > aTol)
221 {
222 theV2 = aV2bFirst;
223 theFactTol = Max(theFactTol, aDelta);
224 isOnOrIn = Standard_False;
225 }
47cbf134 226
c2c2f2b6 227 aDelta = theV2 - aV2bLast;
228 if(aDelta > aTol)
229 {
230 theV2 = aV2bLast;
231 theFactTol = Max(theFactTol, aDelta);
232 isOnOrIn = Standard_False;
233 }
234
235 return isOnOrIn;
236}
237
7fd59977 238//==================================================================================
239// function : IntWalk_PWalking::IntWalk_PWalking
240// purpose :
241//==================================================================================
47cbf134 242IntWalk_PWalking::IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1,
243 const Handle(Adaptor3d_HSurface)& Caro2,
00302ba4 244 const Standard_Real TolTangency,
245 const Standard_Real Epsilon,
246 const Standard_Real Deflection,
247 const Standard_Real Increment )
248 :
249
250done(Standard_True),
251close(Standard_False),
252fleche(Deflection),
253tolconf(Epsilon),
254sensCheminement(1),
255myIntersectionOn2S(Caro1,Caro2,TolTangency),
256STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
257STATIC_PRECEDENT_INFLEXION(0)
7fd59977 258{
259 Standard_Real KELARG=20.;
260 //
b1c5c4e6 261 pasMax=Increment*0.2; //-- June 25 99 after problems with precision
47cbf134 262 Um1 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro1);
263 Vm1 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro1);
264 UM1 = Adaptor3d_HSurfaceTool::LastUParameter(Caro1);
265 VM1 = Adaptor3d_HSurfaceTool::LastVParameter(Caro1);
7fd59977 266
47cbf134 267 Um2 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro2);
268 Vm2 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro2);
269 UM2 = Adaptor3d_HSurfaceTool::LastUParameter(Caro2);
270 VM2 = Adaptor3d_HSurfaceTool::LastVParameter(Caro2);
7fd59977 271
47cbf134 272 ResoU1 = Adaptor3d_HSurfaceTool::UResolution(Caro1,Precision::Confusion());
273 ResoV1 = Adaptor3d_HSurfaceTool::VResolution(Caro1,Precision::Confusion());
7fd59977 274
47cbf134 275 ResoU2 = Adaptor3d_HSurfaceTool::UResolution(Caro2,Precision::Confusion());
276 ResoV2 = Adaptor3d_HSurfaceTool::VResolution(Caro2,Precision::Confusion());
7fd59977 277
278 Standard_Real NEWRESO;
279 Standard_Real MAXVAL;
280 Standard_Real MAXVAL2;
281 //
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; }
286
287
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; }
292
293
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; }
298
299
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; }
304
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);
309
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];
314
315
47cbf134 316 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
e9a6ce82 317 //UM1+=KELARG*pasuv[0]; Um1-=KELARG*pasuv[0];
7fd59977 318 }
319 else {
320 Standard_Real t = UM1-Um1;
47cbf134 321 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro1)) {
322 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro1)-t);
7fd59977 323 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
324 UM1+=t; Um1-=t;
325 }
326 }
00302ba4 327
47cbf134 328 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
e9a6ce82 329 //VM1+=KELARG*pasuv[1]; Vm1-=KELARG*pasuv[1];
7fd59977 330 }
331 else {
332 Standard_Real t = VM1-Vm1;
47cbf134 333 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro1)) {
334 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro1)-t);
7fd59977 335 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
336 VM1+=t; Vm1-=t;
337 }
338 }
00302ba4 339
47cbf134 340 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
e9a6ce82 341 //UM2+=KELARG*pasuv[2]; Um2-=KELARG*pasuv[2];
7fd59977 342 }
343 else {
344 Standard_Real t = UM2-Um2;
47cbf134 345 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro2)) {
346 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro2)-t);
7fd59977 347 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
348 UM2+=t; Um2-=t;
349 }
350 }
00302ba4 351
47cbf134 352 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
e9a6ce82 353 //VM2+=KELARG*pasuv[3]; Vm2-=KELARG*pasuv[3];
7fd59977 354 }
355 else {
356 Standard_Real t = VM2-Vm2;
47cbf134 357 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro2)) {
358 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro2)-t);
7fd59977 359 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
360 VM2+=t; Vm2-=t;
361 }
362 }
363
364 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
365
366 for (Standard_Integer i = 0; i<=3;i++) {
367 if(pasuv[i]>10)
368 pasuv[i] = 10;
369 pasInit[i] = pasSav[i] = pasuv[i];
370 }
371
372
373}
374//==================================================================================
375// function : IntWalk_PWalking
376// purpose :
377//==================================================================================
47cbf134 378IntWalk_PWalking::IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1,
379 const Handle(Adaptor3d_HSurface)& Caro2,
00302ba4 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)
388 :
389
390done(Standard_True),
391close(Standard_False),
392fleche(Deflection),
393tolconf(Epsilon),
394sensCheminement(1),
395myIntersectionOn2S(Caro1,Caro2,TolTangency),
396STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
397STATIC_PRECEDENT_INFLEXION(0)
7fd59977 398{
399 Standard_Real KELARG=20.;
400 //
b1c5c4e6 401 pasMax=Increment*0.2; //-- June 25 99 after problems with precision
7fd59977 402 //
47cbf134 403 Um1 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro1);
404 Vm1 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro1);
405 UM1 = Adaptor3d_HSurfaceTool::LastUParameter(Caro1);
406 VM1 = Adaptor3d_HSurfaceTool::LastVParameter(Caro1);
7fd59977 407
47cbf134 408 Um2 = Adaptor3d_HSurfaceTool::FirstUParameter(Caro2);
409 Vm2 = Adaptor3d_HSurfaceTool::FirstVParameter(Caro2);
410 UM2 = Adaptor3d_HSurfaceTool::LastUParameter(Caro2);
411 VM2 = Adaptor3d_HSurfaceTool::LastVParameter(Caro2);
7fd59977 412
47cbf134 413 ResoU1 = Adaptor3d_HSurfaceTool::UResolution(Caro1,Precision::Confusion());
414 ResoV1 = Adaptor3d_HSurfaceTool::VResolution(Caro1,Precision::Confusion());
7fd59977 415
47cbf134 416 ResoU2 = Adaptor3d_HSurfaceTool::UResolution(Caro2,Precision::Confusion());
417 ResoV2 = Adaptor3d_HSurfaceTool::VResolution(Caro2,Precision::Confusion());
7fd59977 418 //
419 Standard_Real NEWRESO, MAXVAL, MAXVAL2;
420 //
421 MAXVAL = Abs(Um1);
422 MAXVAL2 = Abs(UM1);
423 if(MAXVAL2 > MAXVAL) {
424 MAXVAL = MAXVAL2;
425 }
426 NEWRESO = ResoU1 * MAXVAL ;
427 if(NEWRESO > ResoU1) {
428 ResoU1 = NEWRESO;
429 }
430 //
431 MAXVAL = Abs(Um2);
432 MAXVAL2 = Abs(UM2);
433 if(MAXVAL2 > MAXVAL){
434 MAXVAL = MAXVAL2;
435 }
436 NEWRESO = ResoU2 * MAXVAL ;
437 if(NEWRESO > ResoU2) {
438 ResoU2 = NEWRESO;
439 }
440 //
441 MAXVAL = Abs(Vm1);
442 MAXVAL2 = Abs(VM1);
443 if(MAXVAL2 > MAXVAL) {
444 MAXVAL = MAXVAL2;
445 }
446 NEWRESO = ResoV1 * MAXVAL ;
447 if(NEWRESO > ResoV1) {
448 ResoV1 = NEWRESO;
449 }
450 //
451 MAXVAL = Abs(Vm2);
452 MAXVAL2 = Abs(VM2);
453 if(MAXVAL2 > MAXVAL){
454 MAXVAL = MAXVAL2;
455 }
456 NEWRESO = ResoV2 * MAXVAL ;
457 if(NEWRESO > ResoV2) {
458 ResoV2 = NEWRESO;
459 }
460 //
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);
465 //
47cbf134 466 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro1)==Standard_False) {
7fd59977 467 UM1+=KELARG*pasuv[0];
468 Um1-=KELARG*pasuv[0];
469 }
470 else {
471 Standard_Real t = UM1-Um1;
47cbf134 472 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro1)) {
473 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro1)-t);
7fd59977 474 t=(t>KELARG*pasuv[0])? KELARG*pasuv[0] : t;
475 UM1+=t;
476 Um1-=t;
477 }
478 }
479 //
47cbf134 480 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro1)==Standard_False) {
7fd59977 481 VM1+=KELARG*pasuv[1];
482 Vm1-=KELARG*pasuv[1];
483 }
484 else {
485 Standard_Real t = VM1-Vm1;
47cbf134 486 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro1)) {
487 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro1)-t);
7fd59977 488 t=(t>KELARG*pasuv[1])? KELARG*pasuv[1] : t;
489 VM1+=t; Vm1-=t;
490 }
491 }
492 //
47cbf134 493 if(Adaptor3d_HSurfaceTool::IsUPeriodic(Caro2)==Standard_False) {
7fd59977 494 UM2+=KELARG*pasuv[2];
495 Um2-=KELARG*pasuv[2];
496 }
497 else {
498 Standard_Real t = UM2-Um2;
47cbf134 499 if(t<Adaptor3d_HSurfaceTool::UPeriod(Caro2)) {
500 t=0.5*(Adaptor3d_HSurfaceTool::UPeriod(Caro2)-t);
7fd59977 501 t=(t>KELARG*pasuv[2])? KELARG*pasuv[2] : t;
502 UM2+=t;
503 Um2-=t;
504 }
505 }
00302ba4 506
47cbf134 507 if(Adaptor3d_HSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {
7fd59977 508 VM2+=KELARG*pasuv[3];
509 Vm2-=KELARG*pasuv[3];
510 }
511 else {
512 Standard_Real t = VM2-Vm2;
47cbf134 513 if(t<Adaptor3d_HSurfaceTool::VPeriod(Caro2)) {
514 t=0.5*(Adaptor3d_HSurfaceTool::VPeriod(Caro2)-t);
7fd59977 515 t=(t>KELARG*pasuv[3])? KELARG*pasuv[3] : t;
516 VM2+=t;
517 Vm2-=t;
518 }
519 }
520 //-- ComputePasInit(pasuv,Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2);
521
522 for (Standard_Integer i = 0; i<=3;i++) {
523 pasInit[i] = pasSav[i] = pasuv[i];
524 }
525
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];
530 //
531 TColStd_Array1OfReal Par(1,4);
532 Par(1) = U1;
533 Par(2) = V1;
534 Par(3) = U2;
535 Par(4) = V2;
536 Perform(Par);
537}
538
539//==================================================================================
540// function : PerformFirstPoint
541// purpose :
542//==================================================================================
543Standard_Boolean IntWalk_PWalking::PerformFirstPoint (const TColStd_Array1OfReal& ParDep,
00302ba4 544 IntSurf_PntOn2S& FirstPoint)
7fd59977 545{
546 sensCheminement = 1;
547 close = Standard_False;
548 //
549 Standard_Integer i;
7fd59977 550 TColStd_Array1OfReal Param(1,4);
551 //
552 for (i=1; i<=4; ++i) {
7fd59977 553 Param(i) = ParDep(i);
554 }
b1c5c4e6 555 //-- calculate the first solution point
7fd59977 556 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
557 //
558 myIntersectionOn2S.Perform(Param,Rsnld);
559 if (!myIntersectionOn2S.IsDone()) {
560 return Standard_False;
561 }
c63628e8 562
7fd59977 563 if (myIntersectionOn2S.IsEmpty()) {
564 return Standard_False;
565 }
c63628e8 566
7fd59977 567 FirstPoint = myIntersectionOn2S.Point();
568 return Standard_True;
569}
570//==================================================================================
571// function : Perform
572// purpose :
573//==================================================================================
574void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep)
575{
576 Perform(ParDep,Um1,Vm1,Um2,Vm2,UM1,VM1,UM2,VM2);
577}
578//==================================================================================
579// function : Perform
580// purpose :
581//==================================================================================
582void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
00302ba4 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)
7fd59977 591{
00302ba4 592 const Standard_Real aSQDistMax = 1.0e-14;
7fd59977 593 //xf
00302ba4 594
595 Standard_Integer NbPasOKConseq=0;
596 Standard_Real pasMaxSV[4], aTmp;
7fd59977 597 TColStd_Array1OfReal Param(1,4);
598 IntImp_ConstIsoparametric ChoixIso;
599 //xt
600 //
601 done = Standard_False;
7fd59977 602 //
603 // Caro1 and Caro2
47cbf134 604 const Handle(Adaptor3d_HSurface)& Caro1 =myIntersectionOn2S.Function().AuxillarSurface1();
605 const Handle(Adaptor3d_HSurface)& Caro2 =myIntersectionOn2S.Function().AuxillarSurface2();
7fd59977 606 //
47cbf134 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);
611
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);
7fd59977 616 //
617 ComputePasInit(pasuv,u1min,u1max,v1min,v1max,u2min,u2max,v2min,v2max,
00302ba4 618 Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2,pasMax+pasMax);
7fd59977 619 //
00302ba4 620 if(pasuv[0]<100.0*ResoU1) {
621 pasuv[0]=100.0*ResoU1;
7fd59977 622 }
00302ba4 623 if(pasuv[1]<100.0*ResoV1) {
624 pasuv[1]=100.0*ResoV1;
7fd59977 625 }
00302ba4 626 if(pasuv[2]<100.0*ResoU2) {
627 pasuv[2]=100.0*ResoU2;
7fd59977 628 }
00302ba4 629 if(pasuv[3]<100.0*ResoV2) {
630 pasuv[3]=100.0*ResoV2;
7fd59977 631 }
632 //
00302ba4 633 for (Standard_Integer i=0; i<4; ++i)
634 {
635 if(pasuv[i]>10)
636 {
7fd59977 637 pasuv[i] = 10;
638 }
00302ba4 639
7fd59977 640 pasInit[i] = pasSav[i] = pasuv[i];
641 }
642 //
643 line = new IntSurf_LineOn2S ();
644 //
00302ba4 645 for (Standard_Integer i=1; i<=4; ++i)
646 {
647 aTmp=ParDep(i);
7fd59977 648 Param(i)=ParDep(i);
649 }
b1c5c4e6 650 //-- reproduce steps uv connected to surfaces Caro1 and Caro2
651 //-- pasuv[] and pasSav[] are modified during the marching
00302ba4 652 for(Standard_Integer i = 0; i < 4; ++i)
653 {
654 pasMaxSV[i] = pasSav[i] = pasuv[i] = pasInit[i];
7fd59977 655 }
656
b1c5c4e6 657 //-- calculate the first solution point
7fd59977 658 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
659 //
660 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld);
00302ba4 661 if (!myIntersectionOn2S.IsDone())
662 {
7fd59977 663 return;
664 }
00302ba4 665
7fd59977 666 //
00302ba4 667 if (myIntersectionOn2S.IsEmpty())
668 {
7fd59977 669 return;
670 }
671 //
00302ba4 672 if(myIntersectionOn2S.IsTangent())
673 {
7fd59977 674 return;
675 }
676 //
677 Standard_Boolean Arrive, DejaReparti;
00302ba4 678 const Standard_Integer RejectIndexMAX = 250000;
7fd59977 679 Standard_Integer IncKey, RejectIndex;
680 gp_Pnt pf,pl;
681 //
682 DejaReparti = Standard_False;
683 IncKey = 0;
684 RejectIndex = 0;
685 //
686 previousPoint = myIntersectionOn2S.Point();
687 previoustg = Standard_False;
688 previousd = myIntersectionOn2S.Direction();
689 previousd1 = myIntersectionOn2S.DirectionOnS1();
690 previousd2 = myIntersectionOn2S.DirectionOnS2();
691 indextg = 1;
692 tgdir = previousd;
693 firstd1 = previousd1;
694 firstd2 = previousd2;
695 tgfirst = tglast = Standard_False;
696 choixIsoSav = ChoixIso;
697 //------------------------------------------------------------
b1c5c4e6 698 //-- Test if the first point of marching corresponds
699 //-- to a point on borders.
700 //-- In this case, DejaReparti is initialized as True
7fd59977 701 //--
702 pf = previousPoint.Value();
703 Standard_Boolean bTestFirstPoint = Standard_True;
00302ba4 704
705 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
7fd59977 706 AddAPoint(line,previousPoint);
707 //
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;
714 //
715 Arrive = Standard_False;
00302ba4 716 while(!Arrive) //010
717 {
7fd59977 718 LevelOfIterWithoutAppend++;
00302ba4 719 if(LevelOfIterWithoutAppend>20)
720 {
7fd59977 721 Arrive = Standard_True;
722 if(DejaReparti) {
00302ba4 723 break;
7fd59977 724 }
725 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
726 LevelOfIterWithoutAppend = 0;
727 }
728 //
729 // compute f
730 f = 0.;
731 switch (ChoixIso) {
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;
736 default:break;
737 }
738 //
739 if(f<0.1) {
740 f=0.1;
741 }
742 //
743 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
744 //
745 //--ofv.begin
746 Standard_Real aIncKey, aEps, dP1, dP2, dP3, dP4;
747 //
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;
752 //
753 aIncKey=5.*(Standard_Real)IncKey;
754 aEps=1.e-7;
00302ba4 755 if(ChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < aEps)
756 {
7fd59977 757 dP1 *= aIncKey;
758 }
00302ba4 759
760 if(ChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < aEps)
761 {
7fd59977 762 dP2 *= aIncKey;
763 }
00302ba4 764
765 if(ChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < aEps)
766 {
7fd59977 767 dP3 *= aIncKey;
768 }
00302ba4 769
770 if(ChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < aEps)
771 {
7fd59977 772 dP4 *= aIncKey;
773 }
774 //--ofv.end
775 //
776 Param(1) += dP1;
777 Param(2) += dP2;
778 Param(3) += dP3;
779 Param(4) += dP4;
780 //==========================
781 SvParam[0]=Param(1);
782 SvParam[1]=Param(2);
783 SvParam[2]=Param(3);
784 SvParam[3]=Param(4);
785 //
1eaf1cc1 786 Standard_Integer aTryNumber = 0;
787 Standard_Real isBadPoint = Standard_False;
788 IntImp_ConstIsoparametric aBestIso = ChoixIso;
789 do
790 {
791 isBadPoint = Standard_False;
792
793 ChoixIso= myIntersectionOn2S.Perform(Param, Rsnld, aBestIso);
794
795 if (myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty())
796 {
797 Standard_Real aNewPnt[4], anAbsParamDist[4];
798 myIntersectionOn2S.Point().Parameters(aNewPnt[0], aNewPnt[1], aNewPnt[2], aNewPnt[3]);
799
800 if (aNewPnt[0] < u1min || aNewPnt[0] > u1max ||
801 aNewPnt[1] < v1min || aNewPnt[1] > v1max ||
802 aNewPnt[2] < u2min || aNewPnt[2] > u2max ||
803 aNewPnt[3] < v2min || aNewPnt[3] > v2max)
804 {
805 break; // Out of borders, handle this later.
806 }
807
808 anAbsParamDist[0] = Abs(Param(1) - dP1 - aNewPnt[0]);
809 anAbsParamDist[1] = Abs(Param(2) - dP2 - aNewPnt[1]);
810 anAbsParamDist[2] = Abs(Param(3) - dP3 - aNewPnt[2]);
811 anAbsParamDist[3] = Abs(Param(4) - dP4 - aNewPnt[3]);
812 if (anAbsParamDist[0] < ResoU1 &&
813 anAbsParamDist[1] < ResoV1 &&
814 anAbsParamDist[2] < ResoU2 &&
815 anAbsParamDist[3] < ResoV2 &&
816 Status != IntWalk_PasTropGrand)
817 {
818 isBadPoint = Standard_True;
819 aBestIso = IntImp_ConstIsoparametric((aBestIso + 1) % 4);
820 }
821 }
822 } while (isBadPoint && ++aTryNumber <= 4);
7fd59977 823 //
00302ba4 824 if (!myIntersectionOn2S.IsDone())
825 {
b1c5c4e6 826 //end of line, division
7fd59977 827 Arrive = Standard_False;
828 Param(1)=SvParam[0];
829 Param(2)=SvParam[1];
830 Param(3)=SvParam[2];
831 Param(4)=SvParam[3];
832 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
833 }
00302ba4 834 else //009
835 {
b1c5c4e6 836 //== Calculation of exact point from Param(.) is possible
00302ba4 837 if (myIntersectionOn2S.IsEmpty())
838 {
839 Standard_Real u1,v1,u2,v2;
840 previousPoint.Parameters(u1,v1,u2,v2);
841 //
842 Arrive = Standard_False;
843 if(u1<UFirst1 || u1>ULast1)
844 {
845 Arrive=Standard_True;
846 }
847
848 if(u2<UFirst2 || u2>ULast2)
849 {
850 Arrive=Standard_True;
851 }
852
853 if(v1<VFirst1 || v1>VLast1)
854 {
855 Arrive=Standard_True;
856 }
857
858 if(v2<VFirst2 || v2>VLast2)
859 {
860 Arrive=Standard_True;
861 }
862
863 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
864 LevelOfEmptyInmyIntersectionOn2S++;
865 //
866 if(LevelOfEmptyInmyIntersectionOn2S>10)
867 {
868 pasuv[0]=pasSav[0];
869 pasuv[1]=pasSav[1];
870 pasuv[2]=pasSav[2];
871 pasuv[3]=pasSav[3];
872 }
7fd59977 873 }
00302ba4 874 else //008
875 {
876 //============================================================
877 //== A point has been found : T E S T D E F L E C T I O N
878 //============================================================
879 if(NoTestDeflection)
880 {
881 NoTestDeflection = Standard_False;
882 }
883 else
884 {
885 if(--LevelOfEmptyInmyIntersectionOn2S<=0)
886 {
887 LevelOfEmptyInmyIntersectionOn2S=0;
888 if(LevelOfIterWithoutAppend < 10)
889 {
890 Status = TestDeflection();
891 }
892 else
893 {
894 pasuv[0]*=0.5;
895 pasuv[1]*=0.5;
896 pasuv[2]*=0.5;
897 pasuv[3]*=0.5;
898 }
899 }
900 }
901
902 //============================================================
903 //== T r a i t e m e n t s u r S t a t u s ==
904 //============================================================
905 if(LevelOfPointConfondu > 5)
906 {
907 Status = IntWalk_ArretSurPoint;
908 LevelOfPointConfondu = 0;
909 }
910 //
911 if(Status==IntWalk_OK)
912 {
913 NbPasOKConseq++;
914 if(NbPasOKConseq >= 5)
915 {
916 NbPasOKConseq=0;
917 Standard_Boolean pastroppetit;
918 Standard_Real t;
919 //
920 do
921 {
922 pastroppetit=Standard_True;
923 //
924 if(pasuv[0]<pasInit[0])
925 {
926 t = (pasInit[0]-pasuv[0])*0.25;
927 if(t>0.1*pasInit[0])
928 {
929 t=0.1*pasuv[0];
930 }
931
932 pasuv[0]+=t;
933 pastroppetit=Standard_False;
934 }
935
936 if(pasuv[1]<pasInit[1])
937 {
938 t = (pasInit[1]-pasuv[1])*0.25;
939 if(t>0.1*pasInit[1]) {
940 t=0.1*pasuv[1];
941 }
942
943 pasuv[1]+=t;
944 pastroppetit=Standard_False;
945 }
946
947 if(pasuv[2]<pasInit[2])
948 {
949 t = (pasInit[2]-pasuv[2])*0.25;
950 if(t>0.1*pasInit[2])
951 {
952 t=0.1*pasuv[2];
953 }
954
955 pasuv[2]+=t;
956 pastroppetit=Standard_False;
957 }
958
959 if(pasuv[3]<pasInit[3])
960 {
961 t = (pasInit[3]-pasuv[3])*0.25;
962 if(t>0.1*pasInit[3]) {
963 t=0.1*pasuv[3];
964 }
965 pasuv[3]+=t;
966 pastroppetit=Standard_False;
967 }
968 if(pastroppetit)
969 {
970 if(pasMax<0.1)
971 {
972 pasMax*=1.1;
973 pasInit[0]*=1.1;
974 pasInit[1]*=1.1;
975 pasInit[2]*=1.1;
976 pasInit[3]*=1.1;
977 }
978 else
979 {
980 pastroppetit=Standard_False;
981 }
982 }
983 }
984 while(pastroppetit);
985 }
986 }//Status==IntWalk_OK
987 else
988 NbPasOKConseq=0;
989
990 //
991 switch(Status)//007
992 {
993 case IntWalk_ArretSurPointPrecedent:
994 {
995 Arrive = Standard_False;
996 RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
997 break;
998 }
999 case IntWalk_PasTropGrand:
1000 {
1001 Param(1)=SvParam[0];
1002 Param(2)=SvParam[1];
1003 Param(3)=SvParam[2];
1004 Param(4)=SvParam[3];
1005
1006 if(LevelOfIterWithoutAppend > 5)
1007 {
1008 if(pasSav[0]<pasInit[0])
1009 {
1010 pasInit[0]-=(pasInit[0]-pasSav[0])*0.25;
1011 LevelOfIterWithoutAppend=0;
1012 }
1013
1014 if(pasSav[1]<pasInit[1])
1015 {
1016 pasInit[1]-=(pasInit[1]-pasSav[1])*0.25;
1017 LevelOfIterWithoutAppend=0;
1018 }
1019
1020 if(pasSav[2]<pasInit[2])
1021 {
1022 pasInit[2]-=(pasInit[2]-pasSav[2])*0.25;
1023 LevelOfIterWithoutAppend=0;
1024 }
1025
1026 if(pasSav[3]<pasInit[3])
1027 {
1028 pasInit[3]-=(pasInit[3]-pasSav[3])*0.25;
1029 LevelOfIterWithoutAppend=0;
1030 }
1031 }
1032
1033 break;
1034 }
1035 case IntWalk_PointConfondu:
1036 {
1037 LevelOfPointConfondu++;
1038
1039 if(LevelOfPointConfondu>5)
1040 {
1041 Standard_Boolean pastroppetit;
1042 //
1043 do
1044 {
1045 pastroppetit=Standard_True;
1046
1047 if(pasuv[0]<pasInit[0])
1048 {
1049 pasuv[0]+=(pasInit[0]-pasuv[0])*0.25;
1050 pastroppetit=Standard_False;
1051 }
1052
1053 if(pasuv[1]<pasInit[1])
1054 {
1055 pasuv[1]+=(pasInit[1]-pasuv[1])*0.25;
1056 pastroppetit=Standard_False;
1057 }
1058
1059 if(pasuv[2]<pasInit[2])
1060 {
1061 pasuv[2]+=(pasInit[2]-pasuv[2])*0.25;
1062 pastroppetit=Standard_False;
1063 }
1064
1065 if(pasuv[3]<pasInit[3])
1066 {
1067 pasuv[3]+=(pasInit[3]-pasuv[3])*0.25;
1068 pastroppetit=Standard_False;
1069 }
1070
1071 if(pastroppetit)
1072 {
1073 if(pasMax<0.1)
1074 {
1075 pasMax*=1.1;
1076 pasInit[0]*=1.1;
1077 pasInit[1]*=1.1;
1078 pasInit[2]*=1.1;
1079 pasInit[3]*=1.1;
1080 }
1081 else
1082 {
1083 pastroppetit=Standard_False;
1084 }
1085 }
1086 }
1087 while(pastroppetit);
1088 }
1089
1090 break;
1091 }
1092 case IntWalk_OK:
1093 case IntWalk_ArretSurPoint://006
1094 {
1095 //=======================================================
1096 //== Stop Test t : Frame on Param(.) ==
1097 //=======================================================
1098 //xft arrive here
1099 Arrive = TestArret(DejaReparti,Param,ChoixIso);
1100 // JMB 30th December 1999.
1101 // Some statement below should not be put in comment because they are useful.
1102 // See grid CTO 909 A1 which infinitely loops
1103 if(Arrive==Standard_False && Status==IntWalk_ArretSurPoint)
1104 {
1105 Arrive=Standard_True;
0797d9d3 1106#ifdef OCCT_DEBUG
1107 cout << "IntWalk_PWalking_1.gxx: Problems with intersection"<<endl;
7fd59977 1108#endif
00302ba4 1109 }
1110
1111 if(Arrive)
1112 {
1113 NbPasOKConseq = -10;
1114 }
1115
1116 if(!Arrive)//005
1117 {
1118 //=====================================================
1119 //== Param(.) is in the limits ==
1120 //== and does not end a closed line ==
1121 //=====================================================
1122 //== Check on the current point of myInters
1123 Standard_Boolean pointisvalid = Standard_False;
1124 {
1125 Standard_Real u1,v1,u2,v2;
1126 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
1127
1128 //
1129 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1130 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1131 v1 >= Vm1 && v2 >= Vm2)
1132 {
1133 pointisvalid=Standard_True;
1134 }
1135 }
1136
1137 //
1138 if(pointisvalid)
1139 {
1140 previousPoint = myIntersectionOn2S.Point();
1141 previoustg = myIntersectionOn2S.IsTangent();
1142
1143 if(!previoustg)
1144 {
1145 previousd = myIntersectionOn2S.Direction();
1146 previousd1 = myIntersectionOn2S.DirectionOnS1();
1147 previousd2 = myIntersectionOn2S.DirectionOnS2();
1148 }
1149 //=====================================================
1150 //== Check on the previous Point
1151 {
1152 Standard_Real u1,v1,u2,v2;
1153 previousPoint.Parameters(u1,v1,u2,v2);
1154 if( u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1155 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1156 v1 >= Vm1 && v2 >= Vm2)
1157 {
1158 pl = previousPoint.Value();
1159 if(bTestFirstPoint)
1160 {
1161 if(pf.SquareDistance(pl) < aSQDistMax)
1162 {
1163 IncKey++;
1164 if(IncKey == 5000)
1165 return;
1166 else
1167 continue;
1168 }
1169 else
1170 {
1171 bTestFirstPoint = Standard_False;
1172 }
1173 }
1174 //
1175 AddAPoint(line,previousPoint);
1176 RejectIndex++;
1177
1178 if(RejectIndex >= RejectIndexMAX)
1179 {
1180 break;
1181 }
1182
1183 //
1184 LevelOfIterWithoutAppend = 0;
1185 }
1186 }
1187 }//pointisvalid
1188 //====================================================
1189
1190 if(Status == IntWalk_ArretSurPoint)
1191 {
1192 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1193 }
1194 else
1195 {
1196 if (line->NbPoints() == 2)
1197 {
1198 pasSav[0] = pasuv[0];
1199 pasSav[1] = pasuv[1];
1200 pasSav[2] = pasuv[2];
1201 pasSav[3] = pasuv[3];
1202 }
1203 }
1204 }//005 if(!Arrive)
1205 else //004
1206 {
1207 if(close)
1208 {
1209 //================= la ligne est fermee ===============
1210 AddAPoint(line,line->Value(1)); //ligne fermee
1211 LevelOfIterWithoutAppend=0;
1212 }
1213 else //$$$
1214 {
1215 //====================================================
1216 //== Param was not in the limits (was reframed)
1217 //====================================================
1218 Standard_Boolean bPrevNotTangent = !previoustg || !myIntersectionOn2S.IsTangent();
1219
1220 IntImp_ConstIsoparametric SauvChoixIso = ChoixIso;
1221 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
1222 //
1223 if(!myIntersectionOn2S.IsEmpty()) //002
1224 {
1225 // mutially outpasses in the square or intersection in corner
1226
1227 if(TestArret(Standard_True,Param,ChoixIso))
1228 {
1229 NbPasOKConseq = -10;
1230 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
1231
1232 if(!myIntersectionOn2S.IsEmpty())
1233 {
1234 previousPoint = myIntersectionOn2S.Point();
1235 previoustg = myIntersectionOn2S.IsTangent();
1236
1237 if (!previoustg)
1238 {
1239 previousd = myIntersectionOn2S.Direction();
1240 previousd1 = myIntersectionOn2S.DirectionOnS1();
1241 previousd2 = myIntersectionOn2S.DirectionOnS2();
1242 }
1243
1244 pl = previousPoint.Value();
1245
1246 if(bTestFirstPoint)
1247 {
1248 if(pf.SquareDistance(pl) < aSQDistMax)
1249 {
1250 IncKey++;
1251 if(IncKey == 5000)
1252 return;
1253 else
1254 continue;
1255 }
1256 else
1257 {
1258 bTestFirstPoint = Standard_False;
1259 }
1260 }
1261 //
1262 AddAPoint(line,previousPoint);
1263 RejectIndex++;
1264
1265 if(RejectIndex >= RejectIndexMAX)
1266 {
1267 break;
1268 }
1269
1270 //
1271 LevelOfIterWithoutAppend=0;
1272 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1273 }
1274 else
1275 {
1276 //fail framing divides the step
1277 Arrive = Standard_False;
1278 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1279 NoTestDeflection = Standard_True;
1280 ChoixIso = SauvChoixIso;
1281 }
1282 }//if(TestArret())
1283 else
1284 {
1285 // save the last point
1286 // to revert to it if the current point is out of bounds
1287
1288 IntSurf_PntOn2S previousPointSave = previousPoint;
1289 Standard_Boolean previoustgSave = previoustg;
1290 gp_Dir previousdSave = previousd;
1291 gp_Dir2d previousd1Save = previousd1;
1292 gp_Dir2d previousd2Save = previousd2;
1293
1294 previousPoint = myIntersectionOn2S.Point();
1295 previoustg = myIntersectionOn2S.IsTangent();
1296 Arrive = Standard_False;
1297
1298 if(!previoustg)
1299 {
1300 previousd = myIntersectionOn2S.Direction();
1301 previousd1 = myIntersectionOn2S.DirectionOnS1();
1302 previousd2 = myIntersectionOn2S.DirectionOnS2();
1303 }
1304
1305 //========================================
1306 //== Check on PreviousPoint @@
1307
1308 {
1309 Standard_Real u1,v1,u2,v2;
1310 previousPoint.Parameters(u1,v1,u2,v2);
1311
b1c5c4e6 1312 //To save initial 2d points
1313 gp_Pnt2d ParamPntOnS1(Param(1), Param(2));
1314 gp_Pnt2d ParamPntOnS2(Param(3), Param(4));
00302ba4 1315
b1c5c4e6 1316 ///////////////////////////
00302ba4 1317 Param(1) = u1;
1318 Param(2) = v1;
1319 Param(3) = u2;
1320 Param(4) = v2;
1321 //
1322
1323 //xf
1324 Standard_Boolean bFlag1, bFlag2;
1325 Standard_Real aTol2D=1.e-11;
1326 //
1327 bFlag1=u1 >= Um1-aTol2D && v1 >= Vm1-aTol2D && u1 <= UM1+aTol2D && v1 <= VM1+aTol2D;
1328 bFlag2=u2 >= Um2-aTol2D && v2 >= Vm2-aTol2D && u2 <= UM2+aTol2D && v2 <= VM2+aTol2D;
1329 if (bFlag1 && bFlag2)
1330 {
1331 /*
1332 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1333 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1334 v1 >= Vm1 && v2 >= Vm2) {
1335 */
1336 //xt
1337 pl = previousPoint.Value();
1338
1339 if(bTestFirstPoint)
1340 {
1341 if(pf.SquareDistance(pl) < aSQDistMax)
1342 {
1343 IncKey++;
1344
1345 if(IncKey == 5000)
1346 return;
1347 else
1348 continue;
1349 }
1350 else
1351 {
1352 bTestFirstPoint = Standard_False;
1353 }
1354 }
1355
b1c5c4e6 1356 //To avoid walking around the same point
1357 //in the tangent zone near a border
00302ba4 1358
b1c5c4e6 1359 if (previoustg)
1360 {
1361 Standard_Real prevU1, prevV1, prevU2, prevV2;
1362 previousPointSave.Parameters(prevU1, prevV1, prevU2, prevV2);
1363 gp_Pnt2d prevPntOnS1(prevU1, prevV1), prevPntOnS2(prevU2, prevV2);
1364 gp_Pnt2d curPntOnS1(u1, v1), curPntOnS2(u2, v2);
1365 gp_Vec2d PrevToParamOnS1(prevPntOnS1, ParamPntOnS1);
1366 gp_Vec2d PrevToCurOnS1(prevPntOnS1, curPntOnS1);
1367 gp_Vec2d PrevToParamOnS2(prevPntOnS2, ParamPntOnS2);
1368 gp_Vec2d PrevToCurOnS2(prevPntOnS2, curPntOnS2);
1369 Standard_Real MaxAngle = 3*M_PI/4;
00302ba4 1370
b1c5c4e6 1371 if (Abs(PrevToParamOnS1.Angle(PrevToCurOnS1)) > MaxAngle &&
00302ba4 1372 Abs(PrevToParamOnS2.Angle(PrevToCurOnS2)) > MaxAngle)
b1c5c4e6 1373 {
1374 Arrive = Standard_True;
1375 break;
1376 }
1377 }
00302ba4 1378
b1c5c4e6 1379 ////////////////////////////////////////
00302ba4 1380 AddAPoint(line,previousPoint);
1381 RejectIndex++;
1382
1383 if(RejectIndex >= RejectIndexMAX)
1384 {
1385 break;
1386 }
1387
1388 //
1389
1390 LevelOfIterWithoutAppend=0;
1391 Arrive = Standard_True;
1392 }
1393 else
1394 {
1395 // revert to the last correctly calculated point
1396 previousPoint = previousPointSave;
1397 previoustg = previoustgSave;
1398 previousd = previousdSave;
1399 previousd1 = previousd1Save;
1400 previousd2 = previousd2Save;
1401 }
1402 }
1403
1404 //
1405 Standard_Boolean wasExtended = Standard_False;
1406
1407 if(Arrive && myIntersectionOn2S.IsTangent() && bPrevNotTangent)
1408 {
1409 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
1410 {
1411 wasExtended = Standard_True;
1412 Arrive = Standard_False;
1413 ChoixIso = SauvChoixIso;
1414 }
1415 }
1416
1417 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1418
1419 if(Arrive &&
1420 myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty() &&
1421 myIntersectionOn2S.IsTangent() && bPrevNotTangent &&
1422 !wasExtended)
1423 {
1424 if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
1425 {
1426 wasExtended = Standard_True;
1427 Arrive = Standard_False;
1428 ChoixIso = SauvChoixIso;
1429 }
1430 }
1431 }//else !TestArret() $
1432 }//$$ end successful framing on border (!myIntersectionOn2S.IsEmpty())
1433 else
1434 {
1435 //echec framing on border; division of step
1436 Arrive = Standard_False;
1437 NoTestDeflection = Standard_True;
1438 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
1439 }
1440 }//$$$ end framing on border (!close)
1441 }//004 fin TestArret return Arrive = True
1442 } // 006case IntWalk_ArretSurPoint: end Processing Status = OK or ArretSurPoint
1443 } //007 switch(Status)
b1c5c4e6 1444 } //008 end processing point (TEST DEFLECTION)
1445 } //009 end processing line (else if myIntersectionOn2S.IsDone())
1446 } //010 end if first departure point allows marching while (!Arrive)
00302ba4 1447
7fd59977 1448 done = Standard_True;
1449}
1450// ===========================================================================================================
1451// function: ExtendLineInCommonZone
1452// purpose: Extends already computed line inside tangent zone in the direction given by theChoixIso.
1453// Returns Standard_True if the line was extended through tangent zone and the last computed point
1454// is outside the tangent zone (but it is not put into the line). Otherwise returns Standard_False.
1455// ===========================================================================================================
1456Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsoparametric theChoixIso,
00302ba4 1457 const Standard_Boolean theDirectionFlag)
7fd59977 1458{
1459 Standard_Boolean bOutOfTangentZone = Standard_False;
1460 Standard_Boolean bStop = !myIntersectionOn2S.IsTangent();
1461 Standard_Integer dIncKey = 1;
1462 TColStd_Array1OfReal Param(1,4);
1463 IntWalk_StatusDeflection Status = IntWalk_OK;
1464 Standard_Integer nbIterWithoutAppend = 0;
1465 Standard_Integer nbEqualPoints = 0;
1466 Standard_Integer parit = 0;
1467 Standard_Integer uvit = 0;
1468 IntSurf_SequenceOfPntOn2S aSeqOfNewPoint;
1469
1470 while (!bStop) {
1471 nbIterWithoutAppend++;
1472
1473 if((nbIterWithoutAppend > 20) || (nbEqualPoints > 20)) {
0797d9d3 1474#ifdef OCCT_DEBUG
1475 cout<<"Infinite loop detected. Stop iterations (IntWalk_PWalking_1.gxx)" << endl;
7fd59977 1476#endif
1477 bStop = Standard_True;
1478 break;
1479 }
1480 Standard_Real f = 0.;
1481
1482 switch (theChoixIso)
00302ba4 1483 {
1484 case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
1485 case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
1486 case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
1487 case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
1488 }
7fd59977 1489
1490 if(f<0.1) f=0.1;
00302ba4 1491
7fd59977 1492 previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
1493
1494 Standard_Real dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
1495 Standard_Real dP2 = sensCheminement * pasuv[1] * previousd1.Y() /f;
1496 Standard_Real dP3 = sensCheminement * pasuv[2] * previousd2.X() /f;
1497 Standard_Real dP4 = sensCheminement * pasuv[3] * previousd2.Y() /f;
1498
1499 if(theChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < 1.e-7) dP1 *= (5. * (Standard_Real)dIncKey);
1500 if(theChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < 1.e-7) dP2 *= (5. * (Standard_Real)dIncKey);
1501 if(theChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < 1.e-7) dP3 *= (5. * (Standard_Real)dIncKey);
1502 if(theChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < 1.e-7) dP4 *= (5. * (Standard_Real)dIncKey);
00302ba4 1503
7fd59977 1504 Param(1) += dP1;
1505 Param(2) += dP2;
1506 Param(3) += dP3;
1507 Param(4) += dP4;
1508 Standard_Real SvParam[4];
1509 IntImp_ConstIsoparametric ChoixIso = theChoixIso;
1510
1511 for(parit = 0; parit < 4; parit++) {
1512 SvParam[parit] = Param(parit+1);
1513 }
1514 math_FunctionSetRoot Rsnld(myIntersectionOn2S.Function());
1515 ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld, theChoixIso);
1516
1517 if (!myIntersectionOn2S.IsDone()) {
1518 return bOutOfTangentZone;
1519 }
1520 else {
1521 if (myIntersectionOn2S.IsEmpty()) {
00302ba4 1522 return bOutOfTangentZone;
7fd59977 1523 }
1524
1525 Status = TestDeflection();
1526
1527 if(Status == IntWalk_OK) {
1528
00302ba4 1529 for(uvit = 0; uvit < 4; uvit++) {
1530 if(pasuv[uvit] < pasInit[uvit]) {
1531 pasuv[uvit] = pasInit[uvit];
1532 }
1533 }
7fd59977 1534 }
1535
1536 switch(Status) {
1537 case IntWalk_ArretSurPointPrecedent:
00302ba4 1538 {
1539 bStop = Standard_True;
1540 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1541 break;
1542 }
7fd59977 1543 case IntWalk_PasTropGrand:
00302ba4 1544 {
1545 for(parit = 0; parit < 4; parit++) {
1546 Param(parit+1) = SvParam[parit];
1547 }
1548 Standard_Boolean bDecrease = Standard_False;
1549
1550 for(uvit = 0; uvit < 4; uvit++) {
1551 if(pasSav[uvit] < pasInit[uvit]) {
1552 pasInit[uvit] -= (pasInit[uvit] - pasSav[uvit]) * 0.1;
1553 bDecrease = Standard_True;
1554 }
1555 }
1556
1557 if(bDecrease) nbIterWithoutAppend--;
1558 break;
1559 }
7fd59977 1560 case IntWalk_PointConfondu:
00302ba4 1561 {
1562 for(uvit = 0; uvit < 4; uvit++) {
1563 if(pasuv[uvit] < pasInit[uvit]) {
1564 pasuv[uvit] += (pasInit[uvit] - pasuv[uvit]) * 0.1;
1565 }
1566 }
1567 break;
1568 }
7fd59977 1569 case IntWalk_OK:
1570 case IntWalk_ArretSurPoint:
00302ba4 1571 {
1572 //
1573 bStop = TestArret(theDirectionFlag, Param, ChoixIso);
1574 //
1575
1576 //
1577 if(!bStop) {
1578 Standard_Real u11,v11,u12,v12;
1579 myIntersectionOn2S.Point().Parameters(u11,v11,u12,v12);
1580 Standard_Real u21,v21,u22,v22;
1581 previousPoint.Parameters(u21,v21,u22,v22);
1582
1583 if(((fabs(u11-u21) < ResoU1) && (fabs(v11-v21) < ResoV1)) ||
1584 ((fabs(u12-u22) < ResoU2) && (fabs(v12-v22) < ResoV2))) {
1585 nbEqualPoints++;
1586 }
1587 else {
1588 nbEqualPoints = 0;
1589 }
1590 }
1591 //
1592
1593 bStop = bStop || !myIntersectionOn2S.IsTangent();
1594 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1595
1596 if(!bStop) {
1597 Standard_Boolean pointisvalid = Standard_False;
1598 Standard_Real u1,v1,u2,v2;
1599 myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
1600
1601 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1602 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1603 v1 >= Vm1 && v2 >= Vm2)
1604 pointisvalid = Standard_True;
1605
1606 if(pointisvalid) {
1607 previousPoint = myIntersectionOn2S.Point();
1608 previoustg = myIntersectionOn2S.IsTangent();
1609
1610 if(!previoustg) {
1611 previousd = myIntersectionOn2S.Direction();
1612 previousd1 = myIntersectionOn2S.DirectionOnS1();
1613 previousd2 = myIntersectionOn2S.DirectionOnS2();
1614 }
1615 Standard_Boolean bAddPoint = Standard_True;
1616
1617 if(line->NbPoints() >= 1) {
1618 gp_Pnt pf = line->Value(1).Value();
1619 gp_Pnt pl = previousPoint.Value();
1620
1621 if(pf.Distance(pl) < Precision::Confusion()) {
1622 dIncKey++;
1623 if(dIncKey == 5000) return bOutOfTangentZone;
1624 else bAddPoint = Standard_False;
1625 }
1626 }
1627
1628 if(bAddPoint) {
1629 aSeqOfNewPoint.Append(previousPoint);
1630 nbIterWithoutAppend = 0;
1631 }
1632 }
1633
1634 if (line->NbPoints() == 2) {
1635 for(uvit = 0; uvit < 4; uvit++) {
1636 pasSav[uvit] = pasuv[uvit];
1637 }
1638 }
1639
1640 if ( !pointisvalid ) {
1641 // decrease step if out of bounds
1642 // otherwise the same calculations will be
1643 // repeated several times
1644 if ( ( u1 > UM1 ) || ( u1 < Um1 ) )
1645 pasuv[0] *= 0.5;
1646
1647 if ( ( v1 > VM1 ) || ( v1 < Vm1 ) )
1648 pasuv[1] *= 0.5;
1649
1650 if ( ( u2 > UM2 ) || ( u2 < Um2 ) )
1651 pasuv[2] *= 0.5;
1652
1653 if ( ( v2 > VM2 ) || ( v2 < Vm2 ) )
1654 pasuv[3] *= 0.5;
1655 }
1656 } // end if(!bStop)
1657 else { //if(bStop)
1658 if(close && (line->NbPoints() >= 1)) {
1659
1660 if(!bOutOfTangentZone) {
1661 aSeqOfNewPoint.Append(line->Value(1)); // line end
1662 }
1663 nbIterWithoutAppend = 0;
1664 }
1665 else {
1666 ChoixIso = myIntersectionOn2S.Perform(Param, Rsnld, theChoixIso);
1667
1668 if(myIntersectionOn2S.IsEmpty()) {
1669 bStop = !myIntersectionOn2S.IsTangent();
1670 bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
1671 }
1672 else {
1673 Standard_Boolean bAddPoint = Standard_True;
1674 Standard_Boolean pointisvalid = Standard_False;
1675
1676 previousPoint = myIntersectionOn2S.Point();
1677 Standard_Real u1,v1,u2,v2;
1678 previousPoint.Parameters(u1,v1,u2,v2);
1679
1680 if(u1 <= UM1 && u2 <= UM2 && v1 <= VM1 &&
1681 v2 <= VM2 && u1 >= Um1 && u2 >= Um2 &&
1682 v1 >= Vm1 && v2 >= Vm2)
1683 pointisvalid = Standard_True;
1684
1685 if(pointisvalid) {
1686
1687 if(line->NbPoints() >= 1) {
1688 gp_Pnt pf = line->Value(1).Value();
1689 gp_Pnt pl = previousPoint.Value();
1690
1691 if(pf.Distance(pl) < Precision::Confusion()) {
1692 dIncKey++;
1693 if(dIncKey == 5000) return bOutOfTangentZone;
1694 else bAddPoint = Standard_False;
1695 }
1696 }
1697
1698 if(bAddPoint && !bOutOfTangentZone) {
1699 aSeqOfNewPoint.Append(previousPoint);
1700 nbIterWithoutAppend = 0;
1701 }
1702 }
1703 }
1704 }
1705 }
1706 break;
1707 }
7fd59977 1708 default:
00302ba4 1709 {
1710 break;
1711 }
7fd59977 1712 }
1713 }
1714 }
1715 Standard_Boolean bExtendLine = Standard_False;
1716 Standard_Real u1 = 0., v1 = 0., u2 = 0., v2 = 0.;
1717
1718 Standard_Integer pit = 0;
1719
1720 for(pit = 0; !bExtendLine && (pit < 2); pit++) {
1721 if(pit == 0)
1722 previousPoint.Parameters(u1,v1,u2,v2);
1723 else {
1724 if(aSeqOfNewPoint.Length() > 0)
00302ba4 1725 aSeqOfNewPoint.Value(aSeqOfNewPoint.Length()).Parameters(u1,v1,u2,v2);
7fd59977 1726 else
00302ba4 1727 break;
7fd59977 1728 }
1729
1730 if(((u1 - Um1) < ResoU1) ||
00302ba4 1731 ((UM1 - u1) < ResoU1) ||
1732 ((u2 - Um2) < ResoU2) ||
1733 ((UM2 - u2) < ResoU2) ||
1734 ((v1 - Vm1) < ResoV1) ||
1735 ((VM1 - v1) < ResoV1) ||
1736 ((v2 - Vm2) < ResoV2) ||
1737 ((VM2 - v2) < ResoV2))
7fd59977 1738 bExtendLine = Standard_True;
1739 }
1740
1741 if(!bExtendLine) {
1742 // if(Status == IntWalk_OK || Status == IntWalk_ArretSurPoint) {
1743 if(Status == IntWalk_OK) {
1744 bExtendLine = Standard_True;
1745
1746 if(aSeqOfNewPoint.Length() > 1) {
00302ba4 1747 TColStd_Array1OfReal FirstParams(0, 3), LastParams(0, 3), Resolutions(0, 3);
1748 Resolutions(0) = ResoU1; Resolutions(1) = ResoV1; Resolutions(2) = ResoU2; Resolutions(3) = ResoV2;
1749
1750 aSeqOfNewPoint(1).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1751 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1752 aSeqOfNewPoint(aSeqOfNewPoint.Length()).Parameters(LastParams.ChangeValue(0),
1753 LastParams.ChangeValue(1),
1754 LastParams.ChangeValue(2),
1755 LastParams.ChangeValue(3));
1756 Standard_Integer indexofiso = 0;
1757
1758 if(theChoixIso == IntImp_UIsoparametricOnCaro1) indexofiso = 0;
1759 if(theChoixIso == IntImp_VIsoparametricOnCaro1) indexofiso = 1;
1760 if(theChoixIso == IntImp_UIsoparametricOnCaro2) indexofiso = 2;
1761 if(theChoixIso == IntImp_VIsoparametricOnCaro2) indexofiso = 3;
1762
1763 Standard_Integer afirstindex = (indexofiso < 2) ? 0 : 2;
1764 gp_Vec2d aTangentZoneDir(gp_Pnt2d(FirstParams.Value(afirstindex), FirstParams.Value(afirstindex + 1)),
1765 gp_Pnt2d(LastParams.Value(afirstindex), LastParams.Value(afirstindex + 1)));
1766
1767 gp_Dir2d anIsoDir(0, 1);
1768
1769 if((indexofiso == 1) || (indexofiso == 3))
1770 anIsoDir = gp_Dir2d(1, 0);
1771
1772 if(aTangentZoneDir.SquareMagnitude() > gp::Resolution()) {
1773 Standard_Real piquota = M_PI*0.25;
1774
1775 if(fabs(aTangentZoneDir.Angle(anIsoDir)) > piquota) {
1776 Standard_Integer ii = 1, nextii = 2;
1777 gp_Vec2d d1(0, 0);
1778 Standard_Real asqresol = gp::Resolution();
1779 asqresol *= asqresol;
1780
1781 do {
1782 aSeqOfNewPoint(ii).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1783 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1784 aSeqOfNewPoint(ii + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1785 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1786 d1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1787 FirstParams.Value(afirstindex + 1)),
1788 gp_Pnt2d(LastParams.Value(afirstindex),
1789 LastParams.Value(afirstindex + 1)));
1790 ii++;
1791 }
1792 while((d1.SquareMagnitude() < asqresol) &&
1793 (ii < aSeqOfNewPoint.Length()));
1794
1795 nextii = ii;
1796
1797 while(nextii < aSeqOfNewPoint.Length()) {
1798
1799 gp_Vec2d nextd1(0, 0);
1800 Standard_Integer jj = nextii;
1801
1802 do {
1803 aSeqOfNewPoint(jj).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
1804 FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
1805 aSeqOfNewPoint(jj + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
1806 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
1807 nextd1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
1808 FirstParams.Value(afirstindex + 1)),
1809 gp_Pnt2d(LastParams.Value(afirstindex),
1810 LastParams.Value(afirstindex + 1)));
1811 jj++;
1812
1813 }
1814 while((nextd1.SquareMagnitude() < asqresol) &&
1815 (jj < aSeqOfNewPoint.Length()));
1816 nextii = jj;
1817
1818 if(fabs(d1.Angle(nextd1)) > piquota) {
1819 bExtendLine = Standard_False;
1820 break;
1821 }
1822 d1 = nextd1;
1823 }
1824 }
1825 // end if(fabs(aTangentZoneDir.Angle(anIsoDir)
1826 }
7fd59977 1827 }
1828 }
1829 }
1830
1831 if(!bExtendLine) {
1832 return Standard_False;
1833 }
1834 Standard_Integer i = 0;
1835
1836 for(i = 1; i <= aSeqOfNewPoint.Length(); i++) {
1837 AddAPoint(line, aSeqOfNewPoint.Value(i));
1838 }
1839
1840 return bOutOfTangentZone;
1841}
00302ba4 1842
c2c2f2b6 1843//=======================================================================
1844//function : DistanceMinimizeByGradient
1845//purpose :
1846//=======================================================================
1847Standard_Boolean IntWalk_PWalking::
47cbf134 1848DistanceMinimizeByGradient( const Handle(Adaptor3d_HSurface)& theASurf1,
1849 const Handle(Adaptor3d_HSurface)& theASurf2,
1850 Standard_Real& theU1,
1851 Standard_Real& theV1,
1852 Standard_Real& theU2,
1853 Standard_Real& theV2,
1854 const Standard_Real theStep0U1V1,
1855 const Standard_Real theStep0U2V2)
00302ba4 1856{
1857 const Standard_Integer aNbIterMAX = 60;
1858 const Standard_Real aTol = 1.0e-14;
1859 Handle(Geom_Surface) aS1, aS2;
1860
1861 switch(theASurf1->GetType())
1862 {
1863 case GeomAbs_BezierSurface:
1864 aS1 = theASurf1->Surface().Bezier();
1865 break;
1866 case GeomAbs_BSplineSurface:
1867 aS1 = theASurf1->Surface().BSpline();
1868 break;
1869 default:
1870 return Standard_True;
1871 }
1872
1873 switch(theASurf2->GetType())
1874 {
1875 case GeomAbs_BezierSurface:
1876 aS2 = theASurf2->Surface().Bezier();
1877 break;
1878 case GeomAbs_BSplineSurface:
1879 aS2 = theASurf2->Surface().BSpline();
1880 break;
1881 default:
1882 return Standard_True;
1883 }
1884
1885 Standard_Boolean aStatus = Standard_False;
1886
1887 gp_Pnt aP1, aP2;
1888 gp_Vec aD1u, aD1v, aD2U, aD2V;
1889
1890 aS1->D1(theU1, theV1, aP1, aD1u, aD1v);
1891 aS2->D1(theU2, theV2, aP2, aD2U, aD2V);
1892
1893 Standard_Real aSQDistPrev = aP1.SquareDistance(aP2);
1894
1895 gp_Vec aP12(aP1, aP2);
1896
1897 Standard_Real aGradFu(-aP12.Dot(aD1u));
1898 Standard_Real aGradFv(-aP12.Dot(aD1v));
1899 Standard_Real aGradFU( aP12.Dot(aD2U));
1900 Standard_Real aGradFV( aP12.Dot(aD2V));
1901
1902 Standard_Real aSTEPuv = theStep0U1V1, aStepUV = theStep0U2V2;
1903
1904 Standard_Boolean flRepeat = Standard_True;
1905 Standard_Integer aNbIter = aNbIterMAX;
1906
1907 while(flRepeat)
1908 {
1909 Standard_Real anAdd = aGradFu*aSTEPuv;
c2c2f2b6 1910 Standard_Real aPARu = (anAdd >= 0.0)?
47cbf134 1911 (theU1 - Max(anAdd, Epsilon(theU1))) :
1912 (theU1 + Max(-anAdd, Epsilon(theU1)));
00302ba4 1913 anAdd = aGradFv*aSTEPuv;
c2c2f2b6 1914 Standard_Real aPARv = (anAdd >= 0.0)?
47cbf134 1915 (theV1 - Max(anAdd, Epsilon(theV1))) :
1916 (theV1 + Max(-anAdd, Epsilon(theV1)));
00302ba4 1917 anAdd = aGradFU*aStepUV;
c2c2f2b6 1918 Standard_Real aParU = (anAdd >= 0.0)?
47cbf134 1919 (theU2 - Max(anAdd, Epsilon(theU2))) :
1920 (theU2 + Max(-anAdd, Epsilon(theU2)));
00302ba4 1921 anAdd = aGradFV*aStepUV;
c2c2f2b6 1922 Standard_Real aParV = (anAdd >= 0.0)?
47cbf134 1923 (theV2 - Max(anAdd, Epsilon(theV2))) :
1924 (theV2 + Max(-anAdd, Epsilon(theV2)));
00302ba4 1925
1926 gp_Pnt aPt1, aPt2;
1927
1928 aS1->D1(aPARu, aPARv, aPt1, aD1u, aD1v);
1929 aS2->D1(aParU, aParV, aPt2, aD2U, aD2V);
1930
1931 Standard_Real aSQDist = aPt1.SquareDistance(aPt2);
1932
1933 if(aSQDist < aSQDistPrev)
1934 {
1935 aSQDistPrev = aSQDist;
1936 theU1 = aPARu;
1937 theV1 = aPARv;
1938 theU2 = aParU;
1939 theV2 = aParV;
1940
1941 aStatus = aSQDistPrev < aTol;
1942 aSTEPuv *= 1.2;
1943 aStepUV *= 1.2;
1944 }
1945 else
1946 {
1947 if(--aNbIter < 0)
1948 {
1949 flRepeat = Standard_False;
1950 }
1951 else
1952 {
1953 aS1->D1(theU1, theV1, aPt1, aD1u, aD1v);
1954 aS2->D1(theU2, theV2, aPt2, aD2U, aD2V);
1955
1956 gp_Vec aP12(aPt1, aPt2);
1957 aGradFu = -aP12.Dot(aD1u);
1958 aGradFv = -aP12.Dot(aD1v);
1959 aGradFU = aP12.Dot(aD2U);
1960 aGradFV = aP12.Dot(aD2V);
1961 aSTEPuv = theStep0U1V1;
1962 aStepUV = theStep0U2V2;
1963 }
1964 }
1965 }
1966
1967 return aStatus;
1968}
1969
c2c2f2b6 1970//=======================================================================
1971//function : DistanceMinimizeByExtrema
1972//purpose :
1973//=======================================================================
1974Standard_Boolean IntWalk_PWalking::
47cbf134 1975DistanceMinimizeByExtrema(const Handle(Adaptor3d_HSurface)& theASurf,
1976 const gp_Pnt& theP0,
1977 Standard_Real& theU0,
1978 Standard_Real& theV0,
1979 const Standard_Real theStep0U,
1980 const Standard_Real theStep0V)
00302ba4 1981{
1982 const Standard_Real aTol = 1.0e-14;
1983 gp_Pnt aPS;
1984 gp_Vec aD1Su, aD1Sv, aD2Su, aD2Sv, aD2SuvTemp;
1985 Standard_Real aSQDistPrev = RealLast();
1986 Standard_Real aU = theU0, aV = theV0;
47cbf134 1987
00302ba4 1988 Standard_Integer aNbIter = 10;
1989 do
1990 {
1991 theASurf->D2(aU, aV, aPS, aD1Su, aD1Sv, aD2Su, aD2Sv, aD2SuvTemp);
47cbf134 1992
00302ba4 1993 gp_Vec aVec(theP0, aPS);
47cbf134 1994
00302ba4 1995 Standard_Real aSQDist = aVec.SquareMagnitude();
1996
1997 if(aSQDist >= aSQDistPrev)
1998 break;
1999
2000 aSQDistPrev = aSQDist;
2001 theU0 = aU;
2002 theV0 = aV;
2003 aNbIter--;
2004
2005 if(aSQDistPrev < aTol)
2006 break;
2007
2008 //Functions
2009 const Standard_Real aF1 = aD1Su.Dot(aVec), aF2 = aD1Sv.Dot(aVec);
2010
2011 //Derivatives
2012 const Standard_Real aDf1u = aD2Su.Dot(aVec) + aD1Su.Dot(aD1Su),
47cbf134 2013 aDf1v = aD2Su.Dot(aD1Sv),
2014 aDf2u = aDf1v,
2015 aDf2v = aD2Sv.Dot(aVec) + aD1Sv.Dot(aD1Sv);
00302ba4 2016
2017 const Standard_Real aDet = aDf1u*aDf2v - aDf1v*aDf2u;
2018 aU -= theStep0U*(aDf2v*aF1 - aDf1v*aF2)/aDet;
2019 aV += theStep0V*(aDf2u*aF1 - aDf1u*aF2)/aDet;
2020 }
2021 while(aNbIter > 0);
2022
2023 return (aSQDistPrev < aTol);
2024}
2025
c2c2f2b6 2026//=======================================================================
2027//function : SeekPointOnBoundary
2028//purpose :
2029//=======================================================================
2030Standard_Boolean IntWalk_PWalking::
47cbf134 2031SeekPointOnBoundary(const Handle(Adaptor3d_HSurface)& theASurf1,
2032 const Handle(Adaptor3d_HSurface)& theASurf2,
2033 const Standard_Real theU1,
2034 const Standard_Real theV1,
2035 const Standard_Real theU2,
2036 const Standard_Real theV2,
2037 const Standard_Boolean isTheFirst)
c2c2f2b6 2038{
2039 const Standard_Real aTol = 1.0e-14;
2040 Standard_Boolean isOK = Standard_False;
2041 Standard_Real U1prec = theU1, V1prec = theV1, U2prec = theU2, V2prec = theV2;
2042
2043 Standard_Boolean flFinish = Standard_False;
2044
2045 Standard_Integer aNbIter = 20;
2046 while(!flFinish)
2047 {
2048 flFinish = Standard_False;
2049 Standard_Boolean aStatus = Standard_False;
2050
2051 do
2052 {
2053 aNbIter--;
2054 aStatus = DistanceMinimizeByGradient(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec);
2055 if(aStatus)
2056 {
2057 break;
2058 }
2059
2060 aStatus = DistanceMinimizeByExtrema(theASurf1, theASurf2->Value(U2prec, V2prec), U1prec, V1prec);
2061 if(aStatus)
2062 {
2063 break;
2064 }
2065
2066 aStatus = DistanceMinimizeByExtrema(theASurf2, theASurf1->Value(U1prec, V1prec), U2prec, V2prec);
2067 if(aStatus)
2068 {
2069 break;
2070 }
2071 }
2072 while(!aStatus && (aNbIter > 0));
2073
2074 if(aStatus)
2075 {
2076 const Standard_Real aTolMax = 1.0e-8;
2077 Standard_Real aTolF = 0.0;
2078
2079 Standard_Real u1 = U1prec, v1 = V1prec, u2 = U2prec, v2 = V2prec;
2080
2081 flFinish = Checking(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec, aTolF);
47cbf134 2082
c2c2f2b6 2083 if(aTolF <= aTolMax)
2084 {
2085 gp_Pnt aP1 = theASurf1->Value(u1, v1),
47cbf134 2086 aP2 = theASurf2->Value(u2, v2);
c2c2f2b6 2087 gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
2088
2089 const Standard_Real aSQDist1 = aPInt.SquareDistance(aP1),
47cbf134 2090 aSQDist2 = aPInt.SquareDistance(aP2);
c2c2f2b6 2091 if((aSQDist1 < aTol) && (aSQDist2 < aTol))
2092 {
2093 IntSurf_PntOn2S anIP;
2094 anIP.SetValue(aPInt, u1, v1, u2, v2);
47cbf134 2095
c2c2f2b6 2096 if(isTheFirst)
2097 line->InsertBefore(1,anIP);
2098 else
2099 line->Add(anIP);
2100
2101 isOK = Standard_True;
2102 }
2103 }
2104 }
2105 else
2106 {
2107 break;
2108 }
2109
2110 if(aNbIter < 0)
2111 break;
2112 }
2113
2114 return isOK;
2115}
2116
2117//=======================================================================
2118//function : PutToBoundary
2119//purpose :
2120//=======================================================================
2121Standard_Boolean IntWalk_PWalking::
47cbf134 2122PutToBoundary(const Handle(Adaptor3d_HSurface)& theASurf1,
2123 const Handle(Adaptor3d_HSurface)& theASurf2)
c2c2f2b6 2124{
2125 const Standard_Real aTolMin = Precision::Confusion();
2126
2127 Standard_Boolean hasBeenAdded = Standard_False;
2128
2129 const Standard_Real aU1bFirst = theASurf1->FirstUParameter();
2130 const Standard_Real aU1bLast = theASurf1->LastUParameter();
2131 const Standard_Real aU2bFirst = theASurf2->FirstUParameter();
2132 const Standard_Real aU2bLast = theASurf2->LastUParameter();
2133 const Standard_Real aV1bFirst = theASurf1->FirstVParameter();
2134 const Standard_Real aV1bLast = theASurf1->LastVParameter();
2135 const Standard_Real aV2bFirst = theASurf2->FirstVParameter();
2136 const Standard_Real aV2bLast = theASurf2->LastVParameter();
2137
2138 Standard_Real aTol = 1.0;
2139 aTol = Min(aTol, aU1bLast - aU1bFirst);
2140 aTol = Min(aTol, aU2bLast - aU2bFirst);
2141 aTol = Min(aTol, aV1bLast - aV1bFirst);
2142 aTol = Min(aTol, aV2bLast - aV2bFirst)*1.0e-3;
2143
2144 if(aTol <= 2.0*aTolMin)
2145 return hasBeenAdded;
2146
2147 Standard_Boolean isNeedAdding = Standard_False;
2148 Standard_Boolean isU1parallel = Standard_False, isV1parallel = Standard_False;
2149 Standard_Boolean isU2parallel = Standard_False, isV2parallel = Standard_False;
2150 IsParallel(line, Standard_True, aTol, isU1parallel, isV1parallel);
2151 IsParallel(line, Standard_False, aTol, isU2parallel, isV2parallel);
2152
2153 const Standard_Integer aNbPnts = line->NbPoints();
2154 Standard_Real u1, v1, u2, v2;
2155 line->Value(1).Parameters(u1, v1, u2, v2);
2156 Standard_Real aDelta = 0.0;
47cbf134 2157
c2c2f2b6 2158 if(!isV1parallel)
2159 {
2160 aDelta = u1 - aU1bFirst;
2161 if((aTolMin < aDelta) && (aDelta < aTol))
2162 {
2163 u1 = aU1bFirst - aDelta;
2164 isNeedAdding = Standard_True;
2165 }
2166 else
2167 {
2168 aDelta = aU1bLast - u1;
2169 if((aTolMin < aDelta) && (aDelta < aTol))
2170 {
2171 u1 = aU1bLast + aDelta;
2172 isNeedAdding = Standard_True;
2173 }
2174 }
2175 }
2176
2177 if(!isV2parallel)
2178 {
2179 aDelta = u2 - aU2bFirst;
2180 if((aTolMin < aDelta) && (aDelta < aTol))
2181 {
2182 u2 = aU2bFirst - aDelta;
2183 isNeedAdding = Standard_True;
2184 }
2185 else
2186 {
2187 aDelta = aU2bLast - u2;
2188 if((aTolMin < aDelta) && (aDelta < aTol))
2189 {
2190 u2 = aU2bLast + aDelta;
2191 isNeedAdding = Standard_True;
2192 }
2193 }
2194 }
2195
2196 if(!isU1parallel)
2197 {
2198 aDelta = v1 - aV1bFirst;
2199 if((aTolMin < aDelta) && (aDelta < aTol))
2200 {
2201 v1 = aV1bFirst - aDelta;
2202 isNeedAdding = Standard_True;
2203 }
2204 else
2205 {
2206 aDelta = aV1bLast - v1;
2207 if((aTolMin < aDelta) && (aDelta < aTol))
2208 {
2209 v1 = aV1bLast + aDelta;
2210 isNeedAdding = Standard_True;
2211 }
2212 }
2213 }
2214
2215 if(!isU2parallel)
2216 {
2217 aDelta = v2 - aV2bFirst;
2218 if((aTolMin < aDelta) && (aDelta < aTol))
2219 {
2220 v2 = aV2bFirst - aDelta;
2221 isNeedAdding = Standard_True;
2222 }
2223 else
2224 {
2225 aDelta = aV2bLast - v2;
2226 if((aTolMin < aDelta) && (aDelta < aTol))
2227 {
2228 v2 = aV2bLast + aDelta;
2229 isNeedAdding = Standard_True;
2230 }
2231 }
2232 }
2233
2234 if(isNeedAdding)
2235 {
2236 hasBeenAdded =
2237 SeekPointOnBoundary(theASurf1, theASurf2, u1,
47cbf134 2238 v1, u2, v2, Standard_True);
c2c2f2b6 2239 }
2240
2241 isNeedAdding = Standard_False;
2242 line->Value(aNbPnts).Parameters(u1, v1, u2, v2);
2243
2244 if(!isV1parallel)
2245 {
2246 aDelta = u1 - aU1bFirst;
2247 if((aTolMin < aDelta) && (aDelta < aTol))
2248 {
2249 u1 = aU1bFirst - aDelta;
2250 isNeedAdding = Standard_True;
2251 }
2252 else
2253 {
2254 aDelta = aU1bLast - u1;
2255 if((aTolMin < aDelta) && (aDelta < aTol))
2256 {
2257 u1 = aU1bLast + aDelta;
2258 isNeedAdding = Standard_True;
2259 }
2260 }
2261 }
2262
2263 if(!isV2parallel)
2264 {
2265 aDelta = u2 - aU2bFirst;
2266 if((aTolMin < aDelta) && (aDelta < aTol))
2267 {
2268 u2 = aU2bFirst - aDelta;
2269 isNeedAdding = Standard_True;
2270 }
2271 else
2272 {
2273 aDelta = aU2bLast - u2;
2274 if((aTolMin < aDelta) && (aDelta < aTol))
2275 {
2276 u2 = aU2bLast + aDelta;
2277 isNeedAdding = Standard_True;
2278 }
2279 }
2280 }
2281
2282 if(!isU1parallel)
2283 {
2284 aDelta = v1 - aV1bFirst;
2285 if((aTolMin < aDelta) && (aDelta < aTol))
2286 {
2287 v1 = aV1bFirst - aDelta;
2288 isNeedAdding = Standard_True;
2289 }
2290 else
2291 {
2292 aDelta = aV1bLast - v1;
2293 if((aTolMin < aDelta) && (aDelta < aTol))
2294 {
2295 v1 = aV1bLast + aDelta;
2296 isNeedAdding = Standard_True;
2297 }
2298 }
2299 }
2300
2301 if(!isU2parallel)
2302 {
2303 aDelta = v2 - aV2bFirst;
2304 if((aTolMin < aDelta) && (aDelta < aTol))
2305 {
2306 v2 = aV2bFirst - aDelta;
2307 isNeedAdding = Standard_True;
2308 }
2309 else
2310 {
2311 aDelta = aV2bLast - v2;
2312 if((aTolMin < aDelta) && (aDelta < aTol))
2313 {
2314 v2 = aV2bLast + aDelta;
2315 isNeedAdding = Standard_True;
2316 }
2317 }
2318 }
2319
2320 if(isNeedAdding)
2321 {
2322 hasBeenAdded =
2323 SeekPointOnBoundary(theASurf1, theASurf2, u1,
47cbf134 2324 v1, u2, v2, Standard_False);
c2c2f2b6 2325 }
2326
2327 return hasBeenAdded;
2328}
2329
2330//=======================================================================
2331//function : SeekAdditionalPoints
2332//purpose :
2333//=======================================================================
2334Standard_Boolean IntWalk_PWalking::
47cbf134 2335SeekAdditionalPoints( const Handle(Adaptor3d_HSurface)& theASurf1,
2336 const Handle(Adaptor3d_HSurface)& theASurf2,
2337 const Standard_Integer theMinNbPoints)
00302ba4 2338{
2339 const Standard_Real aTol = 1.0e-14;
2340 Standard_Integer aNbPoints = line->NbPoints();
2341 if(aNbPoints > theMinNbPoints)
2342 return Standard_True;
2343
2344 const Standard_Real aU1bFirst = theASurf1->FirstUParameter();
2345 const Standard_Real aU1bLast = theASurf1->LastUParameter();
2346 const Standard_Real aU2bFirst = theASurf2->FirstUParameter();
2347 const Standard_Real aU2bLast = theASurf2->LastUParameter();
2348 const Standard_Real aV1bFirst = theASurf1->FirstVParameter();
2349 const Standard_Real aV1bLast = theASurf1->LastVParameter();
2350 const Standard_Real aV2bFirst = theASurf2->FirstVParameter();
2351 const Standard_Real aV2bLast = theASurf2->LastVParameter();
2352
47cbf134 2353
00302ba4 2354 Standard_Boolean isPrecise = Standard_False;
2355
2356 Standard_Real U1prec = 0.0, V1prec = 0.0, U2prec = 0.0, V2prec = 0.0;
2357
2358 Standard_Integer aNbPointsPrev = 0;
2359 while(aNbPoints < theMinNbPoints && (aNbPoints != aNbPointsPrev))
2360 {
2361 aNbPointsPrev = aNbPoints;
2362 for(Standard_Integer fp = 1, lp = 2; fp < aNbPoints; fp = lp + 1)
2363 {
2364 Standard_Real U1f, V1f, U2f, V2f; //first point in 1st and 2nd surafaces
2365 Standard_Real U1l, V1l, U2l, V2l; //last point in 1st and 2nd surafaces
2366
2367 lp = fp+1;
2368 line->Value(fp).Parameters(U1f, V1f, U2f, V2f);
2369 line->Value(lp).Parameters(U1l, V1l, U2l, V2l);
2370
2371 U1prec = 0.5*(U1f+U1l);
2372 if(U1prec < aU1bFirst)
2373 U1prec = aU1bFirst;
2374 if(U1prec > aU1bLast)
2375 U1prec = aU1bLast;
2376
2377 V1prec = 0.5*(V1f+V1l);
2378 if(V1prec < aV1bFirst)
2379 V1prec = aV1bFirst;
2380 if(V1prec > aV1bLast)
2381 V1prec = aV1bLast;
2382
2383 U2prec = 0.5*(U2f+U2l);
2384 if(U2prec < aU2bFirst)
2385 U2prec = aU2bFirst;
2386 if(U2prec > aU2bLast)
2387 U2prec = aU2bLast;
2388
2389 V2prec = 0.5*(V2f+V2l);
2390 if(V2prec < aV2bFirst)
2391 V2prec = aV2bFirst;
2392 if(V2prec > aV2bLast)
2393 V2prec = aV2bLast;
2394
2395 Standard_Boolean aStatus = Standard_False;
2396 Standard_Integer aNbIter = 5;
2397 do
2398 {
2399 aStatus = DistanceMinimizeByGradient(theASurf1, theASurf2, U1prec, V1prec, U2prec, V2prec);
2400 if(aStatus)
2401 {
2402 break;
2403 }
2404
2405 aStatus = DistanceMinimizeByExtrema(theASurf1, theASurf2->Value(U2prec, V2prec), U1prec, V1prec);
2406 if(aStatus)
2407 {
2408 break;
2409 }
2410
2411 aStatus = DistanceMinimizeByExtrema(theASurf2, theASurf1->Value(U1prec, V1prec), U2prec, V2prec);
2412 if(aStatus)
2413 {
2414 break;
2415 }
2416 }
2417 while(!aStatus && (--aNbIter > 0));
2418
2419 if(aStatus)
2420 {
2421 gp_Pnt aP1 = theASurf1->Value(U1prec, V1prec),
47cbf134 2422 aP2 = theASurf2->Value(U2prec, V2prec);
00302ba4 2423 gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
2424
2425 const Standard_Real aSQDist1 = aPInt.SquareDistance(aP1),
47cbf134 2426 aSQDist2 = aPInt.SquareDistance(aP2);
00302ba4 2427
2428 if((aSQDist1 < aTol) && (aSQDist2 < aTol))
2429 {
2430 IntSurf_PntOn2S anIP;
2431 anIP.SetValue(aPInt, U1prec, V1prec, U2prec, V2prec);
2432 line->InsertBefore(lp, anIP);
47cbf134 2433
00302ba4 2434 isPrecise = Standard_True;
2435
2436 if(++aNbPoints >= theMinNbPoints)
2437 break;
2438 }
2439 else
2440 {
2441 lp--;
2442 }
2443 }
2444 }
2445 }
2446
2447 return isPrecise;
2448}
c2c2f2b6 2449
47cbf134 2450void IntWalk_PWalking::
2451RepartirOuDiviser(Standard_Boolean& DejaReparti,
2452 IntImp_ConstIsoparametric& ChoixIso,
2453 Standard_Boolean& Arrive)
2454
2455 // at the neighborhood of a point, there is a fail of marching
2456 // it is required to divide the steps to try to continue
2457 // if the step is too small if we are on border
2458 // restart in another direction if it was not done, otherwise stop
2459
2460{
2461 // Standard_Integer i;
2462 if (Arrive) { //restart in the other direction
2463 if (!DejaReparti ) {
2464 Arrive = Standard_False;
2465 DejaReparti = Standard_True;
2466 previousPoint = line->Value(1);
2467 previoustg = Standard_False;
2468 previousd1 = firstd1;
2469 previousd2 = firstd2;
2470 previousd = tgdir;
2471 indextg = line->NbPoints();
2472 tgdir.Reverse();
2473 line->Reverse();
2474
2475 //-- printf("\nIntWalk_PWalking_2.gxx Reverse %3d\n",indextg);
2476 sensCheminement = -1;
2477 tgfirst = tglast;
2478 tglast = Standard_False;
2479 ChoixIso = choixIsoSav;
2480#if 0
2481 pasuv[0]=pasSav[0];
2482 pasuv[1]=pasSav[1];
2483 pasuv[2]=pasSav[2];
2484 pasuv[3]=pasSav[3];
2485#else
2486 Standard_Real u1,v1,u2,v2;
2487 Standard_Real U1,V1,U2,V2;
2488 Standard_Integer nn=line->NbPoints();
2489 if(nn>2) {
2490 line->Value(nn).Parameters(u1,v1,u2,v2);
2491 line->Value(nn-1).Parameters(U1,V1,U2,V2);
2492 pasuv[0]=Abs(u1-U1);
2493 pasuv[1]=Abs(v1-V1);
2494 pasuv[2]=Abs(u2-U2);
2495 pasuv[3]=Abs(v2-V2);
2496 }
2497#endif
2498
2499 }
2500 }
2501 else {
2502 if ( pasuv[0]*0.5 < ResoU1
2503 && pasuv[1]*0.5 < ResoV1
2504 && pasuv[2]*0.5 < ResoU2
2505 && pasuv[3]*0.5 < ResoV2
2506 ) {
2507 if (!previoustg) {
2508 tglast = Standard_True; // IS IT ENOUGH ????
2509 }
2510
2511 if (!DejaReparti) { //restart in the other direction
2512 DejaReparti = Standard_True;
2513 previousPoint = line->Value(1);
2514 previoustg = Standard_False;
2515 previousd1 = firstd1;
2516 previousd2 = firstd2;
2517 previousd = tgdir;
2518 indextg = line->NbPoints();
2519 tgdir.Reverse();
2520 line->Reverse();
2521
2522 //-- printf("\nIntWalk_PWalking_2.gxx Reverse %3d\n",indextg);
2523
2524 sensCheminement = -1;
2525 tgfirst = tglast;
2526 tglast = Standard_False;
2527 ChoixIso = choixIsoSav;
2528
2529#if 0
2530 pasuv[0]=pasSav[0];
2531 pasuv[1]=pasSav[1];
2532 pasuv[2]=pasSav[2];
2533 pasuv[3]=pasSav[3];
2534#else
2535 Standard_Real u1,v1,u2,v2;
2536 Standard_Real U1,V1,U2,V2;
2537 Standard_Integer nn=line->NbPoints();
2538 if(nn>2) {
2539 line->Value(nn).Parameters(u1,v1,u2,v2);
2540 line->Value(nn-1).Parameters(U1,V1,U2,V2);
2541 pasuv[0]=Abs(u1-U1);
2542 pasuv[1]=Abs(v1-V1);
2543 pasuv[2]=Abs(u2-U2);
2544 pasuv[3]=Abs(v2-V2);
2545 }
2546#endif
2547 }
2548 else Arrive = Standard_True;
2549 }
2550 else {
2551 pasuv[0]*=0.5;
2552 pasuv[1]*=0.5;
2553 pasuv[2]*=0.5;
2554 pasuv[3]*=0.5;
2555 }
2556 }
2557}
2558
2559namespace {
2560 //OCC431(apo): modified ->
2561 static const Standard_Real CosRef2D = Cos(M_PI/9.0), AngRef2D = M_PI/2.0;
2562
2563 static const Standard_Real d = 7.0;
2564}
2565
2566IntWalk_StatusDeflection IntWalk_PWalking::TestDeflection()
2567
2568// test if vector is observed by calculating an increase of vector
2569// or the previous point and its tangent, the new calculated point and its
2570// tangent; it is possible to find a cube passing by the 2 points and having as a
2571// derivative the tangents of the intersection
2572// calculate the point with parameter 0.5 on cube=p1
2573// calculate the medium point of 2 points of intersection=p2
2574// if arrow/2<=||p1p2||<= arrow consider that the vector is observed
2575// otherwise adjust the step depending on the ratio ||p1p2||/vector
2576// and the previous step
2577// test if in 2 tangent planes of surfaces there is no too great angle2d
2578// grand : if yes divide the step
2579// test if there is no change of side
2580//
2581{
2582 if(line->NbPoints() ==1 ) {
2583 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=STATIC_PRECEDENT_INFLEXION=0;
2584 }
2585
2586 IntWalk_StatusDeflection Status = IntWalk_OK;
2587 Standard_Real FlecheCourante ,Ratio;
2588
2589
2590 const IntSurf_PntOn2S& CurrentPoint = myIntersectionOn2S.Point();
2591 //==================================================================================
2592 //========= S t o p o n p o i n t ============
2593 //==================================================================================
2594 if (myIntersectionOn2S.IsTangent()) {
2595 return IntWalk_ArretSurPoint;
2596 }
2597
2598 const gp_Dir& TgCourante = myIntersectionOn2S.Direction();
2599
2600 //==================================================================================
2601 //========= R i s k o f i n f l e x i o n p o i n t ============
2602 //==================================================================================
2603 if (TgCourante.Dot(previousd)<0) {
2604 //------------------------------------------------------------
2605 //-- Risk of inflexion point : Divide the step by 2
2606 //-- Initialize STATIC_PRECEDENT_INFLEXION so that
2607 //-- at the next call to return Pas_OK if there is no
2608 //-- more risk of the point of inflexion
2609 //------------------------------------------------------------
2610
2611 pasuv[0]*=0.5;
2612 pasuv[1]*=0.5;
2613 pasuv[2]*=0.5;
2614 pasuv[3]*=0.5;
2615 STATIC_PRECEDENT_INFLEXION+=3;
2616 if (pasuv[0] < ResoU1 && pasuv[1] <ResoV1 && pasuv[2] <ResoU2 && pasuv[3] < ResoV2)
2617 return IntWalk_ArretSurPointPrecedent;
2618 else
2619 return IntWalk_PasTropGrand;
2620 }
2621
2622 else {
2623 if(STATIC_PRECEDENT_INFLEXION > 0) {
2624 STATIC_PRECEDENT_INFLEXION -- ;
2625 return IntWalk_OK;
2626 }
2627 }
2628
2629 //==================================================================================
2630 //========= D e t e c t c o n f u s e d P o in t s ===========
2631 //==================================================================================
2632
2633 Standard_Real Dist = previousPoint.Value().
2634 SquareDistance(CurrentPoint.Value());
2635
2636
2637 if (Dist < tolconf*tolconf ) {
2638 pasuv[0] = Max(5.*ResoU1,Min(1.5*pasuv[0],pasInit[0]));
2639 pasuv[1] = Max(5.*ResoV1,Min(1.5*pasuv[1],pasInit[1]));
2640 pasuv[2] = Max(5.*ResoU2,Min(1.5*pasuv[2],pasInit[2]));
2641 pasuv[3] = Max(5.*ResoV2,Min(1.5*pasuv[3],pasInit[3]));
2642 Status = IntWalk_PointConfondu;
2643 }
2644
2645 //==================================================================================
2646 Standard_Real Up1,Vp1,Uc1,Vc1,Du1,Dv1,AbsDu1,AbsDu2,AbsDv1,AbsDv2;
2647 Standard_Real Up2,Vp2,Uc2,Vc2,Du2,Dv2;
2648
2649 previousPoint.Parameters(Up1,Vp1,Up2,Vp2);
2650 CurrentPoint.Parameters(Uc1,Vc1,Uc2,Vc2);
2651
2652 Du1 = Uc1 - Up1; Dv1 = Vc1 - Vp1;
2653 Du2 = Uc2 - Up2; Dv2 = Vc2 - Vp2;
2654
2655 AbsDu1 = Abs(Du1);
2656 AbsDu2 = Abs(Du2);
2657 AbsDv1 = Abs(Dv1);
2658 AbsDv2 = Abs(Dv2);
2659 //=================================================================================
2660 //==== S t e p o f p r o g r e s s i o n (between previous and Current) =======
2661 //=================================================================================
2662 if ( AbsDu1 < ResoU1 && AbsDv1 < ResoV1
2663 && AbsDu2 < ResoU2 && AbsDv2 < ResoV2) {
2664 pasuv[0] = ResoU1; pasuv[1] = ResoV1; pasuv[2] = ResoU2; pasuv[3] = ResoV2;
2665 return(IntWalk_ArretSurPointPrecedent);
2666 }
2667 //==================================================================================
2668
2669 Standard_Real tolArea = 100.0;
2670 if (ResoU1 < Precision::PConfusion() ||
2671 ResoV1 < Precision::PConfusion() ||
2672 ResoU2 < Precision::PConfusion() ||
2673 ResoV2 < Precision::PConfusion() )
2674 tolArea = tolArea*2.0;
2675
2676 Standard_Real Cosi1, CosRef1, Ang1, AngRef1, ResoUV1, Duv1, d1, tolCoeff1;
2677 Standard_Real Cosi2, CosRef2, Ang2, AngRef2, ResoUV2, Duv2, d2, tolCoeff2;
2678 Cosi1 = Du1*previousd1.X() + Dv1*previousd1.Y();
2679 Cosi2 = Du2*previousd2.X() + Dv2*previousd2.Y();
2680 Duv1 = Du1*Du1 + Dv1*Dv1;
2681 Duv2 = Du2*Du2 + Dv2*Dv2;
2682 ResoUV1 = ResoU1*ResoU1 + ResoV1*ResoV1;
2683 ResoUV2 = ResoU2*ResoU2 + ResoV2*ResoV2;
2684 //
2685 //modified by NIZNHY-PKV Wed Nov 13 12:25:44 2002 f
2686 //
2687 Standard_Real aMinDiv2=Precision::Confusion();
2688 aMinDiv2=aMinDiv2*aMinDiv2;
2689 //
2690 d1=d;
2691 if (Duv1>aMinDiv2) {
2692 d1 = Abs(ResoUV1/Duv1);
2693 d1 = Min(Sqrt(d1)*tolArea, d);
2694 }
2695 //d1 = Abs(ResoUV1/Duv1);
2696 //d1 = Min(Sqrt(d1)*tolArea,d);
2697 //modified by NIZNHY-PKV Wed Nov 13 12:34:30 2002 t
2698 tolCoeff1 = Exp(d1);
2699 //
2700 //modified by NIZNHY-PKV Wed Nov 13 12:34:43 2002 f
2701 d2=d;
2702 if (Duv2>aMinDiv2) {
2703 d2 = Abs(ResoUV2/Duv2);
2704 d2 = Min(Sqrt(d2)*tolArea,d);
2705 }
2706 //d2 = Abs(ResoUV2/Duv2);
2707 //d2 = Min(Sqrt(d2)*tolArea,d);
2708 //modified by NIZNHY-PKV Wed Nov 13 12:34:53 2002 t
2709 tolCoeff2 = Exp(d2);
2710 CosRef1 = CosRef2D/tolCoeff1;
2711 CosRef2 = CosRef2D/tolCoeff2;
2712 //
2713 //==================================================================================
2714 //== The points are not confused : ==
2715 //== 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 ==
2716 //== N o t T o o G r e a t (angle in space UV) ==
2717 //== C h a n g e o f s i d e ==
2718 //==================================================================================
2719 if (Status != IntWalk_PointConfondu) {
2720 if(Cosi1*Cosi1 < CosRef1*Duv1 || Cosi2*Cosi2 < CosRef2*Duv2) {
2721 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2722 if (pasuv[0]<ResoU1 && pasuv[1]<ResoV1 && pasuv[2]<ResoU2 && pasuv[3]<ResoV2) {
2723 return(IntWalk_ArretSurPointPrecedent);
2724 }
2725 else {
2726 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2727 return(IntWalk_PasTropGrand);
2728 }
2729 }
2730 const gp_Dir2d& Tg2dcourante1 = myIntersectionOn2S.DirectionOnS1();
2731 const gp_Dir2d& Tg2dcourante2 = myIntersectionOn2S.DirectionOnS2();
2732 Cosi1 = Du1*Tg2dcourante1.X() + Dv1*Tg2dcourante1.Y();
2733 Cosi2 = Du2*Tg2dcourante2.X() + Dv2*Tg2dcourante2.Y();
2734 Ang1 = Abs(previousd1.Angle(Tg2dcourante1));
2735 Ang2 = Abs(previousd2.Angle(Tg2dcourante2));
2736 AngRef1 = AngRef2D*tolCoeff1;
2737 AngRef2 = AngRef2D*tolCoeff2;
2738 //-------------------------------------------------------
2739 //-- Test : Angle too great in space UV -----
2740 //-- Change of side -----
2741 //-------------------------------------------------------
2742 if(Cosi1*Cosi1 < CosRef1*Duv1 || Cosi2*Cosi2 < CosRef2*Duv2 || Ang1 > AngRef1 || Ang2 > AngRef2) {
2743 pasuv[0]*=0.5; pasuv[1]*=0.5; pasuv[2]*=0.5; pasuv[3]*=0.5;
2744 if (pasuv[0]<ResoU1 && pasuv[1]<ResoV1 && pasuv[2]<ResoU2 && pasuv[3]<ResoV2)
2745 return(IntWalk_ArretSurPoint);
2746 else
2747 return(IntWalk_PasTropGrand);
2748 }
2749 }
2750 //<-OCC431(apo)
2751 //==================================================================================
2752 //== D e t e c t i o n o f : Step Too Small
2753 //== STEP TOO Great
2754 //==================================================================================
2755
2756 //---------------------------------------
2757 //-- Estimate of the vector --
2758 //---------------------------------------
2759 FlecheCourante =
2760 Sqrt(Abs((previousd.XYZ()-TgCourante.XYZ()).SquareModulus()*Dist))/8.;
2761
2762 if ( FlecheCourante<= fleche*0.5) { //-- Current step too small
2763 if(FlecheCourante>1e-16) {
2764 Ratio = 0.5*(fleche/FlecheCourante);
2765 }
2766 else {
2767 Ratio = 10.0;
2768 }
2769 Standard_Real pasSu1 = pasuv[0];
2770 Standard_Real pasSv1 = pasuv[1];
2771 Standard_Real pasSu2 = pasuv[2];
2772 Standard_Real pasSv2 = pasuv[3];
2773
2774 //-- In case if
2775 //-- a point at U+DeltaU is required, ....
2776 //-- return a point at U + Epsilon
2777 //-- Epsilon << DeltaU.
2778
2779 if(pasuv[0]< AbsDu1) pasuv[0] = AbsDu1;
2780 if(pasuv[1]< AbsDv1) pasuv[1] = AbsDv1;
2781 if(pasuv[2]< AbsDu2) pasuv[2] = AbsDu2;
2782 if(pasuv[3]< AbsDv2) pasuv[3] = AbsDv2;
2783
2784 if(pasuv[0]<ResoU1) pasuv[0]=ResoU1;
2785 if(pasuv[1]<ResoV1) pasuv[1]=ResoV1;
2786 if(pasuv[2]<ResoU2) pasuv[2]=ResoU2;
2787 if(pasuv[3]<ResoV2) pasuv[3]=ResoV2;
2788 //-- if(Ratio>10.0 ) { Ratio=10.0; }
2789 Standard_Real R1,R = pasInit[0]/pasuv[0];
2790 R1= pasInit[1]/pasuv[1]; if(R1<R) R=R1;
2791 R1= pasInit[2]/pasuv[2]; if(R1<R) R=R1;
2792 R1= pasInit[3]/pasuv[3]; if(R1<R) R=R1;
2793 if(Ratio > R) Ratio=R;
2794 pasuv[0] = Min(Ratio*pasuv[0],pasInit[0]);
2795 pasuv[1] = Min(Ratio*pasuv[1],pasInit[1]);
2796 pasuv[2] = Min(Ratio*pasuv[2],pasInit[2]);
2797 pasuv[3] = Min(Ratio*pasuv[3],pasInit[3]);
2798 if (pasuv[0] != pasSu1 || pasuv[2] != pasSu2||
2799 pasuv[1] != pasSv1 || pasuv[3] != pasSv2) {
2800 if(++STATIC_BLOCAGE_SUR_PAS_TROP_GRAND > 5) {
2801 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND = 0;
2802 return IntWalk_PasTropGrand;
2803 }
2804 }
2805 if(Status == IntWalk_OK) {
2806 STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=0;
2807 //-- Try to increase the step
2808 }
2809 return Status;
2810 }
2811 else { //-- CurrentVector > vector*0.5
2812 if (FlecheCourante > fleche) { //-- Current step too Great
2813 Ratio = fleche/FlecheCourante;
2814 pasuv[0] = Ratio*pasuv[0];
2815 pasuv[1] = Ratio*pasuv[1];
2816 pasuv[2] = Ratio*pasuv[2];
2817 pasuv[3] = Ratio*pasuv[3];
2818 //if(++STATIC_BLOCAGE_SUR_PAS_TROP_GRAND > 5) {
2819 // STATIC_BLOCAGE_SUR_PAS_TROP_GRAND = 0;
2820 return IntWalk_PasTropGrand;
2821 //}
2822 }
2823 else { //-- vector/2 < CurrentVector <= vector
2824 Ratio = 0.75 * (fleche / FlecheCourante);
2825 }
2826 }
2827 pasuv[0] = Max(5.*ResoU1,Min(Min(Ratio*AbsDu1,pasuv[0]),pasInit[0]));
2828 pasuv[1] = Max(5.*ResoV1,Min(Min(Ratio*AbsDv1,pasuv[1]),pasInit[1]));
2829 pasuv[2] = Max(5.*ResoU2,Min(Min(Ratio*AbsDu2,pasuv[2]),pasInit[2]));
2830 pasuv[3] = Max(5.*ResoV2,Min(Min(Ratio*AbsDv2,pasuv[3]),pasInit[3]));
2831 if(Status == IntWalk_OK) STATIC_BLOCAGE_SUR_PAS_TROP_GRAND=0;
2832 return Status;
2833}
2834
2835Standard_Boolean IntWalk_PWalking::
2836TestArret(const Standard_Boolean DejaReparti,
2837 TColStd_Array1OfReal& Param,
2838 IntImp_ConstIsoparametric& ChoixIso)
2839
2840 //
2841 // test if the point of intersection set by these parameters remains in the
2842 // natural domain of each square.
2843 // if the point outpasses reframe to find the best iso (border)
2844 // that intersects easiest the other square
2845 // otherwise test if closed line is present
2846 //
2847{
2848 Standard_Real Uvd[4],Uvf[4],Epsuv[4],Duv[4],Uvp[4],dv,dv2,ParC[4];
2849 Standard_Real DPc,DPb;
2850 Standard_Integer i = 0, k = 0;
2851 Epsuv[0] = ResoU1;
2852 Epsuv[1] = ResoV1;
2853 Epsuv[2] = ResoU2;
2854 Epsuv[3] = ResoV2;
2855 previousPoint.Parameters(Uvp[0],Uvp[1],Uvp[2],Uvp[3]);
2856
2857 Standard_Real SolParam[4];
2858 myIntersectionOn2S.Point().Parameters(SolParam[0],SolParam[1],SolParam[2],SolParam[3]);
2859
2860 Standard_Boolean Trouve = Standard_False;
2861
2862 Uvd[0]=Um1; Uvf[0]=UM1; Uvd[1]=Vm1; Uvf[1]=VM1;
2863 Uvd[2]=Um2; Uvf[2]=UM2; Uvd[3]=Vm2; Uvf[3]=VM2;
2864
2865 Standard_Integer im1;
2866 for ( i = 1,im1 = 0;i<=4;i++,im1++) {
2867 switch(i) {
2868 case 1: k=2; break;
2869 case 2: k=1; break;
2870 case 3: k=4; break;
2871 case 4: k=3; break;
2872 }
2873 if (Param(i) < (Uvd[im1]-Epsuv[im1]) ||
2874 SolParam[im1] < (Uvd[im1]-Epsuv[im1])) //-- Current ----- Bound Inf ----- Previous
2875 {
2876 Trouve = Standard_True; //--
2877 DPc = Uvp[im1]-Param(i); //-- Previous - Current
2878 DPb = Uvp[im1]-Uvd[im1]; //-- Previous - Bound Inf
2879 ParC[im1] = Uvd[im1]; //-- ParamCorrige
2880 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction)
2881 dv2 = dv*dv;
2882 if(dv2>RealEpsilon()) { //-- Progress at the other Direction ?
2883 Duv[im1] = DPc*DPb + dv2;
2884 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
2885 }
2886 else {
2887 Duv[im1]=-1.0; //-- If no progress, do not change
2888 } //-- the choice of iso
2889 }
2890 else if (Param(i) > (Uvf[im1] + Epsuv[im1]) ||
2891 SolParam[im1] > (Uvf[im1] + Epsuv[im1]))//-- Previous ----- Bound Sup ----- Current
2892 {
2893 Trouve = Standard_True; //--
2894 DPc = Param(i)-Uvp[im1]; //-- Current - Previous
2895 DPb = Uvf[im1]-Uvp[im1]; //-- Bound Sup - Previous
2896 ParC[im1] = Uvf[im1]; //-- Param Corrige
2897 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction)
2898 dv2 = dv*dv;
2899 if(dv2>RealEpsilon()) { //-- Progress in other Direction ?
2900 Duv[im1] = DPc*DPb + dv2;
2901 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
2902 }
2903 else {
2904 Duv[im1]=-1.0; //-- If no progress, do not change
2905 } //-- the choice of iso
2906 }
2907 else {
2908 Duv[im1]= -1.;
2909 ParC[im1]=Param(i);
2910 }
2911 }
2912
2913 if (Trouve) {
2914 //--------------------------------------------------
2915 //-- One of Parameters u1,v1,u2,v2 is outside of --
2916 //-- the natural limits. --
2917 //-- Find the best direction of --
2918 //-- progress and reframe the parameters. --
2919 //--------------------------------------------------
2920 Standard_Real ddv = -1.0;
2921 k=-1;
2922 for (i=0;i<=3;i++) {
2923 Param(i+1) = ParC[i];
2924 if(Duv[i]>ddv) {
2925 ddv = Duv[i];
2926 k=i;
2927 }
2928 }
2929 if(k!=-1) {
2930 ChoixIso = ChoixRef[k];
2931 }
2932 else {
2933 if((ParC[0]<=Uvd[0]+Epsuv[0]) || (ParC[0]>=Uvf[0]-Epsuv[0])) {
2934 ChoixIso = IntImp_UIsoparametricOnCaro1;
2935 }
2936 else if((ParC[1]<=Uvd[1]+Epsuv[1]) || (ParC[1]>=Uvf[1]-Epsuv[1])) {
2937 ChoixIso = IntImp_VIsoparametricOnCaro1;
2938 }
2939 else if((ParC[2]<=Uvd[2]+Epsuv[2]) || (ParC[2]>=Uvf[2]-Epsuv[2])) {
2940 ChoixIso = IntImp_UIsoparametricOnCaro2;
2941 }
2942 else if((ParC[3]<=Uvd[3]+Epsuv[3]) || (ParC[3]>=Uvf[3]-Epsuv[3])) {
2943 ChoixIso = IntImp_VIsoparametricOnCaro2;
2944 }
2945 }
2946 close = Standard_False;
2947 return Standard_True;
2948 }
2949 else
2950 {
2951 if (!DejaReparti) { // find if line closed
2952
2953 Standard_Real u,v;
2954 const IntSurf_PntOn2S& POn2S1=line->Value(1);
2955 //On S1
2956 POn2S1.ParametersOnS1(u,v);
2957 gp_Pnt2d P1uvS1(u,v);
2958 previousPoint.ParametersOnS1(u,v);
2959 gp_Pnt2d PrevuvS1(u,v);
2960 myIntersectionOn2S.Point().ParametersOnS1(u,v);
2961 gp_Pnt2d myIntersuvS1(u,v);
2962 Standard_Boolean close2dS1 = (P1uvS1.XY()-PrevuvS1.XY())*
2963 (P1uvS1.XY()-myIntersuvS1.XY()) < 0.0;
2964 //On S2
2965 POn2S1.ParametersOnS2(u,v);
2966 gp_Pnt2d P1uvS2(u,v);
2967 previousPoint.ParametersOnS2(u,v);
2968 gp_Pnt2d PrevuvS2(u,v);
2969 myIntersectionOn2S.Point().ParametersOnS2(u,v);
2970 gp_Pnt2d myIntersuvS2(u,v);
2971 Standard_Boolean close2dS2 = (P1uvS2.XY()-PrevuvS2.XY())*
2972 (P1uvS2.XY()-myIntersuvS2.XY()) < 0.0;
2973
2974 close = close2dS1 && close2dS2;
2975 return close;
2976 }
2977 else return Standard_False;
2978 }
2979}
c2c2f2b6 2980