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