source: rrlib_geometry/curves/tSplineCurve.h @ 46:d3f0d56168cc

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

Merged with changes from rrlib.org

File size: 7.1 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#include "rrlib/util/variadic_templates.h"
51
52//----------------------------------------------------------------------
53// Internal includes with ""
54//----------------------------------------------------------------------
55#include "rrlib/geometry/curves/tBezierCurve.h"
56
57//----------------------------------------------------------------------
58// Debugging
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Namespace declaration
63//----------------------------------------------------------------------
64namespace rrlib
65{
66namespace geometry
67{
68
69//----------------------------------------------------------------------
70// Forward declarations / typedefs / enums
71//----------------------------------------------------------------------
72
73//----------------------------------------------------------------------
74// Class declaration
75//----------------------------------------------------------------------
76//! Short description of tLine
77/*! A more detailed description of tLine, which
78    Tobias Foehst hasn't done yet !!
79*/
80template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 >
81class tSplineCurve : public tShape<Tdimension, TElement>
82{
83
84  typedef geometry::tShape<Tdimension, TElement> tShape;
85
86//----------------------------------------------------------------------
87// Public methods and typedefs
88//----------------------------------------------------------------------
89public:
90
91  static inline const unsigned int Degree()
92  {
93    return Tdegree;
94  }
95
96  typedef geometry::tBezierCurve<Tdimension, TElement, Tdegree> tBezierCurve;
97  typedef typename tBezierCurve::tParameter tParameter;
98
99  template <typename TIterator>
100  tSplineCurve(TIterator begin, TIterator end);
101
102  template <typename ... TPoints>
103  tSplineCurve(const typename tShape::tPoint &p1, const typename tShape::tPoint &p2, const TPoints &... rest);
104
105  inline const size_t NumberOfControlPoints() const
106  {
107    return this->control_points.size();
108  }
109
110  inline const unsigned int NumberOfSegments() const
111  {
112    return this->control_points.size() - Tdegree;
113  };
114
115  inline const std::vector<typename tShape::tPoint> &ControlPoints() const
116  {
117    return this->control_points;
118  }
119
120  void SetControlPoint(size_t i, const typename tShape::tPoint &point);
121
122  void AppendControlPoint(const typename tShape::tPoint &point);
123
124  void InsertControlPoint(size_t position, const typename tShape::tPoint &point);
125
126  const typename tShape::tPoint operator()(tParameter t) const;
127
128  std::shared_ptr<const tBezierCurve> GetBezierCurveForParameter(tParameter t) const;
129
130  std::shared_ptr<const tBezierCurve> GetBezierCurveForParameter(tParameter t, tParameter &local_t) const;
131
132  std::shared_ptr<const tBezierCurve> GetBezierCurveForSegment(unsigned int i) const;
133
134  template <unsigned int Tother_degree>
135  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
136                        const geometry::tSplineCurve<Tdimension, TElement, Tother_degree> &other_spline) const;
137
138  template <unsigned int Tother_degree>
139  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
140                        const geometry::tBezierCurve<Tdimension, TElement, Tother_degree> &bezier_curve) const;
141
142  void GetIntersections(std::vector<typename tShape::tPoint> &intersection_points, std::vector<tParameter> &intersection_parameters,
143                        const tLine<Tdimension, TElement> &line) const;
144
145  const typename tShape::tPoint GetClosestPoint(const typename tShape::tPoint &reference_point) const;
146
147  virtual tSplineCurve &Translate(const math::tVector<Tdimension, TElement> &translation);
148  virtual tSplineCurve &Rotate(const math::tMatrix<Tdimension, Tdimension, TElement> &rotation);
149  virtual tSplineCurve &Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation);
150
151//----------------------------------------------------------------------
152// Protected methods
153//----------------------------------------------------------------------
154protected:
155
156  virtual void SetChanged();
157
158//----------------------------------------------------------------------
159// Private fields and methods
160//----------------------------------------------------------------------
161private:
162
163  std::vector<typename tShape::tPoint> control_points;
164  mutable std::vector<std::shared_ptr<const tBezierCurve>> bezier_curve_cache;
165
166  virtual void UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const;
167  virtual void UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const;
168
169  virtual unsigned int GetSegmentForParameter(tParameter t) = 0;
170  virtual tParameter GetLocalParameter(tParameter t) = 0;
171  virtual std::shared_ptr<const tBezierCurve> CreateBezierCurveForSegment(unsigned int i) const = 0;
172
173};
174
175//----------------------------------------------------------------------
176// Operators for rrlib_canvas
177//----------------------------------------------------------------------
178#ifdef _LIB_RRLIB_CANVAS_PRESENT_
179
180template <typename TElement, unsigned int Tdegree>
181inline canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tSplineCurve<2, TElement, Tdegree> &spline);
182
183#endif
184
185//----------------------------------------------------------------------
186// End of namespace declaration
187//----------------------------------------------------------------------
188}
189}
190
191#include "rrlib/geometry/curves/tSplineCurve.hpp"
192
193#endif
Note: See TracBrowser for help on using the repository browser.