UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
child_of.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_CHILD_OF_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_CHILD_OF_HPP
44
45// UFO
46#include <ufo/container/tree/code.hpp>
47#include <ufo/container/tree/predicate/filter.hpp>
48
49// STL
50#include <algorithm>
51#include <cstddef>
52
53namespace ufo::pred
54{
55template <std::size_t Dim, bool Negated = false>
56struct ChildOf {
57 TreeCode<Dim> code;
58
59 constexpr ChildOf(TreeCode<Dim> const& code) noexcept : code(code) {}
60};
61
62// Deduction guide
63template <std::size_t Dim>
65
66template <std::size_t Dim, bool Negated>
67[[nodiscard]] constexpr ChildOf<Dim, !Negated> operator!(
68 ChildOf<Dim, Negated> const& p) noexcept
69{
70 return ChildOf<Dim, !Negated>{p.code};
71}
72
73template <std::size_t Dim, bool Negated>
74struct Filter<ChildOf<Dim, Negated>> {
76
77 template <class Tree>
78 static constexpr void init(Pred&, Tree const&) noexcept
79 {
80 }
81
82 template <class Value>
83 [[nodiscard]] static constexpr bool returnableValue(Pred const&, Value const&) noexcept
84 {
85 return true;
86 }
87
88 template <class Tree>
89 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
90 typename Tree::Node const& n) noexcept
91 {
92 if constexpr (Negated) {
93 return !(p.code.depth() > t.depth(n) &&
94 TreeCode<Dim>::equalAtDepth(p.code, t.code(n), p.code.depth()));
95 } else {
96 return p.code.depth() > t.depth(n) &&
97 TreeCode<Dim>::equalAtDepth(p.code, t.code(n), p.code.depth());
98 }
99 }
100
101 template <class Tree>
102 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
103 typename Tree::Node const& n) noexcept
104 {
105 if constexpr (Negated) {
106 return returnable(p, t, n);
107 } else {
108 return TreeCode<Dim>::equalAtDepth(p.code, t.code(n),
109 std::max(p.code.depth(), t.depth(n)));
110 }
111 }
112
113 template <class Tree>
114 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
115 typename Tree::Node const& n,
116 typename Tree::Ray const&) noexcept
117 {
118 return returnable(p, t, n);
119 }
120
121 template <class Tree>
122 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
123 typename Tree::Node const& n,
124 typename Tree::Ray const&) noexcept
125 {
126 return traversable(p, t, n);
127 }
128};
129} // namespace ufo::pred
130
131#endif // UFO_CONTAINER_TREE_PREDICATE_CHILD_OF_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104
depth_type depth() const
Returns the depth of the root node, i.e. numDepthLevels() - 1.
Definition tree.hpp:290