39 #include <visp3/core/vpBSpline.h>
40 #include <visp3/core/vpDebug.h>
49 : controlPoints(), knots(), p(3),
59 : controlPoints(bspline.controlPoints), knots(bspline.knots), p(bspline.p),
60 crossingPoints(bspline.crossingPoints)
86 unsigned int m = (
unsigned int)l_knots.size() - 1;
88 if (l_u > l_knots.back()) {
91 return ((
unsigned int)(m - l_p - 1));
95 if (std::fabs(l_u - l_knots.back()) <=
96 std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
97 return ((
unsigned int)(m - l_p - 1));
100 double high = m - l_p;
101 double middle = (low + high) / 2.0;
103 while (l_u < l_knots[(
unsigned int)middle] || l_u >= l_knots[(
unsigned int)middle + 1]) {
108 middle = (low + high) / 2.0;
111 return (
unsigned int)middle;
148 std::vector<double> &l_knots)
150 vpBasisFunction *N =
new vpBasisFunction[l_p + 1];
154 double *left =
new double[l_p + 1];
155 double *right =
new double[l_p + 1];
158 for (
unsigned int j = 1; j <= l_p; j++) {
159 left[j] = l_u - l_knots[l_i + 1 - j];
160 right[j] = l_knots[l_i + j] - l_u;
163 for (
unsigned int r = 0; r < j; r++) {
164 temp = N[r].value / (right[r + 1] + left[j - r]);
165 N[r].value = saved + right[r + 1] * temp;
166 saved = left[j - r] * temp;
170 for (
unsigned int j = 0; j < l_p + 1; j++) {
171 N[j].i = l_i - l_p + j;
234 std::vector<double> &l_knots)
237 N =
new vpBasisFunction *[l_der + 1];
238 for (
unsigned int j = 0; j <= l_der; j++)
239 N[j] =
new vpBasisFunction[l_p + 1];
245 double *left =
new double[l_p + 1];
246 double *right =
new double[l_p + 1];
249 for (
unsigned int j = 1; j <= l_p; j++) {
250 left[j] = l_u - l_knots[l_i + 1 - j];
251 right[j] = l_knots[l_i + j] - l_u;
254 for (
unsigned int r = 0; r < j; r++) {
255 ndu[j][r] = right[r + 1] + left[j - r];
256 temp = ndu[r][j - 1] / ndu[j][r];
257 ndu[r][j] = saved + right[r + 1] * temp;
258 saved = left[j - r] * temp;
263 for (
unsigned int j = 0; j <= l_p; j++) {
264 N[0][j].value = ndu[j][l_p];
265 N[0][j].i = l_i - l_p + j;
272 vpTRACE(
"l_der must be under or equal to l_p");
281 for (
unsigned int r = 0; r <= l_p; r++) {
285 for (
unsigned int k = 1; k <= l_der; k++) {
290 a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
291 d = a[s2][0] * ndu[(
unsigned int)rk][pk];
297 j1 = (
unsigned int)(-rk);
304 for (
unsigned int j = j1; j <= j2; j++) {
305 a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][(
unsigned int)rk + j];
306 d += a[s2][j] * ndu[(
unsigned int)rk + j][pk];
310 a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
311 d += a[s2][k] * ndu[r][pk];
314 N[k][r].i = l_i - l_p + r;
325 for (
unsigned int k = 1; k <= l_der; k++) {
326 for (
unsigned int j = 0; j <= l_p; j++)
381 std::vector<vpImagePoint> &l_controlPoints)
388 for (
unsigned int j = 0; j <= l_p; j++) {
389 ic = ic + N[j].value * (l_controlPoints[l_i - l_p + j]).get_i();
390 jc = jc + N[j].value * (l_controlPoints[l_i - l_p + j]).get_j();
416 for (
unsigned int j = 0; j <= p; j++) {
417 ic = ic + N[j].value * (controlPoints[N[0].i + j]).get_i();
418 jc = jc + N[j].value * (controlPoints[N[0].i + j]).get_j();
451 std::vector<double> &l_knots, std::vector<vpImagePoint> &l_controlPoints)
459 vpTRACE(
"l_der must be under or equal to l_p");
464 for (
unsigned int k = 0; k <= du; k++) {
465 derivate[k].
set_ij(0.0, 0.0);
466 for (
unsigned int j = 0; j <= l_p; j++) {
467 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_i());
468 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_j());
472 for (
unsigned int j = 0; j <= l_der; j++)
504 vpTRACE(
"der must be under or equal to p");
509 for (
unsigned int k = 0; k <= du; k++) {
510 derivate[k].
set_ij(0.0, 0.0);
511 for (
unsigned int j = 0; j <= p; j++) {
512 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_i());
513 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_j());
517 for (
unsigned int j = 0; j <= der; j++)
Class that provides tools to compute and manipulate a B-Spline curve.
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
static vpImagePoint * computeCurveDers(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
static unsigned int findSpan(double l_u, unsigned int l_p, std::vector< double > &l_knots)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_ij(double ii, double jj)
static Type maximum(const Type &a, const Type &b)
static int round(double x)
Implementation of a matrix and operations on matrices.