linear.h
Go to the documentation of this file.
1#pragma once
2
3#include "../VariantValue.h"
4#include "../exceptions.h"
5
7{
8
9 /**
10 * @brief Linear interpolation visitor: Interpolates between the given values linearly.
11 */
12 class Linear
13 {
14 public:
15 using result_type = VariantValue; ///< Exposed result type.
16
17 public:
18 /**
19 * @brief Interpolator
20 * @param t in [0, 1], where `t = 0` for `lhs` and `t = 1` for `rhs`.
21 */
22 Linear(float t) : t(t)
23 {
24 }
25
26 template <typename U, typename V>
28 operator()(const U&, const V&) const
29 {
31 }
32
34 operator()(const float& lhs, const float& rhs) const
35 {
36 return (1 - t) * lhs + t * rhs;
37 }
38
40 operator()(const Eigen::MatrixXf& lhs, const Eigen::MatrixXf& rhs) const
41 {
42 return (1 - t) * lhs + t * rhs;
43 }
44
46 operator()(const Eigen::Quaternionf& lhs, const Eigen::Quaternionf& rhs) const
47 {
48 return lhs.slerp(t, rhs);
49 }
50
51
52 private:
53 float t;
54 };
55
56 template <typename ReturnT>
57 ReturnT
58 linear(float t, const VariantValue& lhs, const VariantValue& rhs)
59 {
60 VariantValue result = std::visit(Linear{t}, lhs, rhs);
61 return std::get<ReturnT>(result);
62 }
63
64 template <>
65 VariantValue linear<VariantValue>(float t, const VariantValue& lhs, const VariantValue& rhs);
66
67} // namespace armarx::trajectory::interpolate
Eigen::Matrix3f slerp(float, const Eigen::Matrix3f &)
Definition Pose.cpp:233
Linear interpolation visitor: Interpolates between the given values linearly.
Definition linear.h:13
VariantValue operator()(const float &lhs, const float &rhs) const
Definition linear.h:34
VariantValue operator()(const U &, const V &) const
Definition linear.h:28
Linear(float t)
Interpolator.
Definition linear.h:22
VariantValue result_type
Exposed result type.
Definition linear.h:15
VariantValue operator()(const Eigen::Quaternionf &lhs, const Eigen::Quaternionf &rhs) const
Definition linear.h:46
VariantValue operator()(const Eigen::MatrixXf &lhs, const Eigen::MatrixXf &rhs) const
Definition linear.h:40
Quaternion< float, 0 > Quaternionf
ReturnT linear(float t, const VariantValue &lhs, const VariantValue &rhs)
Definition linear.h:58
VariantValue linear< VariantValue >(float t, const VariantValue &lhs, const VariantValue &rhs)
Definition linear.cpp:8
std::variant< float, Eigen::MatrixXf, Eigen::Quaternionf > VariantValue
Variant for trajectory values.