UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
coord.hpp
1
42#ifndef UFO_CONTAINER_TREE_COORD_HPP
43#define UFO_CONTAINER_TREE_COORD_HPP
44
45// UFO
46#include <ufo/numeric/detail/vec.hpp>
47#include <ufo/utility/type_traits.hpp>
48
49// STL
50#include <cstddef>
51#include <ostream>
52#include <type_traits>
53
54namespace ufo
55{
56template <std::size_t Dim, class T = float>
57struct TreeCoord : public Vec<Dim, T> {
58 using Point = Vec<Dim, T>;
59 using coord_t = typename Point::value_type;
60 using depth_t = unsigned;
61
62 depth_t depth{};
63
64 constexpr TreeCoord() noexcept = default;
65 constexpr TreeCoord(TreeCoord const& ohter) noexcept = default;
66 constexpr TreeCoord(TreeCoord&&) noexcept = default;
67
68 template <std::size_t D, class U>
69 constexpr TreeCoord(TreeCoord<D, U> const& other) noexcept
70 : Vec<Dim, T>(static_cast<Vec<D, U> const&>(other)), depth(other.depth)
71 {
72 }
73
74 constexpr TreeCoord& operator=(TreeCoord const&) noexcept = default;
75 constexpr TreeCoord& operator=(TreeCoord&&) noexcept = default;
76
77 template <std::size_t D, class U>
78 constexpr TreeCoord& operator=(TreeCoord<D, U> const& rhs) noexcept
79 {
80 static_cast<Vec<Dim, T>&>(*this) = static_cast<Vec<D, U> const&>(rhs);
81 depth = rhs.depth;
82 return *this;
83 }
84
85 constexpr explicit TreeCoord(T value) noexcept : Point(value) {}
86
87 template <std::size_t D, class U>
88 constexpr explicit TreeCoord(Vec<D, U> const& coord) noexcept : Point(coord)
89 {
90 }
91
92 template <std::size_t D, class U>
93 constexpr TreeCoord(Vec<D, U> const& coord, depth_t depth) noexcept
94 : Point(coord), depth(depth)
95 {
96 }
97
98 template <class... Args,
99 std::enable_if_t<Dim == sizeof...(Args) && (std::is_scalar_v<Args> && ...),
100 bool> = true>
101 constexpr TreeCoord(Args&&... args) noexcept : Point(std::forward<Args>(args)...)
102 {
103 }
104
105 template <class... Args, std::enable_if_t<Dim + 1 == sizeof...(Args) &&
106 (std::is_scalar_v<Args> && ...),
107 bool> = true>
108 constexpr TreeCoord(Args&&... args) noexcept
109 : TreeCoord(std::integral_constant<std::size_t, Dim>{}, std::forward<Args>(args)...)
110 {
111 }
112
113 private:
114 template <std::size_t NumTimes, class First, class... Rest>
115 constexpr TreeCoord(std::integral_constant<std::size_t, NumTimes>, First&& first,
116 Rest&&... rest) noexcept
117 : TreeCoord(std::integral_constant<std::size_t, NumTimes - 1>{},
118 std::forward<Rest>(rest)..., std::forward<First>(first))
119 {
120 }
121
122 template <class Depth, class... Args>
123 constexpr TreeCoord(std::integral_constant<std::size_t, 0>, Depth&& depth,
124 Args&&... args) noexcept
125 : Point(std::forward<Args>(args)...), depth(std::forward<Depth>(depth))
126 {
127 }
128};
129
130//
131// Deduction guide
132//
133
134template <std::size_t Dim, class T>
136
137template <std::size_t Dim, class T>
139
140template <std::size_t Dim, class T>
141constexpr bool operator==(TreeCoord<Dim, T> const& lhs, TreeCoord<Dim, T> const& rhs)
142{
143 return lhs.depth == rhs.depth &&
144 static_cast<Vec<Dim, T> const&>(lhs) == static_cast<Vec<Dim, T> const&>(rhs);
145}
146
147template <std::size_t Dim, class T>
148constexpr bool operator!=(TreeCoord<Dim, T> const& lhs, TreeCoord<Dim, T> const& rhs)
149{
150 return !(lhs == rhs);
151}
152
153template <std::size_t Dim, class T>
154std::ostream& operator<<(std::ostream& out, TreeCoord<Dim, T> const& tc)
155{
156 return out << static_cast<Vec<Dim, T> const&>(tc) << " d: " << tc.depth;
157}
158
159using BinaryCoord = TreeCoord<1, float>;
160using QuadCoord = TreeCoord<2, float>;
161using OctCoord = TreeCoord<3, float>;
162using HexCoord = TreeCoord<4, float>;
163
164template <class T = float>
165using Coord1 = TreeCoord<1, T>;
166template <class T = float>
167using Coord2 = TreeCoord<2, T>;
168template <class T = float>
169using Coord3 = TreeCoord<3, T>;
170template <class T = float>
171using Coord4 = TreeCoord<4, T>;
172
173using Coord1f = TreeCoord<1, float>;
174using Coord2f = TreeCoord<2, float>;
175using Coord3f = TreeCoord<3, float>;
176using Coord4f = TreeCoord<4, float>;
177
178using Coord1d = TreeCoord<1, double>;
179using Coord2d = TreeCoord<2, double>;
180using Coord3d = TreeCoord<3, double>;
181using Coord4d = TreeCoord<4, double>;
182} // namespace ufo
183
184#endif // UFO_CONTAINER_TREE_COORD_HPP
All vision-related classes and functions.
Definition cloud.hpp:49
A fixed-size arithmetic vector of up to 4 dimensions.
Definition vec.hpp:76