0023425: diffimage generate OSD_Exception during execution
[occt.git] / src / IntWalk / IntWalk_IWalking_3.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
20
21#ifndef DEB
22#define No_Standard_RangeError
23#define No_Standard_OutOfRange
24#endif
25
26// modified by NIZHNY-MKK Thu Nov 2 15:07:26 2000.BEGIN
27static Standard_Boolean TestPassedSolutionWithNegativeState(const TColStd_SequenceOfInteger& etat,
28 const TColStd_SequenceOfReal& Umult,
29 const TColStd_SequenceOfReal& Vmult,
30 const TColStd_SequenceOfReal& ustart,
31 const TColStd_SequenceOfReal& vstart,
32 const Standard_Real& prevUp,
33 const Standard_Real& prevVp,
34 const TColStd_SequenceOfInteger& nbMultiplicities,
35 const math_Vector& tolerance,
36 TheIWFunction& sp,
37 math_Vector& UV,
38 Standard_Integer& Irang);
39// modified by NIZHNY-MKK Thu Nov 2 15:07:39 2000.END
40
41
42void IntWalk_IWalking::ComputeOpenLine(const TColStd_SequenceOfReal& Umult,
43 const TColStd_SequenceOfReal& Vmult,
44 const ThePOPIterator& Pnts1,
45 TheIWFunction& Func,
46 Standard_Boolean& Rajout)
47
48// traitement ligne ouvert.
49//
50// 1) pour tout point de depart non passant et non tangent et non encore traite
51// calcul du pas d'avancement = pas en fonction de la fleche et du pas max.
52//
53// 2) calcul d'un point approche (ce point est sur la tangente a la section
54// de distance = pas du point interieur)
55//
56// 3) tant que {
57// (l'ensemble des points calcules ne depassent pas un point dans la
58// liste des points de depart)
59// ou
60// (l'ensemble des points ne forme pas une ligne ouverte allant
61// d 'une frontiere du domaine a un autre ou d un point de tangence
62// a une frontiere ou de 2 points de tangence : cas singuliers)
63//
64// 1) cadrage du point approche sur les frontieres si necessaire (il
65// y a calcul du pas)
66// 2) calcul du point
67// 3) si point non trouve on divise le pas
68// 4) tests d'arrets
69// 5) calcul du pas en fonction de la fleche et du pas maxi,
70// (TestDeflection)
71// arret possible.
72// fin tant que.
73
74{
75 Standard_Integer I, N;
76 static math_Vector BornInf(1,2), BornSup(1,2), UVap(1,2);
77 Standard_Real PasC, PasCu, PasCv;
78 Standard_Boolean Arrive; // indique si ligne terminee
79 Standard_Boolean Cadre; //indique si on est sur frontiere du domaine
80 Standard_Boolean ArretAjout; //indique si on est sur point ajoute
81 IntSurf_PntOn2S Psol;
82 Handle(IntWalk_TheIWLine) CurrentLine; // ligne en construction
83 Standard_Boolean Tgtend;
84
85 IntWalk_StatusDeflection Status, StatusPrecedent;
86
87 Standard_Integer NbDivision;
88 // nombre de fois que l on a divise le pas pour une section
89
90 Standard_Integer StepSign;
91
92 ThePointOfPath PathPnt;
93
94 BornInf(1) = Um;
95 BornSup(1) = UM;
96 BornInf(2) = Vm;
97 BornSup(2) = VM;
98
99 math_FunctionSetRoot Rsnld(Func, tolerance);
100 Standard_Integer nbPath = Pnts1.Length();
101
102 // modified by NIZHNY-MKK Fri Oct 27 12:32:34 2000.BEGIN
103 TColStd_SequenceOfInteger movementdirectioninfo;
104 for (I = 1; I <= nbPath; I++) {
105 movementdirectioninfo.Append(0);
106 }
107 // modified by NIZHNY-MKK Fri Oct 27 12:32:38 2000.END
108
109 for (I = 1; I <= nbPath; I++) {
110 //point de depart de cheminement
111 // if (etat1(I) > 11) {
112 // modified by NIZHNY-MKK Fri Oct 27 12:33:37 2000.BEGIN
113 if ((etat1(I) > 11) || ((etat1(I) < -11) && (movementdirectioninfo(I)!=0))) {
114 // modified by NIZHNY-MKK Fri Oct 27 12:33:43 2000.END
115 PathPnt = Pnts1.Value(I);
116 CurrentLine = new IntWalk_TheIWLine ();
117 CurrentLine->SetTangencyAtBegining(Standard_False);
118 Tgtend = Standard_False;
119 CurrentLine->AddStatusFirst(Standard_False, Standard_True, I, PathPnt);
120 UVap(1) = ustart1(I);
121 UVap(2) = vstart1(I);
122 MakeWalkingPoint(11, UVap(1), UVap(2), Func, previousPoint);
123 previousd3d = Func.Direction3d();
124 previousd2d = Func.Direction2d();
125 CurrentLine->AddPoint(previousPoint);
126 // modified by NIZHNY-MKK Fri Oct 27 12:34:32 2000.BEGIN
127 if(movementdirectioninfo(I) !=0) {
128 if(movementdirectioninfo(I) < 0) {
129 StepSign = -1;
130 CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
131 } else {
132 StepSign = 1;
133 CurrentLine->SetTangentVector(previousd3d,1);
134 }
135 } else {
136 Standard_Real tyutuyt=ThePointOfPathTool::Direction3d(PathPnt) * previousd3d;
137 if( tyutuyt < 0) {
138 StepSign = -1;
139 CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
140 }
141 else {
142 StepSign = 1;
143 CurrentLine->SetTangentVector(previousd3d,1);
144 }
145 }
146 // modified by NIZHNY-MKK Fri Oct 27 12:34:37 2000.END
147
148// Modified by Sergey KHROMOV - Tue Nov 20 10:41:45 2001 Begin
149 etat1(I) = - abs(etat1(I));
150 movementdirectioninfo(I) = (movementdirectioninfo(I)==0) ? StepSign : 0;
151// Modified by Sergey KHROMOV - Tue Nov 20 10:41:56 2001 End
152 // premier pas d avancement
153 Standard_Real d2dx = Abs(previousd2d.X());
154 Standard_Real d2dy = Abs(previousd2d.Y());
155 if (d2dx < tolerance(1)) {
156 PasC = pas * (VM-Vm)/d2dy;
157 }
158 else if (d2dy < tolerance(2)) {
159 PasC = pas * (UM-Um)/d2dx;
160 }
161 else {
162 PasC = pas * Min((UM-Um)/d2dx,(VM-Vm)/d2dy);
163 }
164
165 Arrive = Standard_False;
166 ArretAjout = Standard_False;
167 NbDivision = 0;
168 StatusPrecedent = IntWalk_OK;
169 // modified by NIZHNY-MKK Fri Oct 27 12:39:37 2000
170 Standard_Integer IndexOfPathPointDoNotCheck=0;
171
172 while (!Arrive) { // tant que un des tests d arret est non verifie
173
174 Cadre = Cadrage(BornInf,BornSup,UVap,PasC,StepSign);
175 // Frontiere?
176
177#ifdef CHRONO
178 Chronrsnld.Start();
179#endif
180
181 Rsnld.Perform(Func,UVap,BornInf,BornSup);
182
183#ifdef CHRONO
184 Chronrsnld.Stop();
185#endif
186
187 if (Cadre) {
188 BornInf(1) = Um; BornSup(1) = UM; BornInf(2) = Vm; BornSup(2) = VM;
189 }
190 if (Rsnld.IsDone()) {
191 if (Abs(Func.Root()) > Func.Tolerance()) {
192 PasC = PasC / 2.0;
193 PasCu = Abs(PasC*previousd2d.X());
194 PasCv = Abs(PasC*previousd2d.Y());
195 if (PasCu <= tolerance(1) && PasCv <= tolerance(2)) {
196 if (CurrentLine->NbPoints() == 1) break;
197 Arrive = Standard_True;
198 CurrentLine->AddStatusLast(Standard_False);
199 Tgtend = Standard_True; // a voir
200 Rajout = Standard_True;
201 seqAjout.Append(lines.Length() + 1);
202 }
203 }
204 else { // test arret
205 Rsnld.Root(UVap);
206 Arrive = TestArretPassage(Umult, Vmult, Func, UVap, N);
207 if (Arrive) {
208 Cadre = Standard_False;
209 //au cas ou on aurait cadre et arrive en meme temps
210 }
211 else {
212 if (Rajout) {
213 ArretAjout =TestArretAjout(Func, UVap, N, Psol);
214 if (ArretAjout) {
215 // jag 940615
216 Tgtend = lines.Value(N)->IsTangentAtEnd();
217 N = -N;
218 }
219 }
220 // modified by NIZHNY-MKK Thu Nov 2 15:09:08 2000.BEGIN
221 if(!(Rajout && ArretAjout)) {
222 Standard_Real prevUp, prevVp;
223 if (!reversed) {
224 previousPoint.ParametersOnS2(prevUp, prevVp);
225 }
226 else {
227 previousPoint.ParametersOnS1(prevUp, prevVp);
228 }
229 Arrive = TestPassedSolutionWithNegativeState(etat1, Umult, Vmult, ustart1, vstart1, prevUp, prevVp,
230 nbMultiplicities, tolerance, Func, UVap, N);
231 if(Arrive) {
232 Cadre = Standard_False;
233 }
234 }
235 // modified by NIZHNY-MKK Thu Nov 2 15:09:13 2000.END
236 if (!ArretAjout && Cadre) {
237 if (CurrentLine->NbPoints() == 1) break; // annuler la ligne
238 TestArretCadre(Umult, Vmult, CurrentLine, Func, UVap, N);
239// if (N == 0) {
240 if (N <= 0) { // jag 941017
241 MakeWalkingPoint(2, UVap(1), UVap(2), Func, Psol);
242 Tgtend = Func.IsTangent();
243 N = -N;
244 }
245 }
246 }
247 Status = TestDeflection(Func, Arrive, UVap, StatusPrecedent,
248 NbDivision,PasC,StepSign);
249 StatusPrecedent = Status;
250 if (Status == IntWalk_PasTropGrand) {
251 Arrive = Standard_False;
252 ArretAjout = Standard_False;
253 Tgtend = Standard_False; // jag 940615
254 if (!reversed) {
255 previousPoint.ParametersOnS2(UVap(1), UVap(2));
256 }
257 else {
258 previousPoint.ParametersOnS1(UVap(1), UVap(2));
259 }
260 }
261 else if (ArretAjout || Cadre) {
262 Arrive = Standard_True;
263 CurrentLine->AddStatusLast(Standard_False);
264 if (Status != IntWalk_ArretSurPointPrecedent) {
265 CurrentLine->AddPoint(Psol);
266 }
267 if (Cadre && N==0) {
268 Rajout = Standard_True;
269 seqAjout.Append(lines.Length()+1);
270 }
271 }
272 else if (Status == IntWalk_ArretSurPointPrecedent) {
273 if (CurrentLine->NbPoints() == 1) { //annuler la ligne
274 Arrive = Standard_False;
275 break;
276 }
277 Arrive = Standard_True;
278 Rajout = Standard_True;
279 seqAjout.Append(lines.Length() + 1);
280 CurrentLine->AddStatusLast(Standard_False);
281 Tgtend = Standard_True; // a voir
282 }
283 else if (Arrive) {
284 if (CurrentLine->NbPoints() == 1 && // annuler la ligne
285 (N == I || Status == IntWalk_PointConfondu) ) {
286 // si N == I on s est probablement trompe de uv
287 // principal ou bien le point
288 // est un point d accumulation
289 // si point confondu les donnees de depart sont mauvaises
290 Arrive = Standard_False;
291 break;
292 }
293 // on a necessairement N > 0 jag 940617
294 // point d arret donne en entree
295 PathPnt = Pnts1.Value(N);
296
297 Standard_Integer etat1N=etat1(N);
298 // modified by NIZHNY-MKK Thu Nov 2 15:09:51 2000.BEGIN
299 // if (etat1N < 11) { // point passant qui est un arret
300 if (Abs(etat1N) < 11) { // point passant qui est un arret
301 // modified by NIZHNY-MKK Thu Nov 2 15:12:11 2000.END
302 if (Status == IntWalk_ArretSurPoint) {
303 CurrentLine->AddStatusLast(Standard_False);
304 Tgtend = Standard_True; // a voir
305 }
306 else {
307 Arrive = Standard_False;
308 }
309 CurrentLine->AddIndexPassing(N);
310 }
311 else { // point d arret donne en entree
312 if (etat1N == 11) {
313 Tgtend = Standard_True;
314 }
315 CurrentLine->AddStatusLast(Standard_True, N, PathPnt);
316 }
317 AddPointInCurrentLine(N,PathPnt,CurrentLine);
318 if ((etat1N != 1 && etat1N != 11)) {
319 // modified by NIZHNY-MKK Fri Oct 27 12:43:05 2000.BEGIN
320 // etat1(N)= - etat1N;
321 etat1(N)= - Abs(etat1N);
322 movementdirectioninfo(N) = (movementdirectioninfo(N)==0) ? StepSign : 0;
323 if(Arrive && movementdirectioninfo(N)!=0) {
324 IndexOfPathPointDoNotCheck = N;
325 }
326
327 if(Arrive) {
328 Rajout = Standard_True;
329 seqAjout.Append(lines.Length() + 1);
330 }
331 // modified by NIZHNY-MKK Fri Oct 27 12:45:33 2000.END
332 }
333 }
334 else if (Status == IntWalk_ArretSurPoint) {
335 Arrive = Standard_True;
336 CurrentLine->AddStatusLast(Standard_False);
337 Tgtend = Standard_True;
338 MakeWalkingPoint(1, UVap(1), UVap(2), Func, Psol);
339 CurrentLine->AddPoint(Psol);
340 Rajout = Standard_True;
341 seqAjout.Append(lines.Length() + 1);
342 }
343 else if (Status == IntWalk_OK) {
344 MakeWalkingPoint(2, UVap(1), UVap(2), Func, previousPoint);
345 previousd3d = Func.Direction3d();
346 previousd2d = Func.Direction2d();
347 CurrentLine->AddPoint(previousPoint);
348 }
349 }
350 }
351 else { // pas de solution numerique
352 PasC = PasC / 2.;
353 PasCu = Abs(PasC*previousd2d.X());
354 PasCv = Abs(PasC*previousd2d.Y());
355 if (PasCu <= tolerance(1) && PasCv <= tolerance(2)) {
356 if (CurrentLine->NbPoints()==1) break;
357 Arrive = Standard_True;
358 CurrentLine->AddStatusLast(Standard_False);
359 Tgtend = Standard_True; // a voir
360 Rajout = Standard_True;
361 seqAjout.Append(lines.Length() + 1);
362 }
363 }
364 } // fin de la ligne commencee
365
366 if (Arrive) {
367 CurrentLine->SetTangencyAtEnd(Tgtend);
368 lines.Append(CurrentLine);
369 // modified by NIZHNY-MKK Fri Oct 27 12:59:29 2000.BEGIN
370 movementdirectioninfo(I)=0;
371 if(etat1(I) > 0)
372 // modified by NIZHNY-MKK Fri Oct 27 12:59:42 2000.END
373 etat1(I)=-etat1(I);
374
375 //-- lbr le 5 juin 97 (Pb ds Contap)
376 for(Standard_Integer av=1; av<=nbPath; av++) {
377 // modified by NIZHNY-MKK Fri Oct 27 13:00:22 2000.BEGIN
378 // if (etat1(av) > 11) {
379 if ((etat1(av) > 11) ||
380 ((av!=I) &&
381 (av!=IndexOfPathPointDoNotCheck) &&
382 (etat1(av) < -11) &&
383 (movementdirectioninfo(av)!=0))) {
384 // modified by NIZHNY-MKK Fri Oct 27 13:00:26 2000.END
385 Standard_Real Uav=ustart1(av);
386 Standard_Real Vav=vstart1(av);
387 Standard_Real Uavp,Vavp;
388 const IntSurf_PntOn2S &avP=CurrentLine->Value(CurrentLine->NbPoints());
389 if (!reversed) {
390 avP.ParametersOnS2(Uavp,Vavp);
391 }
392 else {
393 avP.ParametersOnS1(Uavp,Vavp);
394 }
395 Uav-=Uavp;
396 Vav-=Vavp;
397 Uav*=0.001; Vav*=0.001;
398 if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) {
399 // modified by NIZHNY-MKK Fri Oct 27 13:01:38 2000.BEGIN
400 // etat1(av)=-etat1(av);
401 if(etat1(av) < 0) {
402 movementdirectioninfo(av) = 0;
403 } else {
404 etat1(av)=-etat1(av);
405 movementdirectioninfo(av) = StepSign;
406 }
407 // modified by NIZHNY-MKK Fri Oct 27 13:01:42 2000.END
408 CurrentLine->AddStatusLast(Standard_True, av, Pnts1.Value(av));
409 //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
410 }
411
412 const IntSurf_PntOn2S &avPP=CurrentLine->Value(1);
413 if (!reversed) {
414 avPP.ParametersOnS2(Uavp,Vavp);
415 }
416 else {
417 avPP.ParametersOnS1(Uavp,Vavp);
418 }
419 Uav=ustart1(av);
420 Vav=vstart1(av);
421 Uav-=Uavp;
422 Vav-=Vavp;
423 Uav*=0.001; Vav*=0.001;
424 if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) {
425 // modified by NIZHNY-MKK Fri Oct 27 13:02:49 2000.BEGIN
426 // etat1(av)=-etat1(av);
427 if(etat1(av) < 0) {
428 movementdirectioninfo(av) = 0;
429 } else {
430 etat1(av)=-etat1(av);
431 movementdirectioninfo(av) = -StepSign;
432 }
433 // modified by NIZHNY-MKK Fri Oct 27 13:02:52 2000.END
434 //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
435 CurrentLine->AddStatusFirst(Standard_False, Standard_True, av, Pnts1.Value(av));
436 }
437 }
438 }
439
440 }
441 } //fin de traitement d un point
442 } //fin de tous les points
443}
444
445// modified by NIZHNY-MKK Thu Nov 2 15:07:53 2000.BEGIN
446static Standard_Boolean TestPassedSolutionWithNegativeState(const TColStd_SequenceOfInteger& etat,
447 const TColStd_SequenceOfReal& Umult,
448 const TColStd_SequenceOfReal& Vmult,
449 const TColStd_SequenceOfReal& ustart,
450 const TColStd_SequenceOfReal& vstart,
451 const Standard_Real& prevUp,
452 const Standard_Real& prevVp,
453 const TColStd_SequenceOfInteger& nbMultiplicities,
454 const math_Vector& tolerance,
455 TheIWFunction& sp,
456 math_Vector& UV,
457 Standard_Integer& Irang) {
458 Standard_Boolean Arrive = Standard_False;
459 Standard_Real Dup, Dvp, Utest,Vtest;
460 Standard_Real tolu = tolerance(1);
461 Standard_Real tolv = tolerance(2);
462 Standard_Integer i, j, k, N;
463 for (i = 1; i <= etat.Length(); i++) {
464 if (etat(i) < -11) {
465
466 // debug jag voir avec isg
467
468 Utest = ustart(i);
469 Vtest = vstart(i);
470 Dup = prevUp - Utest;
471 Dvp = prevVp - Vtest;
472 if (Abs(Dup) >= tolu || Abs(Dvp) >= tolv) {
473 Standard_Real UV1mUtest = UV(1)-Utest;
474 Standard_Real UV2mVtest = UV(2)-Vtest;
475 if(( (Dup*UV1mUtest + Dvp*UV2mVtest) < 0) ||
476 ( Abs(UV1mUtest) < tolu
477 && Abs(UV2mVtest) < tolv)) {
478 Irang=i;
479 Arrive = Standard_True;
480 UV(1) = Utest;
481 UV(2) = Vtest;
482 }
483 else if (nbMultiplicities(i) > 0) {
484 N=0;
485 for (k = 1; k < i; k++) {
486 N+=nbMultiplicities(k);
487 }
488 for (j = N + 1; j <= N + nbMultiplicities(i); j++) {
489 if (((prevUp-Umult(j))*(UV(1)-Umult(j)) +
490 (prevVp-Vmult(j))*(UV(2)-Vmult(j)) < 0) ||
491 (Abs(UV(1)-Umult(j)) < tolu &&
492 Abs(UV(2)-Vmult(j)) < tolv)) {
493 Irang=i;
494 Arrive = Standard_True;
495 UV(1) = Utest;
496 UV(2) = Vtest;
497 break;
498 }
499 }
500 }
501 if (Arrive) {
502 static math_Vector bidF(1,1);
503 static math_Matrix bidD(1,1,1,2);
6e6cd5d9 504 sp.Values(UV,bidF,bidD);
7fd59977 505 break;
506 }
507 }
508 }
509 }
510 return Arrive;
511}
512// modified by NIZHNY-MKK Thu Nov 2 15:07:58 2000.END