source: rrlib_geometry/curves/tBSplineCurve.h @ 96:5a75c0a06ee1

14.08
Last change on this file since 96:5a75c0a06ee1 was 96:5a75c0a06ee1, checked in by Tobias Föhst <foehst@…>, 4 months ago

Postpones calculation of knot vector and padds splines of higher degree to get end point interpolation

File size: 7.0 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tBSplineCurve.h
23 *
24 * \author  Patrick Fleischmann
25 *
26 * \date    2012-04-18
27 *
28 * \brief
29 *
30 * \b tBSplineCurve.h
31 *
32 *
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__geometry__curves__tBSplineCurve_h__
37#define __rrlib__geometry__curves__tBSplineCurve_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42
43//----------------------------------------------------------------------
44// Internal includes with ""
45//----------------------------------------------------------------------
46#include "rrlib/geometry/tPoint.h"
47#include "rrlib/geometry/curves/tSplineCurve.h"
48
49//----------------------------------------------------------------------
50// Debugging
51//----------------------------------------------------------------------
52
53//----------------------------------------------------------------------
54// Namespace declaration
55//----------------------------------------------------------------------
56//----------------------------------------------------------------------
57// Namespace declaration
58//----------------------------------------------------------------------
59namespace rrlib
60{
61namespace geometry
62{
63
64//----------------------------------------------------------------------
65// Forward declarations / typedefs / enums
66//----------------------------------------------------------------------
67
68//----------------------------------------------------------------------
69// Class declaration
70//----------------------------------------------------------------------
71template <size_t Tdimension, typename TElement, unsigned int Tdegree = 3>
72class tBSplineCurve : public tSplineCurve<Tdimension, TElement, Tdegree>
73{
74  typedef geometry::tSplineCurve<Tdimension, TElement, Tdegree> tSplineCurve;
75  typedef geometry::tShape<Tdimension, TElement> tShape;
76
77//----------------------------------------------------------------------
78// Public methods and typedefs
79//----------------------------------------------------------------------
80public:
81
82  tBSplineCurve();
83
84  /*!
85     * Construct a uniform B-spline using control points and a knot vector
86     */
87  template <typename TIterator, typename TKnotIterator>
88  tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end);
89
90  /*!
91   * Construct a uniform B-spline using control points. The (uniform knot) vector is calculated automatically.
92   */
93  template <typename TIterator>
94  tBSplineCurve(TIterator begin, TIterator end);
95
96  virtual const unsigned int NumberOfSegments() const;
97
98  /*! Get the knot vector for the current control points
99   *
100   * \note The knots are calculated on demand. Clear the vector if a control point changes!
101   */
102  const std::vector<typename tSplineCurve::tParameter> &Knots() const;
103
104  template <typename TIterator>
105  void SetKnots(TIterator begin, TIterator end)
106  {
107    this->knots.assign(begin, end);
108    this->CalculateBezierControlPoints();
109  }
110
111//----------------------------------------------------------------------
112// Protected methods
113//----------------------------------------------------------------------
114protected:
115  /*!
116   * Method is called in control point insertion, appending and modification. Causes knot vector and bezier control point recalculation
117   */
118  virtual void SetChanged();
119
120//----------------------------------------------------------------------
121// Private fields and methods
122//----------------------------------------------------------------------
123private:
124  /*! B-spline knot vector (#knots = #control points + degree + 1) */
125  mutable std::vector<typename tSplineCurve::tParameter> knots;
126  /*! Bezier control points used to evaluate b-spline curve which is converted to a set of bezier curves  */
127  mutable std::vector<typename tShape::tPoint> bezier_control_points;
128  mutable unsigned int number_of_segments;
129
130  /*! Get control points for Bezier representation
131   *
132   * \note The control points are lazily calculated on demand. Clear the vector if a spline control point changes!
133   */
134  const std::vector<typename tShape::tPoint> &BezierControlPoints() const;
135
136  /*!
137   * Recalculate control points affected by a knot insertion
138   * @param at Index of the knot to be inserted
139   * @param knots_before_insertion Knot vector before knot insertion
140   * @param knot The new knot that should be inserted
141   * @param control_points Control points before insertion
142   * @return Control points after knot insertion
143   */
144  static std::vector<typename tShape::tPoint> InsertKnot(int at, const std::vector<typename tSplineCurve::tParameter> &knots_before_insertion, typename tSplineCurve::tParameter knot, const std::vector<typename tShape::tPoint> &control_points);
145
146  virtual unsigned int GetSegmentForParameter(typename tSplineCurve::tParameter t) const;
147  virtual typename tSplineCurve::tParameter GetLocalParameter(typename tSplineCurve::tParameter t) const;
148
149  /*!
150   * Create the bezier representation of the B-spline for the given segment id
151   * @param id ID of the segment
152   * @return Bezier curve of the segment
153   */
154  virtual std::shared_ptr<const typename tSplineCurve::tBezierCurve> CreateBezierCurveForSegment(unsigned int i) const;
155
156};
157
158//----------------------------------------------------------------------
159// Operators for rrlib_serialization
160//----------------------------------------------------------------------
161#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_
162
163template <size_t Tdimension, typename TElement, unsigned int Tdegree>
164serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBSplineCurve<Tdimension, TElement, Tdegree> &spline);
165
166template <size_t Tdimension, typename TElement, unsigned int Tdegree>
167serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBSplineCurve<Tdimension, TElement, Tdegree> &spline);
168
169#endif
170
171//----------------------------------------------------------------------
172// End of namespace declaration
173//----------------------------------------------------------------------
174}
175}
176
177
178#include "rrlib/geometry/curves/tBSplineCurve.hpp"
179
180#endif
Note: See TracBrowser for help on using the repository browser.