smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
variant.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
10#include <tuple>
11#include <variant>
12
14
15SMOOTH_BEGIN_NAMESPACE
16
17namespace traits {
21template<Manifold... Ms>
22struct man<std::variant<Ms...>>
23{
24 // \cond
25 using Scalar = std::common_type_t<typename traits::man<Ms>::Scalar...>;
26 using PlainObject = std::variant<Ms...>;
27 template<typename NewScalar>
28 using CastT = std::variant<typename traits::man<Ms>::template CastT<NewScalar>...>;
29
30 static constexpr int Dof = -1;
31
32 static inline Eigen::Index dof(const PlainObject & m)
33 {
34 const auto visitor = []<Manifold Mi>(const Mi & x) { return traits::man<Mi>::dof(x); }; // NOLINT
35 return std::visit(visitor, m);
36 }
37
38 static inline PlainObject Default(Eigen::Index dof)
39 {
40 return traits::man<std::tuple_element_t<0, std::tuple<Ms...>>>::Default(dof);
41 }
42
43 template<typename NewScalar>
44 static inline CastT<NewScalar> cast(const PlainObject & m)
45 {
46 const auto visitor = []<Manifold Mi>(const Mi & x) -> CastT<NewScalar> {
47 return traits::man<Mi>::template cast<NewScalar>(x);
48 };
49 return std::visit(visitor, m);
50 }
51
52 template<typename Derived>
53 static inline PlainObject rplus(const PlainObject & m, const Eigen::MatrixBase<Derived> & a)
54 {
55 const auto visitor = [&a]<Manifold Mi>(const Mi & x) -> PlainObject { return traits::man<Mi>::rplus(x, a); };
56 return std::visit(visitor, m);
57 }
58
59 static inline Eigen::Matrix<Scalar, Dof, 1> rminus(const PlainObject & m1, const PlainObject & m2)
60 {
61 const auto visitor = [&m2]<Manifold Mi>(const Mi & x) -> Eigen::VectorX<Scalar> {
62 return traits::man<Mi>::rminus(x, std::get<Mi>(m2));
63 };
64 return std::visit(visitor, m1);
65 }
66 // \endcond
67};
68
69} // namespace traits
70
71SMOOTH_END_NAMESPACE
Class-external Manifold interface defined through the traits::man trait class.
Definition manifold.hpp:31
PlainObject< M > Default()
Default-initialized Manifold with static dof.
Definition manifold.hpp:135
typename traits::man< M >::Scalar Scalar
Manifold scalar type.
Definition manifold.hpp:88
Eigen::Index dof(const M &m)
Manifold degrees of freedom (tangent space dimension)
Definition manifold.hpp:145
Tangent< M > rminus(const M &g1, const Mo &g2)
Manifold right-minus.
Definition manifold.hpp:172
PlainObject< M > rplus(const M &m, const Eigen::MatrixBase< Derived > &a)
Manifold right-plus.
Definition manifold.hpp:163
typename traits::man< M >::template CastT< NewScalar > CastT
Cast'ed type.
Definition manifold.hpp:100
CastT< NewScalar, M > cast(const M &m)
Cast to different scalar type.
Definition manifold.hpp:154
typename traits::man< M >::PlainObject PlainObject
Manifold default type.
Definition manifold.hpp:94
Trait class for making a class a Manifold instance via specialization.
Definition manifold.hpp:21