UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
cost.hpp
1
42#ifndef UFO_MAP_COST_PREDICATE_COST_HPP
43#define UFO_MAP_COST_PREDICATE_COST_HPP
44
45// UFO
46#include <ufo/container/tree/index.hpp>
47#include <ufo/container/tree/predicate/filter.hpp>
48#include <ufo/container/tree/predicate/predicate_compare.hpp>
49#include <ufo/map/cost/propagation_criteria.hpp>
50
51// STL
52#include <cassert>
53
54namespace ufo::pred
55{
56template <PredicateCompare PC = PredicateCompare::EQUAL>
57struct Cost {
58 using cost_t = float;
59
60 Cost(cost_t cost) : cost(cost) {}
61
62 cost_t cost;
63
64 protected:
65 template <class T>
66 friend class Filter;
67};
68
69using CostE = Cost<>;
75
76using CostMin = CostGE;
77using CostMax = CostLE;
78
79template <PredicateCompare PC>
80struct Filter<Cost<PC>> {
81 using Pred = Cost<PC>;
82
83 template <class Tree>
84 static constexpr void init(Pred& p, Tree const& t)
85 {
86 }
87
88 template <class Tree>
89 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
90 TreeIndex n)
91 {
92 if constexpr (PredicateCompare::EQUAL == PC) {
93 return t.cost(n) == p.cost;
94 } else if constexpr (PredicateCompare::NOT_EQUAL == PC) {
95 return t.cost(n) != p.cost;
96 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
97 return t.cost(n) <= p.cost;
98 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
99 return t.cost(n) >= p.cost;
100 } else if constexpr (PredicateCompare::LESS == PC) {
101 return t.cost(n) < p.cost;
102 } else if constexpr (PredicateCompare::GREATER == PC) {
103 return t.cost(n) > p.cost;
104 }
105 }
106
107 template <class Tree>
108 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
109 TreeIndex n)
110 {
111 switch (t.costPropagationCriteria()) {
112 case CostPropagationCriteria::MIN:
113 if constexpr (PredicateCompare::EQUAL == PC) {
114 return t.cost(n) <= p.cost;
115 } else if constexpr (PredicateCompare::NOT_EQUAL == PC) {
116 return true;
117 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
118 return t.cost(n) <= p.cost;
119 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
120 return true;
121 } else if constexpr (PredicateCompare::LESS == PC) {
122 return t.cost(n) < p.cost;
123 } else if constexpr (PredicateCompare::GREATER == PC) {
124 return true;
125 }
126 case CostPropagationCriteria::MAX:
127 if constexpr (PredicateCompare::EQUAL == PC) {
128 return t.cost(n) >= p.cost;
129 } else if constexpr (PredicateCompare::NOT_EQUAL == PC) {
130 return true;
131 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
132 return true;
133 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
134 return t.cost(n) >= p.cost;
135 } else if constexpr (PredicateCompare::LESS == PC) {
136 return true;
137 } else if constexpr (PredicateCompare::GREATER == PC) {
138 return t.cost(n) > p.cost;
139 }
140 case CostPropagationCriteria::MEAN: return true;
141 case CostPropagationCriteria::NONE: return true;
142 }
143 assert(false);
144 return true;
145 }
146};
147} // namespace ufo::pred
148
149#endif // UFO_MAP_COST_PREDICATE_COST_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104