source: rrlib_geometry/curves/tUniformBSplineCurve.hpp @ 60:a22756932ab5

Last change on this file since 60:a22756932ab5 was 60:a22756932ab5, checked in by Tobias Föhst <foehst@…>, 6 years ago

Added and updated license information

File size: 5.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 modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (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 along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tUniformBSplineCurve.hpp
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-09-01
27 *
28 */
29//----------------------------------------------------------------------
30
31//----------------------------------------------------------------------
32// External includes (system with <>, local with "")
33//----------------------------------------------------------------------
34
35//----------------------------------------------------------------------
36// Internal includes with ""
37//----------------------------------------------------------------------
38
39//----------------------------------------------------------------------
40// Debugging
41//----------------------------------------------------------------------
42#include <cassert>
43
44//----------------------------------------------------------------------
45// Namespace declaration
46//----------------------------------------------------------------------
47namespace rrlib
48{
49namespace geometry
50{
51
52//----------------------------------------------------------------------
53// Forward declarations / typedefs / enums
54//----------------------------------------------------------------------
55
56//----------------------------------------------------------------------
57// Const values
58//----------------------------------------------------------------------
59
60//----------------------------------------------------------------------
61// Implementation
62//----------------------------------------------------------------------
63
64//----------------------------------------------------------------------
65// tUniformBSplineCurve constructor
66//----------------------------------------------------------------------
67template <size_t Tdimension, typename TElement>
68template <typename TIterator>
69tUniformBSplineCurve<Tdimension, TElement>::tUniformBSplineCurve(TIterator begin, TIterator end, double tension)
70  : tSplineCurve(begin, end),
71    tension(tension)
72{}
73
74//----------------------------------------------------------------------
75// tUniformBSplineCurve SetTension
76//----------------------------------------------------------------------
77template <size_t Tdimension, typename TElement>
78void tUniformBSplineCurve<Tdimension, TElement>::SetTension(double tension)
79{
80  this->tension = tension;
81  this->SetChanged();
82}
83
84//----------------------------------------------------------------------
85// tUniformBSplineCurve GetSegmentForParameter
86//----------------------------------------------------------------------
87template <size_t Tdimension, typename TElement>
88unsigned int tUniformBSplineCurve<Tdimension, TElement>::GetSegmentForParameter(typename tSplineCurve::tParameter t) const
89{
90  assert((0 <= t) && (t <= this->NumberOfSegments()));
91  return static_cast<unsigned int>(t < this->NumberOfSegments() ? t : t - 1.0);
92}
93
94//----------------------------------------------------------------------
95// tUniformBSplineCurve GetLocalParameter
96//----------------------------------------------------------------------
97template <size_t Tdimension, typename TElement>
98typename tSplineCurve<Tdimension, TElement, 3>::tParameter tUniformBSplineCurve<Tdimension, TElement>::GetLocalParameter(typename tSplineCurve::tParameter t) const
99{
100  assert((0 <= t) && (t <= this->NumberOfSegments()));
101  return t < this->NumberOfSegments() ? t - std::trunc(t) : 1.0;
102}
103
104//----------------------------------------------------------------------
105// tUniformBSplineCurve CreateBezierCurveForSegment
106//----------------------------------------------------------------------
107template <size_t Tdimension, typename TElement>
108std::shared_ptr<const typename tSplineCurve<Tdimension, TElement, 3>::tBezierCurve> tUniformBSplineCurve<Tdimension, TElement>::CreateBezierCurveForSegment(unsigned int i) const
109{
110  typename tShape::tPoint bezier_control_points[4];
111
112  bezier_control_points[0] = (1.0 - this->tension) / 6.0 * (this->ControlPoints()[i] + this->ControlPoints()[i + 2]) + (2.0 + this->tension) / 3.0 * this->ControlPoints()[i + 1];
113  bezier_control_points[1] = (2.0 + this->tension) / 3.0 * this->ControlPoints()[i + 1] + (1.0 - this->tension) / 3.0 * this->ControlPoints()[i + 2];
114  bezier_control_points[2] = (1.0 - this->tension) / 3.0 * this->ControlPoints()[i + 1] + (2.0 + this->tension) / 3.0 * this->ControlPoints()[i + 2];
115  bezier_control_points[3] = (1.0 - this->tension) / 6.0 * (this->ControlPoints()[i + 1] + this->ControlPoints()[i + 3]) + (2.0 + this->tension) / 3.0 * this->ControlPoints()[i + 2];
116
117  return std::shared_ptr<const typename tSplineCurve::tBezierCurve>(new typename tSplineCurve::tBezierCurve(bezier_control_points, bezier_control_points + 4));
118}
119
120//----------------------------------------------------------------------
121// End of namespace declaration
122//----------------------------------------------------------------------
123}
124}
Note: See TracBrowser for help on using the repository browser.