1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 // pmn, 30/10/98 : Protection dans les cas surcontraint -> "isready"
18 // Approximation d une MultiLine de points decrite par le tool MLineTool.
19 // Ce programme utilise les moindres carres pour le cas suivant:
20 // passage et tangences aux extremites.
23 #define No_Standard_RangeError
24 #define No_Standard_OutOfRange
25 #define No_Standard_DimensionError
27 #include <math_Householder.hxx>
28 #include <math_Crout.hxx>
29 #include <AppParCurves.hxx>
31 #include <gp_Pnt2d.hxx>
33 #include <gp_Vec2d.hxx>
34 #include <TColgp_Array1OfPnt.hxx>
35 #include <TColgp_Array1OfPnt2d.hxx>
36 #include <TColgp_Array1OfVec.hxx>
37 #include <TColgp_Array1OfVec2d.hxx>
38 #include <TColStd_Array1OfInteger.hxx>
39 #include <TColStd_Array1OfReal.hxx>
40 #include <AppParCurves_Constraint.hxx>
41 #include <AppParCurves_MultiPoint.hxx>
42 #include <StdFail_NotDone.hxx>
43 #include <Standard_NoSuchObject.hxx>
44 #include <TColStd_Array1OfReal.hxx>
45 #include <math_Recipes.hxx>
46 #include <math_Crout.hxx>
50 static int FlatLength(const TColStd_Array1OfInteger& Mults) {
52 Standard_Integer sum = 0;
53 for (Standard_Integer i = Mults.Lower(); i <= Mults.Upper(); i++) {
54 sum += Mults.Value(i);
59 //=======================================================================
60 //function : CheckTangents
61 //purpose : Checks if theArrTg3d and theArrTg2d have direction
62 // corresponded to the direction between theArrPt1 and theArrPt2.
63 // If it is not then reverses tangent vectors.
64 // theArrPt1 (as same as theArrPt2) is sub-set of all 3D-points in
65 // one multy-point (multy-point is union of sets of 2D- and 3D-points).
68 // The property of correlation between Tg3d and Tg2d is used here.
69 // Therefore, only 3D-coinciding is checked.
70 //=======================================================================
71 static void CheckTangents(const TColgp_Array1OfPnt& theArrPt1,
72 const TColgp_Array1OfPnt& theArrPt2,
73 TColgp_Array1OfVec& theArrTg3d,
74 TColgp_Array1OfVec2d& theArrTg2d)
76 if(theArrPt1.Lower() != theArrPt2.Lower())
79 if(theArrPt1.Upper() != theArrPt2.Upper())
82 if(theArrTg3d.Length() != theArrPt1.Length())
85 Standard_Boolean isToChangeDir = Standard_False;
87 for(Standard_Integer i = theArrPt1.Lower(); i <= theArrPt1.Upper(); i++)
89 const gp_Vec aV1(theArrPt1(i), theArrPt2(i));
90 const gp_Vec& aV2 = theArrTg3d(i);
92 if(aV1.Dot(aV2) < 0.0)
94 isToChangeDir = Standard_True;
102 //Change directions for every 2D- and 3D-tangents
104 for(Standard_Integer i = theArrTg3d.Lower(); i <= theArrTg3d.Upper(); i++)
106 theArrTg3d(i).Reverse();
109 for(Standard_Integer i = theArrTg2d.Lower(); i <= theArrTg2d.Upper(); i++)
111 theArrTg2d(i).Reverse();
115 //=======================================================================
116 //function : CheckTangents
117 //purpose : Checks if theArrTg2d have direction
118 // corresponded to the direction between theArrPt1 and theArrPt2.
119 // If it is not then reverses tangent vector.
120 // theArrPt1 (as same as theArrPt2) is sub-set of all 2D-points in
121 // one multy-point (multy-point is union of sets of 2D- and 3D-points).
122 //=======================================================================
123 static void CheckTangents(const TColgp_Array1OfPnt2d& theArrPt1,
124 const TColgp_Array1OfPnt2d& theArrPt2,
125 TColgp_Array1OfVec2d& theArrTg2d)
127 if(theArrPt1.Lower() != theArrPt2.Lower())
130 if(theArrPt1.Upper() != theArrPt2.Upper())
133 for(Standard_Integer i = theArrPt1.Lower(); i <= theArrPt1.Upper(); i++)
135 const gp_Vec2d aV1(theArrPt1(i), theArrPt2(i));
136 const gp_Vec2d& aV2 = theArrTg2d(i);
138 if(aV1.Dot(aV2) < 0.0)
140 theArrTg2d(i).Reverse();
146 AppParCurves_LeastSquare::
147 AppParCurves_LeastSquare(const MultiLine& SSP,
148 const Standard_Integer FirstPoint,
149 const Standard_Integer LastPoint,
150 const AppParCurves_Constraint FirstCons,
151 const AppParCurves_Constraint LastCons,
152 const math_Vector& Parameters,
153 const Standard_Integer NbPol):
157 A(FirstPoint, LastPoint, 1, NbPol),
158 DA(FirstPoint, LastPoint, 1, NbPol),
159 B2(TheFirstPoint(FirstCons, FirstPoint),
160 Max(TheFirstPoint(FirstCons, FirstPoint),
161 TheLastPoint(LastCons, LastPoint)),
163 mypoints(FirstPoint, LastPoint, 1, NbBColumns(SSP)),
165 Vec1t(1, NbBColumns(SSP)),
166 Vec1c(1, NbBColumns(SSP)),
167 Vec2t(1, NbBColumns(SSP)),
168 Vec2c(1, NbBColumns(SSP)),
169 theError(FirstPoint, LastPoint,
170 1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
171 myindex(FirstPoint, LastPoint, 0),
174 FirstConstraint = FirstCons;
175 LastConstraint = LastCons;
176 Init(SSP, FirstPoint, LastPoint);
182 AppParCurves_LeastSquare::
183 AppParCurves_LeastSquare(const MultiLine& SSP,
184 const Standard_Integer FirstPoint,
185 const Standard_Integer LastPoint,
186 const AppParCurves_Constraint FirstCons,
187 const AppParCurves_Constraint LastCons,
188 const Standard_Integer NbPol):
192 A(FirstPoint, LastPoint, 1, NbPol),
193 DA(FirstPoint, LastPoint, 1, NbPol),
194 B2(TheFirstPoint(FirstCons, FirstPoint),
195 Max(TheFirstPoint(FirstCons, FirstPoint),
196 TheLastPoint(LastCons, LastPoint)),
198 mypoints(FirstPoint, LastPoint, 1, NbBColumns(SSP)),
200 Vec1t(1, NbBColumns(SSP)),
201 Vec1c(1, NbBColumns(SSP)),
202 Vec2t(1, NbBColumns(SSP)),
203 Vec2c(1, NbBColumns(SSP)),
204 theError(FirstPoint, LastPoint,
205 1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
206 myindex(FirstPoint, LastPoint, 0),
209 FirstConstraint = FirstCons;
210 LastConstraint = LastCons;
211 Init(SSP, FirstPoint, LastPoint);
215 AppParCurves_LeastSquare::
216 AppParCurves_LeastSquare(const MultiLine& SSP,
217 const TColStd_Array1OfReal& Knots,
218 const TColStd_Array1OfInteger& Mults,
219 const Standard_Integer FirstPoint,
220 const Standard_Integer LastPoint,
221 const AppParCurves_Constraint FirstCons,
222 const AppParCurves_Constraint LastCons,
223 const math_Vector& Parameters,
224 const Standard_Integer NbPol):
228 A(FirstPoint, LastPoint, 1, NbPol),
229 DA(FirstPoint, LastPoint, 1, NbPol),
230 B2(TheFirstPoint(FirstCons, FirstPoint),
231 Max(TheFirstPoint(FirstCons, FirstPoint),
232 TheLastPoint(LastCons, LastPoint)),
234 mypoints(FirstPoint, LastPoint, 1, NbBColumns(SSP)),
235 Vflatknots(1, FlatLength(Mults)),
236 Vec1t(1, NbBColumns(SSP)),
237 Vec1c(1, NbBColumns(SSP)),
238 Vec2t(1, NbBColumns(SSP)),
239 Vec2c(1, NbBColumns(SSP)),
240 theError(FirstPoint, LastPoint,
241 1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
242 myindex(FirstPoint, LastPoint, 0),
245 FirstConstraint = FirstCons;
246 LastConstraint = LastCons;
247 myknots = new TColStd_HArray1OfReal(Knots.Lower(), Knots.Upper());
248 myknots->ChangeArray1() = Knots;
249 mymults = new TColStd_HArray1OfInteger(Mults.Lower(), Mults.Upper());
250 mymults->ChangeArray1() = Mults;
252 SCU.SetMultiplicities(Mults);
253 Init(SSP, FirstPoint, LastPoint);
259 AppParCurves_LeastSquare::
260 AppParCurves_LeastSquare(const MultiLine& SSP,
261 const TColStd_Array1OfReal& Knots,
262 const TColStd_Array1OfInteger& Mults,
263 const Standard_Integer FirstPoint,
264 const Standard_Integer LastPoint,
265 const AppParCurves_Constraint FirstCons,
266 const AppParCurves_Constraint LastCons,
267 const Standard_Integer NbPol):
271 A(FirstPoint, LastPoint, 1, NbPol),
272 DA(FirstPoint, LastPoint, 1, NbPol),
273 B2(TheFirstPoint(FirstCons, FirstPoint),
274 Max(TheFirstPoint(FirstCons, FirstPoint),
275 TheLastPoint(LastCons, LastPoint)),
277 mypoints(FirstPoint, LastPoint, 1, NbBColumns(SSP)),
278 Vflatknots(1, FlatLength(Mults)),
279 Vec1t(1, NbBColumns(SSP)),
280 Vec1c(1, NbBColumns(SSP)),
281 Vec2t(1, NbBColumns(SSP)),
282 Vec2c(1, NbBColumns(SSP)),
283 theError(FirstPoint, LastPoint,
284 1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
285 myindex(FirstPoint, LastPoint, 0),
288 myknots = new TColStd_HArray1OfReal(Knots.Lower(), Knots.Upper());
289 myknots->ChangeArray1() = Knots;
290 mymults = new TColStd_HArray1OfInteger(Mults.Lower(), Mults.Upper());
291 mymults->ChangeArray1() = Mults;
293 SCU.SetMultiplicities(Mults);
294 FirstConstraint = FirstCons;
295 LastConstraint = LastCons;
296 Init(SSP, FirstPoint, LastPoint);
301 void AppParCurves_LeastSquare::Init(const MultiLine& SSP,
302 const Standard_Integer FirstPoint,
303 const Standard_Integer LastPoint)
305 // Variable de controle
306 iscalculated = Standard_False;
307 isready = Standard_True;
309 myfirstp = FirstPoint;
311 FirstP = TheFirstPoint(FirstConstraint, myfirstp);
312 LastP = TheLastPoint(LastConstraint, mylastp);
314 // Reperage des contraintes aux extremites:
315 // ========================================
316 Standard_Integer i, j, k, i2;
318 nbP2d = ToolLine::NbP2d(SSP);
319 nbP = ToolLine::NbP3d(SSP);
324 Standard_Integer mynbP2d = nbP2d, mynbP = nbP;
325 if (nbP2d == 0) mynbP2d = 1;
326 if (nbP == 0) mynbP = 1;
327 TColgp_Array1OfPnt TabP(1, mynbP);
328 TColgp_Array1OfPnt2d TabP2d(1, mynbP2d);
329 TColgp_Array1OfVec TabV(1, mynbP);
330 TColgp_Array1OfVec2d TabV2d(1, mynbP2d);
335 if (!mymults.IsNull()) {
336 Standard_Integer sum = 0;
337 for (i = mymults->Lower(); i <= mymults->Upper(); i++) {
338 sum += mymults->Value(i);
340 deg = sum -nbpoles-1;
343 for (i = myknots->Lower(); i <= myknots->Upper(); i++) {
344 for (j = 1; j <= mymults->Value(i); j++) {
345 val = myknots->Value(i);
353 Affect(SSP, FirstPoint, FirstConstraint, Vec1t, Vec1c);
355 Affect(SSP, LastPoint, LastConstraint, Vec2t, Vec2c);
357 for (j = myfirstp; j <= mylastp; j++) {
359 if (nbP != 0 && nbP2d != 0) ToolLine::Value(SSP, j, TabP,TabP2d);
360 else if (nbP2d != 0) ToolLine::Value(SSP, j, TabP2d);
361 else ToolLine::Value(SSP, j, TabP);
362 for (i = 1; i <= nbP; i++) {
363 (TabP(i)).Coord(mypoints(j,i2),mypoints(j,i2+1),mypoints(j,i2+2));
366 for (i = 1;i <= nbP2d; i++) {
367 (TabP2d(i)).Coord(mypoints(j, i2), mypoints(j, i2+1));
372 AppParCurves_MultiPoint Pole1(nbP, nbP2d), PoleN(nbP, nbP2d);
374 if (FirstConstraint == AppParCurves_PassPoint ||
375 FirstConstraint == AppParCurves_TangencyPoint ||
376 FirstConstraint == AppParCurves_CurvaturePoint) {
378 for (i = 1; i <= nbP; i++) {
379 Poi.SetCoord(mypoints(myfirstp, i2),
380 mypoints(myfirstp, i2+1),
381 mypoints(myfirstp, i2+2));
382 Pole1.SetPoint(i, Poi);
385 for (i = 1; i <= nbP2d; i++) {
386 Poi2d.SetCoord(mypoints(myfirstp, i2), mypoints(myfirstp, i2+1));
387 Pole1.SetPoint2d(i+nbP, Poi2d);
390 for (i = 1; i <= mypoles.ColNumber(); i++)
391 mypoles(1, i) = mypoints(myfirstp, i);
396 if (LastConstraint == AppParCurves_PassPoint ||
397 LastConstraint == AppParCurves_TangencyPoint ||
398 FirstConstraint == AppParCurves_CurvaturePoint) {
400 for (i = 1; i <= nbP; i++) {
401 Poi.SetCoord(mypoints(mylastp, i2),
402 mypoints(mylastp, i2+1),
403 mypoints(mylastp, i2+2));
404 PoleN.SetPoint(i, Poi);
407 for (i = 1; i <= nbP2d; i++) {
408 Poi2d.SetCoord(mypoints(mylastp, i2),
409 mypoints(mylastp, i2+1));
410 PoleN.SetPoint2d(i+nbP, Poi2d);
414 for (i = 1; i <= mypoles.ColNumber(); i++)
415 mypoles(nbpoles, i) = mypoints(mylastp, i);
419 if (FirstConstraint == AppParCurves_NoConstraint) {
421 SCU.SetValue(1, Pole1);
422 if (LastConstraint == AppParCurves_NoConstraint) {
425 else if (LastConstraint == AppParCurves_PassPoint) {
427 SCU.SetValue(nbpoles, PoleN);
429 else if (LastConstraint == AppParCurves_TangencyPoint) {
431 SCU.SetValue(nbpoles, PoleN);
433 else if (LastConstraint == AppParCurves_CurvaturePoint) {
435 SCU.SetValue(nbpoles, PoleN);
438 else if (FirstConstraint == AppParCurves_PassPoint) {
440 SCU.SetValue(1, Pole1);
441 if (LastConstraint == AppParCurves_NoConstraint) {
444 else if (LastConstraint == AppParCurves_PassPoint) {
446 SCU.SetValue(nbpoles, PoleN);
448 else if (LastConstraint == AppParCurves_TangencyPoint) {
450 SCU.SetValue(nbpoles, PoleN);
452 else if (LastConstraint == AppParCurves_CurvaturePoint) {
454 SCU.SetValue(nbpoles, PoleN);
457 else if (FirstConstraint == AppParCurves_TangencyPoint) {
459 SCU.SetValue(1, Pole1);
460 if (LastConstraint == AppParCurves_NoConstraint) {
463 if (LastConstraint == AppParCurves_PassPoint) {
465 SCU.SetValue(nbpoles, PoleN);
467 if (LastConstraint == AppParCurves_TangencyPoint) {
469 SCU.SetValue(nbpoles, PoleN);
471 else if (LastConstraint == AppParCurves_CurvaturePoint) {
473 SCU.SetValue(nbpoles, PoleN);
476 else if (FirstConstraint == AppParCurves_CurvaturePoint) {
478 SCU.SetValue(1, Pole1);
479 if (LastConstraint == AppParCurves_NoConstraint) {
482 if (LastConstraint == AppParCurves_PassPoint) {
484 SCU.SetValue(nbpoles, PoleN);
486 if (LastConstraint == AppParCurves_TangencyPoint) {
488 SCU.SetValue(nbpoles, PoleN);
490 else if (LastConstraint == AppParCurves_CurvaturePoint) {
492 SCU.SetValue(nbpoles, PoleN);
496 Standard_Integer Nincx = resfin-resinit+1;
497 if (Nincx<1) { //Impossible d'aller plus loin
498 isready = Standard_False;
501 Standard_Integer Neq = LastP-FirstP+1;
506 if (FirstConstraint >= AppParCurves_TangencyPoint) Ninc++;
507 if (LastConstraint >= AppParCurves_TangencyPoint) Ninc++;
513 void AppParCurves_LeastSquare::Perform(const math_Vector& Parameters) {
515 done = Standard_False;
519 Standard_Integer i, j, k, Ci, i2, k1, k2;
520 Standard_Integer nbpol1 = nbpoles-1, Ninc1 = Ninc-1;
521 Standard_Real AD1, A0;
524 iscalculated = Standard_False;
526 // calcul de la matrice A et DA des fonctions d approximation:
527 ComputeFunction(Parameters);
529 if (FirstConstraint != AppParCurves_TangencyPoint &&
530 LastConstraint != AppParCurves_TangencyPoint) {
531 if (FirstConstraint == AppParCurves_NoConstraint) {
532 if (LastConstraint == AppParCurves_NoConstraint ) {
534 math_Householder HouResol(A, mypoints);
535 if (!(HouResol.IsDone())) {
536 done = Standard_False;
539 done = Standard_True;
540 mypoles = HouResol.AllValues();
545 for (j = FirstP; j <= LastP; j++) {
547 for (i = 1; i <= B2.ColNumber(); i++) {
548 B2(j, i) = mypoints(j,i) - AD1*mypoles(nbpoles, i);
553 else if (FirstConstraint == AppParCurves_PassPoint) {
554 if (LastConstraint == AppParCurves_NoConstraint) {
555 for (j = FirstP; j <= LastP; j++) {
557 for (i = 1; i <= B2.ColNumber(); i++) {
558 B2(j, i) = mypoints(j, i)- A0*mypoles(1, i);
562 else if (LastConstraint == AppParCurves_PassPoint) {
563 for (j = FirstP; j <= LastP; j++) {
566 for (i = 1; i <= B2.ColNumber(); i++) {
567 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
568 - AD1* mypoles(nbpoles, i);
576 Standard_Integer Nincx = resfin-resinit+1;
578 done = Standard_True;
581 math_IntegerVector Index(1, Nincx);
583 math_Matrix mytab(resinit, resfin, 1, B2.ColNumber(),0.0);
584 math_Vector TheAA(1, Index(Nincx), 0.0);
585 math_Vector myTABB(1, Nincx, 0.0);
587 MakeTAA(TheAA, mytab);
588 DACTCL_Decompose(TheAA, Index);
590 Standard_Integer kk2;
591 for (j = 1; j <= B2.ColNumber(); j++) {
593 for (i = resinit; i <= resfin; i++) {
594 myTABB(kk2) = mytab(i, j);
597 DACTCL_Solve(TheAA, myTABB, Index);
600 for (k = resinit; k <= resfin; k++) {
601 mypoles(k, j) = myTABB.Value(i2);
605 done = Standard_True;
608 // ===========================================================
610 // ===========================================================
612 Standard_Integer Nincx = resfin-resinit+1;
613 Standard_Integer deport = 0, Nincx2 = 2*Nincx;
615 math_IntegerVector InternalIndex(1, Nincx);
616 SearchIndex(InternalIndex);
617 math_IntegerVector Index(1, Ninc);
619 Standard_Integer l = 1;
620 if (resinit <= resfin) {
621 for (j = 0; j <= NA-1; j++) {
622 deport = j*InternalIndex(Nincx);
623 for (i = 1; i <= Nincx; i++) {
624 Index(l) = InternalIndex(i) + deport;
630 if (resinit > resfin) Index(1) = 1;
632 if (FirstConstraint >= AppParCurves_TangencyPoint &&
633 LastConstraint >= AppParCurves_TangencyPoint)
634 Index(Ninc1) = Index(Ninc1 - 1) + Ninc1;
636 if (FirstConstraint >= AppParCurves_TangencyPoint ||
637 LastConstraint >= AppParCurves_TangencyPoint)
638 Index(Ninc) = Index(Ninc-1) + Ninc;
641 math_Vector TheA(1, Index(Ninc), 0.0);
642 math_Vector myTAB(1, Ninc, 0.0);
644 MakeTAA(TheA, myTAB);
646 Standard_Integer Error = DACTCL_Decompose(TheA, Index);
647 Error = DACTCL_Solve(TheA, myTAB, Index);
649 if (!Error) done = Standard_True;
651 if (FirstConstraint >= AppParCurves_TangencyPoint &&
652 LastConstraint >= AppParCurves_TangencyPoint) {
653 lambda1 = myTAB.Value(Ninc1);
654 lambda2 = myTAB.Value(Ninc);
656 else if (FirstConstraint >= AppParCurves_TangencyPoint)
657 lambda1 = myTAB.Value(Ninc);
658 else if (LastConstraint >= AppParCurves_TangencyPoint)
659 lambda2 = myTAB.Value(Ninc);
663 // Les resultats sont stockes dans mypoles.
664 //=========================================
667 for (Ci = 1; Ci <= nbP; Ci++) {
669 for (j = resinit; j <= resfin; j++) {
670 mypoles(j, k) = myTAB.Value(i2);
671 mypoles(j, k1) = myTAB.Value(i2+Nincx);
672 mypoles(j, k2) = myTAB.Value(i2+Nincx2);
676 if (FirstConstraint >= AppParCurves_TangencyPoint) {
677 mypoles(2, k) = mypoints(myfirstp, k) + lambda1*Vec1t(k);
678 mypoles(2, k1) = mypoints(myfirstp, k1) + lambda1*Vec1t(k1);
679 mypoles(2, k2) = mypoints(myfirstp, k2) + lambda1*Vec1t(k2);
681 if (LastConstraint >= AppParCurves_TangencyPoint) {
682 mypoles(nbpol1, k) = mypoints(mylastp, k) - lambda2*Vec2t(k);
683 mypoles(nbpol1, k1) = mypoints(mylastp, k1) - lambda2*Vec2t(k1);
684 mypoles(nbpol1, k2) = mypoints(mylastp, k2) - lambda2*Vec2t(k2);
686 k += 3; i2 += Nincx2;
689 for (Ci = 1; Ci <= nbP2d; Ci++) {
691 for (j = resinit; j <= resfin; j++) {
692 mypoles(j, k) = myTAB.Value(i2);
693 mypoles(j, k1) = myTAB.Value(i2+Nincx);
696 if (FirstConstraint >= AppParCurves_TangencyPoint) {
697 mypoles(2, k) = mypoints(myfirstp, k) + lambda1*Vec1t(k);
698 mypoles(2, k1) = mypoints(myfirstp, k1) + lambda1*Vec1t(k1);
700 if (LastConstraint >= AppParCurves_TangencyPoint) {
701 mypoles(nbpol1, k) = mypoints(mylastp, k) - lambda2*Vec2t(k);
702 mypoles(nbpol1, k1) = mypoints(mylastp, k1) - lambda2*Vec2t(k1);
709 void AppParCurves_LeastSquare::Perform(const math_Vector& Parameters,
710 const math_Vector& V1t,
711 const math_Vector& V2t,
712 const Standard_Real l1,
713 const Standard_Real l2)
715 done = Standard_False;
719 Standard_Integer i, lower1 = V1t.Lower(), lower2 = V2t.Lower();
720 resinit = 3; resfin = nbpoles-2;
721 Standard_Integer Nincx = resfin-resinit+1;
723 FirstConstraint = AppParCurves_TangencyPoint;
724 LastConstraint = AppParCurves_TangencyPoint;
725 for (i = 1; i <= Vec1t.Upper(); i++) {
726 Vec1t(i) = V1t(i+lower1-1);
727 Vec2t(i) = V2t(i+lower2-1);
729 Perform (Parameters, l1, l2);
733 void AppParCurves_LeastSquare::Perform(const math_Vector& Parameters,
734 const math_Vector& V1t,
735 const math_Vector& V2t,
736 const math_Vector& V1c,
737 const math_Vector& V2c,
738 const Standard_Real l1,
739 const Standard_Real l2) {
740 done = Standard_False;
744 Standard_Integer i, lower1 = V1t.Lower(), lower2 = V2t.Lower();
745 Standard_Integer lowc1 = V1c.Lower(), lowc2 = V2c.Lower();
746 resinit = 4; resfin = nbpoles-3;
747 Standard_Integer Nincx = resfin-resinit+1;
749 FirstConstraint = AppParCurves_CurvaturePoint;
750 LastConstraint = AppParCurves_CurvaturePoint;
752 for (i = 1; i <= Vec1t.Upper(); i++) {
753 Vec1t(i) = V1t(i+lower1-1);
754 Vec2t(i) = V2t(i+lower2-1);
755 Vec1c(i) = V1c(i+lowc1-1);
756 Vec2c(i) = V2c(i+lowc2-1);
758 Perform (Parameters, l1, l2);
763 void AppParCurves_LeastSquare::Perform(const math_Vector& Parameters,
764 const Standard_Real l1,
765 const Standard_Real l2) {
766 done = Standard_False;
770 if (FirstConstraint < AppParCurves_TangencyPoint &&
771 LastConstraint < AppParCurves_TangencyPoint) {
775 iscalculated = Standard_False;
779 Standard_Integer i, j, k, i2;
780 Standard_Real AD0, AD1, AD2, A0, A1, A2;
781 // gp_Pnt Pt, P1, P2;
782 // gp_Pnt2d Pt2d, P12d, P22d;
783 Standard_Real l11 = deg*l1, l22 = deg*l2;
785 ComputeFunction(Parameters);
787 if (FirstConstraint >= AppParCurves_TangencyPoint) {
788 for (i = 1; i <= mypoles.ColNumber(); i++)
789 mypoles(2, i) = mypoints(myfirstp, i) + l1*Vec1t(i);
793 if (FirstConstraint == AppParCurves_CurvaturePoint) {
794 for (i = 1; i <= mypoles.ColNumber(); i++)
795 mypoles(3, i) = 2*mypoles(2, i)-mypoles(1, i)
796 + l11*l11*Vec1c(i)/(deg*(deg-1));
800 if (LastConstraint >= AppParCurves_TangencyPoint) {
801 for (i = 1; i <= mypoles.ColNumber(); i++)
802 mypoles(nbpoles-1, i) = mypoints(mylastp, i) - l2*Vec2t(i);
806 if (LastConstraint == AppParCurves_CurvaturePoint) {
807 for (i = 1; i <= mypoles.ColNumber(); i++)
808 mypoles(nbpoles-2, i) = 2*mypoles(nbpoles-1, i) - mypoles(nbpoles, i)
809 + l22*l22*Vec2c(i)/(deg*(deg-1));
812 if (resinit > resfin) {
813 done = Standard_True;
817 if (FirstConstraint == AppParCurves_NoConstraint) {
818 if (LastConstraint == AppParCurves_TangencyPoint) {
819 for (j = FirstP; j <= LastP; j++) {
820 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1);
821 for (i = 1; i <= B2.ColNumber(); i++) {
822 B2(j, i) = mypoints(j, i) - AD0 * mypoles(nbpoles, i)
823 - AD1 * mypoles(nbpoles-1, i);
827 if (LastConstraint == AppParCurves_CurvaturePoint) {
828 for (j = FirstP; j <= LastP; j++) {
829 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1); AD2 = A(j, nbpoles-2);
830 for (i = 1; i <= B2.ColNumber(); i++) {
831 B2(j, i) = mypoints(j, i) - AD0 * mypoles(nbpoles, i)
832 - AD1 * mypoles(nbpoles-1, i)
833 - AD2 * mypoles(nbpoles-2, i);
838 else if (FirstConstraint == AppParCurves_PassPoint) {
839 if (LastConstraint == AppParCurves_TangencyPoint) {
840 for (j = FirstP; j <= LastP; j++) {
842 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1);
843 for (i = 1; i <= B2.ColNumber(); i++) {
844 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
845 - AD0 * mypoles(nbpoles, i)
846 - AD1 * mypoles(nbpoles-1, i);
850 if (LastConstraint == AppParCurves_CurvaturePoint) {
851 for (j = FirstP; j <= LastP; j++) {
853 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1); AD2 = A(j, nbpoles-2);
854 for (i = 1; i <= B2.ColNumber(); i++) {
855 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
856 - AD0 * mypoles(nbpoles, i)
857 - AD1 * mypoles(nbpoles-1, i)
858 - AD2 * mypoles(nbpoles-2, i);
863 else if (FirstConstraint == AppParCurves_TangencyPoint) {
864 if (LastConstraint == AppParCurves_NoConstraint) {
865 for (j = FirstP; j <= LastP; j++) {
866 A0 = A(j, 1); A1 = A(j, 2);
867 for (i = 1; i <= B2.ColNumber(); i++) {
868 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
869 - A1 * mypoles(2, i);
873 else if (LastConstraint == AppParCurves_PassPoint) {
874 for (j = FirstP; j <= LastP; j++) {
875 A0 = A(j, 1); AD0 = A(j, nbpoles); A1 = A(j, 2);
876 for (i = 1; i <= B2.ColNumber(); i++) {
877 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
878 - AD0 * mypoles(nbpoles, i)
879 - A1 * mypoles(2, i);
883 else if (LastConstraint == AppParCurves_TangencyPoint) {
884 for (j = FirstP; j <= LastP; j++) {
885 A0 = A(j, 1); AD0 = A(j, nbpoles); A1 = A(j, 2); AD1 = A(j, nbpoles-1);
886 for (i = 1; i <= B2.ColNumber(); i++) {
887 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
888 - AD0 * mypoles(nbpoles, i)
890 - AD1 * mypoles(nbpoles-1, i);
895 else if (FirstConstraint == AppParCurves_CurvaturePoint) {
896 if (LastConstraint == AppParCurves_NoConstraint) {
897 for (j = FirstP; j <= LastP; j++) {
898 A0 = A(j, 1); A1 = A(j, 2); A2 = A(j, 3);
899 for (i = 1; i <= B2.ColNumber(); i++) {
900 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
902 - A2 * mypoles(3, i);
906 else if (LastConstraint == AppParCurves_PassPoint) {
907 for (j = FirstP; j <= LastP; j++) {
908 A0 = A(j, 1); A1 = A(j, 2); A2 = A(j, 3); AD0 = A(j, nbpoles);
909 for (i = 1; i <= B2.ColNumber(); i++) {
910 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
913 - AD0 * mypoles(nbpoles, i);
917 else if (LastConstraint == AppParCurves_TangencyPoint) {
918 for (j = FirstP; j <= LastP; j++) {
919 A0 = A(j, 1); A1 = A(j, 2); A2 = A(j, 3);
920 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1);
921 for (i = 1; i <= B2.ColNumber(); i++) {
922 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
925 - AD0 * mypoles(nbpoles, i)
926 - AD1 * mypoles(nbpoles-1, i);
930 else if (LastConstraint == AppParCurves_CurvaturePoint) {
931 for (j = FirstP; j <= LastP; j++) {
932 A0 = A(j, 1); A1 = A(j, 2); A2 = A(j, 3);
933 AD0 = A(j, nbpoles); AD1 = A(j, nbpoles-1); AD2 = A(j, nbpoles-2);
934 for (i = 1; i <= B2.ColNumber(); i++) {
935 B2(j, i) = mypoints(j, i) - A0 * mypoles(1, i)
938 - AD0 * mypoles(nbpoles, i)
939 - AD1 * mypoles(nbpoles-1, i)
940 - AD2 * mypoles(nbpoles-2, i);
946 Standard_Integer Nincx = resfin-resinit+1;
948 math_Matrix mytab(resinit, resfin, 1, B2.ColNumber(),0.0);
949 math_IntegerVector Index(1, Nincx);
951 math_Vector AA(1, Index(Nincx), 0.0);
954 math_Vector myTABB(1, Nincx, 0.0);
956 DACTCL_Decompose(AA, Index);
958 Standard_Integer kk2;
959 for (j = 1; j <= B2.ColNumber(); j++) {
961 for (i = resinit; i <= resfin; i++) {
962 myTABB(kk2) = mytab(i, j);
966 DACTCL_Solve(AA, myTABB, Index);
969 for (k = resinit; k <= resfin; k++) {
970 mypoles(k, j) = myTABB.Value(i2);
976 done = Standard_True;
982 //=======================================================================
984 //purpose : Index is an ID of the point in MultiLine. Every point is set of
985 // several 3D- and 2D-points. E.g. every points of Walking-line,
986 // obtained in intersection algorithm, is set of one 3D points
987 // (nbP == 1) and two 2D-points (nbP2d == 2).
988 //=======================================================================
989 void AppParCurves_LeastSquare::Affect(const MultiLine& SSP,
990 const Standard_Integer Index,
991 AppParCurves_Constraint& Cons,
995 // Vt: vector of tangent, Vc: vector of curvature.
997 if (Cons >= AppParCurves_TangencyPoint) {
998 Standard_Integer i, i2 = 1;
1000 Standard_Integer mynbP2d = nbP2d, mynbP = nbP;
1001 if (nbP2d == 0) mynbP2d = 1;
1002 if (nbP == 0) mynbP = 1;
1003 TColgp_Array1OfVec TabV(1, mynbP);
1004 TColgp_Array1OfVec2d TabV2d(1, mynbP2d);
1006 if (Cons == AppParCurves_CurvaturePoint)
1008 if (nbP != 0 && nbP2d != 0)
1010 Ok = ToolLine::Curvature(SSP, Index,TabV,TabV2d);
1011 if (!Ok) { Cons = AppParCurves_TangencyPoint;}
1013 else if (nbP2d != 0)
1015 Ok = ToolLine::Curvature(SSP, Index, TabV2d);
1016 if (!Ok) { Cons = AppParCurves_TangencyPoint;}
1019 Ok = ToolLine::Curvature(SSP, Index, TabV);
1020 if (!Ok) { Cons = AppParCurves_TangencyPoint;}
1023 for (i = 1; i <= nbP; i++) {
1024 (TabV(i)).Coord(Vc(i2), Vc(i2+1), Vc(i2+2));
1028 for (i = 1; i <= nbP2d; i++) {
1029 (TabV2d(i)).Coord(Vc(i2), Vc(i2+1));
1036 if (Cons >= AppParCurves_TangencyPoint) {
1037 if (nbP != 0 && nbP2d != 0) {
1038 Ok = ToolLine::Tangency(SSP, Index, TabV, TabV2d);
1039 if (!Ok) { Cons = AppParCurves_PassPoint;}
1041 else if (nbP2d != 0) {
1042 Ok = ToolLine::Tangency(SSP, Index, TabV2d);
1043 if (!Ok) { Cons = AppParCurves_PassPoint;}
1046 Ok = ToolLine::Tangency(SSP, Index, TabV);
1047 if (!Ok) { Cons = AppParCurves_PassPoint;}
1052 TColgp_Array1OfPnt anArrPts3d1(1, mynbP), anArrPts3d2(1, mynbP);
1056 if(Index < ToolLine::LastPoint(SSP))
1058 ToolLine::Value(SSP, Index, anArrPts3d1);
1059 ToolLine::Value(SSP, Index+1, anArrPts3d2);
1062 {// (Index == ToolLine::LastPoint(theML))
1063 ToolLine::Value(SSP, Index-1, anArrPts3d1);
1064 ToolLine::Value(SSP, Index, anArrPts3d2);
1067 CheckTangents(anArrPts3d1, anArrPts3d2, TabV, TabV2d);
1071 TColgp_Array1OfPnt2d anArrPts2d1(1, mynbP2d), anArrPts2d2(1, mynbP2d);
1073 if(Index < ToolLine::LastPoint(SSP))
1075 ToolLine::Value(SSP, Index, anArrPts3d1, anArrPts2d1);
1076 ToolLine::Value(SSP, Index+1, anArrPts3d2, anArrPts2d2);
1079 {// (Index == ToolLine::LastPoint(theML))
1080 ToolLine::Value(SSP, Index-1, anArrPts3d1, anArrPts2d1);
1081 ToolLine::Value(SSP, Index, anArrPts3d2, anArrPts2d2);
1084 CheckTangents(anArrPts2d1, anArrPts2d2, TabV2d);
1087 for (i = 1; i <= nbP; i++) {
1088 (TabV(i)).Coord(Vt(i2), Vt(i2+1), Vt(i2+2));
1092 for (i = 1; i <= nbP2d; i++) {
1093 (TabV2d(i)).Coord(Vt(i2), Vt(i2+1));
1103 Standard_Integer AppParCurves_LeastSquare::NbBColumns(
1104 const MultiLine& SSP) const
1106 Standard_Integer BCol;
1107 BCol = (ToolLine::NbP3d(SSP))*3 +
1108 (ToolLine::NbP2d(SSP))*2;
1113 void AppParCurves_LeastSquare::Error(Standard_Real& F,
1114 Standard_Real& MaxE3d,
1115 Standard_Real& MaxE2d)
1118 if (!done) {throw StdFail_NotDone();}
1119 Standard_Integer i, j, k, i2, indexdeb, indexfin;
1120 Standard_Integer i21, i22;
1121 Standard_Real AA, BB, CC, Fi, FX, FY, FZ, AIJ;
1122 MaxE3d = MaxE2d = 0.0;
1125 math_Vector Px(1, nbpoles), Py(1, nbpoles), Pz(1, nbpoles);
1127 for (k = 1 ; k <= nbP+nbP2d; k++) {
1128 i21 = i2+1; i22 = i2+2;
1129 for (i = 1; i <= nbpoles; i++) {
1130 Px(i) = mypoles(i, i2);
1131 Py(i) = mypoles(i, i21);
1132 if (k <= nbP) Pz(i) = mypoles(i, i22);
1134 for (i = FirstP; i <= LastP; i++) {
1135 AA = 0.0; BB = 0.0; CC = 0.0;
1136 indexdeb = myindex(i) + 1;
1137 indexfin = indexdeb + deg;
1138 for (j = indexdeb; j <= indexfin; j++) {
1142 if (k <= nbP) CC += AIJ*Pz(j);
1144 FX = AA-mypoints(i, i2);
1145 FY = BB-mypoints(i, i21);
1148 FZ = CC-mypoints(i, i22);
1150 if (Fi > MaxE3d) MaxE3d = Fi;
1153 if (Fi > MaxE2d) MaxE2d = Fi;
1155 theError(i, k) = Fi;
1158 if (k <= nbP) i2 += 3;
1161 MaxE3d = Sqrt(MaxE3d);
1162 MaxE2d = Sqrt(MaxE2d);
1166 void AppParCurves_LeastSquare::ErrorGradient(math_Vector& Grad,
1168 Standard_Real& MaxE3d,
1169 Standard_Real& MaxE2d)
1171 if (!done) {throw StdFail_NotDone();}
1172 Standard_Integer i, j, k, i2, indexdeb, indexfin;
1173 Standard_Real AA, BB, CC, Fi, FX, FY, FZ, AIJ;
1174 // Standard_Real DAIJ, DAA, DBB, DCC, Gr, gr1= 0.0, gr2= 0.0;
1175 Standard_Real DAIJ, DAA, DBB, DCC, Gr;
1176 MaxE3d = MaxE2d = 0.0;
1177 // Standard_Integer i21, i22, diff = (deg-1);
1178 Standard_Integer i21, i22;
1181 math_Vector Px(1, nbpoles), Py(1, nbpoles), Pz(1, nbpoles);
1183 for (k = Grad.Lower(); k <= Grad.Upper(); k++) Grad(k) = 0.0;
1185 for (k = 1 ; k <= nbP+nbP2d; k++) {
1186 i21 = i2+1; i22 = i2+2;
1187 for (i = 1; i <= nbpoles; i++) {
1188 Px(i) = mypoles(i, i2);
1189 Py(i) = mypoles(i, i21);
1190 if (k <= nbP) Pz(i) = mypoles(i, i22);
1192 for (i = FirstP; i <= LastP; i++) {
1193 AA = 0.0; BB = 0.0; CC = 0.0; DAA = 0.0; DBB = 0.0; DCC = 0.0;
1194 indexdeb = myindex(i) + 1;
1195 indexfin = indexdeb + deg;
1196 for (j = indexdeb; j <= indexfin; j++) {
1197 AIJ = A(i, j); DAIJ = DA(i, j);
1198 AA += AIJ*Px(j); DAA += DAIJ*Px(j);
1199 BB += AIJ*Py(j); DBB += DAIJ*Py(j);
1205 FX = AA-mypoints(i, i2);
1206 FY = BB-mypoints(i, i2+1);
1208 Gr = 2.0*(DAA*FX + DBB*FY);
1211 FZ = CC-mypoints(i, i2+2);
1214 if (Fi > MaxE3d) MaxE3d = Fi;
1217 if (Fi > MaxE2d) MaxE2d = Fi;
1219 theError(i, k) = Fi;
1223 if (k <= nbP) i2 += 3;
1226 MaxE3d = Sqrt(MaxE3d);
1227 MaxE2d = Sqrt(MaxE2d);
1232 const math_Matrix& AppParCurves_LeastSquare::Distance()
1234 if (!iscalculated) {
1235 for (Standard_Integer i = myfirstp; i <= mylastp; i++) {
1236 for (Standard_Integer j = 1; j <= nbP+nbP2d; j++) {
1237 theError(i, j) = Sqrt(theError(i, j));
1240 iscalculated = Standard_True;
1246 Standard_Real AppParCurves_LeastSquare::FirstLambda() const
1251 Standard_Real AppParCurves_LeastSquare::LastLambda() const
1258 Standard_Boolean AppParCurves_LeastSquare::IsDone() const
1264 AppParCurves_MultiCurve AppParCurves_LeastSquare::BezierValue()
1266 if (!myknots.IsNull()) throw Standard_NoSuchObject();
1267 return (AppParCurves_MultiCurve)(BSplineValue());
1271 const AppParCurves_MultiBSpCurve& AppParCurves_LeastSquare::BSplineValue()
1273 if (!done) {throw StdFail_NotDone();}
1275 Standard_Integer i, j, j2, npoints = nbP+nbP2d;
1278 Standard_Integer ideb = resinit, ifin = resfin;
1279 if (ideb >= 2) ideb = 2;
1280 if (ifin <= nbpoles-1) ifin = nbpoles-1;
1282 // On met le resultat dans les curves correspondantes
1283 for (i = ideb; i <= ifin; i++) {
1285 AppParCurves_MultiPoint MPole(nbP, nbP2d);
1286 for (j = 1; j <= nbP; j++) {
1287 Pt.SetCoord(mypoles(i, j2), mypoles(i, j2+1), mypoles(i,j2+2));
1288 MPole.SetPoint(j, Pt);
1291 for (j = nbP+1;j <= npoints; j++) {
1292 Pt2d.SetCoord(mypoles(i, j2), mypoles(i, j2+1));
1293 MPole.SetPoint2d(j, Pt2d);
1296 SCU.SetValue(i, MPole);
1303 const math_Matrix& AppParCurves_LeastSquare::FunctionMatrix() const
1305 if (!done) {throw StdFail_NotDone();}
1310 const math_Matrix& AppParCurves_LeastSquare::DerivativeFunctionMatrix() const
1312 if (!done) {throw StdFail_NotDone();}
1319 Standard_Integer AppParCurves_LeastSquare::
1320 TheFirstPoint(const AppParCurves_Constraint FirstCons,
1321 const Standard_Integer FirstPoint) const
1323 if (FirstCons == AppParCurves_NoConstraint)
1326 return FirstPoint + 1;
1331 Standard_Integer AppParCurves_LeastSquare::
1332 TheLastPoint(const AppParCurves_Constraint LastCons,
1333 const Standard_Integer LastPoint) const
1335 if (LastCons == AppParCurves_NoConstraint)
1338 return LastPoint - 1;
1342 void AppParCurves_LeastSquare::ComputeFunction(const math_Vector& Parameters)
1344 if (myknots.IsNull()) {
1345 AppParCurves::Bernstein(nbpoles, Parameters, A, DA);
1348 AppParCurves::SplineFunction(nbpoles, deg, Parameters,
1349 Vflatknots, A, DA, myindex);
1355 const math_Matrix& AppParCurves_LeastSquare::Points() const
1360 const math_Matrix& AppParCurves_LeastSquare::Poles() const
1367 const math_IntegerVector& AppParCurves_LeastSquare::KIndex() const
1375 void AppParCurves_LeastSquare::MakeTAA(math_Vector& TheA,
1378 Standard_Integer i, j, k, Ci, i2, i21, i22;
1379 Standard_Real xx = 0.0, yy = 0.0;
1381 Standard_Integer Nincx = resfin-resinit+1;
1382 Standard_Integer Nrow, Neq = LastP-FirstP+1;
1384 Standard_Integer Ninc1;
1386 if (FirstConstraint >= AppParCurves_TangencyPoint &&
1387 LastConstraint >= AppParCurves_TangencyPoint) {
1392 Standard_Integer myfirst = A.LowerRow();
1393 Standard_Integer ix, iy, iz;
1394 Standard_Integer mylast = myfirst+Nlignes-1;
1395 Standard_Integer k1;
1396 Standard_Real taf1 = 0.0, taf2 = 0.0, taf3 = 0.0,
1397 tab1 = 0.0, tab2 = 0.0;
1398 Standard_Integer nb, inc, jinit, jfin, u;
1399 Standard_Integer indexdeb, indexfin;
1400 Standard_Integer NA1 = NA-1;
1401 Standard_Real v1=0, v2=0, b;
1402 Standard_Real Ai2, Aid, Akj;
1403 math_Vector myB(myfirst, mylast, 0.0),
1404 myV1(myfirst, mylast, 0.0),
1405 myV2(myfirst, mylast, 0.0);
1406 math_Vector TheV1(1, Ninc, 0.0), TheV2(1, Ninc, 0.0);
1409 for (i = FirstP; i <= LastP; i++) {
1411 Aid = A(i, nbpoles-1);
1412 if (FirstConstraint >= AppParCurves_PassPoint) xx = A(i, 1);
1413 if (FirstConstraint >= AppParCurves_TangencyPoint) xx += Ai2;
1414 if (LastConstraint >= AppParCurves_PassPoint) yy = A(i, nbpoles);
1415 if (LastConstraint >= AppParCurves_TangencyPoint) yy += Aid;
1417 Nrow = myfirst-FirstP;
1418 for (Ci = 1; Ci <= nbP; Ci++) {
1419 i21 = i2+1; i22 = i2+2;
1420 ix = i+Nrow; iy = ix+Neq; iz = iy+Neq;
1421 if (FirstConstraint >= AppParCurves_TangencyPoint) {
1422 myV1(ix) = Ai2*Vec1t(i2);
1423 myV1(iy) = Ai2*Vec1t(i21);
1424 myV1(iz) = Ai2*Vec1t(i22);
1426 if (LastConstraint >= AppParCurves_TangencyPoint) {
1427 myV2(ix) = -Aid*Vec2t(i2);
1428 myV2(iy) = -Aid*Vec2t(i21);
1429 myV2(iz) = -Aid*Vec2t(i22);
1431 myB(ix) = mypoints(i, i2) - xx*mypoints(myfirstp, i2)
1432 - yy*mypoints(mylastp, i2);
1433 myB(iy) = mypoints(i, i21) - xx*mypoints(myfirstp, i21)
1434 - yy*mypoints(mylastp, i21);
1435 myB(iz) = mypoints(i, i22) - xx*mypoints(myfirstp, i22)
1436 - yy*mypoints(mylastp, i22);
1438 Nrow = Nrow + 3*Neq;
1441 for (Ci = 1; Ci <= nbP2d; Ci++) {
1442 i21 = i2+1; i22 = i2+2;
1443 ix = i+Nrow; iy = ix+Neq;
1444 if (FirstConstraint >= AppParCurves_TangencyPoint) {
1445 myV1(ix) = Ai2*Vec1t(i2);
1446 myV1(iy) = Ai2*Vec1t(i21);
1448 if (LastConstraint >= AppParCurves_TangencyPoint) {
1449 myV2(ix) = -Aid*Vec2t(i2);
1450 myV2(iy) = -Aid*Vec2t(i21);
1452 myB(ix) = mypoints(i, i2) - xx*mypoints(myfirstp, i2)
1453 - yy*mypoints(mylastp, i2);
1454 myB(iy) = mypoints(i, i21) - xx*mypoints(myfirstp, i21)
1455 - yy*mypoints(mylastp, i21);
1456 Nrow = Nrow + 2*Neq;
1463 // Construction de TA*A et TA*B:
1465 for (k = FirstP; k <= LastP; k++) {
1466 indexdeb = myindex(k)+1;
1467 indexfin = indexdeb + deg;
1468 jinit = Max(resinit, indexdeb);
1469 jfin = Min(resfin, indexfin);
1470 k1 = k + myfirst - FirstP;
1471 for (i = 0; i <= NA1; i++) {
1473 if (FirstConstraint >= AppParCurves_TangencyPoint)
1475 if (LastConstraint >= AppParCurves_TangencyPoint)
1478 inc = i*Nincx-resinit+1;
1479 for (j = jinit; j <= jfin; j++) {
1482 if (FirstConstraint >= AppParCurves_TangencyPoint)
1484 if (LastConstraint >= AppParCurves_TangencyPoint)
1488 if (FirstConstraint >= AppParCurves_TangencyPoint) {
1492 if (LastConstraint >= AppParCurves_TangencyPoint) {
1496 if (FirstConstraint >= AppParCurves_TangencyPoint &&
1497 LastConstraint >= AppParCurves_TangencyPoint) {
1504 if (FirstConstraint >= AppParCurves_TangencyPoint) {
1505 TheV1(Ninc1) = taf1;
1506 myTAB(Ninc1) = tab1;
1508 if (LastConstraint >= AppParCurves_TangencyPoint) {
1512 if (FirstConstraint >= AppParCurves_TangencyPoint &&
1513 LastConstraint >= AppParCurves_TangencyPoint) {
1514 TheV2(Ninc1) = taf3;
1518 if (resinit <= resfin) {
1519 math_IntegerVector Index(1, Nincx);
1521 math_Vector AA(1, Index(Nincx));
1524 Standard_Integer kk = 1;
1525 for (k = 1; k <= NA; k++) {
1526 for(i = 1; i <= AA.Length(); i++) {
1533 Standard_Integer length = TheA.Length();
1535 if (FirstConstraint >= AppParCurves_TangencyPoint &&
1536 LastConstraint >= AppParCurves_TangencyPoint) {
1537 for (j = 1; j <= Ninc1; j++)
1538 TheA(length- 2*Ninc+j+1) = TheV1(j);
1539 for (j = 1; j <= Ninc; j++)
1540 TheA(length- Ninc+j) = TheV2(j);
1544 else if (FirstConstraint >= AppParCurves_TangencyPoint) {
1545 for (j = 1; j <= Ninc; j++)
1546 TheA(length- Ninc+j) = TheV1(j);
1549 else if (LastConstraint >= AppParCurves_TangencyPoint) {
1550 for (j = 1; j <= Ninc; j++)
1551 TheA(length- Ninc+j) = TheV2(j);
1558 void AppParCurves_LeastSquare::MakeTAA(math_Vector& AA,
1561 Standard_Integer i, j, k;
1562 Standard_Integer indexdeb, indexfin, jinit, jfin;
1563 Standard_Integer iinit, ifin;
1565 math_Matrix TheA(resinit, resfin, resinit, resfin);
1568 for (k = FirstP ; k <= LastP; k++) {
1569 indexdeb = myindex(k)+1;
1570 indexfin = indexdeb + deg;
1571 jinit = Max(resinit, indexdeb);
1572 jfin = Min(resfin, indexfin);
1573 for (i = jinit; i <= jfin; i++) {
1575 for (j = jinit; j <= i; j++) {
1576 TheA(i, j) += A(k, j) * Akj;
1578 for (j = 1; j <= B2.ColNumber(); j++) {
1579 myTAB(i, j) += Akj*B2(k, j);
1584 Standard_Integer len;
1585 if (!myknots.IsNull()) len = myknots->Length();
1587 Standard_Integer d, i2 = 1;
1590 ifin = Min(resfin, deg+1);
1591 for (k = 2; k <= len; k++) {
1592 for (i = iinit; i <= ifin; i++) {
1593 for (j = jinit; j <= i; j++) {
1594 AA(i2) = TheA(i, j);
1598 if (!mymults.IsNull()) {
1600 d = ifin + mymults->Value(k);
1601 ifin = Min(d, resfin);
1602 jinit = Max(resinit, d - deg);
1608 void AppParCurves_LeastSquare::MakeTAA(math_Vector& AA)
1610 Standard_Integer i, j, k;
1611 Standard_Integer indexdeb, indexfin, jinit, jfin;
1612 Standard_Integer iinit, ifin;
1614 math_Matrix TheA(resinit, resfin, resinit, resfin, 0.0);
1617 for (k = FirstP ; k <= LastP; k++) {
1618 indexdeb = myindex(k)+1;
1619 indexfin = indexdeb + deg;
1620 jinit = Max(resinit, indexdeb);
1621 jfin = Min(resfin, indexfin);
1622 for (i = jinit; i <= jfin; i++) {
1624 for (j = jinit; j <= i; j++) {
1625 TheA(i, j) += A(k, j) * Akj;
1631 Standard_Integer i2 = 1;
1634 ifin = Min(resfin, deg+1);
1635 Standard_Integer len, d;
1636 if (!myknots.IsNull()) len = myknots->Length();
1638 for (k = 2; k <= len; k++) {
1639 for (i = iinit; i <= ifin; i++) {
1640 for (j = jinit; j <= i; j++) {
1641 AA(i2) = TheA(i, j);
1645 if (!mymults.IsNull()) {
1647 d = ifin + mymults->Value(k);
1648 ifin = Min(d, resfin);
1649 jinit = Max(resinit, d - deg);
1657 void AppParCurves_LeastSquare::SearchIndex(math_IntegerVector& Index)
1659 Standard_Integer iinit, jinit, ifin;
1660 Standard_Integer i, j, k, d, i2 = 1;
1661 Standard_Integer len;
1662 Standard_Integer Nincx = resfin-resinit+1;
1665 if (myknots.IsNull()) {
1666 if (resinit <= resfin) {
1667 Standard_Integer l = 1;
1668 for (i = 2; i <= Nincx; i++) {
1670 Index(l) = Index(l-1)+i;
1678 ifin = Min(resfin, deg+1);
1679 len = myknots->Length();
1681 for (k = 2; k <= len; k++) {
1682 for (i = iinit; i <= ifin; i++) {
1683 for (j = jinit; j <= i; j++) {
1685 Index(i2) = Index(i2-1) + i-jinit+1;
1690 d = ifin + mymults->Value(k);
1691 ifin = Min(d, resfin);
1692 jinit = Max(resinit, d - deg);