smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
bundle.hpp
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <tuple>
6
7#include "detail/bundle.hpp"
8#include "detail/macro.hpp"
9#include "detail/tn.hpp"
10#include "lie_group_base.hpp"
11
12SMOOTH_BEGIN_NAMESPACE
13
14// \cond
15// Specializing liebase_info for Eigen vectors makes it possible to use
16// Eigen vectors in the Bundle
17template<int _N, typename _Scalar>
18struct liebase_info<Eigen::Matrix<_Scalar, _N, 1>>
19{
21 using Impl = TnImpl<_N, _Scalar>;
23 using Scalar = _Scalar;
24
26 template<typename NewScalar>
27 using PlainObject = Eigen::Matrix<NewScalar, _N, 1>;
28};
29
30// \endcond
31
47template<typename _Derived>
48class BundleBase : public LieGroupBase<_Derived>
49{
51 using Impl = typename liebase_info<_Derived>::Impl;
52
53protected:
54 BundleBase() = default;
55
56public:
57 SMOOTH_INHERIT_TYPEDEFS;
58
62 static constexpr auto BundleSize = Impl::BundleSize;
63
67 template<std::size_t Idx>
69
73 template<std::size_t Idx>
74 static constexpr auto PartStart = Impl::DofsPsum[Idx];
75
79 template<std::size_t Idx>
80 static constexpr auto PartDof = Impl::Dofs[Idx];
81
85 template<std::size_t Idx>
87 requires is_mutable
88 {
89 return MapDispatch<PartType<Idx>>(static_cast<_Derived &>(*this).data() + std::get<Idx>(Impl::RepSizesPsum));
90 }
91
95 template<std::size_t Idx>
97 {
99 static_cast<const _Derived &>(*this).data() + std::get<Idx>(Impl::RepSizesPsum));
100 }
101};
102
104template<typename T>
105concept LieImplemented = requires {
107 typename liebase_info<T>::Impl;
108};
109
110// \cond
111template<LieImplemented... _Gs>
112class Bundle;
113// \endcond
114
115// \cond
116template<LieImplemented... _Gs>
117struct liebase_info<Bundle<_Gs...>>
118{
119 static constexpr bool is_mutable = true;
120
121 using Impl = BundleImpl<typename liebase_info<_Gs>::Impl...>;
122 using Scalar = std::common_type_t<typename liebase_info<_Gs>::Scalar...>;
123
124 static_assert((std::is_same_v<Scalar, typename liebase_info<_Gs>::Scalar> && ...), "Scalar types must be identical");
125
126 template<typename NewScalar>
128
129 template<std::size_t Idx>
130 using PartPlainObject =
131 typename liebase_info<std::tuple_element_t<Idx, std::tuple<_Gs...>>>::template PlainObject<Scalar>;
132};
133// \endcond
134
140template<LieImplemented... _Gs>
141class Bundle : public BundleBase<Bundle<_Gs...>>
142{
143 using Base = BundleBase<Bundle<_Gs...>>;
144
145 SMOOTH_GROUP_API(Bundle);
146
147public:
151 template<typename... S>
152 requires(std::is_assignable_v<_Gs, S> && ...)
154 {
155 const auto tpl = std::forward_as_tuple(gs...);
156#ifdef __clang__
157#pragma GCC diagnostic push
158#pragma GCC diagnostic ignored "-Wunused-lambda-capture"
159#endif
160 utils::static_for<sizeof...(_Gs)>([this, &tpl](auto i) { Base::template part<i>() = std::get<i>(tpl); });
161#ifdef __clang__
162#pragma GCC diagnostic pop
163#endif
164 }
165};
166
167// \cond
168template<LieImplemented... _Gs>
169struct liebase_info<Map<Bundle<_Gs...>>> : public liebase_info<Bundle<_Gs...>>
170{};
171// \endcond
172
178template<LieImplemented... _Gs>
179class Map<Bundle<_Gs...>> : public BundleBase<Map<Bundle<_Gs...>>>
180{
181 using Base = BundleBase<Map<Bundle<_Gs...>>>;
182
183 SMOOTH_MAP_API();
184};
185
186// \cond
187template<LieImplemented... _Gs>
188struct liebase_info<Map<const Bundle<_Gs...>>> : public liebase_info<Bundle<_Gs...>>
189{
190 static constexpr bool is_mutable = false;
191};
192// \endcond
193
199template<LieImplemented... _Gs>
200class Map<const Bundle<_Gs...>> : public BundleBase<Map<const Bundle<_Gs...>>>
201{
202 using Base = BundleBase<Map<const Bundle<_Gs...>>>;
203
204 SMOOTH_CONST_MAP_API();
205};
206
207SMOOTH_END_NAMESPACE
Base class for Bundle lie groups.
Definition bundle.hpp:49
typename liebase_info< _Derived >::template PartPlainObject< Idx > PartType
Part type.
Definition bundle.hpp:68
static constexpr auto BundleSize
Number of elements in Bundle.
Definition bundle.hpp:62
MapDispatch< PartType< Idx > > part()
Access part no Idx of Bundle.
Definition bundle.hpp:86
static constexpr auto PartDof
Part degrees of freedom.
Definition bundle.hpp:80
MapDispatch< const PartType< Idx > > part() const
Const access part no Idx of Bundle.
Definition bundle.hpp:96
static constexpr auto PartStart
Part starting index (degrees of freedom).
Definition bundle.hpp:74
Storage implementation of Bundle lie group.
Definition bundle.hpp:142
Base class for Lie group types.
static constexpr bool is_mutable
True if underlying storage supports modification.
Eigen::Matrix< Scalar, Dim, Dim > Matrix
Lie group matrix type.
Memory mapping of internal Lie group types.
Type for which liebase_info is properly specified.
Definition bundle.hpp:105
typename traits::man< M >::Scalar Scalar
Manifold scalar type.
Definition manifold.hpp:88
typename traits::man< M >::PlainObject PlainObject
Manifold default type.
Definition manifold.hpp:94
Type trait that maps a type to Lie group operations.