voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
search.hpp
1 #ifndef OCTREE_SEARCH_HPP
2 #define OCTREE_SEARCH_HPP
3 
4 #include "blub/math/axisAlignedBox.hpp"
5 #include "blub/math/octree/container.hpp"
6 #include "blub/math/sphere.hpp"
7 
8 #include <boost/bind.hpp>
9 #include <boost/function/function1.hpp>
10 
11 
12 namespace blub
13 {
14 namespace octree
15 {
16 
17 
18 template<typename containerType>
19 class search
20 {
21 public:
23 
25  typedef typename t_container::t_leafPtr t_leafPtr;
26  typedef typename t_container::t_nodePtr t_nodePtr;
27  typedef typename t_container::t_leafList t_leafList;
28  typedef typename t_container::t_data t_data;
29  typedef typename t_container::t_dataList t_dataList;
30 
31 
32  static t_leafList getLeafesBySphere(const t_container& toSearchIn, const sphere& insideSphere)
33  {
34  return getLeafsByUserDefinedFunction(toSearchIn, boost::bind(&t_thisClass::getLeafsBySphereSearchFunction, insideSphere, _1));
35  }
36 
37  static t_dataList getDataBySphere(const t_container& toSearchIn, const sphere& insideSphere)
38  {
39  t_dataList result;
40 
41  t_leafList leafs(getLeafesBySphere(toSearchIn, insideSphere));
42 
43  for (t_leafPtr leaf : leafs)
44  {
45  for (t_data data : leaf->getData())
46  {
47  result.insert(data);
48  }
49  }
50 
51  return result;
52  }
53 
54  static t_leafList getLeafsByUserDefinedFunction(const t_container& toSearchIn, const boost::function<bool (t_nodePtr)>& isInside)
55  {
56  t_leafList result;
57  getLeafsByUserDefinedFunctionRecursively(toSearchIn, toSearchIn.getRootNode(), isInside, &result);
58 
59  return result;
60  }
61 
62  static t_dataList getDataByUserDefinedFunction(const t_container& toSearchIn, const boost::function<bool (t_nodePtr)>& isInside)
63  {
64  t_dataList result;
65 
66  t_leafList leafs(getLeafsByUserDefinedFunction(toSearchIn, isInside));
67 
68  for (t_leafPtr leaf : leafs)
69  {
70  for (t_data data : leaf->getData())
71  {
72  result.insert(data);
73  }
74  }
75 
76  return result;
77  }
78 
79 private:
80  static void getLeafsByUserDefinedFunctionRecursively( const t_container& tree,
81  const t_nodePtr& toSearchIn,
82  const boost::function<bool (t_nodePtr)>& isInside,
83  t_leafList* result)
84  {
85  if (isInside(toSearchIn))
86  {
87  t_leafPtr lf(tree.isLeaf(toSearchIn));
88  if (lf)
89  {
90  result->insert(lf);
91  return;
92  }
93  for (int8 child = 0; child < 8; ++child)
94  {
95  t_nodePtr childNode(toSearchIn->getNode(child));
96  if (childNode != nullptr)
97  {
98  getLeafsByUserDefinedFunctionRecursively(tree, childNode, isInside, result);
99  }
100  }
101  }
102 
103  }
104 
105  static bool getLeafsBySphereSearchFunction(const sphere& sphere_, t_nodePtr node)
106  {
107  return sphere_.intersects(node->getBoundingBox());
108  }
109 
110 
111 };
112 
113 
114 }
115 }
116 
117 
118 #endif // OCTREE_SEARCH_HPP
bool intersects(const sphere &s) const
Definition: sphere.cpp:9
Definition: container.hpp:74
Definition: container.hpp:20
Definition: search.hpp:19
Definition: hashList.hpp:19
Definition: container.hpp:23
Definition: deadlineTimer.hpp:10
Definition: customVertexInformation.cpp:177
Definition: sphere.hpp:10