smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
fit.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 "bspline.hpp"
13#include "spline.hpp"
14
15SMOOTH_BEGIN_NAMESPACE
16
20template<typename T>
21concept SplineSpec = requires(T t) {
22 // clang-format off
23 { T::Degree } -> std::convertible_to<int>;
24 { T::OptDeg } -> std::convertible_to<int>;
25 { T::InnCnt } -> std::convertible_to<int>;
26 { t.LeftDeg };
27 { t.RghtDeg };
28 // clang-format on
29};
30
31namespace spline_specs {
32
38template<LieGroup G, int K>
40{
42 static constexpr int Degree = K;
44 static constexpr int OptDeg = -1;
46 static constexpr int InnCnt = int(K) - 1;
47
49 static constexpr std::array<int, 0> LeftDeg{};
51 std::array<Tangent<G>, 0> left_values{};
52
54 static constexpr std::array<int, 0> RghtDeg{};
56 std::array<Tangent<G>, 0> rght_values{};
57};
58
60template<LieGroup G>
62
64template<LieGroup G>
66
73template<LieGroup G, int P1 = 2, int P2 = P1>
75{
77 static constexpr int Degree = 3;
79 static constexpr int OptDeg = -1;
81 static constexpr int InnCnt = 2;
82
84 static constexpr std::array<int, 1> LeftDeg{P1};
86 std::array<Tangent<G>, 1> left_values{Tangent<G>::Zero()};
87
89 static constexpr std::array<int, 1> RghtDeg{P2};
91 std::array<Tangent<G>, 1> rght_values{Tangent<G>::Zero()};
92};
93
101template<LieGroup G, int K = 6, int O = 3, int P = 3>
103{
105 static constexpr int Degree = K;
107 static constexpr int OptDeg = O;
109 static constexpr int InnCnt = P;
110
112 static constexpr std::array<int, std::size_t(P - 1)> LeftDeg = []() {
113 std::array<int, std::size_t(P - 1)> ret;
114 for (auto i = 0; i + 1 < P; ++i) { ret[static_cast<std::size_t>(i)] = i + 1; }
115 return ret;
116 }();
117
119 std::array<Tangent<G>, std::size_t(P - 1)> left_values = []() {
120 std::array<Tangent<G>, std::size_t(P - 1)> ret;
121 ret.fill(Tangent<G>::Zero());
122 return ret;
123 }();
124
126 static constexpr std::array<int, std::size_t(P - 1)> RghtDeg = LeftDeg;
128 std::array<Tangent<G>, std::size_t(P - 1)> rght_values = left_values;
129};
130
131} // namespace spline_specs
132
150Eigen::VectorXd
151fit_spline_1d(std::ranges::sized_range auto && dt_r, std::ranges::sized_range auto && dx_r, const SplineSpec auto & ss);
152
168 std::ranges::random_access_range auto && ts, std::ranges::random_access_range auto && gs, const SplineSpec auto & ss);
169
181auto fit_spline_cubic(std::ranges::range auto && ts, std::ranges::range auto && gs);
182
200template<int K>
201auto fit_bspline(std::ranges::range auto && ts, std::ranges::range auto && gs, const double dt);
202
203SMOOTH_END_NAMESPACE
204#include "detail/fit_impl.hpp"
B-splines on Lie groups.
Spline specification.
Definition fit.hpp:21
auto fit_spline(std::ranges::random_access_range auto &&ts, std::ranges::random_access_range auto &&gs, const SplineSpec auto &ss)
Fit a Spline to given points.
Eigen::VectorXd fit_spline_1d(std::ranges::sized_range auto &&dt_r, std::ranges::sized_range auto &&dx_r, const SplineSpec auto &ss)
Find N degree K Bernstein polynomials p_i(t) for i = 0, ..., N s.t that satisfies constraints and s....
auto fit_bspline(std::ranges::range auto &&ts, std::ranges::range auto &&gs, const double dt)
Fit a bpsline to data points by solving the optimization problem.
auto fit_spline_cubic(std::ranges::range auto &&ts, std::ranges::range auto &&gs)
Fit a cubic Spline with natural boundary conditions.
Eigen::Vector< Scalar< M >, Dof< M > > Tangent
Tangent as a Dof-length vector.
Definition manifold.hpp:106
Piecewise polynomial splines on lie groups.
SplineSpec for a cubic spline with two boundary conditions.
Definition fit.hpp:75
static constexpr int OptDeg
Optimization degree (absolute integral of derivative OptDeg is minimized)
Definition fit.hpp:79
std::array< Tangent< G >, 1 > rght_values
Values of right-side boundary constraints.
Definition fit.hpp:91
static constexpr std::array< int, 1 > LeftDeg
Degrees of left-side boundary constraints: P1.
Definition fit.hpp:84
static constexpr int InnCnt
Number of derivatives to enforce continuity for.
Definition fit.hpp:81
static constexpr std::array< int, 1 > RghtDeg
Degrees of right-side boundary constraints: P2.
Definition fit.hpp:89
static constexpr int Degree
Polynomial degree.
Definition fit.hpp:77
std::array< Tangent< G >, 1 > left_values
Values of left-side boundary constraints.
Definition fit.hpp:86
SplineSpec for optimized spline.
Definition fit.hpp:103
static constexpr std::array< int, std::size_t(P - 1)> RghtDeg
Degrees of left-side boundary constraints: 1, 2, ..., P-1.
Definition fit.hpp:126
std::array< Tangent< G >, std::size_t(P - 1)> left_values
Values of left-side boundary constraints.
Definition fit.hpp:119
static constexpr std::array< int, std::size_t(P - 1)> LeftDeg
Degrees of left-side boundary constraints: 1, 2, ..., P-1.
Definition fit.hpp:112
std::array< Tangent< G >, std::size_t(P - 1)> rght_values
Values of right-side boundary constraints.
Definition fit.hpp:128
static constexpr int InnCnt
Number of derivatives to enforce continuity for.
Definition fit.hpp:109
static constexpr int Degree
Polynomial degree.
Definition fit.hpp:105
static constexpr int OptDeg
Optimization degree (absolute integral of derivative OptDeg is minimized)
Definition fit.hpp:107
SplineSpec without boundary constraints.
Definition fit.hpp:40
static constexpr std::array< int, 0 > LeftDeg
Degrees of left-side boundary constraints (no constraints)
Definition fit.hpp:49
static constexpr std::array< int, 0 > RghtDeg
Degrees of right-side boundary constraints (no constraints)
Definition fit.hpp:54
static constexpr int OptDeg
Optimization degree (absolute integral of derivative OptDeg is minimized)
Definition fit.hpp:44
std::array< Tangent< G >, 0 > left_values
Values of left-side boundary constraints.
Definition fit.hpp:51
std::array< Tangent< G >, 0 > rght_values
Values of right-side boundary constraints.
Definition fit.hpp:56
static constexpr int InnCnt
Number of derivatives to enforce continuity for.
Definition fit.hpp:46
static constexpr int Degree
Polynomial degree.
Definition fit.hpp:42