AAKdTree.h
Go to the documentation of this file.
1 #ifndef __AAKDTREE_HEADER__
2 #define __AAKDTREE_HEADER__
3 
4 #include <GfxTL/BaseTree.h>
5 #include <GfxTL/NullClass.h>
6 #include <GfxTL/AACube.h>
8 #include <GfxTL/Intersect.h>
9 #include <list>
10 #include <vector>
11 #include <limits>
12 
13 namespace GfxTL
14 {
15  template< class Point, class Base >
16  class AAKdCell
17  : public Base
18  {
19  public:
20  typedef Point PointType;
21  typedef Base BaseType;
23  typedef typename Point::ScalarType ScalarType;
24  enum { NChildren = 2 };
25 
26  AAKdCell();
27  AAKdCell(const AAKdCell< Point, Base >& cell);
28  ~AAKdCell();
29  const ThisType* operator[](unsigned int index) const;
30  ThisType* operator[](unsigned int index);
31  void Child(unsigned int index, ThisType* child);
32  ScalarType Split() const;
33  void Split(ScalarType split);
34  unsigned int Axis() const;
35  void Axis(unsigned int axis);
36 
37  private:
38  unsigned int _axis;
39  ScalarType _splitValue;
40  ThisType* _children[2];
41  };
42 
43  template< class Strategies >
44  class AAKdTree
45  : public Strategies::StrategyBase
46  <
47  BaseTree
48  <
49  AAKdCell
50  <
51  typename Strategies::PointType,
52  typename Strategies::CellData
53  <
54  typename Strategies::PointType
55  >
56  >
57  >
58  >
59  {
60  public:
61  typedef AAKdCell
62  <
63  typename Strategies::PointType,
64  typename Strategies::CellData
65  <
66  typename Strategies::PointType
67  >
69  typedef typename CellType::PointType PointType;
70  typedef typename CellType::ScalarType ScalarType;
71  typedef typename Strategies::StrategyBase
72  <
73  BaseTree
74  <
75  AAKdCell
76  <
77  typename Strategies::PointType,
78  typename Strategies::CellData
79  <
80  typename Strategies::PointType
81  >
82  >
83  >
85  typedef typename StrategyBaseType::HandleType HandleType;
86  typedef ::GfxTL::NearestNeighbor< ScalarType > NN;
87  enum { Dim = PointType::Dim };
88 
89  void Build();
90  void PointsInSphere(const PointType& center, ScalarType radius,
91  std::vector< size_t >* points) const;
92  void PointsInAACube(const AACube< PointType >& cube,
93  std::vector< size_t >* points) const;
94  void PointsInAACube(const PointType& center, ScalarType width,
95  std::vector< size_t >* points) const;
97  void NearestNeighbor(const PointType& p, size_t* neighbor,
98  ScalarType* dist) const;
99  void KNearestNeighbors(const PointType& p, unsigned int k,
100  std::vector< NN >* neighbors,
101  ScalarType* dist) const;
102 
103  private:
104  void NearestNeighbor(const CellType& cell,
105  const AABox< PointType >& box, const PointType& p,
106  size_t* neighbor, ScalarType* dist2) const;
107  void KNearestNeighbors(const CellType& cell,
108  const AABox< PointType >& box, const PointType& p,
109  unsigned int k, std::vector< NN >* neighbors,
110  size_t* worstIdx, ScalarType* dist2) const;
111  void ReadjustData(CellType* cell);
112  void PointsInSphere(const CellType* cell, const PointType& center,
113  ScalarType radius, std::vector< size_t >* points) const;
114  void PointsInAACube(const CellType* cell, const PointType& center,
115  ScalarType radius, std::vector< HandleType >* points) const;
116  bool ShouldSubdivide(const CellType* cell) const;
117  void Subdivide(CellType* cell);
118  ScalarType Absolute(ScalarType f) const;
119  };
120 };
121 
122 #include "AAKdTree.hpp"
123 
124 #endif
GfxTL::AAKdTree::Build
void Build()
Definition: AAKdTree.hpp:93
GfxTL::AACube
Definition: AACube.h:11
visionx::armem::pointcloud::PointType
PointType
Definition: constants.h:78
index
uint8_t index
Definition: EtherCATFrame.h:59
GfxTL::AAKdCell::NChildren
@ NChildren
Definition: AAKdTree.h:24
GfxTL::AAKdCell::ThisType
AAKdCell< Point, Base > ThisType
Definition: AAKdTree.h:22
AACube.h
GfxTL::AAKdTree::StrategyBaseType
Strategies::StrategyBase< BaseTree< AAKdCell< typename Strategies::PointType, typename Strategies::CellData< typename Strategies::PointType > > > > StrategyBaseType
Definition: AAKdTree.h:84
Point::ScalarType
float ScalarType
Definition: PointCloud.h:24
GfxTL::AAKdCell
Definition: AAKdTree.h:16
GfxTL::AAKdTree::KNearestNeighbors
void KNearestNeighbors(const PointType &p, unsigned int k, std::vector< NN > *neighbors, ScalarType *dist) const
Definition: AAKdTree.hpp:229
GfxTL::AAKdTree
Definition: AAKdTree.h:44
GfxTL::BaseTree
Definition: BaseTree.h:9
NearestNeighbors.h
GfxTL::AAKdTree::CellType
AAKdCell< typename Strategies::PointType, typename Strategies::CellData< typename Strategies::PointType > > CellType
Definition: AAKdTree.h:68
GfxTL::AAKdTree::NN
::GfxTL::NearestNeighbor< ScalarType > NN
Definition: AAKdTree.h:86
Point
Definition: PointCloud.h:21
BaseTree.h
GfxTL::AAKdCell::ScalarType
Point::ScalarType ScalarType
Definition: AAKdTree.h:23
AAKdTree.hpp
GfxTL
Definition: AABox.h:8
GfxTL::AAKdCell::AAKdCell
AAKdCell()
Definition: AAKdTree.hpp:7
GfxTL::AAKdTree::PointType
CellType::PointType PointType
Definition: AAKdTree.h:69
GfxTL::AAKdCell::Split
ScalarType Split() const
Definition: AAKdTree.hpp:67
GfxTL::AAKdTree::ScalarType
CellType::ScalarType ScalarType
Definition: AAKdTree.h:70
NullClass.h
GfxTL::AAKdTree::RefreshWithNewTreeData
void RefreshWithNewTreeData(const AACube< PointType > &bc)
Definition: AAKdTree.hpp:163
GfxTL::AAKdCell::Child
void Child(unsigned int index, ThisType *child)
Definition: AAKdTree.hpp:60
GfxTL::AAKdTree::PointsInSphere
void PointsInSphere(const PointType &center, ScalarType radius, std::vector< size_t > *points) const
Definition: AAKdTree.hpp:123
GfxTL::AAKdCell::operator[]
const ThisType * operator[](unsigned int index) const
Definition: AAKdTree.hpp:47
GfxTL::AAKdCell::BaseType
Base BaseType
Definition: AAKdTree.h:21
GfxTL::AAKdCell::Axis
unsigned int Axis() const
Definition: AAKdTree.hpp:79
Point::Dim
@ Dim
Definition: PointCloud.h:23
GfxTL::AAKdTree::Dim
@ Dim
Definition: AAKdTree.h:87
GfxTL::AAKdTree::NearestNeighbor
void NearestNeighbor(const PointType &p, size_t *neighbor, ScalarType *dist) const
Definition: AAKdTree.hpp:211
GfxTL::AAKdCell::~AAKdCell
~AAKdCell()
Definition: AAKdTree.hpp:36
GfxTL::AAKdCell::PointType
Point PointType
Definition: AAKdTree.h:20
GfxTL::AAKdTree::HandleType
StrategyBaseType::HandleType HandleType
Definition: AAKdTree.h:85
GfxTL::AABox
Definition: AABox.h:18
GfxTL::AAKdTree::PointsInAACube
void PointsInAACube(const AACube< PointType > &cube, std::vector< size_t > *points) const
Definition: AAKdTree.hpp:136
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36