UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
length.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_LENGTH_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_LENGTH_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/depth.hpp>
47#include <ufo/container/tree/predicate/filter.hpp>
48#include <ufo/container/tree/predicate/predicate_interval.hpp>
49
50// TODO: Implement
51
52namespace ufo::pred
53{
54namespace detail
55{
56struct Length {
57 using value_type = double;
58
59 int min_depth{};
60 int max_depth{};
61};
62} // namespace detail
63
64template <bool Negated = false>
66
67static constexpr inline Length<false> const length;
68
69template <bool Negated>
70struct Filter<Length<Negated>> {
71 using Pred = Length<Negated>;
72
73 template <class Tree>
74 static constexpr void init(Pred& p, Tree const& t) noexcept
75 {
76 int min_d = -1;
77 int max_d = -1;
78 int num = t.maxNumDepthLevels();
79 for (int d{}; d < num; ++d) {
80 auto l = t.length(d);
81 if (p.min >= l && p.max >= l) {
82 min_d = -1 == min_d ? d : min_d;
83 max_d = d;
84 }
85 }
86
87 if (min_d > 0 && max_d > 0) {
88 p.min_depth = min_d;
89 p.max_depth = max_d;
90 return;
91 }
92
93 if constexpr (Negated) {
94 p.min_depth = std::numeric_limits<int>::lowest();
95 p.max_depth = std::numeric_limits<int>::max();
96 } else {
97 p.min_depth = std::numeric_limits<int>::max();
98 p.max_depth = std::numeric_limits<int>::lowest();
99 }
100 }
101
102 template <class Value>
103 [[nodiscard]] static constexpr bool returnableValue(Pred const&, Value const&) noexcept
104 {
105 return true;
106 }
107
108 template <class Tree>
109 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
110 typename Tree::Node const& n) noexcept
111 {
112 // Cast to int to prevent int to be promoted to unsigned
113 int depth = static_cast<int>(t.depth(n));
114 if constexpr (Negated) {
115 return p.min_depth > depth || p.max_depth < depth;
116 } else {
117 return p.min_depth <= depth && p.max_depth >= depth;
118 }
119 }
120
121 template <class Tree>
122 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
123 typename Tree::Node const& n) noexcept
124 {
125 // Cast to int to prevent int to be promoted to unsigned
126 int depth = static_cast<int>(t.depth(n));
127 if constexpr (Negated) {
128 return 0 < p.min_depth || p.max_depth + 1 < depth;
129 } else {
130 return p.min_depth < depth;
131 }
132 }
133
134 template <class Tree>
135 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
136 typename Tree::Node const& n,
137 typename Tree::Ray const&) noexcept
138 {
139 return returnable(p, t, n);
140 }
141
142 template <class Tree>
143 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
144 typename Tree::Node const& n,
145 typename Tree::Ray const&) noexcept
146 {
147 return traversable(p, t, n);
148 }
149};
150} // namespace ufo::pred
151
152#endif // UFO_CONTAINER_TREE_PREDICATE_LENGTH_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
Length length() const
Returns the length of the tree (/ root node), i.e. leaf_node_length * 2^depth().
Definition tree.hpp:342
static constexpr depth_type maxNumDepthLevels() noexcept
Returns the maximum number of depth levels a tree can have.
Definition tree.hpp:278