UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
index.hpp
1
42#ifndef UFO_CONTAINER_TREE_INDEX_HPP
43#define UFO_CONTAINER_TREE_INDEX_HPP
44
45// STL
46#include <algorithm>
47#include <cstdint>
48#include <functional>
49#include <limits>
50#include <ostream>
51
52namespace ufo
53{
54struct TreeIndex {
55 // 64 bits instead, either
56 // 32 bits X high levels
57 // 32 bits Y low levels
58 // or
59 // 32-Dim bits X high levels
60 // 32 bits Y low levels
61 // Dim bits for offset
62
63 using pos_type = std::uint32_t;
64 using offset_type = std::uint32_t;
65
66 static constexpr pos_type const TYPE_BIT =
67 pos_type(1) << (std::numeric_limits<pos_type>::digits - 1);
68 static constexpr pos_type const NULL_POS = std::numeric_limits<pos_type>::max();
69 static constexpr pos_type const PROCESSING_POS = NULL_POS - 1;
70 static constexpr pos_type const INVALID_POS = NULL_POS - 2;
71 static constexpr pos_type const MAX_VALID_POS = INVALID_POS - 1;
72
73 pos_type pos{NULL_POS};
74 offset_type offset{0};
75
76 constexpr TreeIndex() noexcept = default;
77
78 constexpr TreeIndex(pos_type pos, offset_type offset) noexcept
79 : pos(pos), offset(offset)
80 {
81 }
82
83 friend void swap(TreeIndex& lhs, TreeIndex& rhs) noexcept
84 {
85 std::swap(lhs.pos, rhs.pos);
86 std::swap(lhs.offset, rhs.offset);
87 }
88
89 constexpr bool operator==(TreeIndex rhs) const
90 {
91 return pos == rhs.pos && offset == rhs.offset;
92 }
93
94 constexpr bool operator!=(TreeIndex rhs) const { return !(operator==(rhs)); }
95
96 [[nodiscard]] constexpr TreeIndex sibling(offset_type offset) const
97 {
98 return {pos, offset};
99 }
100
101 [[nodiscard]] constexpr bool valid() const { return MAX_VALID_POS >= pos; }
102};
103
104inline std::ostream& operator<<(std::ostream& out, TreeIndex index)
105{
106 return out << "pos: " << +index.pos << " offset: " << +index.offset;
107}
108} // namespace ufo
109
110namespace std
111{
112template <>
113struct hash<ufo::TreeIndex> {
114 std::size_t operator()(ufo::TreeIndex index) const
115 {
116 return (static_cast<std::uint64_t>(index.pos) << 3) | index.offset;
117 }
118};
119} // namespace std
120
121#endif // UFO_CONTAINER_TREE_INDEX_HPP
STL namespace.
All vision-related classes and functions.
Definition cloud.hpp:49