1 // Created on: 1998-12-08
2 // Created by: Igor FEOKTISTOV
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 void AppParCurves_Variational::Project(const Handle(FEmTool_Curve)& C,
18 const TColStd_Array1OfReal& Ti,
19 TColStd_Array1OfReal& ProjTi,
20 TColStd_Array1OfReal& Distance,
21 Standard_Integer& NumPoints,
22 Standard_Real& MaxErr,
23 Standard_Real& QuaErr,
24 Standard_Real& AveErr,
25 const Standard_Integer NbIterations) const
30 const Standard_Real Seuil = 1.e-9, Eps = 1.e-12;
32 MaxErr = QuaErr = AveErr = 0.;
34 Standard_Integer Ipnt, NItCv, Iter, i, i0 = -myDimension, d0 = Distance.Lower() - 1;
36 Standard_Real TNew, Dist, T0, Dist0, F1, F2, Aux, DF, Ecart;
38 Standard_Boolean EnCour;
40 TColStd_Array1OfReal ValOfC(1, myDimension), FirstDerOfC(1, myDimension),
41 SecndDerOfC(1, myDimension);
43 for(Ipnt = 1; Ipnt <= ProjTi.Length(); Ipnt++) {
49 EnCour = Standard_True;
55 for(i = 1; i <= myDimension; i++) {
56 Aux = ValOfC(i) - myTabPoints->Value(i0 + i);
61 // ------- Newton's method for solving (C'(t),C(t) - P) = 0
69 C->D2(TNew, SecndDerOfC);
70 C->D1(TNew, FirstDerOfC);
73 for(i = 1; i <= myDimension; i++) {
74 Aux = ValOfC(i) - myTabPoints->Value(i0 + i);
76 F1 += Aux*DF; // (C'(t),C(t) - P)
77 F2 += DF*DF + Aux * SecndDerOfC(i); // ((C'(t),C(t) - P))'
81 EnCour = Standard_False;
83 // Formula of Newton x(k+1) = x(k) - F(x(k))/F'(x(k))
85 if(TNew < 0.) TNew = 0.;
86 if(TNew > 1.) TNew = 1.;
94 for(i = 1; i <= myDimension; i++) {
95 Aux = ValOfC(i) - myTabPoints->Value(i0 + i);
100 Ecart = Dist0 - Dist;
102 if(Ecart <= -Seuil) {
103 // Pas d'amelioration on s'arrete
104 EnCour = Standard_False;
108 else if(Ecart <= Seuil)
114 if((NItCv >= 2) || (Iter >= NbIterations)) EnCour = Standard_False;
121 Distance(d0 + Ipnt) = Dist;
126 QuaErr += Dist * Dist;
130 NumPoints = NumPoints + myFirstPoint - 1;// Setting NumPoints to interval [myFirstPoint, myLastPoint]