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_PREDICATE_COORD_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_COORD_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/container/tree/predicate/predicate_interval.hpp>
48
49namespace ufo::pred
50{
51namespace detail
52{
53template <std::size_t Axis>
54struct Coord {
55 using value_type = float;
56};
57} // namespace detail
58
59template <std::size_t Axis, bool Negated = false>
61
62template <bool Negated = false>
63using X = Coord<0, Negated>;
64
65template <bool Negated = false>
66using Y = Coord<1, Negated>;
67
68template <bool Negated = false>
69using Z = Coord<2, Negated>;
70
71template <bool Negated = false>
72using W = Coord<3, Negated>;
73
74static constexpr inline X<false> const x;
75static constexpr inline Y<false> const y;
76static constexpr inline Z<false> const z;
77static constexpr inline W<false> const w;
78
79template <std::size_t Axis, bool Negated>
80struct Filter<Coord<Axis, Negated>> {
82
83 template <class Tree>
84 static constexpr void init(Pred&, Tree const&) noexcept
85 {
86 }
87
88 template <class Value>
89 [[nodiscard]] static constexpr bool returnableValue(Pred const&, Value const&) noexcept
90 {
91 return true;
92 }
93
94 template <class Tree>
95 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
96 typename Tree::Node const& n) noexcept
97 {
98 auto c = t.centerAxis(n, Axis);
99 auto hl = t.halfLength(n)[Axis];
100
101 if constexpr (Negated) {
102 // Check if the interval is outside the node
103 return p.min > c + hl || p.max < c - hl;
104 } else {
105 // Check if the node overlaps with the interval
106 return p.min <= c + hl && p.max >= c - hl;
107 }
108 }
109
110 template <class Tree>
111 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
112 typename Tree::Node const& n) noexcept
113 {
114 auto c = t.centerAxis(n, Axis);
115 auto hl = t.halfLength(n)[Axis];
116
117 if constexpr (Negated) {
118 // Check if the whole node is contained in the negated interval
119 return !(p.min <= c - hl && p.max >= c + hl);
120 } else {
121 // Check if the node overlaps with the interval
122 return p.min <= c + hl && p.max >= c - hl;
123 }
124 }
125
126 template <class Tree>
127 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
128 typename Tree::Node const& n,
129 typename Tree::Ray const&) noexcept
130 {
131 return returnable(p, t, n);
132 }
133
134 template <class Tree>
135 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
136 typename Tree::Node const& n,
137 typename Tree::Ray const&) noexcept
138 {
139 return traversable(p, t, n);
140 }
141};
142} // namespace ufo::pred
143
144#endif // UFO_CONTAINER_TREE_PREDICATE_COORD_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104
Length halfLength() const
Returns the half length of the tree (/ root node), i.e. length() / 2.
Definition tree.hpp:379
coord_type centerAxis(std::size_t axis) const
Returns the center of the tree (/ root node) for the axis specified.
Definition tree.hpp:697