My Project 1.0
Holistic Fusion: A Generic Framework for Multimodal Sensor Fusion
Loading...
Searching...
No Matches
AdmissibleGtsamSymbols.h
Go to the documentation of this file.
1/*
2Copyright 2024 by Julian Nubert, Robotic Systems Lab, ETH Zurich.
3All rights reserved.
4This file is released under the "BSD-3-Clause License".
5Please see the LICENSE file that has been included as part of this package.
6 */
7
8#ifndef ADMISSIBLE_GTSAM_SYMBOLS_H
9#define ADMISSIBLE_GTSAM_SYMBOLS_H
10
11namespace holistic_fusion {
12
13// Compile Time Functions and Constants for Admissible GTSAM Symbols --------------------------------
14// Admissible SYMBOL_CHARs
15constexpr char ADMISSIBLE_DYNAMIC_SYMBOL_CHARS[4] = {'r', 'c', 'd', 'l'};
17
18// Get index of letter at compile time
19template <char SYMBOL_CHAR>
20constexpr int getSymbolIndex() {
21 for (int i = 0; i < sizeof(ADMISSIBLE_DYNAMIC_SYMBOL_CHARS); ++i) {
22 if (SYMBOL_CHAR == ADMISSIBLE_DYNAMIC_SYMBOL_CHARS[i]) {
23 return i;
24 }
25 }
26 // If not found, return -1
27 return -1;
28}
29
30// Count number of n-D states
31template <int n>
32constexpr int countNDStates() {
33 int count = 0;
34 for (int i = 0; i < sizeof(ADMISSIBLE_DYNAMIC_SYMBOL_CHARS); ++i) {
35 if (ADMISSIBLE_DYNAMIC_STATE_DIM[i] == n) {
36 count++;
37 }
38 }
39 return count;
40}
41
42// Get Symbol Array of nD-States
43template <int n, int numStates>
44constexpr std::array<char, numStates> getSymbolArrayForNDStates() {
45 std::array<char, numStates> symbols{};
46 int count = 0;
47 for (int i = 0; i < sizeof(ADMISSIBLE_DYNAMIC_SYMBOL_CHARS); ++i) {
48 if (ADMISSIBLE_DYNAMIC_STATE_DIM[i] == n) {
49 symbols[count] = ADMISSIBLE_DYNAMIC_SYMBOL_CHARS[i];
50 count++;
51 }
52 }
53 return symbols;
54}
55
56// Helper Function to create an array of size N with all elements set to value
57template <typename T, size_t N>
58constexpr auto makeValuedArray(T value) -> std::array<T, N> {
59 std::array<T, N> a{};
60 for (auto& x : a) x = value;
61 return a;
62}
63
64// Function to check whether it is an admissible symbol shorthand
65template <char SYMBOL_CHAR>
66constexpr bool isAdmissibleSymbol() {
67 for (int i = 0; i < sizeof(ADMISSIBLE_DYNAMIC_SYMBOL_CHARS); ++i) {
68 if (SYMBOL_CHAR == ADMISSIBLE_DYNAMIC_SYMBOL_CHARS[i]) {
69 return true;
70 }
71 }
72 return false;
73}
74
75// Use static_assert to include SYMBOL_CHAR in the message
76template <char SYMBOL_CHAR>
77constexpr void checkSymbol() {
78 static_assert(isAdmissibleSymbol<SYMBOL_CHAR>(), "Symbol is not admissible");
79};
80
81// Runtime Helper Functions for Admissible GTSAM Symbols --------------------------------
82// Check whether symbol is in provided character array
83template <int ARRAY_SIZE>
84inline bool isCharInCharArray(const char c, std::array<char, ARRAY_SIZE> charArray) {
85 for (int i = 0; i < ARRAY_SIZE; ++i) {
86 if (c == charArray[i]) {
87 return true;
88 }
89 }
90 return false;
91}
92
93} // namespace holistic_fusion
94
95#endif // ADMISSIBLE_GTSAM_SYMBOLS_H
constexpr int getSymbolIndex()
constexpr auto makeValuedArray(T value) -> std::array< T, N >
constexpr int ADMISSIBLE_DYNAMIC_STATE_DIM[sizeof(ADMISSIBLE_DYNAMIC_SYMBOL_CHARS)]
constexpr bool isAdmissibleSymbol()
constexpr std::array< char, numStates > getSymbolArrayForNDStates()
bool isCharInCharArray(const char c, std::array< char, ARRAY_SIZE > charArray)
constexpr char ADMISSIBLE_DYNAMIC_SYMBOL_CHARS[4]
constexpr void checkSymbol()
constexpr int countNDStates()