1 | // |
---|
2 | // You received this file as part of RRLib |
---|
3 | // Robotics Research Library |
---|
4 | // |
---|
5 | // Copyright (C) AG Robotersysteme TU Kaiserslautern |
---|
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 tBSplineCurve.h |
---|
23 | * |
---|
24 | * \author Patrick Fleischmann |
---|
25 | * |
---|
26 | * \date 2012-04-18 |
---|
27 | * |
---|
28 | * \brief |
---|
29 | * |
---|
30 | * \b tBSplineCurve.h |
---|
31 | * |
---|
32 | * |
---|
33 | * |
---|
34 | */ |
---|
35 | //---------------------------------------------------------------------- |
---|
36 | #ifndef __rrlib__geometry__curves__tBSplineCurve_h__ |
---|
37 | #define __rrlib__geometry__curves__tBSplineCurve_h__ |
---|
38 | |
---|
39 | //---------------------------------------------------------------------- |
---|
40 | // External includes (system with <>, local with "") |
---|
41 | //---------------------------------------------------------------------- |
---|
42 | |
---|
43 | //---------------------------------------------------------------------- |
---|
44 | // Internal includes with "" |
---|
45 | //---------------------------------------------------------------------- |
---|
46 | #include "rrlib/geometry/tPoint.h" |
---|
47 | #include "rrlib/geometry/curves/tSplineCurve.h" |
---|
48 | |
---|
49 | //---------------------------------------------------------------------- |
---|
50 | // Debugging |
---|
51 | //---------------------------------------------------------------------- |
---|
52 | |
---|
53 | //---------------------------------------------------------------------- |
---|
54 | // Namespace declaration |
---|
55 | //---------------------------------------------------------------------- |
---|
56 | //---------------------------------------------------------------------- |
---|
57 | // Namespace declaration |
---|
58 | //---------------------------------------------------------------------- |
---|
59 | namespace rrlib |
---|
60 | { |
---|
61 | namespace geometry |
---|
62 | { |
---|
63 | |
---|
64 | //---------------------------------------------------------------------- |
---|
65 | // Forward declarations / typedefs / enums |
---|
66 | //---------------------------------------------------------------------- |
---|
67 | |
---|
68 | //---------------------------------------------------------------------- |
---|
69 | // Class declaration |
---|
70 | //---------------------------------------------------------------------- |
---|
71 | template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 > |
---|
72 | class tBSplineCurve : public tSplineCurve<Tdimension, TElement, Tdegree> |
---|
73 | { |
---|
74 | typedef geometry::tSplineCurve<Tdimension, TElement, Tdegree> tSplineCurve; |
---|
75 | typedef geometry::tShape<Tdimension, TElement> tShape; |
---|
76 | |
---|
77 | //---------------------------------------------------------------------- |
---|
78 | // Public methods and typedefs |
---|
79 | //---------------------------------------------------------------------- |
---|
80 | public: |
---|
81 | |
---|
82 | tBSplineCurve(); |
---|
83 | |
---|
84 | /*! |
---|
85 | * Construct a uniform B-spline using control points and a knot vector |
---|
86 | */ |
---|
87 | template <typename TIterator, typename TKnotIterator> |
---|
88 | tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end); |
---|
89 | |
---|
90 | /*! |
---|
91 | * Construct a uniform B-spline using control points. The (uniform knot) vector is calculated automatically. |
---|
92 | */ |
---|
93 | template <typename TIterator> |
---|
94 | tBSplineCurve(TIterator begin, TIterator end); |
---|
95 | |
---|
96 | virtual const unsigned int NumberOfSegments() const; |
---|
97 | |
---|
98 | const std::vector<typename tSplineCurve::tParameter> &Knots() const |
---|
99 | { |
---|
100 | return this->knots; |
---|
101 | } |
---|
102 | |
---|
103 | template <typename TIterator> |
---|
104 | void SetKnots(TIterator begin, TIterator end) |
---|
105 | { |
---|
106 | this->knots.assign(begin, end); |
---|
107 | this->CalculateBezierControlPoints(); |
---|
108 | } |
---|
109 | |
---|
110 | //---------------------------------------------------------------------- |
---|
111 | // Protected methods |
---|
112 | //---------------------------------------------------------------------- |
---|
113 | protected: |
---|
114 | /*! |
---|
115 | * Method is called in control point insertion, appending and modification. Causes knot vector and bezier control point recalculation |
---|
116 | */ |
---|
117 | virtual void SetChanged(); |
---|
118 | |
---|
119 | //---------------------------------------------------------------------- |
---|
120 | // Private fields and methods |
---|
121 | //---------------------------------------------------------------------- |
---|
122 | private: |
---|
123 | /*! B-spline knot vector (#knots = #control points + degree + 1) */ |
---|
124 | std::vector<typename tSplineCurve::tParameter> knots; |
---|
125 | /*! Bezier control points used to evaluate b-spline curve which is converted to a set of bezier curves */ |
---|
126 | mutable std::vector<typename tShape::tPoint> bezier_control_point_cache; |
---|
127 | mutable unsigned int number_of_segments; |
---|
128 | |
---|
129 | /*! |
---|
130 | * Calculate a uniform knot vector, this->knots will be modified |
---|
131 | */ |
---|
132 | void CalculateKnotVector(); |
---|
133 | |
---|
134 | /*! |
---|
135 | * Calculate all Bezier control points by knot insertion, this->bezier_control_points will be modified |
---|
136 | */ |
---|
137 | void CalculateBezierControlPoints() const; |
---|
138 | |
---|
139 | /*! |
---|
140 | * Recalculate control points affected by a knot insertion |
---|
141 | * @param at Index of the knot to be inserted |
---|
142 | * @param knots_before_insertion Knot vector before knot insertion |
---|
143 | * @param knot The new knot that should be inserted |
---|
144 | * @param control_points Control points before insertion |
---|
145 | * @return Control points after knot insertion |
---|
146 | */ |
---|
147 | static std::vector<typename tShape::tPoint> InsertKnot(int at, const std::vector<typename tSplineCurve::tParameter> &knots_before_insertion, typename tSplineCurve::tParameter knot, const std::vector<typename tShape::tPoint> &control_points); |
---|
148 | |
---|
149 | virtual unsigned int GetSegmentForParameter(typename tSplineCurve::tParameter t) const; |
---|
150 | virtual typename tSplineCurve::tParameter GetLocalParameter(typename tSplineCurve::tParameter t) const; |
---|
151 | |
---|
152 | /*! |
---|
153 | * Create the bezier representation of the B-spline for the given segment id |
---|
154 | * @param id ID of the segment |
---|
155 | * @return Bezier curve of the segment |
---|
156 | */ |
---|
157 | virtual std::shared_ptr<const typename tSplineCurve::tBezierCurve> CreateBezierCurveForSegment(unsigned int i) const; |
---|
158 | |
---|
159 | }; |
---|
160 | |
---|
161 | //---------------------------------------------------------------------- |
---|
162 | // Operators for rrlib_serialization |
---|
163 | //---------------------------------------------------------------------- |
---|
164 | #ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ |
---|
165 | |
---|
166 | template <size_t Tdimension, typename TElement, unsigned int Tdegree> |
---|
167 | serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBSplineCurve<Tdimension, TElement, Tdegree> &spline); |
---|
168 | |
---|
169 | template <size_t Tdimension, typename TElement, unsigned int Tdegree> |
---|
170 | serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBSplineCurve<Tdimension, TElement, Tdegree> &spline); |
---|
171 | |
---|
172 | #endif |
---|
173 | |
---|
174 | //---------------------------------------------------------------------- |
---|
175 | // End of namespace declaration |
---|
176 | //---------------------------------------------------------------------- |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | #include "rrlib/geometry/curves/tBSplineCurve.hpp" |
---|
182 | |
---|
183 | #endif |
---|