source: rrlib_geometry/curves/tBSplineCurve.h @ 47:73eab926c138

Last change on this file since 47:73eab926c138 was 47:73eab926c138, checked in by Tobias Föhst <foehst@…>, 7 years ago

Added serialization operators for curves

File size: 6.6 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) AG Robotersysteme TU Kaiserslautern
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (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
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tBSplineCurve.h
23 *
24 * \author  Patrick Fleischmann
25 *
26 * \date    Apr 18, 2012
27 *
28 * \brief
29 *
30 * \b tBSplineCurve.h
31 *
32 *
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef TBSPLINECURVE_H_
37#define 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  /*!
83     * Construct a uniform B-spline using control points and a knot vector
84     */
85  template <typename TIterator, typename TKnotIterator>
86  tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end);
87
88  /*!
89   * Construct a uniform B-spline using control points. The (uniform knot) vector is calculated automatically.
90   */
91  template <typename TIterator>
92  tBSplineCurve(TIterator begin, TIterator end);
93
94  const std::vector<double> &Knots() const
95  {
96    return this->knots;
97  }
98
99  template <typename TIterator>
100  void SetKnots(TIterator begin, TIterator end)
101  {
102    this->knots.assign(begin, end);
103    this->CalculateBezierControlPoints();
104  }
105
106//----------------------------------------------------------------------
107// Protected methods
108//----------------------------------------------------------------------
109protected:
110  /*!
111   * Method is called in control point insertion, appending and modification. Causes knot vector and bezier control point recalculation
112   */
113  virtual void SetChanged();
114
115//----------------------------------------------------------------------
116// Private fields and methods
117//----------------------------------------------------------------------
118private:
119  /*! B-spline knot vector (#knots = #control points + degree + 1) */
120  std::vector<double> knots;
121  /*! Bezier control points used to evaluate b-spline curve which is converted to a set of bezier curves  */
122  std::vector<typename tShape::tPoint> bezier_control_points;
123
124  /*!
125   * Calculate a uniform knot vector, this->knots will be modified
126   */
127  void CalculateKnotVector();
128
129  /*!
130   * Calculate all Bezier control points by knot insertion, this->bezier_control_points will be modified
131   */
132  void CalculateBezierControlPoints();
133
134  /*!
135   * Recalculate control points affected by a knot insertion
136   * @param at Index of the knot to be inserted
137   * @param knots_before_insertion Knot vector before knot insertion
138   * @param knot The new knot that should be inserted
139   * @param control_points Control points before insertion
140   * @return Control points after knot insertion
141   */
142  std::vector<typename tShape::tPoint> InsertKnot(int at, const std::vector<double> &knots_before_insertion, double knot, const std::vector<typename tShape::tPoint> &control_points) const;
143
144  virtual unsigned int GetSegmentForParameter(typename tSplineCurve::tParameter t);
145  virtual typename tSplineCurve::tParameter GetLocalParameter(typename tSplineCurve::tParameter t);
146
147  /*!
148   * Create the bezier representation of the B-spline for the given segment id
149   * @param id ID of the segment
150   * @return Bezier curve of the segment
151   */
152  virtual std::shared_ptr<const typename tSplineCurve::tBezierCurve> CreateBezierCurveForSegment(unsigned int i) const;
153
154};
155
156//----------------------------------------------------------------------
157// Operators for rrlib_serialization
158//----------------------------------------------------------------------
159#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_
160
161template <size_t Tdimension, typename TElement, unsigned int Tdegree>
162serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBSplineCurve<Tdimension, TElement, Tdegree> &spline);
163
164template <size_t Tdimension, typename TElement, unsigned int Tdegree>
165serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBSplineCurve<Tdimension, TElement, Tdegree> &spline);
166
167#endif
168
169//----------------------------------------------------------------------
170// End of namespace declaration
171//----------------------------------------------------------------------
172}
173}
174
175
176#include "rrlib/geometry/curves/tBSplineCurve.hpp"
177
178#endif
Note: See TracBrowser for help on using the repository browser.