UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
inside.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_INSIDE_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_INSIDE_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/container/tree/predicate/spatial.hpp>
48#include <ufo/geometry/inside.hpp>
49#include <ufo/geometry/intersects.hpp>
50
51// STL
52#include <type_traits>
53
54namespace ufo::pred
55{
56template <class Geometry, bool Negated = false>
57struct Inside {
58 Geometry geometry;
59};
60
61template <class Geometry, bool Negated>
62[[nodiscard]] constexpr Inside<Geometry, !Negated> operator!(
63 Inside<Geometry, Negated> const& p) noexcept
64{
65 return Inside<Geometry, !Negated>{p.geometry};
66}
67
68template <class Geometry, bool Negated>
69struct Filter<Inside<Geometry, Negated>> {
71
72 template <class Tree>
73 static constexpr void init(Pred&, Tree const&) noexcept
74 {
75 }
76
77 template <class Value>
78 [[nodiscard]] static constexpr bool returnableValue(Pred const& p,
79 Value const& v) noexcept
80 {
81 if constexpr (Negated) {
82 if constexpr (is_pair_v<std::remove_cvref_t<Value>>) {
83 return !inside(v.first, p.geometry);
84 } else {
85 return !inside(v, p.geometry);
86 }
87 } else {
88 if constexpr (is_pair_v<std::remove_cvref_t<Value>>) {
89 return inside(v.first, p.geometry);
90 } else {
91 return inside(v, p.geometry);
92 }
93 }
94 }
95
96 template <class Tree>
97 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
98 typename Tree::Node const& n) noexcept
99 {
100 if constexpr (Negated) {
101 return !inside(t.bounds(n), p.geometry);
102 } else {
103 return inside(t.bounds(n), p.geometry);
104 }
105 }
106
107 template <class Tree>
108 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
109 typename Tree::Node const& n) noexcept
110 {
111 if constexpr (Negated) {
112 return !inside(t.bounds(n), p.geometry);
113 } else {
114 return intersects(t.bounds(n), p.geometry);
115 }
116 }
117
118 template <class Tree>
119 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
120 typename Tree::Node const& n,
121 typename Tree::Ray const&) noexcept
122 {
123 return returnable(p, t, n);
124 }
125
126 template <class Tree>
127 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
128 typename Tree::Node const& n,
129 typename Tree::Ray const&) noexcept
130 {
131 return traversable(p, t, n);
132 }
133};
134
135namespace detail
136{
137template <class Geometry, bool Negated>
138struct is_spatial_pred<Inside<Geometry, Negated>> : std::true_type {
139};
140} // namespace detail
141
142} // namespace ufo::pred
143
144#endif // UFO_CONTAINER_TREE_PREDICATE_INSIDE_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104
Bounds bounds() const
Returns the bounds of the tree (/ root node).
Definition tree.hpp:567
constexpr bool inside(A const &a, B const &b)
Checks if a shape is inside another shape.
Definition inside.hpp:62
constexpr bool intersects(A const &a, B const &b)
Checks if two shapes intersect.