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