Visual Servoing Platform  version 3.6.1 under development (2024-05-26)
vpBSpline.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * This class implements the B-Spline
32  */
33 
34 #ifndef vpBSpline_H
35 #define vpBSpline_H
36 
42 #include <visp3/core/vpImagePoint.h>
43 
44 #include <list>
45 #include <vector>
46 #include <visp3/core/vpMatrix.h>
47 
48 #ifndef DOXYGEN_SHOULD_SKIP_THIS
49 
60 typedef struct vpBasisFunction
61 {
62  unsigned int i;
63  unsigned int p;
64  double u;
65  unsigned int k;
66  double value;
67 } vpBasisFunction;
68 #endif
69 
106 class VISP_EXPORT vpBSpline
107 {
108 public /*protected*/:
110  std::vector<vpImagePoint> controlPoints;
112  std::vector<double> knots;
114  unsigned int p;
116  std::vector<vpImagePoint> crossingPoints;
117 
118 public:
119  vpBSpline();
120  vpBSpline(const vpBSpline &bspline);
121  virtual ~vpBSpline();
122 
128  inline unsigned int get_p() const { return p; }
129 
136  inline void get_controlPoints(std::list<vpImagePoint> &list) const
137  {
138  list.clear();
139  for (unsigned int i = 0; i < controlPoints.size(); i++) {
140  list.push_back(*(&(controlPoints[0]) + i));
141  }
142  }
143 
149  inline void get_knots(std::list<double> &list) const
150  {
151  list.clear();
152  for (unsigned int i = 0; i < knots.size(); i++) {
153  list.push_back(*(&(knots[0]) + i));
154  }
155  }
156 
163  inline void get_crossingPoints(std::list<vpImagePoint> &list) const
164  {
165  list.clear();
166  for (unsigned int i = 0; i < crossingPoints.size(); i++) {
167  list.push_back(*(&(crossingPoints[0]) + i));
168  }
169  }
170 
176  inline void set_p(unsigned int degree) { this->p = degree; }
177 
183  inline void set_controlPoints(const std::list<vpImagePoint> &list)
184  {
185  controlPoints.clear();
186  for (std::list<vpImagePoint>::const_iterator it = list.begin(); it != list.end(); ++it) {
187  controlPoints.push_back(*it);
188  }
189  }
190 
196  inline void set_knots(const std::list<double> &list)
197  {
198  knots.clear();
199  for (std::list<double>::const_iterator it = list.begin(); it != list.end(); ++it) {
200  knots.push_back(*it);
201  }
202  }
203 
210  inline void set_crossingPoints(const std::list<vpImagePoint> &list)
211  {
212  crossingPoints.clear();
213  for (std::list<vpImagePoint>::const_iterator it = list.begin(); it != list.end(); ++it) {
214  crossingPoints.push_back(*it);
215  }
216  }
217 
218  static unsigned int findSpan(double l_u, unsigned int l_p, const std::vector<double> &l_knots);
219  unsigned int findSpan(double u) const;
220 
221  static vpBasisFunction *computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p,
222  const std::vector<double> &l_knots);
223  vpBasisFunction *computeBasisFuns(double u) const;
224 
225  static vpBasisFunction **computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der,
226  const std::vector<double> &l_knots);
227  vpBasisFunction **computeDersBasisFuns(double u, unsigned int der) const;
228 
229  static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, const std::vector<double> &l_knots,
230  const std::vector<vpImagePoint> &l_controlPoints);
231  vpImagePoint computeCurvePoint(double u) const;
232 
233  static vpImagePoint *computeCurveDers(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der,
234  const std::vector<double> &l_knots, const std::vector<vpImagePoint> &l_controlPoints);
235  vpImagePoint *computeCurveDers(double u, unsigned int der) const;
236 };
237 
238 #endif
Class that provides tools to compute and manipulate a B-Spline curve.
Definition: vpBSpline.h:107
void get_controlPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:136
void set_p(unsigned int degree)
Definition: vpBSpline.h:176
void set_crossingPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:210
unsigned int get_p() const
Definition: vpBSpline.h:128
void get_crossingPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:163
void set_controlPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:183
void get_knots(std::list< double > &list) const
Definition: vpBSpline.h:149
void set_knots(const std::list< double > &list)
Definition: vpBSpline.h:196
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82