ListQueryEngine3-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ListQueryEngine3-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Ad-hoc list-based 3-D intersection/nearest-neighbor query engine.
6 > Created Time: 2017/10/14
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_LIST_QUERY_ENGINE3_IMPL_H
10 #define CUBBYFLOW_LIST_QUERY_ENGINE3_IMPL_H
11 
12 namespace CubbyFlow
13 {
14  template <typename T>
15  void ListQueryEngine3<T>::Add(const T& item)
16  {
17  m_items.push_back(item);
18  }
19 
20  template <typename T>
21  void ListQueryEngine3<T>::Add(const std::vector<T>& items)
22  {
23  m_items.insert(m_items.end(), items.begin(), items.end());
24  }
25 
26  template <typename T>
28  const BoundingBox3D& box,
29  const BoxIntersectionTestFunc3<T>& testFunc) const
30  {
31  for (const auto& item : m_items)
32  {
33  if (testFunc(item, box))
34  {
35  return true;
36  }
37  }
38 
39  return false;
40  }
41 
42  template <typename T>
44  const Ray3D& ray, const RayIntersectionTestFunc3<T>& testFunc) const
45  {
46  for (const auto& item : m_items)
47  {
48  if (testFunc(item, ray))
49  {
50  return true;
51  }
52  }
53 
54  return false;
55  }
56 
57  template <typename T>
59  const BoundingBox3D& box, const BoxIntersectionTestFunc3<T>& testFunc,
60  const IntersectionVisitorFunc3<T>& visitorFunc) const
61  {
62  for (const auto& item : m_items)
63  {
64  if (testFunc(item, box))
65  {
66  visitorFunc(item);
67  }
68  }
69  }
70 
71  template <typename T>
73  const Ray3D& ray, const RayIntersectionTestFunc3<T>& testFunc,
74  const IntersectionVisitorFunc3<T>& visitorFunc) const
75  {
76  for (const auto& item : m_items)
77  {
78  if (testFunc(item, ray))
79  {
80  visitorFunc(item);
81  }
82  }
83  }
84 
85  template <typename T>
87  const Ray3D& ray, const GetRayIntersectionFunc3<T>& testFunc) const
88  {
90 
91  for (const auto& item : m_items)
92  {
93  double dist = testFunc(item, ray);
94  if (dist < best.distance)
95  {
96  best.distance = dist;
97  best.item = &item;
98  }
99  }
100 
101  return best;
102  }
103 
104  template <typename T>
106  const Vector3D& pt,
107  const NearestNeighborDistanceFunc3<T>& distanceFunc) const
108  {
110 
111  for (const auto& item : m_items)
112  {
113  double dist = distanceFunc(item, pt);
114  if (dist < best.distance)
115  {
116  best.item = &item;
117  best.distance = dist;
118  }
119  }
120 
121  return best;
122  }
123 }
124 
125 #endif
3-D vector class.
Definition: Vector3.h:26
const T * item
Definition: NearestNeighborQueryEngine3.h:20
ClosestIntersectionQueryResult3< T > GetClosestIntersection(const Ray3D &ray, const GetRayIntersectionFunc3< T > &testFunc) const override
Returns the closest intersection for given ray.
Definition: ListQueryEngine3-Impl.h:86
std::function< bool(const T &, const BoundingBox3D &)> BoxIntersectionTestFunc3
Box-item intersection test function.
Definition: IntersectionQueryEngine3.h:31
const T * item
Definition: IntersectionQueryEngine3.h:21
std::function< double(const T &, const Ray3D &)> GetRayIntersectionFunc3
Ray-item closest intersection evaluation function.
Definition: IntersectionQueryEngine3.h:39
double distance
Definition: IntersectionQueryEngine3.h:22
Definition: pybind11Utils.h:24
void ForEachIntersectingItem(const BoundingBox3D &box, const BoxIntersectionTestFunc3< T > &testFunc, const IntersectionVisitorFunc3< T > &visitorFunc) const override
Invokes visitorFunc for every intersecting items.
Definition: ListQueryEngine3-Impl.h:58
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Closest intersection query result.
Definition: IntersectionQueryEngine3.h:19
bool IsIntersects(const BoundingBox3D &box, const BoxIntersectionTestFunc3< T > &testFunc) const override
Returns true if given box intersects with any of the stored items.
Definition: ListQueryEngine3-Impl.h:27
double distance
Definition: NearestNeighborQueryEngine3.h:21
std::function< void(const T &)> IntersectionVisitorFunc3
Visitor function which is invoked for each intersecting item.
Definition: IntersectionQueryEngine3.h:43
std::function< bool(const T &, const Ray3D &)> RayIntersectionTestFunc3
Ray-item intersection test function.
Definition: IntersectionQueryEngine3.h:35
NearestNeighborQueryResult3< T > GetNearestNeighbor(const Vector3D &pt, const NearestNeighborDistanceFunc3< T > &distanceFunc) const override
Returns the nearest neighbor for given point and distance measure function.
Definition: ListQueryEngine3-Impl.h:105
Nearest neighbor query result.
Definition: NearestNeighborQueryEngine3.h:18
void Add(const T &item)
Adds an item to the container.
Definition: ListQueryEngine3-Impl.h:15
Class for 3-D ray.
Definition: Ray3.h:23
std::function< double(const T &, const Vector3D &)> NearestNeighborDistanceFunc3
Nearest neighbor distance measure function.
Definition: NearestNeighborQueryEngine3.h:26