source: rrlib_geometry/curves/tSplineCurve.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: 7.9 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
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    tSplineCurve.h
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-09-01
27 *
28 * \brief   Contains tSplineCurve
29 *
30 * \b tSplineCurve
31 *
32 * A few words for tSplineCurve
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__geometry__curves__tSplineCurve_h__
37#define __rrlib__geometry__curves__tSplineCurve_h__
38
39#include "rrlib/geometry/tShape.h"
40//----------------------------------------------------------------------
41// External includes (system with <>, local with "")
42//----------------------------------------------------------------------
43#include <memory>
44
45#ifdef _LIB_RRLIB_CANVAS_PRESENT_
46#include "rrlib/canvas/tCanvas2D.h"
47#include "rrlib/canvas/tCanvas3D.h"
48#endif
49
50#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_
51#include "rrlib/serialization/serialization.h"
52#endif
53
54#include "rrlib/util/variadic_templates.h"
55
56//----------------------------------------------------------------------
57// Internal includes with ""
58//----------------------------------------------------------------------
59#include "rrlib/geometry/curves/tBezierCurve.h"
60
61//----------------------------------------------------------------------
62// Debugging
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Namespace declaration
67//----------------------------------------------------------------------
68namespace rrlib
69{
70namespace geometry
71{
72
73//----------------------------------------------------------------------
74// Forward declarations / typedefs / enums
75//----------------------------------------------------------------------
76
77//----------------------------------------------------------------------
78// Class declaration
79//----------------------------------------------------------------------
80//! Short description of tLine
81/*! A more detailed description of tLine, which
82    Tobias Foehst hasn't done yet !!
83*/
84template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 >
85class tSplineCurve : public tShape<Tdimension, TElement>
86{
87
88  typedef geometry::tShape<Tdimension, TElement> tShape;
89
90//----------------------------------------------------------------------
91// Public methods and typedefs
92//----------------------------------------------------------------------
93public:
94
95  static inline const unsigned int Degree()
96  {
97    return Tdegree;
98  }
99
100  typedef geometry::tBezierCurve<Tdimension, TElement, Tdegree> tBezierCurve;
101  typedef typename tBezierCurve::tParameter tParameter;
102
103  template <typename TIterator>
104  tSplineCurve(TIterator begin, TIterator end);
105
106  template <typename ... TPoints>
107  tSplineCurve(const typename tShape::tPoint &p1, const typename tShape::tPoint &p2, const TPoints &... rest);
108
109  inline const size_t NumberOfControlPoints() const
110  {
111    return this->control_points.size();
112  }
113
114  inline const unsigned int NumberOfSegments() const
115  {
116    return this->control_points.size() - Tdegree;
117  };
118
119  inline const std::vector<typename tShape::tPoint> &ControlPoints() const
120  {
121    return this->control_points;
122  }
123
124  void SetControlPoint(size_t i, const typename tShape::tPoint &point);
125
126  void AppendControlPoint(const typename tShape::tPoint &point);
127
128  void InsertControlPoint(size_t position, const typename tShape::tPoint &point);
129
130  template <typename TIterator>
131  void SetControlPoints(TIterator begin, TIterator end);
132
133  const typename tShape::tPoint operator()(tParameter t) const;
134
135  std::shared_ptr<const tBezierCurve> GetBezierCurveForParameter(tParameter t) const;
136
137  std::shared_ptr<const tBezierCurve> GetBezierCurveForParameter(tParameter t, tParameter &local_t) const;
138
139  std::shared_ptr<const tBezierCurve> GetBezierCurveForSegment(unsigned int i) const;
140
141  template <unsigned int Tother_degree>
142  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
143                        const geometry::tSplineCurve<Tdimension, TElement, Tother_degree> &other_spline) const;
144
145  template <unsigned int Tother_degree>
146  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
147                        const geometry::tBezierCurve<Tdimension, TElement, Tother_degree> &bezier_curve) const;
148
149  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
150                        const tLine<Tdimension, TElement> &line) const;
151
152  const typename tShape::tPoint GetClosestPoint(const typename tShape::tPoint &reference_point) const;
153
154  virtual tSplineCurve &Translate(const math::tVector<Tdimension, TElement> &translation);
155  virtual tSplineCurve &Rotate(const math::tMatrix<Tdimension, Tdimension, TElement> &rotation);
156  virtual tSplineCurve &Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation);
157
158//----------------------------------------------------------------------
159// Protected methods
160//----------------------------------------------------------------------
161protected:
162
163  virtual void SetChanged();
164
165//----------------------------------------------------------------------
166// Private fields and methods
167//----------------------------------------------------------------------
168private:
169
170  std::vector<typename tShape::tPoint> control_points;
171  mutable std::vector<std::shared_ptr<const tBezierCurve>> bezier_curve_cache;
172
173  virtual void UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const;
174  virtual void UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const;
175
176  virtual unsigned int GetSegmentForParameter(tParameter t) = 0;
177  virtual tParameter GetLocalParameter(tParameter t) = 0;
178  virtual std::shared_ptr<const tBezierCurve> CreateBezierCurveForSegment(unsigned int i) const = 0;
179
180};
181
182//----------------------------------------------------------------------
183// Operators for rrlib_canvas
184//----------------------------------------------------------------------
185#ifdef _LIB_RRLIB_CANVAS_PRESENT_
186
187template <typename TElement, unsigned int Tdegree>
188inline canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tSplineCurve<2, TElement, Tdegree> &spline);
189
190#endif
191
192//----------------------------------------------------------------------
193// Operators for rrlib_serialization
194//----------------------------------------------------------------------
195#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_
196
197template <size_t Tdimension, typename TElement, unsigned int Tdegree>
198serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tSplineCurve<Tdimension, TElement, Tdegree> &spline);
199
200template <size_t Tdimension, typename TElement, unsigned int Tdegree>
201serialization::tInputStream &operator >> (serialization::tInputStream &stream, tSplineCurve<Tdimension, TElement, Tdegree> &spline);
202
203#endif
204
205//----------------------------------------------------------------------
206// End of namespace declaration
207//----------------------------------------------------------------------
208}
209}
210
211#include "rrlib/geometry/curves/tSplineCurve.hpp"
212
213#endif
Note: See TracBrowser for help on using the repository browser.