farm-ng-core
params.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 
11 #include "sophus/common/common.h"
12 #include "sophus/concepts/point.h"
13 #include "sophus/concepts/utils.h"
14 
15 namespace sophus {
16 namespace concepts {
17 
18 template <class TT>
19 concept ParamsImpl = std::is_same_v<
20  typename TT::Params,
21  Eigen::Vector<typename TT::Scalar, TT::kNumParams>> &&
22  requires(typename TT::Params params) {
23  // constructors and factories
24  { TT::areParamsValid(params) } -> ConvertibleTo<sophus::Expected<Success>>;
25 
26  { TT::paramsExamples() } -> ConvertibleTo<std::vector<typename TT::Params>>;
27 
28  {
29  TT::invalidParamsExamples()
30  } -> ConvertibleTo<std::vector<typename TT::Params>>;
31 };
32 
33 template <class TT>
34 concept Tangent = std::is_same_v<
35  typename TT::Tangent,
36  Eigen::Vector<typename TT::Scalar, TT::kDof>> && requires() {
37  { TT::tangentExamples() } -> ConvertibleTo<std::vector<typename TT::Tangent>>;
38 };
39 
40 template <class TT>
41 concept Params = std::is_same_v<
42  typename TT::Params,
43  Eigen::Vector<typename TT::Scalar, TT::kNumParams>> &&
44  requires(TT m, typename TT::Params params) {
45  // constructors and factories
46  { TT::fromParams(params) } -> ConvertibleTo<TT>;
47 
48  {m.setParams(params)};
49 
50  { m.params() } -> ConvertibleTo<typename TT::Params>;
51 
52  { m.ptr() } -> ConvertibleTo<typename TT::Scalar const *>;
53 
54  { m.unsafeMutPtr() } -> ConvertibleTo<typename TT::Scalar *>;
55 };
56 
57 // Example scalar type to be used when specifying concepts interfaces.
58 //
59 // The main motivation are compatible scalar types such as
60 // ceres::Jet<double,...> which mix well with the scalar ``double``.
61 // However, we do not want include ceres::Jet<double,...> here.
62 template <class TT>
64  CompatScalarEx(TT const &value) : value(value) {}
65 
66  TT value;
67 };
68 
69 } // namespace concepts
70 } // namespace sophus
71 
72 namespace Eigen {
73 
74 // This is mirrored from ceres::Jet.
75 template <class TT>
76 struct NumTraits<sophus::concepts::CompatScalarEx<TT>> {
81 
82  static bool constexpr IsComplex = false;
83  static bool constexpr IsInteger = false;
84 
87  }
88 
89  inline static Real epsilon() {
90  return Real(std::numeric_limits<TT>::epsilon());
91  }
92 
93  inline static int digits10() { return NumTraits<TT>::digits10(); }
94 
95  inline static Real highest() {
97  }
98  inline static Real lowest() {
100  }
101 };
102 
103 template <class BinaryOp, class TT>
104 struct ScalarBinaryOpTraits<
105  sophus::concepts::CompatScalarEx<TT>,
106  TT,
107  BinaryOp> {
109 };
110 template <class BinaryOp, class TT>
111 struct ScalarBinaryOpTraits<
112  TT,
113  sophus::concepts::CompatScalarEx<TT>,
114  BinaryOp> {
116 };
117 
118 } // namespace Eigen
Eigen
Definition: params.h:72
point.h
Eigen::NumTraits< sophus::concepts::CompatScalarEx< TT > >::lowest
static Real lowest()
Definition: params.h:98
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
Eigen::NumTraits< sophus::concepts::CompatScalarEx< TT > >::digits10
static int digits10()
Definition: params.h:93
sophus::concepts::ParamsImpl
concept ParamsImpl
Definition: params.h:19
sophus::concepts::CompatScalarEx::CompatScalarEx
CompatScalarEx(TT const &value)
Definition: params.h:64
Eigen::NumTraits< sophus::concepts::CompatScalarEx< TT > >::epsilon
static Real epsilon()
Definition: params.h:89
utils.h
sophus::concepts::Tangent
concept Tangent
Definition: params.h:34
sophus::concepts::CompatScalarEx::value
TT value
Definition: params.h:66
Eigen::NumTraits< sophus::concepts::CompatScalarEx< TT > >::dummy_precision
static sophus::concepts::CompatScalarEx< TT > dummy_precision()
Definition: params.h:85
common.h
Eigen::NumTraits< sophus::concepts::CompatScalarEx< TT > >::highest
static Real highest()
Definition: params.h:95
sophus::concepts::CompatScalarEx
Definition: params.h:63
sophus::max
auto max(TPoint const &a, TPoint const &b) -> TPoint
Definition: vector_space.h:114
sophus::concepts::Params
concept Params
Definition: params.h:41