farm-ng-core
common.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 /// @file
10 /// Common functionality.
11 
12 #pragma once
13 
14 #include <Eigen/Core>
15 #include <Eigen/Geometry>
21 
22 #include <cmath>
23 #include <cstdio>
24 #include <cstdlib>
25 #include <random>
26 #include <type_traits>
27 
28 #ifdef __GNUC__
29 #define TION __PRETTY_FUNCTION__
30 #elif (_MSC_VER >= 1310)
31 #define TION __FUNCTION__
32 #else
33 #define TION "unknown"
34 #endif
35 
36 // from <farm_ng/core/logging/format.h>cd
37 #define SOPHUS_FORMAT(...) FARM_FORMAT(__VA_ARGS__)
38 
39 // from <farm_ng/core/logging/logger.h>
40 #define SOPHUS_ASSERT(...) FARM_ASSERT(__VA_ARGS__)
41 #define SOPHUS_ASSERT_EQ(...) FARM_ASSERT_EQ(__VA_ARGS__)
42 #define SOPHUS_ASSERT_GE(...) FARM_ASSERT_GE(__VA_ARGS__)
43 #define SOPHUS_ASSERT_GT(...) FARM_ASSERT_GT(__VA_ARGS__)
44 #define SOPHUS_ASSERT_LE(...) FARM_ASSERT_LE(__VA_ARGS__)
45 #define SOPHUS_ASSERT_LT(...) FARM_ASSERT_LT(__VA_ARGS__)
46 #define SOPHUS_ASSERT_NE(...) FARM_ASSERT_NE(__VA_ARGS__)
47 #define SOPHUS_ASSERT_NEAR(...) FARM_ASSERT_NEAR(__VA_ARGS__)
48 #define SOPHUS_AT(...) FARM_AT(__VA_ARGS__)
49 #define SOPHUS_INFO(...) FARM_INFO(__VA_ARGS__)
50 #define SOPHUS_PANIC(...) FARM_PANIC(__VA_ARGS__)
51 #define SOPHUS_UNIMPLEMENTED(...) FARM_UNIMPLEMENTED(__VA_ARGS__)
52 #define SOPHUS_UNWRAP(...) FARM_UNWRAP(__VA_ARGS__)
53 
54 // from <farm_ng/core/logging/expected.h>
55 #define SOPHUS_TRY(...) FARM_TRY(__VA_ARGS__)
56 #define SOPHUS_ASSERT_OR_ERROR(...) FARM_ASSERT_OR_ERROR(__VA_ARGS__)
57 #define SOPHUS_UNEXPECTED(...) FARM_UNEXPECTED(__VA_ARGS__)
58 
59 namespace sophus {
60 
61 // from <farm_ng/core/misc/variant_utils.h>
65 
66 // from <farm_ng/core/logging/expected.h>
68 using ::farm_ng::Success;
69 
70 struct UninitTag {};
71 
72 template <class TScalar>
73 TScalar const kEpsilon = TScalar(1e-10);
74 
75 template <>
76 inline float const kEpsilon<float> = float(1e-5);
77 
78 static float const kEpsilonF32 = kEpsilon<float>;
79 static float const kEpsilonF64 = kEpsilon<double>;
80 
81 template <class TScalar>
82 TScalar const kEpsilonPlus =
83  kEpsilon<TScalar>*(TScalar(1.) + kEpsilon<TScalar>);
84 
85 using std::sqrt;
86 template <class TScalar>
87 TScalar const kEpsilonSqrt = TScalar(1e-5);
88 
89 template <>
90 inline float const kEpsilonSqrt<float> = float(3.16227766e-3);
91 
92 static float const kEpsilonSqrtF32 = kEpsilonSqrt<float>;
93 static float const kEpsilonSqrtF64 = kEpsilonSqrt<double>;
94 
95 template <class TScalar>
96 TScalar const kPi = TScalar(3.141592653589793238462643383279502884);
97 float const kPiF32 = kPi<float>;
98 double const kPiF64 = kPi<double>;
99 
100 template <class TGenerator>
102  static bool const kValue =
103  std::is_unsigned<typename TGenerator::result_type>::value &&
104  std::is_unsigned<decltype(TGenerator::min())>::value &&
105  std::is_unsigned<decltype(TGenerator::max())>::value;
106 };
107 
108 template <class TGenerator>
111 
112 } // namespace sophus
eigen.h
farm_ng::AlwaysFalse
constexpr bool AlwaysFalse
https://en.cppreference.com/w/cpp/utility/variant/visit
Definition: variant_utils.h:31
sophus::kEpsilonSqrt< float >
const float kEpsilonSqrt< float >
Definition: common.h:90
farm_ng::has_type_v
constexpr bool has_type_v
Definition: variant_utils.h:51
logger.h
sophus::kEpsilon
const TScalar kEpsilon
Definition: common.h:73
format.h
sophus::kPiF64
const double kPiF64
Definition: common.h:98
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::min
auto min(TPoint const &a, TPoint const &b) -> TPoint
Definition: vector_space.h:104
sophus::IsUniformRandomBitGenerator::kValue
static const bool kValue
Definition: common.h:102
expected.h
farm_ng::Overload
Overload(Ts...) -> Overload< Ts... >
sophus::kIsUniformRandomBitGeneratorV
constexpr bool kIsUniformRandomBitGeneratorV
Definition: common.h:109
variant_utils.h
sophus::IsUniformRandomBitGenerator
Definition: common.h:101
sophus::kEpsilonSqrt
const TScalar kEpsilonSqrt
Definition: common.h:87
sophus::kEpsilonPlus
const TScalar kEpsilonPlus
Definition: common.h:82
sophus::kPiF32
const float kPiF32
Definition: common.h:97
sophus::max
auto max(TPoint const &a, TPoint const &b) -> TPoint
Definition: vector_space.h:114
farm_ng::Expected
tl::expected< TT, TE > Expected
Definition: expected.h:37
sophus::kEpsilon< float >
const float kEpsilon< float >
Definition: common.h:76
sophus::UninitTag
Definition: common.h:70
sophus::kPi
const TScalar kPi
Definition: common.h:96