UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
distance_2d_lut_gen.cpp
1#include <array>
2#include <bitset>
3#include <cstdint>
4#include <iostream>
5#include <limits>
6#include <utility>
7#include <vector>
8
9void print(std::array<std::array<bool, 13>, 13> const& adj)
10{
11 for (unsigned i{}; adj.size() > i; ++i) {
12 for (unsigned j{}; adj[i].size() > j; ++j) {
13 std::cout << adj[i][j] << ' ';
14 }
15 std::cout << '\n';
16 }
17}
18
19[[nodiscard]] std::vector<std::pair<unsigned, unsigned>> generate(unsigned idx)
20{
21 std::array<std::array<bool, 13>, 13> adj{};
22
23 // Center is always there
24 adj[4][4] = true;
25
26 for (unsigned i{}; 8 > i; ++i) {
27 if (4 <= i) {
28 adj[i + 1][i + 1] = (idx & (1u << i)) ? true : false;
29 } else {
30 adj[i][i] = (idx & (1u << i)) ? true : false;
31 }
32 }
33
34 for (unsigned i = 9; 13 > i; ++i) {
35 adj[i][i] = true;
36 }
37
38 // if (1 == idx) {
39 // std::cout << '\n';
40 // print(adj);
41 // exit(0);
42 // }
43
44 // 0 -> 1
45 // 0 -> 3
46 // 0 -> 9
47 adj[0][1] = adj[0][0] && adj[1][1];
48 adj[0][3] = adj[0][0] && adj[3][3];
49 adj[0][9] = adj[0][0] && !(adj[1][1] && adj[3][3]);
50
51 // 1 -> 2
52 // 1 -> 4
53 // 1 -> 9
54 // 1 -> 10
55 adj[1][2] = adj[1][1] && adj[2][2];
56 adj[1][4] = adj[1][1] && ((!adj[0][0] && !adj[3][3]) || (!adj[2][2] && !adj[5][5]));
57 adj[1][9] = adj[1][1] && !adj[0][0] && adj[3][3];
58 adj[1][10] = adj[1][1] && !adj[2][2] && adj[5][5];
59
60 // 2 -> 5
61 // 2 -> 10
62 adj[2][5] = adj[2][2] && adj[5][5];
63 adj[2][10] = adj[2][2] && !(adj[1][1] && adj[5][5]);
64
65 // 3 -> 4
66 // 3 -> 6
67 // 3 -> 9
68 // 3 -> 11
69 adj[3][4] = adj[3][3] && ((!adj[0][0] && !adj[1][1]) || (!adj[6][6] && !adj[7][7]));
70 adj[3][6] = adj[3][3] && adj[6][6];
71 adj[3][9] = adj[3][3] && !adj[0][0] && adj[1][1];
72 adj[3][11] = adj[3][3] && !adj[6][6] && adj[7][7];
73
74 // 4 -> 5
75 // 4 -> 7
76 // 4 -> 9
77 // 4 -> 10
78 // 4 -> 11
79 // 4 -> 12
80 // 4, 4 always exists
81 adj[4][5] = ((!adj[1][1] && !adj[2][2]) || (!adj[7][7] && !adj[8][8]));
82 adj[4][7] = ((!adj[3][3] && !adj[6][6]) || (!adj[5][5] && !adj[8][8]));
83 adj[4][9] = adj[0][0] && !(adj[1][1] && adj[3][3]);
84 adj[4][10] = adj[2][2] && !(adj[1][1] && adj[5][5]);
85 adj[4][11] = adj[6][6] && !(adj[3][3] && adj[7][7]);
86 adj[4][12] = adj[8][8] && !(adj[5][5] && adj[7][7]);
87
88 // 5 -> 8
89 // 5 -> 10
90 // 5 -> 12
91 adj[5][8] = adj[5][5] && adj[8][8];
92 adj[5][10] = adj[5][5] && adj[1][1] && !adj[2][2];
93 adj[5][12] = adj[5][5] && adj[7][7] && !adj[8][8];
94
95 // 6 -> 7
96 // 6 -> 11
97 adj[6][7] = adj[6][6] && adj[7][7];
98 adj[6][11] = adj[6][6] && !(adj[3][3] && adj[7][7]);
99
100 // 7 -> 8
101 // 7 -> 11
102 // 7 -> 12
103 adj[7][8] = adj[7][7] && adj[8][8];
104 adj[7][11] = adj[7][7] && adj[3][3] && !adj[6][6];
105 adj[7][12] = adj[7][7] && adj[5][5] && !adj[8][8];
106
107 // 8 -> 12
108 adj[8][12] = adj[8][8] && !(adj[5][5] && adj[7][7]);
109
110 std::vector<std::pair<unsigned, unsigned>> edges;
111
112 for (unsigned i{}; adj.size() > i; ++i) {
113 for (unsigned j = i + 1; adj[i].size() > j; ++j) {
114 if (adj[i][i] && adj[j][j] && adj[i][j]) {
115 edges.emplace_back(i, j);
116 }
117 }
118 }
119
120 return edges;
121}
122
123int main(int argc, char* argv[])
124{
125 for (unsigned i{}; std::numeric_limits<std::uint8_t>::max() >= i; ++i) {
126 // std::cout << "Index: " << i << " (" << std::bitset<8>(i) << ")\n";
127 std::cout << R"(std::array<std::uint8_t, 25>{)";
128 auto a = generate(i);
129 std::cout << (2 * a.size());
130 for (auto [a, b] : a) {
131 std::cout << ", " << a << ", " << b;
132 }
133 std::cout << "},\n";
134 }
135
136 return 0;
137}
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.
Definition lab.hpp:326
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
Definition lab.hpp:310