smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
spline.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
10#include <ranges>
11
12#include "../lie_groups.hpp"
13#include "common.hpp"
14
15SMOOTH_BEGIN_NAMESPACE
16
26template<int K, LieGroup G>
27class Spline
28{
29public:
30 static_assert(Dof<G> > 0, "Dof<G> must be known at compile time.");
31
36 Spline(const G & ga = Identity<G>());
37
45 Spline(double T, Eigen::Matrix<double, Dof<G>, K> && V, G && ga = Identity<G>());
46
54 template<typename Derived>
55 Spline(double T, const Eigen::MatrixBase<Derived> & V, const G & ga = Identity<G>());
56
64 template<std::ranges::range Rv>
65 requires(std::is_same_v<std::ranges::range_value_t<Rv>, Tangent<G>>)
66 Spline(double T, const Rv & vs, const G & ga = Identity<G>());
67
69 Spline(const Spline &) = default;
70
72 Spline(Spline &&) = default;
73
75 Spline & operator=(const Spline &) = default;
76
78 Spline & operator=(Spline &&) = default;
79
81 ~Spline() = default;
82
95 [[nodiscard]] static Spline ConstantVelocityGoal(const G & gb, double T = 1, const G & ga = Identity<G>());
96
109 [[nodiscard]] static Spline ConstantVelocity(const Tangent<G> & v, double T = 1, const G & ga = Identity<G>());
110
119 [[nodiscard]] static Spline
120 FixedCubic(const G & gb, const Tangent<G> & va, const Tangent<G> & vb, double T = 1, const G & ga = Identity<G>())
121 requires(K == 3);
122
124 [[nodiscard]] std::size_t size() const;
125
127 [[nodiscard]] bool empty() const;
128
130 void reserve(std::size_t capacity);
131
133 [[nodiscard]] double t_min() const;
134
136 [[nodiscard]] double t_max() const;
137
139 [[nodiscard]] G start() const;
140
142 [[nodiscard]] G end() const;
143
146
160 Spline & concat_global(const Spline & other);
161
178 Spline & concat_local(const Spline & other);
179
187 Spline & operator+=(const Spline & other);
188
194 [[nodiscard]] Spline operator+(const Spline & other);
195
209 template<typename S = double>
210 CastT<S, G> operator()(const S & t, OptTangent<CastT<S, G>> vel = {}, OptTangent<CastT<S, G>> acc = {}) const;
211
223 [[nodiscard]] Tangent<G> arclength(double t) const
224 requires(K == 3);
225
242 [[nodiscard]] Spline crop(double ta, double tb = std::numeric_limits<double>::infinity(), bool localize = true) const;
243
244private:
245 std::size_t find_idx(double t) const;
246
247 // segment i is defined by
248 //
249 // - time interval: m_end_t[i-1], m_end_t[i]
250 // - g interval: m_end_g[i-1], m_end_g[i]
251 // - velocities: m_Vs[i]
252 // - crop: m_seg_T0[i], m_seg_Del[i]
253 //
254 // s.t.
255 //
256 // u(t) = T0[i] + Del[i] * (t - end_t[i-1]) / (end_t[i] - end_t[i-1])
257 //
258 // x(t) = xu(u(t)) where xu is spline defined in [0, 1]
259
260 // Spline starting point
261 G m_g0;
262
263 // segment end times
264 std::vector<double> m_end_t;
265
266 // segment end points
267 std::vector<G> m_end_g;
268
269 // segment bezier velocities
270 std::vector<Eigen::Matrix<double, Dof<G>, K>> m_Vs;
271
272 // segment crop information
273 std::vector<double> m_seg_T0, m_seg_Del;
274};
275
279template<LieGroup G>
281
282SMOOTH_END_NAMESPACE
283#include "detail/spline_impl.hpp"
Single-parameter Lie group-valued function.
Definition spline.hpp:28
Spline & operator=(Spline &&)=default
Move assignment.
Spline & concat_global(const Spline &other)
In-place concatenation with a global Spline.
Spline & concat_local(const Spline &other)
In-place local concatenation.
double t_min() const
Start time of Spline (always equal to zero).
void reserve(std::size_t capacity)
Allocate space for capacity segments.
G start() const
Spline start value (always equal to identity).
double t_max() const
End time of Spline.
Spline(Spline &&)=default
Move constructor.
static Spline ConstantVelocity(const Tangent< G > &v, double T=1, const G &ga=Identity< G >())
Create constant-velocity Spline.
Tangent< G > arclength(double t) const
Get approximate arclength traversed at time T.
~Spline()=default
Destructor.
static Spline FixedCubic(const G &gb, const Tangent< G > &va, const Tangent< G > &vb, double T=1, const G &ga=Identity< G >())
Create Spline with given start and end position and velocities.
Spline & operator+=(const Spline &other)
Operator overload for local concatenation.
Spline(double T, const Rv &vs, const G &ga=Identity< G >())
Create Spline with one segment and given velocities.
Spline(double T, const Eigen::MatrixBase< Derived > &V, const G &ga=Identity< G >())
Create Spline with one segment and given velocity control points.
bool empty() const
True if Spline has zero size()
Spline(const Spline &)=default
Copy constructor.
Spline & operator=(const Spline &)=default
Copy assignment.
Spline(const G &ga=Identity< G >())
Default constructor creates an empty Spline starting at a given point.
static Spline ConstantVelocityGoal(const G &gb, double T=1, const G &ga=Identity< G >())
Create constant-velocity Spline that reaches a given target state.
std::size_t size() const
Number of Spline segments.
CastT< S, G > operator()(const S &t, OptTangent< CastT< S, G > > vel={}, OptTangent< CastT< S, G > > acc={}) const
Evaluate Spline at given time.
Spline(double T, Eigen::Matrix< double, Dof< G >, K > &&V, G &&ga=Identity< G >())
Create Spline with one segment and given velocity control points.
void make_local()
Move start of Spline to Identity()
Spline crop(double ta, double tb=std::numeric_limits< double >::infinity(), bool localize=true) const
Crop Spline.
G end() const
Spline end value.
Spline operator+(const Spline &other)
Local Spline concatenation.
Eigen::Vector< Scalar< M >, Dof< M > > Tangent
Tangent as a Dof-length vector.
Definition manifold.hpp:106
typename traits::man< M >::template CastT< NewScalar > CastT
Cast'ed type.
Definition manifold.hpp:100