// Created on: 1998-12-08 // Created by: Igor FEOKTISTOV // Copyright (c) 1998-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. void AppParCurves_Variational::Project(const Handle(FEmTool_Curve)& C, const TColStd_Array1OfReal& Ti, TColStd_Array1OfReal& ProjTi, TColStd_Array1OfReal& Distance, Standard_Integer& NumPoints, Standard_Real& MaxErr, Standard_Real& QuaErr, Standard_Real& AveErr, const Standard_Integer NbIterations) const { // Initialisation const Standard_Real Seuil = 1.e-9, Eps = 1.e-12; MaxErr = QuaErr = AveErr = 0.; Standard_Integer Ipnt, NItCv, Iter, i, i0 = -myDimension, d0 = Distance.Lower() - 1; Standard_Real TNew, Dist, T0, Dist0, F1, F2, Aux, DF, Ecart; Standard_Boolean EnCour; TColStd_Array1OfReal ValOfC(1, myDimension), FirstDerOfC(1, myDimension), SecndDerOfC(1, myDimension); for(Ipnt = 1; Ipnt <= ProjTi.Length(); Ipnt++) { i0 += myDimension; TNew = Ti(Ipnt); EnCour = Standard_True; NItCv = 0; Iter = 0; C->D0(TNew, ValOfC); Dist = 0; for(i = 1; i <= myDimension; i++) { Aux = ValOfC(i) - myTabPoints->Value(i0 + i); Dist += Aux * Aux; } Dist = Sqrt(Dist); // ------- Newton's method for solving (C'(t),C(t) - P) = 0 while( EnCour ) { Iter++; T0 = TNew; Dist0 = Dist; C->D2(TNew, SecndDerOfC); C->D1(TNew, FirstDerOfC); F1 = F2 = 0.; for(i = 1; i <= myDimension; i++) { Aux = ValOfC(i) - myTabPoints->Value(i0 + i); DF = FirstDerOfC(i); F1 += Aux*DF; // (C'(t),C(t) - P) F2 += DF*DF + Aux * SecndDerOfC(i); // ((C'(t),C(t) - P))' } if(Abs(F2) < Eps) EnCour = Standard_False; else { // Formula of Newton x(k+1) = x(k) - F(x(k))/F'(x(k)) TNew -= F1 / F2; if(TNew < 0.) TNew = 0.; if(TNew > 1.) TNew = 1.; // Analysis of result C->D0(TNew, ValOfC); Dist = 0; for(i = 1; i <= myDimension; i++) { Aux = ValOfC(i) - myTabPoints->Value(i0 + i); Dist += Aux * Aux; } Dist = Sqrt(Dist); Ecart = Dist0 - Dist; if(Ecart <= -Seuil) { // Pas d'amelioration on s'arrete EnCour = Standard_False; TNew = T0; Dist = Dist0; } else if(Ecart <= Seuil) // Convergence NItCv++; else NItCv = 0; if((NItCv >= 2) || (Iter >= NbIterations)) EnCour = Standard_False; } } ProjTi(Ipnt) = TNew; Distance(d0 + Ipnt) = Dist; if(Dist > MaxErr) { MaxErr = Dist; NumPoints = Ipnt; } QuaErr += Dist * Dist; AveErr += Dist; } NumPoints = NumPoints + myFirstPoint - 1;// Setting NumPoints to interval [myFirstPoint, myLastPoint] }