UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
occupancy_state.hpp
1
42#ifndef UFO_MAP_OCCUPANCY_PREDICATE_OCCUPANCY_STATE_HPP
43#define UFO_MAP_OCCUPANCY_PREDICATE_OCCUPANCY_STATE_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/map/occupancy/propagation_criteria.hpp>
48#include <ufo/map/occupancy/state.hpp>
49
50namespace ufo::pred
51{
52template <ufo::OccupancyState State, bool Negated = false>
54};
55
59
60template <ufo::OccupancyState State, bool Negated>
62{
64}
65
66template <ufo::OccupancyState State, bool Negated>
67struct Filter<OccupancyState<State, Negated>>
68 : public FilterBase<OccupancyState<State, Negated>> {
70
71 template <class Tree>
72 static constexpr void init(Pred&, Tree const&)
73 {
74 }
75
76 template <class Tree, class Node>
77 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
78 Node const& n)
79 {
80 bool v = [&]() -> bool {
81 if constexpr (ufo::OccupancyState::UNKNOWN == State) {
82 return t.occupancyUnknown(n.index);
83 } else if constexpr (ufo::OccupancyState::FREE == State) {
84 return t.occupancyFree(n.index);
85 } else if constexpr (ufo::OccupancyState::OCCUPIED == State) {
86 return t.occupancyOccupied(n.index);
87 }
88 }();
89
90 if constexpr (Negated) {
91 v = !v;
92 }
93
94 return v;
95 }
96
97 template <class Tree, class Node>
98 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
99 Node const& n)
100 {
101 if constexpr (Negated) {
102 if constexpr (ufo::OccupancyState::UNKNOWN == State) {
103 return t.occupancyContainsFree(n.index) || t.occupancyContainsOccupied(n.index);
104 } else if constexpr (ufo::OccupancyState::FREE == State) {
105 return t.occupancyContainsUnknown(n.index) ||
106 t.occupancyContainsOccupied(n.index);
107 } else if constexpr (ufo::OccupancyState::OCCUPIED == State) {
108 return t.occupancyContainsUnknown(n.index) || t.occupancyContainsFree(n.index);
109 }
110 } else {
111 if constexpr (ufo::OccupancyState::UNKNOWN == State) {
112 return t.occupancyContainsUnknown(n.index);
113 } else if constexpr (ufo::OccupancyState::FREE == State) {
114 return t.occupancyContainsFree(n.index);
115 } else if constexpr (ufo::OccupancyState::OCCUPIED == State) {
116 return t.occupancyContainsOccupied(n.index);
117 }
118 }
119 }
120};
121} // namespace ufo::pred
122
123#endif // UFO_MAP_OCCUPANCY_PREDICATE_OCCUPANCY_STATE_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104