source: rrlib_geometry/curves/tBezierCurve.h @ 24:627bf1924b86

Last change on this file since 24:627bf1924b86 was 24:627bf1924b86, checked in by Tobias Föhst <foehst@…>, 8 years ago

Added streaming operators for rrlib_canvas

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