UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
label.hpp
1
42#ifndef UFO_MAP_LABELS_PREDICATE_LABEL_HPP
43#define UFO_MAP_LABELS_PREDICATE_LABEL_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/container/tree/predicate/predicate_compare.hpp>
48#include <ufo/core/label.hpp>
49#include <ufo/map/labels/propagation_criteria.hpp>
50
51namespace ufo::pred
52{
53template <bool Negated = false>
54struct Label {
55 Label(label_t label) : label(label) {}
56
57 label_t label;
58};
59
60template <bool Negated>
62{
63 return {};
64}
65
66template <bool Negated>
67struct Filter<Label<Negated>> {
68 using Pred = Label<Negated>;
69
70 template <class Tree>
71 static constexpr void init(Pred& p, Tree const& t)
72 {
73 }
74
75 template <class Tree, class Node>
76 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
77 Node const& n)
78 {
79 // TODO: Do this better
80 auto ls = t.labels(n.index);
81 if constexpr (Negated) {
82 return ls.find(p.label) == ls.end();
83 } else {
84 return ls.find(p.label) != ls.end();
85 }
86 }
87
88 template <class Tree, class Node>
89 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
90 Node const& n)
91 {
92 if constexpr (Negated) {
93 return true;
94 } else {
95 // TODO: Do this better
96 auto ls = t.labels(n.index);
97 switch (t.labelsPropagationCriteria()) {
98 case LabelsPropagationCriteria::ALL: {
99 return ls.find(p.label) != ls.end();
100 }
101 case LabelsPropagationCriteria::SUMMARY: {
102 return !ls.empty() && *ls.begin() & p.label == p.label;
103 }
104 case LabelsPropagationCriteria::MIN: {
105 return !ls.empty() && *ls.begin() < p.label;
106 }
107 case LabelsPropagationCriteria::MAX: {
108 return !ls.empty() && *ls.begin() > p.label;
109 return true;
110 }
111 case LabelsPropagationCriteria::NONE: {
112 return true;
113 }
114 }
115 }
116 return true;
117 }
118};
119
120} // namespace ufo::pred
121
122#endif // UFO_MAP_LABELS_PREDICATE_LABEL_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104