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.
15 #define No_Standard_RangeError
16 #define No_Standard_OutOfRange
19 #include <AppParCurves.hxx>
20 #include <BSplCLib.hxx>
21 #include <gp_Pnt2d.hxx>
22 #include <gp_Vec2d.hxx>
23 #include <math_Matrix.hxx>
24 #include <TColStd_Array1OfReal.hxx>
26 void AppParCurves::BernsteinMatrix(const Standard_Integer NbPoles,
30 Standard_Integer i, j, id;
31 Standard_Real u0, u1, y0, y1, xs;
32 Standard_Integer first = U.Lower(), last = U.Upper();
33 math_Vector B(1, NbPoles-1);
36 for (i = first; i <= last; i++) {
41 for (id = 2; id <= NbPoles-1; id++) {
45 for (j = 2; j <= id-1; j++) {
54 A(i, NbPoles) = u0*B(NbPoles-1);
55 for (j = 2; j <= NbPoles-1; j++) {
56 A(i, j) = u1*B(j)+u0*B(j-1);
62 void AppParCurves::Bernstein(const Standard_Integer NbPoles,
67 Standard_Integer i, j, id, Ndeg = NbPoles-1;
68 Standard_Real u0, u1, y0, y1, xs, bj, bj1;
69 Standard_Integer first = U.Lower(), last = U.Upper();
70 math_Vector B(1, NbPoles-1);
73 for (i = first; i <= last; i++) {
78 for (id = 2; id <= NbPoles-1; id++) {
82 for (j = 2; j <= id-1; j++) {
90 DA(i, 1) = -Ndeg*B(1);
91 DA(i, NbPoles) = Ndeg*B(NbPoles-1);
93 A(i, NbPoles) = u0*B(NbPoles-1);
94 for (j = 2; j <= NbPoles-1; j++) {
95 bj = B(j); bj1 = B(j-1);
96 DA(i,j) = Ndeg*(bj1-bj);
97 A(i, j) = u1*bj+u0*bj1;
103 void AppParCurves::SecondDerivativeBernstein(const Standard_Real U,
105 // Standard_Real U1 = 1-U, Y0, Y1, Xs;
106 Standard_Real Y0, Y1, Xs;
107 Standard_Integer NbPoles = DDA.Length();
108 Standard_Integer id, j, N4, deg = NbPoles-1;
110 math_Vector B(1, deg-1);
113 // Cas particulier si degre = 1:
125 for (id = 2; id <= deg-1; id++) {
129 for (j = 2; j <= id-1; j++) {
139 DDA(2) = N4*(-2*B(1) + B(2));
140 DDA(deg) = N4*(B(deg-2) - 2*B(deg-1));
141 DDA(deg+1) = N4*B(deg-1);
143 for(j = 2; j <= deg-2; j++) {
144 DDA(j+1) = N4*(B(j-1)-2*B(j)+B(j+1));
151 void AppParCurves::SplineFunction(const Standard_Integer nbpoles,
152 const Standard_Integer deg,
153 const math_Vector& Parameters,
154 const math_Vector& flatknots,
157 math_IntegerVector& index)
159 // Standard_Real U, NewU, co, diff, t1, t2;
160 Standard_Real U, NewU;
163 // Standard_Integer i, j, k, iter, in, ik, deg1 = deg+1;
164 Standard_Integer i, j, deg1 = deg+1;
165 // Standard_Integer oldkindex, kindex, theindex, ttindex;
166 Standard_Integer oldkindex, kindex, theindex;
167 math_Vector locpoles(1 , deg1);
168 math_Vector locdpoles(1 , deg1);
169 Standard_Integer firstp = Parameters.Lower(), lastp = Parameters.Upper();
171 TColStd_Array1OfReal Aflatknots(flatknots.Lower(), flatknots.Upper());
172 for (i = flatknots.Lower(); i <= flatknots.Upper(); i++) {
173 Aflatknots(i) = flatknots(i);
179 Standard_Integer pp, qq;
180 Standard_Real Saved, Inverse, LocalInverse, locqq, locdqq, val;
182 for (i = firstp; i <= lastp; i++) {
186 BSplCLib::LocateParameter(deg, Aflatknots, U, Standard_False,
187 deg1, nbpoles+1, kindex, NewU);
191 // On stocke les index:
192 index(i) = kindex - deg-1;
196 for (qq = 2; qq <= deg; qq++) {
198 for (pp = 1; pp <= qq-1; pp++) {
199 Inverse = 1.0 / (flatknots(kindex + pp) - flatknots(kindex - qq + pp + 1)) ;
200 Saved = (U - flatknots(kindex - qq + pp + 1)) * Inverse * locpoles(pp);
201 locpoles(pp) *= (flatknots(kindex + pp) - U) * Inverse ;
202 locpoles(pp) += locpoles(qq) ;
203 locpoles(qq) = Saved ;
208 for (pp = 1; pp <= deg; pp++) {
209 locdpoles(pp)= locpoles(pp);
214 for (pp = 1; pp <= deg; pp++) {
215 Inverse = 1.0 / (flatknots(kindex + pp) - flatknots(kindex - qq + pp + 1));
216 Saved = (U - flatknots(kindex - qq + pp + 1)) * Inverse * locpoles(pp);
217 locpoles(pp) *= (flatknots(kindex + pp) - U) * Inverse;
218 locpoles(pp) += locqq;
220 LocalInverse = (Standard_Real) (deg) * Inverse;
221 Saved = LocalInverse * locdpoles(pp);
222 locdpoles(pp) *= - LocalInverse ;
223 locdpoles(pp) += locdqq;
227 locpoles(qq) = locqq;
228 locdpoles(qq) = locdqq;
230 for (j = 1; j <= deg1; j++) {
232 theindex = j+oldkindex-deg1;
233 A(i, theindex) = val;
234 DA(i, theindex) = locdpoles(j);
237 for (j = 1; j < oldkindex-deg; j++)
238 A(i, j) = DA(i, j) = 0.0;
239 for (j = oldkindex+1; j <= nbpoles; j++)
240 A(i, j) = DA(i, j) = 0.0;