UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
depth.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_DEPTH_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_DEPTH_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{
53struct Depth {
54 using value_type = int;
55};
56} // namespace detail
57
58template <bool Negated = false>
60
61static constexpr inline Depth<false> const depth;
62
63template <bool Negated>
64struct Filter<Depth<Negated>> {
65 using Pred = Depth<Negated>;
66
67 template <class Tree>
68 static constexpr void init(Pred&, Tree const&) noexcept
69 {
70 }
71
72 template <class Value>
73 [[nodiscard]] static constexpr bool returnableValue(Pred const&, Value const&) noexcept
74 {
75 return true;
76 }
77
78 template <class Tree>
79 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
80 typename Tree::Node const& n) noexcept
81 {
82 // Cast to int to prevent int to be promoted to unsigned
83 int depth = static_cast<int>(t.depth(n));
84 bool ret = p.min <= depth && depth <= p.max;
85 if constexpr (Negated) {
86 return !ret;
87 } else {
88 return ret;
89 }
90 }
91
92 template <class Tree>
93 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
94 typename Tree::Node const& n) noexcept
95 {
96 // Cast to int to prevent int to be promoted to unsigned
97 int depth = static_cast<int>(t.depth(n));
98 if constexpr (Negated) {
99 return 0 < p.min || p.max + 1 < depth;
100 } else {
101 return p.min < depth;
102 }
103 }
104
105 template <class Tree>
106 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
107 typename Tree::Node const& n,
108 typename Tree::Ray const&) noexcept
109 {
110 return returnable(p, t, n);
111 }
112
113 template <class Tree>
114 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
115 typename Tree::Node const& n,
116 typename Tree::Ray const&) noexcept
117 {
118 return traversable(p, t, n);
119 }
120};
121} // namespace ufo::pred
122
123#endif // UFO_CONTAINER_TREE_PREDICATE_DEPTH_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