summaryrefslogtreecommitdiff
path: root/inc/IntWalk_IWalking_3.gxx
blob: 447d6293cb7dd348c5a9b735ec6e043527cb7d16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
//-- File IntWalk_IWalking_3.gxx


#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif

// modified by NIZHNY-MKK  Thu Nov  2 15:07:26 2000.BEGIN
static Standard_Boolean TestPassedSolutionWithNegativeState(const TColStd_SequenceOfInteger& etat,
							    const TColStd_SequenceOfReal& Umult,
							    const TColStd_SequenceOfReal& Vmult,
							    const TColStd_SequenceOfReal& ustart,
							    const TColStd_SequenceOfReal& vstart,
							    const Standard_Real& prevUp, 
							    const Standard_Real& prevVp,
							    const TColStd_SequenceOfInteger& nbMultiplicities,
							    const math_Vector& tolerance,
							    TheIWFunction& sp,
							    math_Vector& UV,
							    Standard_Integer& Irang);
// modified by NIZHNY-MKK  Thu Nov  2 15:07:39 2000.END


void IntWalk_IWalking::ComputeOpenLine(const TColStd_SequenceOfReal& Umult,
				       const TColStd_SequenceOfReal& Vmult,
				       const ThePOPIterator& Pnts1,
				       TheIWFunction& Func,
				       Standard_Boolean& Rajout) 

// traitement ligne ouvert.
//
// 1) pour tout point de depart non passant et non tangent et non encore traite
//    calcul du pas d'avancement = pas en fonction de la fleche et du pas max.
//
// 2) calcul d'un point approche (ce point est sur la tangente a la section
// de distance = pas du point interieur)
//  
// 3) tant que {
//            (l'ensemble des points calcules ne depassent pas un point dans la
//             liste des points de depart)
//                              ou                    
//            (l'ensemble des points ne forme pas une ligne ouverte allant 
//            d 'une frontiere du domaine a un autre ou d un point de tangence
//            a une frontiere ou de 2 points de tangence : cas singuliers)
//  
//     1) cadrage du point approche sur les frontieres si necessaire (il
//        y a calcul du pas)
//     2) calcul du point
//     3) si point non trouve on divise le pas
//     4) tests d'arrets    
//     5) calcul du pas en fonction de la fleche et du pas maxi,
//        (TestDeflection)
//        arret possible.
//    fin tant que.

