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>
12#include <GfxTL/NullClass.h>
13
14namespace GfxTL
15{
16 template <class Point, class Base>
17 class AAKdCell : public Base
18 {
19 public:
21 typedef Base BaseType;
23 typedef typename Point::ScalarType ScalarType;
24
25 enum
26 {
28 };
29
33 const ThisType* operator[](unsigned int index) const;
34 ThisType* operator[](unsigned int index);
35 void Child(unsigned int index, ThisType* child);
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>>
59 typedef typename Strategies::StrategyBase<
60 BaseTree<AAKdCell<typename Strategies::PointType,
61 typename Strategies::CellData<typename Strategies::PointType>>>>
63 typedef typename StrategyBaseType::HandleType HandleType;
64 typedef ::GfxTL::NearestNeighbor<ScalarType> NN;
65
66 enum
67 {
68 Dim = PointType::Dim
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
uint8_t index
AAKdCell< Point, Base > ThisType
Definition AAKdTree.h:22
void Split(ScalarType split)
Definition AAKdTree.hpp:74
AAKdCell(const AAKdCell< Point, Base > &cell)
const ThisType * operator[](unsigned int index) const
Definition AAKdTree.hpp:46
Point::ScalarType ScalarType
Definition AAKdTree.h:23
ScalarType Split() const
Definition AAKdTree.hpp:67
void Axis(unsigned int axis)
Definition AAKdTree.hpp:88
void Child(unsigned int index, ThisType *child)
Definition AAKdTree.hpp:60
Point PointType
Definition AAKdTree.h:20
unsigned int Axis() const
Definition AAKdTree.hpp:81
ThisType * operator[](unsigned int index)
Definition AAKdTree.hpp:53
void RefreshWithNewTreeData(const AACube< PointType > &bc)
Definition AAKdTree.hpp:171
void PointsInSphere(const PointType &center, ScalarType radius, std::vector< size_t > *points) const
Definition AAKdTree.hpp:128
::GfxTL::NearestNeighbor< ScalarType > NN
Definition AAKdTree.h:64
void PointsInAACube(const AACube< PointType > &cube, std::vector< size_t > *points) const
Definition AAKdTree.hpp:142
void NearestNeighbor(const PointType &p, size_t *neighbor, ScalarType *dist) const
Definition AAKdTree.hpp:220
void KNearestNeighbors(const PointType &p, unsigned int k, std::vector< NN > *neighbors, ScalarType *dist) const
Definition AAKdTree.hpp:240
Strategies::StrategyBase< BaseTree< AAKdCell< typename Strategies::PointType, typename Strategies::CellData< typename Strategies::PointType > > > > StrategyBaseType
Definition AAKdTree.h:62
AAKdCell< typename Strategies::PointType, typename Strategies::CellData< typename Strategies::PointType > > CellType
Definition AAKdTree.h:56
CellType::PointType PointType
Definition AAKdTree.h:57
StrategyBaseType::HandleType HandleType
Definition AAKdTree.h:63
CellType::ScalarType ScalarType
Definition AAKdTree.h:58
Definition AABox.h:10
float ScalarType
Definition PointCloud.h:28