UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
count_map.hpp
1
42#ifndef UFO_MAP_COUNT_PREDICATE_COUNT_MAP_HPP
43#define UFO_MAP_COUNT_PREDICATE_COUNT_MAP_HPP
44
45// UFO
46#include <ufo/map/count/is_count_map.hpp>
47#include <ufo/map/predicate/predicate.hpp>
48
49namespace ufo::pred
50{
51template <bool Negated = false>
52struct CountMap {
53 private:
54 bool enabled;
55
56 friend struct Init<CountMap>;
57 friend struct InnerCheck<CountMap>;
58 friend struct ValueCheck<CountMap>;
59 friend struct ShaderInnerCheck<CountMap>;
60 friend struct ShaderValueCheck<CountMap>;
61};
62
63template <bool Negated>
65{
66 return {};
67}
68
69template <bool Negated>
70struct Init<CountMap<Negated>> {
71 using Pred = CountMap<Negated>;
72
73 template <class Map>
74 static inline void apply(Pred& p, Map const& m)
75 {
76 p.enabled = m.isMapTypesEnabled(MapType::COUNT);
77 }
78};
79
80template <bool Negated>
81struct InnerCheck<CountMap<Negated>> {
82 using Pred = CountMap<Negated>;
83
84 template <class Map, class Node>
85 static constexpr bool apply(Pred p, Map const&, Node const&)
86 {
87 if constexpr (!Map::enableDisableUtilityPresent()) {
88 if constexpr (Negated) {
89 return !is_count_map_v<Map>;
90 } else {
91 return is_count_map_v<Map>;
92 }
93 } else {
94 if constexpr (Negated) {
95 return !p.enabled;
96 } else {
97 return p.enabled;
98 }
99 }
100 }
101};
102
103template <bool Negated, class PredPost>
104struct InnerCheck<Then<CountMap<Negated>, PredPost>> {
105 using Pred = Then<CountMap<Negated>, PredPost>;
106
107 template <class Map, class Node>
108 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
109 {
110 if constexpr (!Map::enableDisableUtilityPresent()) {
111 if constexpr (InnerCheck<CountMap<Negated>>::apply(p.pre, m, n)) {
112 return InnerCheck<PredPost>::apply(p.post, m, n);
113 } else {
114 return true;
115 }
116 } else {
117 return !InnerCheck<CountMap<Negated>>::apply(p.pre, m, n) ||
118 InnerCheck<PredPost>::apply(p.post, m, n);
119 }
120 }
121};
122
123template <bool Negated>
124struct ValueCheck<CountMap<Negated>> {
125 using Pred = CountMap<Negated>;
126
127 template <class Map, class Node>
128 static constexpr bool apply(Pred p, Map const&, Node const& n)
129 {
130 if constexpr (!Map::enableDisableUtilityPresent()) {
131 if constexpr (Negated) {
132 return !is_count_map_v<Map>;
133 } else {
134 return is_count_map_v<Map>;
135 }
136 } else {
137 if constexpr (Negated) {
138 return !p.enabled;
139 } else {
140 return p.enabled;
141 }
142 }
143 }
144};
145
146template <bool Negated, class PredPost>
147struct ValueCheck<Then<CountMap<Negated>, PredPost>> {
148 using Pred = Then<CountMap<Negated>, PredPost>;
149
150 template <class Map, class Node>
151 static constexpr bool apply(Pred const& p, Map const& m, Node const& n)
152 {
153 if constexpr (!Map::enableDisableUtilityPresent()) {
154 if constexpr (ValueCheck<CountMap<Negated>>::apply(p.pre, m, n)) {
155 return ValueCheck<PredPost>::apply(p.post, m, n);
156 } else {
157 return true;
158 }
159 } else {
160 return !ValueCheck<CountMap<Negated>>::apply(p.pre, m, n) ||
161 ValueCheck<PredPost>::apply(p.post, m, n);
162 }
163 }
164};
165} // namespace ufo::pred
166
167#endif // UFO_MAP_COUNT_PREDICATE_COUNT_MAP_HPP