{
  Standard_Integer I, N;
  static math_Vector BornInf(1,2), BornSup(1,2), UVap(1,2);
  Standard_Real PasC, PasCu, PasCv;
  Standard_Boolean Arrive; // indique si ligne terminee
  Standard_Boolean Cadre;  //indique si on est sur frontiere du domaine
  Standard_Boolean ArretAjout;  //indique si on est sur point ajoute
  IntSurf_PntOn2S Psol;
  Handle(IntWalk_TheIWLine)  CurrentLine;    // ligne en construction
  Standard_Boolean Tgtend;

  IntWalk_StatusDeflection Status, StatusPrecedent;
  
  Standard_Integer NbDivision; 
  // nombre de fois que l on a divise le pas pour une section

  Standard_Integer StepSign;
  
  ThePointOfPath PathPnt;

  BornInf(1) = Um;
  BornSup(1) = UM;
  BornInf(2) = Vm;
  BornSup(2) = VM;

  math_FunctionSetRoot Rsnld(Func, tolerance);
  Standard_Integer nbPath = Pnts1.Length();

  // modified by NIZHNY-MKK  Fri Oct 27 12:32:34 2000.BEGIN
  TColStd_SequenceOfInteger movementdirectioninfo;
  for (I = 1; I <= nbPath; I++) {
    movementdirectioninfo.Append(0);
  }
  // modified by NIZHNY-MKK  Fri Oct 27 12:32:38 2000.END

  for (I = 1; I <= nbPath; I++) {
    //point de depart de cheminement
    //     if (etat1(I) > 11) {                
    // modified by NIZHNY-MKK  Fri Oct 27 12:33:37 2000.BEGIN
    if ((etat1(I) > 11) || ((etat1(I) < -11) && (movementdirectioninfo(I)!=0))) {
    // modified by NIZHNY-MKK  Fri Oct 27 12:33:43 2000.END
      PathPnt = Pnts1.Value(I);     
      CurrentLine = new IntWalk_TheIWLine ();
      CurrentLine->SetTangencyAtBegining(Standard_False);
      Tgtend = Standard_False;
      CurrentLine->AddStatusFirst(Standard_False, Standard_True, I, PathPnt);
      UVap(1) = ustart1(I);
      UVap(2) = vstart1(I);
      MakeWalkingPoint(11, UVap(1), UVap(2), Func, previousPoint);
      previousd3d = Func.Direction3d();
      previousd2d = Func.Direction2d();
      CurrentLine->AddPoint(previousPoint);
      // modified by NIZHNY-MKK  Fri Oct 27 12:34:32 2000.BEGIN
      if(movementdirectioninfo(I) !=0) {
	if(movementdirectioninfo(I) < 0) {
	  StepSign = -1;
	  CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
	} else {
	  StepSign = 1; 
	  CurrentLine->SetTangentVector(previousd3d,1);
	}
      } else {
	Standard_Real tyutuyt=ThePointOfPathTool::Direction3d(PathPnt) * previousd3d;
	if( tyutuyt < 0) {
	  StepSign = -1;
	  CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
	}
	else {
	  StepSign = 1; 
	  CurrentLine->SetTangentVector(previousd3d,1);
	}
      }
      // modified by NIZHNY-MKK  Fri Oct 27 12:34:37 2000.END

//  Modified by Sergey KHROMOV - Tue Nov 20 10:41:45 2001 Begin
      etat1(I) = - abs(etat1(I));
      movementdirectioninfo(I) = (movementdirectioninfo(I)==0) ? StepSign : 0;
//  Modified by Sergey KHROMOV - Tue Nov 20 10:41:56 2001 End
      // premier pas d avancement
      Standard_Real d2dx = Abs(previousd2d.X()); 
      Standard_Real d2dy = Abs(previousd2d.Y()); 
      if (d2dx < tolerance(1)) {
	PasC = pas * (VM-Vm)/d2dy;
      }
      else if (d2dy < tolerance(2)) {
	PasC = pas * (UM-Um)/d2dx;
      }
      else {
	PasC = pas * Min((UM-Um)/d2dx,(VM-Vm)/d2dy);
      }

      Arrive = Standard_False;
      ArretAjout = Standard_False;
      NbDivision = 0;
      StatusPrecedent = IntWalk_OK;
      // modified by NIZHNY-MKK  Fri Oct 27 12:39:37 2000
      Standard_Integer IndexOfPathPointDoNotCheck=0;

      while (!Arrive) { //    tant que un des tests d  arret est non verifie

	Cadre = Cadrage(BornInf,BornSup,UVap,PasC,StepSign);
	//  Frontiere?

#ifdef CHRONO
	Chronrsnld.Start();
#endif

	Rsnld.Perform(Func,UVap,BornInf,BornSup);

#ifdef CHRONO
	Chronrsnld.Stop();
#endif

	if (Cadre) {
	  BornInf(1) = Um; BornSup(1) = UM; BornInf(2) = Vm; BornSup(2) = VM;
	}
	if (Rsnld.IsDone()) {
	  if (Abs(Func.Root()) > Func.Tolerance()) {
	    PasC = PasC / 2.0;
	    PasCu = Abs(PasC*previousd2d.X());
	    PasCv = Abs(PasC*previousd2d.Y());
	    if (PasCu <= tolerance(1) && PasCv <= tolerance(2)) {
	      if (CurrentLine->NbPoints() == 1) break;
	      Arrive = Standard_True;
	      CurrentLine->AddStatusLast(Standard_False);
	      Tgtend = Standard_True; // a voir
              Rajout = Standard_True;
	      seqAjout.Append(lines.Length() + 1);
	    }  
	  }
	  else { // test arret
	    Rsnld.Root(UVap);
	    Arrive = TestArretPassage(Umult, Vmult, Func, UVap, N);
	    if (Arrive) {
	      Cadre = Standard_False;
	      //au cas ou on aurait cadre et arrive en meme temps
	    }
	    else {
	      if (Rajout) {
		ArretAjout =TestArretAjout(Func, UVap, N, Psol);
		if (ArretAjout) {
		  // jag 940615
		  Tgtend = lines.Value(N)->IsTangentAtEnd();
		  N = -N;
		}
	      }
	      // modified by NIZHNY-MKK  Thu Nov  2 15:09:08 2000.BEGIN
	      if(!(Rajout && ArretAjout)) {
		Standard_Real prevUp, prevVp;
		if (!reversed) {
		  previousPoint.ParametersOnS2(prevUp, prevVp);
		}
		else {
		  previousPoint.ParametersOnS1(prevUp, prevVp);
		}
		Arrive = TestPassedSolutionWithNegativeState(etat1, Umult, Vmult, ustart1, vstart1, prevUp, prevVp,
							     nbMultiplicities, tolerance, Func, UVap, N);		
		if(Arrive) {
		  Cadre = Standard_False;
		}
	      }
	      // modified by NIZHNY-MKK  Thu Nov  2 15:09:13 2000.END
	      if (!ArretAjout && Cadre) {
		if (CurrentLine->NbPoints() == 1) break; // annuler la ligne
		TestArretCadre(Umult, Vmult, CurrentLine, Func, UVap, N);
//		if (N == 0) {
		if (N <= 0) { // jag 941017
		  MakeWalkingPoint(2, UVap(1), UVap(2), Func, Psol);
		  Tgtend = Func.IsTangent();
                  N = -N;
		}
	      }
	    }
	    Status = TestDeflection(Func, Arrive, UVap, StatusPrecedent,
				    NbDivision,PasC,StepSign);
	    StatusPrecedent = Status;
	    if (Status == IntWalk_PasTropGrand) {
	      Arrive = Standard_False;
	      ArretAjout = Standard_False;
	      Tgtend = Standard_False; // jag 940615
	      if (!reversed) {
		previousPoint.ParametersOnS2(UVap(1), UVap(2));
	      }
	      else {
		previousPoint.ParametersOnS1(UVap(1), UVap(2));
	      }
	    }
	    else if (ArretAjout || Cadre) {
	      Arrive = Standard_True;
	      CurrentLine->AddStatusLast(Standard_False);
	      if (Status != IntWalk_ArretSurPointPrecedent) {
		CurrentLine->AddPoint(Psol);                      
	      }
	      if (Cadre && N==0) {
		Rajout = Standard_True;
		seqAjout.Append(lines.Length()+1);
	      }
	    }
	    else if (Status == IntWalk_ArretSurPointPrecedent) {
	      if (CurrentLine->NbPoints() == 1) { //annuler la ligne
		Arrive = Standard_False;
		break;
	      }
	      Arrive = Standard_True;
	      Rajout = Standard_True;
              seqAjout.Append(lines.Length() + 1);
	      CurrentLine->AddStatusLast(Standard_False);
	      Tgtend = Standard_True; // a voir
	    }
	    else if (Arrive)  {
	      if (CurrentLine->NbPoints() == 1 &&    // annuler la ligne
		  (N == I || Status == IntWalk_PointConfondu) ) {
		// si N == I on s est probablement trompe de uv 
		// principal ou bien le point 
		// est un point d accumulation
		// si point confondu les donnees de depart sont mauvaises
		Arrive =  Standard_False;
		break;
	      }
	      // on a necessairement N > 0 jag 940617
              // point d arret donne en entree 
	      PathPnt = Pnts1.Value(N);
	      
	      Standard_Integer etat1N=etat1(N);
	      // modified by NIZHNY-MKK  Thu Nov  2 15:09:51 2000.BEGIN
	      // 	      if (etat1N < 11) { // point passant qui est un arret  
	      if (Abs(etat1N) < 11) { // point passant qui est un arret  
		// modified by NIZHNY-MKK  Thu Nov  2 15:12:11 2000.END
		if (Status == IntWalk_ArretSurPoint) { 
		  CurrentLine->AddStatusLast(Standard_False);
		  Tgtend = Standard_True; // a voir
		}
		else { 
		  Arrive = Standard_False;
		}
		CurrentLine->AddIndexPassing(N);
	      }
	      else { // point d  arret donne en entree
		if (etat1N == 11) {
		  Tgtend = Standard_True;
		}
		CurrentLine->AddStatusLast(Standard_True, N, PathPnt);
	      }
	      AddPointInCurrentLine(N,PathPnt,CurrentLine);
	      if ((etat1N != 1 && etat1N != 11)) {
		// modified by NIZHNY-MKK  Fri Oct 27 12:43:05 2000.BEGIN
		// 		etat1(N)= - etat1N;
		etat1(N)= - Abs(etat1N);		
		movementdirectioninfo(N) = (movementdirectioninfo(N)==0) ? StepSign : 0;
		if(Arrive && movementdirectioninfo(N)!=0) {
		  IndexOfPathPointDoNotCheck = N;
		}

		if(Arrive) {
		  Rajout = Standard_True;
		  seqAjout.Append(lines.Length() + 1);
		}
		// modified by NIZHNY-MKK  Fri Oct 27 12:45:33 2000.END
	      }
	    }
	    else if (Status == IntWalk_ArretSurPoint) {
	      Arrive = Standard_True;                   
	      CurrentLine->AddStatusLast(Standard_False);
	      Tgtend = Standard_True;
              MakeWalkingPoint(1, UVap(1), UVap(2), Func, Psol);
	      CurrentLine->AddPoint(Psol);
	      Rajout = Standard_True;
              seqAjout.Append(lines.Length() + 1);
	    }
	    else if (Status == IntWalk_OK) { 
              MakeWalkingPoint(2, UVap(1), UVap(2), Func, previousPoint);
	      previousd3d = Func.Direction3d();
	      previousd2d = Func.Direction2d();
	      CurrentLine->AddPoint(previousPoint);
	    }                           
	  }
	}
	else { // pas de solution numerique
	  PasC = PasC / 2.;
	  PasCu = Abs(PasC*previousd2d.X());
	  PasCv = Abs(PasC*previousd2d.Y());
	  if (PasCu <= tolerance(1) && PasCv <= tolerance(2)) {
	    if (CurrentLine->NbPoints()==1) break;
	    Arrive = Standard_True;
	    CurrentLine->AddStatusLast(Standard_False);
	    Tgtend = Standard_True; // a voir
	    Rajout = Standard_True;
            seqAjout.Append(lines.Length() + 1);
	  }  
	}
      } // fin de la ligne commencee
      
      if (Arrive) {
	CurrentLine->SetTangencyAtEnd(Tgtend);
	lines.Append(CurrentLine);
	// modified by NIZHNY-MKK  Fri Oct 27 12:59:29 2000.BEGIN
	movementdirectioninfo(I)=0;
	if(etat1(I) > 0)
	// modified by NIZHNY-MKK  Fri Oct 27 12:59:42 2000.END
	  etat1(I)=-etat1(I);

	//-- lbr le 5 juin 97 (Pb ds Contap)
	for(Standard_Integer av=1; av<=nbPath; av++) { 
	  // modified by NIZHNY-MKK  Fri Oct 27 13:00:22 2000.BEGIN
	  // 	  if (etat1(av) > 11) {
	  if ((etat1(av) > 11) || 
	      ((av!=I) && 
	       (av!=IndexOfPathPointDoNotCheck) && 
	       (etat1(av) < -11)  && 
	       (movementdirectioninfo(av)!=0))) {
	  // modified by NIZHNY-MKK  Fri Oct 27 13:00:26 2000.END
	    Standard_Real Uav=ustart1(av);
	    Standard_Real Vav=vstart1(av);
	    Standard_Real Uavp,Vavp;
	    const IntSurf_PntOn2S &avP=CurrentLine->Value(CurrentLine->NbPoints());
	    if (!reversed) {
	      avP.ParametersOnS2(Uavp,Vavp);
	    }
	    else {
	      avP.ParametersOnS1(Uavp,Vavp);
	    }
	    Uav-=Uavp;
	    Vav-=Vavp;
	    Uav*=0.001; Vav*=0.001;
	    if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) { 
	      // modified by NIZHNY-MKK  Fri Oct 27 13:01:38 2000.BEGIN
	      // 	      etat1(av)=-etat1(av);
	      if(etat1(av) < 0) {
		movementdirectioninfo(av) = 0;
	      } else {
		etat1(av)=-etat1(av);
		movementdirectioninfo(av) = StepSign;
	      }
	      // modified by NIZHNY-MKK  Fri Oct 27 13:01:42 2000.END
	      CurrentLine->AddStatusLast(Standard_True, av, Pnts1.Value(av));
	      //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
	    }
	    
	    const IntSurf_PntOn2S &avPP=CurrentLine->Value(1);
	    if (!reversed) {
	      avPP.ParametersOnS2(Uavp,Vavp);
	    }
	    else {
	      avPP.ParametersOnS1(Uavp,Vavp);
	    }
	    Uav=ustart1(av);
	    Vav=vstart1(av);
	    Uav-=Uavp;
	    Vav-=Vavp;
	    Uav*=0.001; Vav*=0.001;
	    if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) { 
	      // modified by NIZHNY-MKK  Fri Oct 27 13:02:49 2000.BEGIN
	      // 	      etat1(av)=-etat1(av);
	      if(etat1(av) < 0) {
		movementdirectioninfo(av) = 0;
	      } else {
		etat1(av)=-etat1(av);
		movementdirectioninfo(av) = -StepSign;
	      }
	      // modified by NIZHNY-MKK  Fri Oct 27 13:02:52 2000.END
	      //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
	      CurrentLine->AddStatusFirst(Standard_False, Standard_True, av, Pnts1.Value(av));
	    }
	  }
	}
	  
      }
    } //fin de traitement d  un point
  } //fin de tous les points
}

