1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #define No_Standard_RangeError
23 #define No_Standard_OutOfRange
26 // modified by NIZHNY-MKK Thu Nov 2 15:07:26 2000.BEGIN
27 static 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,
38 Standard_Integer& Irang);
39 // modified by NIZHNY-MKK Thu Nov 2 15:07:39 2000.END
42 void IntWalk_IWalking::ComputeOpenLine(const TColStd_SequenceOfReal& Umult,
43 const TColStd_SequenceOfReal& Vmult,
44 const ThePOPIterator& Pnts1,
46 Standard_Boolean& Rajout)
48 // Processing of open line.
50 // 1) for any starting point, which is not passing and not tangent and not yet processed,
51 // calculation of the step of advancement = step depending on the arrow and the maximum step.
53 // 2) calculate a point of approach (this point is on the tangent to the section
54 // of distance = no point in the interior)
57 // (all calculated points do not exceed a point in the
58 // list of starting points)
60 // (all points do not form an open line going
61 // from one border of the domain to the other or from a point tangent
62 // to border or from 2 tangent points : single cases)
64 // 1) framing of approached point on borders if necessary (there is
65 // calculation of step)
66 // 2) calculation of the point
67 // 3) if the point is not found the step is divided
69 // 5) calculation of the step depending on the arrow and the max step,
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; // shows if the line ends
79 Standard_Boolean Cadre; // shows if one is on border of the domain
80 Standard_Boolean ArretAjout; //shows if one is on added point
82 Handle(IntWalk_TheIWLine) CurrentLine; // line under construction
83 Standard_Boolean Tgtend;
85 IntWalk_StatusDeflection Status, StatusPrecedent;
87 Standard_Integer NbDivision;
88 // number of divisions of step for each section
90 Standard_Integer StepSign;
92 ThePointOfPath PathPnt;
99 math_FunctionSetRoot Rsnld(Func, tolerance);
100 Standard_Integer nbPath = Pnts1.Length();
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);
107 // modified by NIZHNY-MKK Fri Oct 27 12:32:38 2000.END
109 for (I = 1; I <= nbPath; I++) {
110 //start point of the progression
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) {
130 CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
133 CurrentLine->SetTangentVector(previousd3d,1);
136 Standard_Real tyutuyt=ThePointOfPathTool::Direction3d(PathPnt) * previousd3d;
139 CurrentLine->SetTangentVector(previousd3d.Reversed(),1);
143 CurrentLine->SetTangentVector(previousd3d,1);
146 // modified by NIZHNY-MKK Fri Oct 27 12:34:37 2000.END
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 // first step of advancement
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;
158 else if (d2dy < tolerance(2)) {
159 PasC = pas * (UM-Um)/d2dx;
162 PasC = pas * Min((UM-Um)/d2dx,(VM-Vm)/d2dy);
165 Arrive = Standard_False;
166 ArretAjout = Standard_False;
168 StatusPrecedent = IntWalk_OK;
169 // modified by NIZHNY-MKK Fri Oct 27 12:39:37 2000
170 Standard_Integer IndexOfPathPointDoNotCheck=0;
172 while (!Arrive) { // as one of stop tests is not checked
174 Cadre = Cadrage(BornInf,BornSup,UVap,PasC,StepSign);
181 Rsnld.Perform(Func,UVap,BornInf,BornSup);
188 BornInf(1) = Um; BornSup(1) = UM; BornInf(2) = Vm; BornSup(2) = VM;
190 if (Rsnld.IsDone()) {
191 if (Abs(Func.Root()) > Func.Tolerance()) {
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; // check
200 Rajout = Standard_True;
201 seqAjout.Append(lines.Length() + 1);
206 Arrive = TestArretPassage(Umult, Vmult, Func, UVap, N);
208 Cadre = Standard_False;
209 //in case if there is a frame and arrive at the same time
213 ArretAjout =TestArretAjout(Func, UVap, N, Psol);
216 Tgtend = lines.Value(N)->IsTangentAtEnd();
220 // modified by NIZHNY-MKK Thu Nov 2 15:09:08 2000.BEGIN
221 if(!(Rajout && ArretAjout)) {
222 Standard_Real prevUp, prevVp;
224 previousPoint.ParametersOnS2(prevUp, prevVp);
227 previousPoint.ParametersOnS1(prevUp, prevVp);
229 Arrive = TestPassedSolutionWithNegativeState(etat1, Umult, Vmult, ustart1, vstart1, prevUp, prevVp,
230 nbMultiplicities, tolerance, Func, UVap, N);
232 Cadre = Standard_False;
235 // modified by NIZHNY-MKK Thu Nov 2 15:09:13 2000.END
236 if (!ArretAjout && Cadre) {
237 if (CurrentLine->NbPoints() == 1) break; // cancel the line
238 TestArretCadre(Umult, Vmult, CurrentLine, Func, UVap, N);
240 if (N <= 0) { // jag 941017
241 MakeWalkingPoint(2, UVap(1), UVap(2), Func, Psol);
242 Tgtend = Func.IsTangent();
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
255 previousPoint.ParametersOnS2(UVap(1), UVap(2));
258 previousPoint.ParametersOnS1(UVap(1), UVap(2));
261 else if (ArretAjout || Cadre) {
262 Arrive = Standard_True;
263 CurrentLine->AddStatusLast(Standard_False);
264 if (Status != IntWalk_ArretSurPointPrecedent) {
265 CurrentLine->AddPoint(Psol);
268 Rajout = Standard_True;
269 seqAjout.Append(lines.Length()+1);
272 else if (Status == IntWalk_ArretSurPointPrecedent) {
273 if (CurrentLine->NbPoints() == 1) { //cancel the line
274 Arrive = Standard_False;
277 Arrive = Standard_True;
278 Rajout = Standard_True;
279 seqAjout.Append(lines.Length() + 1);
280 CurrentLine->AddStatusLast(Standard_False);
281 Tgtend = Standard_True; // check
284 if (CurrentLine->NbPoints() == 1 && // cancel the line
285 (N == I || Status == IntWalk_PointConfondu) ) {
286 // if N == I the main uv is probably lost
287 // or the point is a point of accumulation
288 // if point is confused the start data is bad
289 Arrive = Standard_False;
292 // necessairily N > 0 jag 940617
293 // point of stop given at input
294 PathPnt = Pnts1.Value(N);
296 Standard_Integer etat1N=etat1(N);
297 // modified by NIZHNY-MKK Thu Nov 2 15:09:51 2000.BEGIN
298 // if (etat1N < 11) { // passing point that is a stop
299 if (Abs(etat1N) < 11) { // passing point that is a stop
300 // modified by NIZHNY-MKK Thu Nov 2 15:12:11 2000.END
301 if (Status == IntWalk_ArretSurPoint) {
302 CurrentLine->AddStatusLast(Standard_False);
303 Tgtend = Standard_True; // need check
306 Arrive = Standard_False;
308 CurrentLine->AddIndexPassing(N);
310 else { // point of stop given at input
312 Tgtend = Standard_True;
314 CurrentLine->AddStatusLast(Standard_True, N, PathPnt);
316 AddPointInCurrentLine(N,PathPnt,CurrentLine);
317 if ((etat1N != 1 && etat1N != 11)) {
318 // modified by NIZHNY-MKK Fri Oct 27 12:43:05 2000.BEGIN
319 // etat1(N)= - etat1N;
320 etat1(N)= - Abs(etat1N);
321 movementdirectioninfo(N) = (movementdirectioninfo(N)==0) ? StepSign : 0;
322 if(Arrive && movementdirectioninfo(N)!=0) {
323 IndexOfPathPointDoNotCheck = N;
327 Rajout = Standard_True;
328 seqAjout.Append(lines.Length() + 1);
330 // modified by NIZHNY-MKK Fri Oct 27 12:45:33 2000.END
333 else if (Status == IntWalk_ArretSurPoint) {
334 Arrive = Standard_True;
335 CurrentLine->AddStatusLast(Standard_False);
336 Tgtend = Standard_True;
337 MakeWalkingPoint(1, UVap(1), UVap(2), Func, Psol);
338 CurrentLine->AddPoint(Psol);
339 Rajout = Standard_True;
340 seqAjout.Append(lines.Length() + 1);
342 else if (Status == IntWalk_OK) {
343 MakeWalkingPoint(2, UVap(1), UVap(2), Func, previousPoint);
344 previousd3d = Func.Direction3d();
345 previousd2d = Func.Direction2d();
346 CurrentLine->AddPoint(previousPoint);
350 else { // no numerical solution
352 PasCu = Abs(PasC*previousd2d.X());
353 PasCv = Abs(PasC*previousd2d.Y());
354 if (PasCu <= tolerance(1) && PasCv <= tolerance(2)) {
355 if (CurrentLine->NbPoints()==1) break;
356 Arrive = Standard_True;
357 CurrentLine->AddStatusLast(Standard_False);
358 Tgtend = Standard_True; // need check
359 Rajout = Standard_True;
360 seqAjout.Append(lines.Length() + 1);
363 } // end of started line
366 CurrentLine->SetTangencyAtEnd(Tgtend);
367 lines.Append(CurrentLine);
368 // modified by NIZHNY-MKK Fri Oct 27 12:59:29 2000.BEGIN
369 movementdirectioninfo(I)=0;
371 // modified by NIZHNY-MKK Fri Oct 27 12:59:42 2000.END
374 //-- lbr le 5 juin 97 (Pb ds Contap)
375 for(Standard_Integer av=1; av<=nbPath; av++) {
376 // modified by NIZHNY-MKK Fri Oct 27 13:00:22 2000.BEGIN
377 // if (etat1(av) > 11) {
378 if ((etat1(av) > 11) ||
380 (av!=IndexOfPathPointDoNotCheck) &&
382 (movementdirectioninfo(av)!=0))) {
383 // modified by NIZHNY-MKK Fri Oct 27 13:00:26 2000.END
384 Standard_Real Uav=ustart1(av);
385 Standard_Real Vav=vstart1(av);
386 Standard_Real Uavp,Vavp;
387 const IntSurf_PntOn2S &avP=CurrentLine->Value(CurrentLine->NbPoints());
389 avP.ParametersOnS2(Uavp,Vavp);
392 avP.ParametersOnS1(Uavp,Vavp);
396 Uav*=0.001; Vav*=0.001;
397 if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) {
398 // modified by NIZHNY-MKK Fri Oct 27 13:01:38 2000.BEGIN
399 // etat1(av)=-etat1(av);
401 movementdirectioninfo(av) = 0;
403 etat1(av)=-etat1(av);
404 movementdirectioninfo(av) = StepSign;
406 // modified by NIZHNY-MKK Fri Oct 27 13:01:42 2000.END
407 CurrentLine->AddStatusLast(Standard_True, av, Pnts1.Value(av));
408 //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
411 const IntSurf_PntOn2S &avPP=CurrentLine->Value(1);
413 avPP.ParametersOnS2(Uavp,Vavp);
416 avPP.ParametersOnS1(Uavp,Vavp);
422 Uav*=0.001; Vav*=0.001;
423 if(Abs(Uav)<tolerance(1) && Abs(Vav)<tolerance(2)) {
424 // modified by NIZHNY-MKK Fri Oct 27 13:02:49 2000.BEGIN
425 // etat1(av)=-etat1(av);
427 movementdirectioninfo(av) = 0;
429 etat1(av)=-etat1(av);
430 movementdirectioninfo(av) = -StepSign;
432 // modified by NIZHNY-MKK Fri Oct 27 13:02:52 2000.END
433 //-- cout<<"\n Debug ? lbr ds IntWalk_IWalking_3.gxx"<<endl;
434 CurrentLine->AddStatusFirst(Standard_False, Standard_True, av, Pnts1.Value(av));
440 } //end of point processing
441 } //end of all points
444 // modified by NIZHNY-MKK Thu Nov 2 15:07:53 2000.BEGIN
445 static Standard_Boolean TestPassedSolutionWithNegativeState(const TColStd_SequenceOfInteger& etat,
446 const TColStd_SequenceOfReal& Umult,
447 const TColStd_SequenceOfReal& Vmult,
448 const TColStd_SequenceOfReal& ustart,
449 const TColStd_SequenceOfReal& vstart,
450 const Standard_Real& prevUp,
451 const Standard_Real& prevVp,
452 const TColStd_SequenceOfInteger& nbMultiplicities,
453 const math_Vector& tolerance,
456 Standard_Integer& Irang) {
457 Standard_Boolean Arrive = Standard_False;
458 Standard_Real Dup, Dvp, Utest,Vtest;
459 Standard_Real tolu = tolerance(1);
460 Standard_Real tolv = tolerance(2);
461 Standard_Integer i, j, k, N;
462 for (i = 1; i <= etat.Length(); i++) {
465 // debug jag see with isg
469 Dup = prevUp - Utest;
470 Dvp = prevVp - Vtest;
471 if (Abs(Dup) >= tolu || Abs(Dvp) >= tolv) {
472 Standard_Real UV1mUtest = UV(1)-Utest;
473 Standard_Real UV2mVtest = UV(2)-Vtest;
474 if(( (Dup*UV1mUtest + Dvp*UV2mVtest) < 0) ||
475 ( Abs(UV1mUtest) < tolu
476 && Abs(UV2mVtest) < tolv)) {
478 Arrive = Standard_True;
482 else if (nbMultiplicities(i) > 0) {
484 for (k = 1; k < i; k++) {
485 N+=nbMultiplicities(k);
487 for (j = N + 1; j <= N + nbMultiplicities(i); j++) {
488 if (((prevUp-Umult(j))*(UV(1)-Umult(j)) +
489 (prevVp-Vmult(j))*(UV(2)-Vmult(j)) < 0) ||
490 (Abs(UV(1)-Umult(j)) < tolu &&
491 Abs(UV(2)-Vmult(j)) < tolv)) {
493 Arrive = Standard_True;
501 static math_Vector bidF(1,1);
502 static math_Matrix bidD(1,1,1,2);
503 sp.Values(UV,bidF,bidD);
511 // modified by NIZHNY-MKK Thu Nov 2 15:07:58 2000.END