farm-ng-core
typetraits.h
Go to the documentation of this file.
1 // Copyright (c) 2011, Hauke Strasdat
2 // Copyright (c) 2012, Steven Lovegrove
3 // Copyright (c) 2021, farm-ng, inc.
4 //
5 // Use of this source code is governed by an MIT-style
6 // license that can be found in the LICENSE file or at
7 // https://opensource.org/licenses/MIT.
8 
9 #pragma once
10 #include "sophus/common/common.h"
11 
12 #include <ceres/ceres.h>
13 
14 #include <type_traits>
15 
16 namespace sophus {
17 
18 template <class TScalar, std::size_t = sizeof(TScalar)>
19 constexpr std::true_type complete(TScalar*);
20 constexpr std::false_type complete(...);
21 
22 template <class TScalar>
23 using IsSpecialized = decltype(complete(std::declval<TScalar*>()));
24 
25 /// Type trait used to distinguish mappable vector types from scalars
26 ///
27 /// We use this class to distinguish Eigen::Vector<Scalar, kMatrixDim> from
28 /// Scalar types in LieGroup<TScalar>::Tangent
29 ///
30 /// Primary use is mapping LieGroup::Tangent over raw data, with 2 options:
31 /// - LieGroup::Tangent is "scalar" (for Rotation2), then we just dereference
32 /// pointer
33 /// - LieGroup::Tangent is Eigen::Vector<...>, then we need to use Eigen::Map
34 ///
35 /// Specialization of Eigen::internal::traits<TScalar> for TScalar is crucial
36 /// for for constructing Eigen::Map<TScalar>, thus we use that property for
37 /// distinguishing between those two options. At this moment there seem to be no
38 /// option to check this using only "external" API of Eigen
39 template <class TScalar>
40 using IsMappable =
42 
43 template <class TScalar>
45 
46 /// Helper for mapping tangent vectors (scalars) over pointers to data
47 template <class TScalar, typename TE = void>
48 struct Mapper {
49  using Scalar = TScalar;
50  using Map = Scalar&;
51  using ConstMap = Scalar const&;
52 
53  static Map map(Scalar* ptr) noexcept { return *ptr; }
54  static ConstMap map(Scalar const* ptr) noexcept { return *ptr; }
55 };
56 
57 template <class TScalar>
58 struct Mapper<TScalar, typename std::enable_if<kIsMappableV<TScalar>>::type> {
59  using Scalar = typename TScalar::Scalar;
60  using Map = Eigen::Map<TScalar>;
61  using ConstMap = Eigen::Map<const TScalar>;
62 
63  static Map map(Scalar* ptr) noexcept { return Map(ptr); }
64  static ConstMap map(Scalar const* ptr) noexcept { return ConstMap(ptr); }
65 };
66 
67 } // namespace sophus
sophus::Mapper::map
static ConstMap map(Scalar const *ptr) noexcept
Definition: typetraits.h:54
sophus::Mapper::Map
Scalar & Map
Definition: typetraits.h:50
sophus::Mapper< TScalar, typename std::enable_if< kIsMappableV< TScalar > >::type >::ConstMap
Eigen::Map< const TScalar > ConstMap
Definition: typetraits.h:61
sophus::complete
constexpr std::true_type complete(TScalar *)
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::kIsMappableV
constexpr bool kIsMappableV
Definition: typetraits.h:44
sophus::Mapper< TScalar, typename std::enable_if< kIsMappableV< TScalar > >::type >::Scalar
typename TScalar::Scalar Scalar
Definition: typetraits.h:59
sophus::Mapper::Scalar
TScalar Scalar
Definition: typetraits.h:49
sophus::Mapper< TScalar, typename std::enable_if< kIsMappableV< TScalar > >::type >::map
static Map map(Scalar *ptr) noexcept
Definition: typetraits.h:63
sophus::Mapper< TScalar, typename std::enable_if< kIsMappableV< TScalar > >::type >::Map
Eigen::Map< TScalar > Map
Definition: typetraits.h:60
sophus::IsSpecialized
decltype(complete(std::declval< TScalar * >())) IsSpecialized
Definition: typetraits.h:23
sophus::IsMappable
IsSpecialized< Eigen::internal::traits< std::decay_t< TScalar > >> IsMappable
Type trait used to distinguish mappable vector types from scalars.
Definition: typetraits.h:41
common.h
sophus::Mapper
Helper for mapping tangent vectors (scalars) over pointers to data.
Definition: typetraits.h:48
sophus::Mapper::map
static Map map(Scalar *ptr) noexcept
Definition: typetraits.h:53
sophus::Mapper< TScalar, typename std::enable_if< kIsMappableV< TScalar > >::type >::map
static ConstMap map(Scalar const *ptr) noexcept
Definition: typetraits.h:64
sophus::Mapper::ConstMap
Scalar const & ConstMap
Definition: typetraits.h:51
core.event_service.type
type
Definition: event_service.py:547