smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
native.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
11
12SMOOTH_BEGIN_NAMESPACE
13
14namespace traits {
20template<typename G>
22 requires {
23 // clang-format off
24 typename G::Scalar;
25 typename G::Tangent;
26 typename G::PlainObject;
27 {G::Dof}->std::convertible_to<int>;
28 {G::IsCommutative}->std::convertible_to<bool>;
29} &&
30(!(G::Dof > 0) || requires {
31 {G::Identity()}->std::convertible_to<typename G::PlainObject>;
32 {G::Random()}->std::convertible_to<typename G::PlainObject>;
33}) &&
34(!(G::Dof == -1) || requires (Eigen::Index dof) { //NOLINT
35 {G::Identity(dof)}->std::convertible_to<typename G::PlainObject>;
36 {G::Random(dof)}->std::convertible_to<typename G::PlainObject>;
37}) &&
38(G::Tangent::SizeAtCompileTime == G::Dof) &&
39requires(const G & g1, const G & g2, typename G::Scalar eps) {
40 {g1.dof()}->std::convertible_to<Eigen::Index>; // degrees of freedom at runtime
41 {g1.Ad()}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof>>;
42 {g1 * g2}->std::convertible_to<typename G::PlainObject>;
43 {g1.inverse()}->std::convertible_to<typename G::PlainObject>;
44 {g1.isApprox(g2, eps)}->std::convertible_to<bool>;
45 {g1.log()}->std::convertible_to<Eigen::Vector<typename G::Scalar, G::Dof>>;
46} &&
47requires(const Eigen::Vector<typename G::Scalar, G::Dof> & a) {
48 {G::ad(a)}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof>>;
49 {G::exp(a)}->std::convertible_to<typename G::PlainObject>;
50 {G::dr_exp(a)}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof>>;
51 {G::dr_expinv(a)}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof>>;
52 {G::d2r_exp(a)}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof * G::Dof>>;
53 {G::d2r_expinv(a)}->std::convertible_to<Eigen::Matrix<typename G::Scalar, G::Dof, G::Dof * G::Dof>>;
54 // clang-format on
55 }; // NOLINT
56
60template<NativeLieGroup G>
61struct lie<G>
62{
63 // \cond
64 using Scalar = typename G::Scalar;
65 template<typename NewScalar>
66 using CastT = typename G::template CastT<NewScalar>;
67 using PlainObject = typename G::PlainObject;
68
69 static constexpr int Dof = G::Dof;
70 static constexpr bool IsCommutative = G::IsCommutative;
71
72 // group interface
73
74 static inline PlainObject Identity([[maybe_unused]] Eigen::Index dof)
75 {
76 if constexpr (G::Dof == -1) {
77 return G::Identity(dof);
78 } else {
79 return G::Identity();
80 }
81 }
82 static inline PlainObject Random([[maybe_unused]] Eigen::Index dof)
83 {
84 if constexpr (G::Dof == -1) {
85 return G::Random(dof);
86 } else {
87 return G::Random();
88 }
89 }
90 static inline typename G::TangentMap Ad(const G & g) { return g.Ad(); }
91 template<NativeLieGroup Go>
92 static inline PlainObject composition(const G & g1, const Go & g2)
93 {
94 return g1.operator*(g2);
95 }
96 static inline Eigen::Index dof(const G &) { return G::Dof; }
97 static inline PlainObject inverse(const G & g) { return g.inverse(); }
98 template<NativeLieGroup Go>
99 static inline bool isApprox(const G & g, const Go & go, Scalar eps)
100 {
101 return g.isApprox(go, eps);
102 }
103 static inline typename G::Tangent log(const G & g) { return g.log(); }
104 template<typename NewScalar>
105 static inline CastT<NewScalar> cast(const G & g)
106 {
107 return g.template cast<NewScalar>();
108 }
109
110 // tangent interface
111
112 template<typename Derived>
113 static inline typename G::TangentMap ad(const Eigen::MatrixBase<Derived> & a)
114 {
115 return G::ad(a);
116 }
117 template<typename Derived>
118 static inline PlainObject exp(const Eigen::MatrixBase<Derived> & a)
119 {
120 return G::exp(a);
121 }
122 template<typename Derived>
123 static inline typename G::TangentMap dr_exp(const Eigen::MatrixBase<Derived> & a)
124 {
125 return G::dr_exp(a);
126 }
127 template<typename Derived>
128 static inline typename G::TangentMap dr_expinv(const Eigen::MatrixBase<Derived> & a)
129 {
130 return G::dr_expinv(a);
131 }
132 template<typename Derived>
133 static inline typename G::Hessian d2r_exp(const Eigen::MatrixBase<Derived> & a)
134 {
135 return G::d2r_exp(a);
136 }
137 template<typename Derived>
138 static inline typename G::Hessian d2r_expinv(const Eigen::MatrixBase<Derived> & a)
139 {
140 return G::d2r_expinv(a);
141 }
142 // \endcond
143};
144
145} // namespace traits
146
147SMOOTH_END_NAMESPACE
Concept defining class with an internal Lie group interface.
Definition native.hpp:21
TangentMap< G > Ad(const G &g)
Group adjoint .
PlainObject< G > Random()
Random element in Lie group with static Dof.
Hessian< G > d2r_exp(Arg &&a)
Right Hessian of exponential map.
bool isApprox(const G &g, Arg &&a, typename traits::lie< G >::Scalar eps=Eigen::NumTraits< typename traits::lie< G >::Scalar >::dummy_precision())
Check if two group elements are approximately equal.
Tangent< G > log(const G &g)
Group logarithm.
TangentMap< G > dr_exp(Arg &&a)
Right Jacobian of exponential map.
PlainObject< G > composition(const G &g, Arg &&a)
Group binary composition.
PlainObject< G > exp(Arg &&a)
Lie algebra exponential.
Hessian< G > d2r_expinv(Arg &&a)
Right Hessian of exponential map inverse.
PlainObject< G > Identity()
Identity in Lie group with static Dof.
TangentMap< G > ad(Arg &&a)
Lie algebra adjoint .
PlainObject< G > inverse(const G &g)
Group inverse.
TangentMap< G > dr_expinv(Arg &&a)
Right Jacobian of exponential map inverse.
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
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 LieGroup instance via specialization.
Definition lie_group.hpp:23