1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 // 30-01-1996 : PMN Version originale
17 #define No_Standard_RangeError
18 #define No_Standard_OutOfRange
22 #include <BSplCLib.hxx>
23 #include <FairCurve_DistributionOfTension.hxx>
24 #include <gp_Pnt2d.hxx>
26 #include <math_Matrix.hxx>
27 #include <math_Vector.hxx>
29 FairCurve_DistributionOfTension::FairCurve_DistributionOfTension(const Standard_Integer BSplOrder,
30 const Handle(TColStd_HArray1OfReal)& FlatKnots,
31 const Handle(TColgp_HArray1OfPnt2d)& Poles,
32 const Standard_Integer DerivativeOrder,
33 const Standard_Real LengthSliding,
34 const FairCurve_BattenLaw& Law,
35 const Standard_Integer NbValAux,
36 const Standard_Boolean Uniform ) :
37 FairCurve_DistributionOfEnergy(BSplOrder,
42 MyLengthSliding (LengthSliding),
45 if (Uniform) {MyLaw.Value(0.5, MyHeight);} // it used in MVC to avoid Parametrization Problemes
51 Standard_Boolean FairCurve_DistributionOfTension::Value(const math_Vector& TParam, math_Vector& FTension)
53 Standard_Boolean Ok = Standard_True;
54 Standard_Integer ier, ii, jj, kk;
56 Standard_Integer LastGradientIndex, FirstNonZero, LastZero;
58 // (0.0) initialisations generales
60 math_Matrix Base(1, 3, 1, MyBSplOrder ); // On shouhaite utiliser la derive premieres
61 // Dans EvalBsplineBasis C' <=> DerivOrder = 2
62 // et il faut ajouter 1 rang dans la matrice Base => 3 rang
64 ier = BSplCLib::EvalBsplineBasis(1, MyBSplOrder,
65 MyFlatKnots->Array1(), TParam(TParam.Lower()),
67 if (ier != 0) return Standard_False;
68 LastZero = FirstNonZero - 1;
69 FirstNonZero = 2*LastZero+1;
71 // (0.1) evaluation de CPrim
72 for (ii= 1; ii<= MyBSplOrder; ii++) {
73 CPrim += Base(2, ii) * MyPoles->Value(ii+LastZero).Coord();
76 // (1) Evaluation de la tension locale --------------------------------
77 Standard_Real NormeCPrim = CPrim.Modulus();
78 Standard_Real Hauteur, Difference;
80 if (MyHeight > 0) {Hauteur = MyHeight;} // it used in MVC to avoid Parametrization Problemes
82 Ok = MyLaw.Value (TParam(TParam.Lower()), Hauteur);
85 Difference = NormeCPrim - MyLengthSliding;
87 FTension(FTension.Lower()) = Hauteur * pow(Difference, 2) / MyLengthSliding ;
89 if (MyDerivativeOrder >= 1) {
90 // (2) Evaluation du gradient de la tension locale ----------------------
91 math_Vector GradDifference (1, 2*MyBSplOrder+MyNbValAux);
92 Standard_Real Xaux, Yaux, Facteur;
94 Xaux = CPrim.X() / NormeCPrim;
95 Yaux = CPrim.Y() / NormeCPrim;
96 Facteur = 2 * Hauteur * Difference / MyLengthSliding;
98 kk = FTension.Lower() + FirstNonZero;
100 for (ii=1; ii<= MyBSplOrder; ii++) {
101 GradDifference(jj) = Base(2, ii) * Xaux;
102 FTension(kk) = Facteur * GradDifference(jj);
104 GradDifference(jj) = Base(2, ii) * Yaux;
105 FTension(kk+1) = Facteur * GradDifference(jj);
109 if (MyNbValAux == 1) {
110 LastGradientIndex = FTension.Lower() + 2*MyPoles->Length() + 1;
111 GradDifference( GradDifference.Upper()) = (1 - pow( NormeCPrim/MyLengthSliding, 2));
112 FTension(LastGradientIndex) = Hauteur * GradDifference(GradDifference.Upper());
115 else { LastGradientIndex = FTension.Lower() + 2*MyPoles->Length(); }
118 if (MyDerivativeOrder >= 2) {
120 // (3) Evaluation du Hessien de la tension locale ----------------------
122 Standard_Real FacteurX = Difference * (1-pow(Xaux,2)) / NormeCPrim;
123 Standard_Real FacteurY = Difference * (1-pow(Yaux,2)) / NormeCPrim;
124 Standard_Real FacteurXY = - Difference * Xaux*Yaux / NormeCPrim;
125 Standard_Real Produit;
126 Standard_Integer k1, k2;
128 Facteur = 2 * Hauteur / MyLengthSliding;
131 k2 = LastGradientIndex + (kk-1)*kk/2;
133 for (ii=2; ii<= 2*MyBSplOrder; ii+=2) {
134 k1 = k2+FirstNonZero;
137 for (jj=2; jj< ii; jj+=2) {
138 Produit = Base(2, ii/2) * Base(2, jj/2);
140 FTension(k1) = Facteur * ( GradDifference(ii-1)*GradDifference(jj-1)
141 + FacteurX * Produit) ; // derivation en XiXj
143 FTension(k1) = Facteur * ( GradDifference(ii)*GradDifference(jj-1)
144 + FacteurXY * Produit); // derivation en YiXj
146 FTension(k2) = Facteur * ( GradDifference(ii-1)*GradDifference(jj)
147 + FacteurXY * Produit); // derivation en XiYj
149 FTension(k2) = Facteur * ( GradDifference(ii)*GradDifference(jj)
150 + FacteurY * Produit); // derivation en YiYj
153 // cas ou jj = ii : remplisage en triangle
154 Produit = pow (Base(2, ii/2), 2);
156 FTension(k1) = Facteur * ( GradDifference(ii-1)*GradDifference(ii-1)
157 + FacteurX * Produit) ; // derivation en XiXi
158 FTension(k2) = Facteur * ( GradDifference(ii)*GradDifference(ii-1)
159 + FacteurXY * Produit); // derivation en XiYi
161 FTension(k2) = Facteur * ( GradDifference(ii)*GradDifference(ii)
162 + FacteurY * Produit); // derivation en YiYi
164 if (MyNbValAux == 1) {
165 FacteurX = -2*CPrim.X()*Hauteur / pow (MyLengthSliding, 2);
166 FacteurY = -2*CPrim.Y()*Hauteur / pow (MyLengthSliding, 2);
168 ii = LastGradientIndex-FTension.Lower();
169 kk = LastGradientIndex + (ii-1)*ii/2 + FirstNonZero;
170 for (ii=1; ii<= MyBSplOrder; ii++) {
171 FTension(kk) = FacteurX * Base(2, ii);
173 FTension(kk) = FacteurY * Base(2, ii);
176 FTension(FTension.Upper()) = 2 * Hauteur * pow (NormeCPrim/MyLengthSliding, 2)