smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
manifold.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <Eigen/Core>
6
7#include "smooth/version.hpp"
8
13SMOOTH_BEGIN_NAMESPACE
14
15namespace traits {
16
20template<typename T>
21struct man;
22
23} // namespace traits
24
25// clang-format off
26
30template<typename M>
31concept Manifold =
32requires (Eigen::Index dof) { //NOLINT
33 // Underlying scalar type
35 // Default representation
37 // Compile-time degrees of freedom (tangent space dimension). Can be dynamic (equal to -1)
38 {traits::man<M>::Dof}->std::convertible_to<int>;
39 // A default-initialized Manifold object (if Dof > 0 then dof = Dof can be assumed)
40 {traits::man<M>::Default(dof)}->std::convertible_to<typename traits::man<M>::PlainObject>;
41} &&
42requires(const M & m1, const M & m2, const Eigen::Vector<typename traits::man<M>::Scalar, traits::man<M>::Dof> & a) {
43 // Run-time degrees of freedom (tangent space dimension)
44 {traits::man<M>::dof(m1)}->std::convertible_to<Eigen::Index>;
45 // Right-plus: add a tangent vector to a Manifold element to obtain a new Manifold element
46 {traits::man<M>::rplus(m1, a)}->std::convertible_to<typename traits::man<M>::PlainObject>;
47 // Right-minus: subtract a Manifold element from another to obtain the difference tangent vector
48 {traits::man<M>::rminus(m1, m2)}->std::convertible_to<Eigen::Vector<typename traits::man<M>::Scalar, traits::man<M>::Dof>>; //NOLINT
49} && (
50 !std::is_convertible_v<typename traits::man<M>::Scalar, double> ||
51 requires (const M & m) { //NOLINT
52 {traits::man<M>::template cast<double>(m)}->std::convertible_to<typename traits::man<M>::template CastT<double>>;
53 }
54) && (
55 !std::is_convertible_v<typename traits::man<M>::Scalar, float> ||
56 requires (const M & m) { //NOLINT
57 {traits::man<M>::template cast<float>(m)}->std::convertible_to<typename traits::man<M>::template CastT<float>>;
58 }
59) &&
60// PlainObject must be default-constructible
61std::is_default_constructible_v<typename traits::man<M>::PlainObject> &&
62std::is_copy_constructible_v<typename traits::man<M>::PlainObject> &&
63// PlainObject must be assignable from M
64std::is_assignable_v<typename traits::man<M>::PlainObject &, M>;
65
66// clang-format on
67
71
72// Static constants
73
79template<Manifold M>
80static inline constexpr int Dof = traits::man<M>::Dof;
81
82// Types
83
87template<Manifold M>
89
93template<Manifold M>
95
99template<typename NewScalar, Manifold M>
101
105template<Manifold M>
106using Tangent = Eigen::Vector<Scalar<M>, Dof<M>>;
107
111template<Manifold M>
112using TangentMap = Eigen::Matrix<Scalar<M>, Dof<M>, Dof<M>>;
113
117template<Manifold M>
118using Hessian = Eigen::Matrix<Scalar<M>, Dof<M>, (Dof<M> > 0 ? Dof<M> * Dof<M> : -1)>;
119
120// Functions
121
125template<Manifold M>
126inline PlainObject<M> Default(Eigen::Index dof)
127{
129}
130
134template<Manifold M>
136 requires(Dof<M> > 0)
137{
138 return traits::man<M>::Default(Dof<M>);
139}
140
144template<Manifold M>
145inline Eigen::Index dof(const M & m)
146{
147 return traits::man<M>::dof(m);
148}
149
153template<typename NewScalar, Manifold M>
154inline CastT<NewScalar, M> cast(const M & m)
155{
156 return traits::man<M>::template cast<NewScalar>(m);
157}
158
162template<Manifold M, typename Derived>
163inline PlainObject<M> rplus(const M & m, const Eigen::MatrixBase<Derived> & a)
164{
165 return traits::man<M>::rplus(m, a);
166}
167
171template<Manifold M, Manifold Mo>
172inline Tangent<M> rminus(const M & g1, const Mo & g2)
173{
174 return traits::man<M>::rminus(g1, g2);
175}
176
177SMOOTH_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
Eigen::Matrix< Scalar< M >, Dof< M >,(Dof< M > > 0 ? Dof< M > *Dof< M > :-1)> Hessian
Matrix of size Dof x Dof*Dof.
Definition manifold.hpp:118
Eigen::Vector< Scalar< M >, Dof< M > > Tangent
Tangent as a Dof-length vector.
Definition manifold.hpp:106
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
Eigen::Matrix< Scalar< M >, Dof< M >, Dof< M > > TangentMap
Matrix of size Dof x Dof.
Definition manifold.hpp:112
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