// modified by NIZHNY-MKK  Thu Nov  2 15:07:53 2000.BEGIN
static Standard_Boolean TestPassedSolutionWithNegativeState(const TColStd_SequenceOfInteger& etat,
							    const TColStd_SequenceOfReal& Umult,
							    const TColStd_SequenceOfReal& Vmult,
							    const TColStd_SequenceOfReal& ustart,
							    const TColStd_SequenceOfReal& vstart,
							    const Standard_Real& prevUp,
							    const Standard_Real& prevVp,
							    const TColStd_SequenceOfInteger& nbMultiplicities,
							    const math_Vector& tolerance,
							    TheIWFunction& sp,
							    math_Vector& UV,
							    Standard_Integer& Irang) {
  Standard_Boolean Arrive = Standard_False;
  Standard_Real Dup, Dvp, Utest,Vtest;
  Standard_Real tolu = tolerance(1);
  Standard_Real tolv = tolerance(2);
  Standard_Integer i, j, k, N;
  for (i = 1; i <= etat.Length(); i++) {
    if (etat(i) < -11) {

 // debug jag voir avec isg

      Utest = ustart(i);
      Vtest = vstart(i);
      Dup = prevUp - Utest;
      Dvp = prevVp - Vtest;
      if (Abs(Dup) >= tolu || Abs(Dvp) >= tolv) {
	Standard_Real UV1mUtest = UV(1)-Utest;
	Standard_Real UV2mVtest = UV(2)-Vtest;
	if(( (Dup*UV1mUtest + Dvp*UV2mVtest) < 0) ||
	   (   Abs(UV1mUtest) < tolu 
	    && Abs(UV2mVtest) < tolv)) {
	  Irang=i;
	  Arrive = Standard_True;
	  UV(1) = Utest;
	  UV(2) = Vtest;
	}
	else if (nbMultiplicities(i) > 0) {
	  N=0;
	  for (k = 1; k < i; k++) { 
	    N+=nbMultiplicities(k);
	  }
	  for (j = N + 1; j <= N + nbMultiplicities(i); j++) {
	    if (((prevUp-Umult(j))*(UV(1)-Umult(j)) +
		 (prevVp-Vmult(j))*(UV(2)-Vmult(j)) < 0) ||
		(Abs(UV(1)-Umult(j)) < tolu &&
		 Abs(UV(2)-Vmult(j)) < tolv)) {
	      Irang=i;
	      Arrive = Standard_True;
	      UV(1) = Utest;
	      UV(2) = Vtest;
	      break;
	    }
	  }
	}
	if (Arrive) {
	  static math_Vector bidF(1,1);
	  static math_Matrix bidD(1,1,1,2);
	  sp.Values(UV,bidF,bidD);
	  break;
	}
      }
    }    
  }
  return Arrive;
}
// modified by NIZHNY-MKK  Thu Nov  2 15:07:58 2000.END