Visual Servoing Platform  version 3.6.1 under development (2024-10-13)
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 
39 #ifndef vpBSpline_H
40 #define vpBSpline_H
41 
42 #include <visp3/core/vpImagePoint.h>
43 
44 #include <list>
45 #include <vector>
46 #include <visp3/core/vpMatrix.h>
47 
48 BEGIN_VISP_NAMESPACE
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 
61 typedef struct vpBasisFunction
62 {
63  unsigned int i;
64  unsigned int p;
65  double u;
66  unsigned int k;
67  double value;
68 } vpBasisFunction;
69 #endif
70 
107 class VISP_EXPORT vpBSpline
108 {
109 public /*protected*/:
111  std::vector<vpImagePoint> controlPoints;
113  std::vector<double> knots;
115  unsigned int p;
117  std::vector<vpImagePoint> crossingPoints;
118 
119 public:
120  vpBSpline();
121  vpBSpline(const vpBSpline &bspline);
122  virtual ~vpBSpline();
123 
129  inline unsigned int get_p() const { return p; }
130 
137  inline void get_controlPoints(std::list<vpImagePoint> &list) const
138  {
139  list.clear();
140  for (unsigned int i = 0; i < controlPoints.size(); i++) {
141  list.push_back(*(&(controlPoints[0]) + i));
142  }
143  }
144 
150  inline void get_knots(std::list<double> &list) const
151  {
152  list.clear();
153  for (unsigned int i = 0; i < knots.size(); i++) {
154  list.push_back(*(&(knots[0]) + i));
155  }
156  }
157 
164  inline void get_crossingPoints(std::list<vpImagePoint> &list) const
165  {
166  list.clear();
167  for (unsigned int i = 0; i < crossingPoints.size(); i++) {
168  list.push_back(*(&(crossingPoints[0]) + i));
169  }
170  }
171 
177  inline void set_p(unsigned int degree) { this->p = degree; }
178 
184  inline void set_controlPoints(const std::list<vpImagePoint> &list)
185  {
186  controlPoints.clear();
187  for (std::list<vpImagePoint>::const_iterator it = list.begin(); it != list.end(); ++it) {
188  controlPoints.push_back(*it);
189  }
190  }
191 
197  inline void set_knots(const std::list<double> &list)
198  {
199  knots.clear();
200  for (std::list<double>::const_iterator it = list.begin(); it != list.end(); ++it) {
201  knots.push_back(*it);
202  }
203  }
204 
211  inline void set_crossingPoints(const std::list<vpImagePoint> &list)
212  {
213  crossingPoints.clear();
214  for (std::list<vpImagePoint>::const_iterator it = list.begin(); it != list.end(); ++it) {
215  crossingPoints.push_back(*it);
216  }
217  }
218 
219  static unsigned int findSpan(double l_u, unsigned int l_p, const std::vector<double> &l_knots);
220  unsigned int findSpan(double u) const;
221 
222  static vpBasisFunction *computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p,
223  const std::vector<double> &l_knots);
224  vpBasisFunction *computeBasisFuns(double u) const;
225 
226  static vpBasisFunction **computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der,
227  const std::vector<double> &l_knots);
228  vpBasisFunction **computeDersBasisFuns(double u, unsigned int der) const;
229 
230  static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, const std::vector<double> &l_knots,
231  const std::vector<vpImagePoint> &l_controlPoints);
232  vpImagePoint computeCurvePoint(double u) const;
233 
234  static vpImagePoint *computeCurveDers(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der,
235  const std::vector<double> &l_knots, const std::vector<vpImagePoint> &l_controlPoints);
236  vpImagePoint *computeCurveDers(double u, unsigned int der) const;
237 };
238 END_VISP_NAMESPACE
239 #endif
Class that provides tools to compute and manipulate a B-Spline curve.
Definition: vpBSpline.h:108
void get_controlPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:137
void set_p(unsigned int degree)
Definition: vpBSpline.h:177
void set_crossingPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:211
unsigned int get_p() const
Definition: vpBSpline.h:129
void get_crossingPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:164
void set_controlPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:184
void get_knots(std::list< double > &list) const
Definition: vpBSpline.h:150
void set_knots(const std::list< double > &list)
Definition: vpBSpline.h:197
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82