ListQueryEngine-Impl.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_LIST_QUERY_ENGINE_IMPL_HPP
12 #define CUBBYFLOW_LIST_QUERY_ENGINE_IMPL_HPP
13 
14 namespace CubbyFlow
15 {
16 template <typename T, size_t N>
17 void ListQueryEngine<T, N>::Add(const T& item)
18 {
19  m_items.Append(item);
20 }
21 
22 template <typename T, size_t N>
24 {
25  m_items.Append(items);
26 }
27 
28 template <typename T, size_t N>
30  const BoundingBox<double, N>& box,
31  const BoxIntersectionTestFunc<T, N>& testFunc) const
32 {
33  return std::any_of(m_items.begin(), m_items.end(),
34  [&](const T& item) { return testFunc(item, box); });
35 }
36 
37 template <typename T, size_t N>
39  const Ray<double, N>& ray,
40  const RayIntersectionTestFunc<T, N>& testFunc) const
41 {
42  return std::any_of(m_items.begin(), m_items.end(),
43  [&](const T& item) { return testFunc(item, ray); });
44 }
45 
46 template <typename T, size_t N>
48  const BoundingBox<double, N>& box,
49  const BoxIntersectionTestFunc<T, N>& testFunc,
50  const IntersectionVisitorFunc<T>& visitorFunc) const
51 {
52  for (const auto& item : m_items)
53  {
54  if (testFunc(item, box))
55  {
56  visitorFunc(item);
57  }
58  }
59 }
60 
61 template <typename T, size_t N>
63  const Ray<double, N>& ray, const RayIntersectionTestFunc<T, N>& testFunc,
64  const IntersectionVisitorFunc<T>& visitorFunc) const
65 {
66  for (const auto& item : m_items)
67  {
68  if (testFunc(item, ray))
69  {
70  visitorFunc(item);
71  }
72  }
73 }
74 
75 template <typename T, size_t N>
77  const Ray<double, N>& ray,
78  const GetRayIntersectionFunc<T, N>& testFunc) const
79 {
81 
82  for (const auto& item : m_items)
83  {
84  if (double dist = testFunc(item, ray); dist < best.distance)
85  {
86  best.distance = dist;
87  best.item = &item;
88  }
89  }
90 
91  return best;
92 }
93 
94 template <typename T, size_t N>
96  const Vector<double, N>& pt,
97  const NearestNeighborDistanceFunc<T, N>& distanceFunc) const
98 {
100 
101  for (const auto& item : m_items)
102  {
103  if (double dist = distanceFunc(item, pt); dist < best.distance)
104  {
105  best.item = &item;
106  best.distance = dist;
107  }
108  }
109 
110  return best;
111 }
112 } // namespace CubbyFlow
113 
114 #endif
void Add(const T &item)
Adds an item to the container.
Definition: ListQueryEngine-Impl.hpp:17
N-D nearest neighbor query result.
Definition: NearestNeighborQueryEngine.hpp:23
Class for N-D ray.
Definition: Ray.hpp:25
NearestNeighborQueryResult< T, N > Nearest(const Vector< double, N > &pt, const NearestNeighborDistanceFunc< T, N > &distanceFunc) const override
Definition: ListQueryEngine-Impl.hpp:95
Definition: Matrix.hpp:27
N-D closest intersection query result.
Definition: IntersectionQueryEngine.hpp:25
Definition: pybind11Utils.hpp:20
ClosestIntersectionQueryResult< T, N > ClosestIntersection(const Ray< double, N > &ray, const GetRayIntersectionFunc< T, N > &testFunc) const override
Returns the closest intersection for given ray.
Definition: ListQueryEngine-Impl.hpp:76
const T * item
Definition: NearestNeighborQueryEngine.hpp:25
std::function< bool(const T &, const BoundingBox< double, N > &)> BoxIntersectionTestFunc
N-D box-item intersection test function.
Definition: IntersectionQueryEngine.hpp:55
double distance
Definition: IntersectionQueryEngine.hpp:28
void ForEachIntersectingItem(const BoundingBox< double, N > &box, const BoxIntersectionTestFunc< T, N > &testFunc, const IntersectionVisitorFunc< T > &visitorFunc) const override
Invokes visitorFunc for every intersecting items.
Definition: ListQueryEngine-Impl.hpp:47
Generic N-dimensional array class interface.
Definition: Array.hpp:32
const T * item
Definition: IntersectionQueryEngine.hpp:27
std::function< double(const T &, const Vector< double, N > &)> NearestNeighborDistanceFunc
N-D nearest neighbor distance measure function.
Definition: NearestNeighborQueryEngine.hpp:40
std::function< bool(const T &, const Ray< double, N > &)> RayIntersectionTestFunc
N-D ray-item intersection test function.
Definition: IntersectionQueryEngine.hpp:68
std::function< double(const T &, const Ray< double, N > &)> GetRayIntersectionFunc
N-D ray-item closest intersection evaluation function.
Definition: IntersectionQueryEngine.hpp:81
double distance
Definition: NearestNeighborQueryEngine.hpp:26
bool Intersects(const BoundingBox< double, N > &box, const BoxIntersectionTestFunc< T, N > &testFunc) const override
Returns true if given box intersects with any of the stored items.
Definition: ListQueryEngine-Impl.hpp:29
std::function< void(const T &)> IntersectionVisitorFunc
Visitor function which is invoked for each intersecting item.
Definition: IntersectionQueryEngine.hpp:93