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