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