ViSP  2.9.0
vpBSpline.h
1 /****************************************************************************
2  *
3  * $Id: vpBSpline.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * This class implements the B-Spline
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 #ifndef vpBSpline_H
43 #define vpBSpline_H
44 
50 #include <visp/vpImagePoint.h>
51 
52 #include <vector>
53 #include <list>
54 
55 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
56 # include <visp/vpList.h>
57 #endif
58 #include <visp/vpMatrix.h>
59 
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 
71 typedef struct vpBasisFunction{
72  unsigned int i;
73  unsigned int p;
74  double u;
75  unsigned int k;
76  double value;
77 } vpBasisFunction;
78 #endif
79 
109 class VISP_EXPORT vpBSpline
110 {
111  public/*protected*/:
113  std::vector<vpImagePoint> controlPoints;
115  std::vector<double> knots;
117  unsigned int p;
119  std::vector<vpImagePoint> crossingPoints;
120 
121  public:
122 
123  vpBSpline();
124  vpBSpline(const vpBSpline &bspline);
125  virtual ~vpBSpline();
126 
132  inline unsigned int get_p() const {return p;}
133 
139  inline void get_controlPoints(std::list<vpImagePoint> &list) const {
140  list.clear();
141  for (unsigned int i = 0; i < controlPoints.size(); i++)
142  list.push_back(*(&(controlPoints[0])+i));
143  }
144 
150  inline void get_knots(std::list<double> &list) const {
151  list.clear();
152  for (unsigned int i = 0; i < knots.size(); i++)
153  list.push_back(*(&(knots[0])+i));
154  }
155 
161  inline void get_crossingPoints(std::list<vpImagePoint> &list) const {
162  list.clear();
163  for (unsigned int i = 0; i < crossingPoints.size(); i++)
164  list.push_back(*(&(crossingPoints[0])+i));
165  }
166 
167 
173  inline void set_p(unsigned int degree) {this->p = degree;}
174 
175 
181  inline void set_controlPoints(const std::list<vpImagePoint> &list) {
182  controlPoints.clear();
183  for(std::list<vpImagePoint>::const_iterator it = list.begin(); it!=list.end(); ++it){
184  controlPoints.push_back(*it);
185  }
186  }
187 
193  inline void set_knots(const std::list<double> &list) {
194  knots.clear();
195  for(std::list<double>::const_iterator it = list.begin(); it!=list.end(); ++it){
196  knots.push_back(*it);
197  }
198  }
199 
205  inline void set_crossingPoints(const std::list<vpImagePoint> &list) {
206  crossingPoints.clear();
207  for(std::list<vpImagePoint>::const_iterator it=list.begin(); it!=list.end(); ++it){
208  crossingPoints.push_back(*it);
209  }
210  }
211 
212  static unsigned int findSpan(double l_u, unsigned int l_p, std::vector<double> &l_knots);
213  unsigned int findSpan(double u);
214 
215  static vpBasisFunction* computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector<double> &l_knots);
216  vpBasisFunction* computeBasisFuns(double u);
217 
218  static vpBasisFunction** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector<double> &l_knots);
219  vpBasisFunction** computeDersBasisFuns(double u, unsigned int der);
220 
221  static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector<double> &l_knots, std::vector<vpImagePoint> &l_controlPoints);
222  vpImagePoint computeCurvePoint(double u);
223 
224  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);
225  vpImagePoint* computeCurveDers(double u, unsigned int der);
226 
227 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
228 
237  vp_deprecated vpList<vpImagePoint> get_controlPoints() const {
239  for (unsigned int i = 0; i < controlPoints.size(); i++) list.addRight(*(&(controlPoints[0])+i));
240  return list; }
241 
248  vp_deprecated inline vpList<double> get_knots() const {
249  vpList<double> list;
250  for (unsigned int i = 0; i < knots.size(); i++) list.addRight(*(&(knots[0])+i));
251  return list; }
252 
259  vp_deprecated inline vpList<vpImagePoint> get_crossingPoints() const {
261  for (unsigned int i = 0; i < crossingPoints.size(); i++) list.addRight(*(&(crossingPoints[0])+i));
262  return list; }
263 
270  vp_deprecated inline void set_controlPoints(vpList<vpImagePoint> &list) {
271  controlPoints.clear();
272  list.front();
273  for (unsigned int i = 0; i < list.nbElements(); i++)
274  {
275  controlPoints.push_back(list.value());
276  list.next();
277  }
278  }
279 
286  vp_deprecated inline void set_knots(vpList<double> &list) {
287  knots.clear();
288  list.front();
289  for (unsigned int i = 0; i < list.nbElements(); i++)
290  {
291  knots.push_back(list.value());
292  list.next();
293  }
294  }
295 
302  vp_deprecated inline void set_crossingPoints(vpList<vpImagePoint> &list) {
303  crossingPoints.clear();
304  list.front();
305  for (unsigned int i = 0; i < list.nbElements(); i++)
306  {
307  crossingPoints.push_back(list.value());
308  list.next();
309  }
310  }
311 #endif
312 
313 };
314 
315 #endif
vp_deprecated void set_controlPoints(vpList< vpImagePoint > &list)
Definition: vpBSpline.h:270
unsigned int nbElements(void)
return the number of element in the list
Definition: vpList.h:259
vp_deprecated vpList< vpImagePoint > get_crossingPoints() const
Definition: vpBSpline.h:259
void get_controlPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:139
Provide simple list management.
Definition: vpList.h:113
void next(void)
position the current element on the next one
Definition: vpList.h:273
vp_deprecated void set_knots(vpList< double > &list)
Definition: vpBSpline.h:286
void get_crossingPoints(std::list< vpImagePoint > &list) const
Definition: vpBSpline.h:161
vp_deprecated vpList< vpImagePoint > get_controlPoints() const
Definition: vpBSpline.h:237
void front(void)
Position the current element on the first element of the list.
Definition: vpList.h:384
type & value(void)
return the value of the current element
Definition: vpList.h:301
void set_p(unsigned int degree)
Definition: vpBSpline.h:173
void addRight(const type &el)
add a new element in the list, at the right of the current one
Definition: vpList.h:478
void set_crossingPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:205
unsigned int get_p() const
Definition: vpBSpline.h:132
void set_controlPoints(const std::list< vpImagePoint > &list)
Definition: vpBSpline.h:181
Class that provides tools to compute and manipulate a B-Spline curve.
Definition: vpBSpline.h:109
vp_deprecated void set_crossingPoints(vpList< vpImagePoint > &list)
Definition: vpBSpline.h:302
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void get_knots(std::list< double > &list) const
Definition: vpBSpline.h:150
void set_knots(const std::list< double > &list)
Definition: vpBSpline.h:193
vp_deprecated vpList< double > get_knots() const
Definition: vpBSpline.h:248