source: rrlib_geometry/curves/tBezierCurve.h @ 17:3daa58ced492

Last change on this file since 17:3daa58ced492 was 17:3daa58ced492, checked in by Tobias Föhst <foehst@…>, 9 years ago

Merged with changes from rrlab

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