UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
surfel_predicate.hpp
1
42#ifndef UFO_MAP_PREDICATE_SURFEL_HPP
43#define UFO_MAP_PREDICATE_SURFEL_HPP
44
45// UFO
46#include <ufo/map/node.hpp>
47#include <ufo/map/predicate/predicate.hpp>
48
49namespace ufo::pred
50{
51//
52// Predicates
53//
54
55struct SurfelMap {
56};
57
58template <bool Negated = false>
59struct HasSurfel {
60};
61
62template <bool Negated>
63constexpr HasSurfel<!Negated> operator!(HasSurfel<Negated> const& p)
64{
65 return HasSurfel<!Negated>();
66}
67
68template <PredicateCompare PC = PredicateCompare::EQUAL>
70 constexpr NumSurfelPoints(std::size_t num_surfel_points)
71 : num_surfel_points(num_surfel_points)
72 {
73 }
74
75 std::size_t num_surfel_points;
76};
77
83
86
88 constexpr NumSurfelPointsInterval(std::size_t min, std::size_t max) : min(min), max(max)
89 {
90 }
91
94};
95
96template <PredicateCompare PC = PredicateCompare::EQUAL>
98 constexpr SurfelPlanarity(double planarity) : planarity(planarity) {}
99
100 double planarity;
101};
102
108
111
113 constexpr SurfelPlanarityInterval(double min, double max) : min(min), max(max) {}
114
117};
118
119//
120// Predicate value/return check
121//
122
123template <>
124struct ValueCheck<SurfelMap> {
125 using Pred = SurfelMap;
126
127 template <class Map, class Node>
128 static constexpr bool apply(Pred, Map const&, Node)
129 {
130 return IsSurfelMap<Map>;
131 }
132};
133
134template <class PredPost>
135struct ValueCheck<Then<SurfelMap, PredPost>> {
136 using Pred = Then<SurfelMap, PredPost>;
137
138 template <class Map, class Node>
139 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
140 {
141 if constexpr (ValueCheck<SurfelMap>::apply(p.pre, m, n)) {
142 return ValueCheck<PredPost>::apply(p.post, m, n);
143 } else {
144 return true;
145 }
146 }
147};
148
149template <bool Negated>
150struct ValueCheck<HasSurfel<Negated>> {
151 using Pred = HasSurfel<Negated>;
152
153 template <class Map, class Node>
154 static constexpr bool apply(Pred const&, Map const& m, Node const& n)
155 {
156 if constexpr (Negated) {
157 return !m.hasSurfel(n.index());
158 } else {
159 return m.hasSurfel(n.index());
160 }
161 }
162};
163
164template <PredicateCompare PC>
165struct ValueCheck<NumSurfelPoints<PC>> {
167
168 template <class Map, class Node>
169 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
170 {
171 if constexpr (PredicateCompare::EQUAL == PC) {
172 return m.getNumSurfelPoints(n.index()) == p.num_surfel_points;
173 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
174 return m.getNumSurfelPoints(n.index()) <= p.num_surfel_points;
175 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
176 return m.getNumSurfelPoints(n.index()) >= p.num_surfel_points;
177 } else if constexpr (PredicateCompare::LESS == PC) {
178 return m.getNumSurfelPoints(n.index()) < p.num_surfel_points;
179 } else if constexpr (PredicateCompare::GREATER == PC) {
180 return m.getNumSurfelPoints(n.index()) > p.num_surfel_points;
181 } else {
182 static_assert("Non-supported predicate comparison.");
183 }
184 }
185};
186
187template <>
188struct ValueCheck<NumSurfelPointsInterval> {
190
191 template <class Map, class Node>
192 static inline bool apply(Pred const& p, Map const& m, Node const& n)
193 {
194 return ValueCheck<std::decay_t<decltype(p.min)>>::apply(p.min, m, n) &&
195 ValueCheck<std::decay_t<decltype(p.max)>>::apply(p.max, m, n);
196 }
197};
198
199template <PredicateCompare PC>
200struct ValueCheck<SurfelPlanarity<PC>> {
202
203 template <class Map, class Node>
204 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
205 {
206 if constexpr (PredicateCompare::EQUAL == PC) {
207 return m.getSurfel(n.index()).getPlanarity() == p.planarity;
208 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
209 return m.getSurfel(n.index()).getPlanarity() <= p.planarity;
210 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
211 return m.getSurfel(n.index()).getPlanarity() >= p.planarity;
212 } else if constexpr (PredicateCompare::LESS == PC) {
213 return m.getSurfel(n.index()).getPlanarity() < p.planarity;
214 } else if constexpr (PredicateCompare::GREATER == PC) {
215 return m.getSurfel(n.index()).getPlanarity() > p.planarity;
216 } else {
217 static_assert("Non-supported predicate comparison.");
218 }
219 }
220};
221
222template <>
223struct ValueCheck<SurfelPlanarityInterval> {
225
226 template <class Map, class Node>
227 static inline bool apply(Pred const& p, Map const& m, Node const& n)
228 {
229 return ValueCheck<std::decay_t<decltype(p.min)>>::apply(p.min, m, n) &&
230 ValueCheck<std::decay_t<decltype(p.max)>>::apply(p.max, m, n);
231 }
232};
233
234//
235// Predicate inner check
236//
237
238template <>
239struct InnerCheck<SurfelMap> {
240 using Pred = SurfelMap;
241
242 template <class Map, class Node>
243 static constexpr bool apply(Pred, Map const&, Node)
244 {
245 return IsSurfelMap<Map>;
246 }
247};
248
249template <class PredPost>
250struct InnerCheck<Then<SurfelMap, PredPost>> {
251 using Pred = Then<SurfelMap, PredPost>;
252
253 template <class Map, class Node>
254 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
255 {
256 if constexpr (InnerCheck<SurfelMap>::apply(p.pre, m, n)) {
257 return InnerCheck<PredPost>::apply(p.post, m, n);
258 } else {
259 return true;
260 }
261 }
262};
263
264template <bool Negated>
265struct InnerCheck<HasSurfel<Negated>> {
266 using Pred = HasSurfel<Negated>;
267
268 template <class Map, class Node>
269 static constexpr bool apply(Pred const&, Map const& m, Node n)
270 {
271 if constexpr (Negated) {
272 return true;
273 } else {
274 return m.hasSurfel(n.index());
275 }
276 }
277};
278
279template <PredicateCompare PC>
280struct InnerCheck<NumSurfelPoints<PC>> {
282
283 template <class Map, class Node>
284 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
285 {
286 // FIXME: Check how time step is propagated to determine
287
288 if constexpr (PredicateCompare::EQUAL == PC) {
289 return m.getNumSurfelPoints(n.index()) >= p.num_surfel_points;
290 } else if constexpr (PredicateCompare::LESS_EQUAL == PC) {
291 return true;
292 } else if constexpr (PredicateCompare::GREATER_EQUAL == PC) {
293 return m.getNumSurfelPoints(n.index()) >= p.num_surfel_points;
294 } else if constexpr (PredicateCompare::LESS == PC) {
295 return true;
296 } else if constexpr (PredicateCompare::GREATER == PC) {
297 return m.getNumSurfelPoints(n.index()) > p.num_surfel_points;
298 } else {
299 static_assert("Non-supported predicate comparison.");
300 }
301 }
302};
303
304template <>
305struct InnerCheck<NumSurfelPointsInterval> {
307
308 template <class Map, class Node>
309 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
310 {
311 return InnerCheck<std::decay_t<decltype(p.min)>>::apply(p.min, m, n) &&
312 InnerCheck<std::decay_t<decltype(p.max)>>::apply(p.max, m, n);
313 }
314};
315
316template <PredicateCompare PC>
317struct InnerCheck<SurfelPlanarity<PC>> {
319
320 template <class Map, class Node>
321 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
322 {
323 return true;
324 }
325};
326
327template <>
328struct InnerCheck<SurfelPlanarityInterval> {
330
331 template <class Map, class Node>
332 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
333 {
334 return InnerCheck<std::decay_t<decltype(p.min)>>::apply(p.min, m, n) &&
335 InnerCheck<std::decay_t<decltype(p.max)>>::apply(p.max, m, n);
336 }
337};
338
339} // namespace ufo::pred
340
341#endif // UFO_MAP_PREDICATE_SURFEL_HPP
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > max(Geometry const &g)
Returns the maximum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
Definition fun.hpp:72
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > min(Geometry const &g)
Returns the minimum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
Definition fun.hpp:58