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