-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpartitioner.h
119 lines (95 loc) · 2.66 KB
/
partitioner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef PARTITIONER_H
#define PARTITIONER_H
#include "pointcloud.h"
template <size_t DIMENSION>
class Partitioner
{
public:
typedef typename Point<DIMENSION>::Vector Vector;
Partitioner(const PointCloud<DIMENSION> *pointCloud)
: mPointCloud(pointCloud)
{
}
virtual ~Partitioner()
{
}
const PointCloud<DIMENSION>* pointCloud() const
{
return mPointCloud;
}
size_t level() const
{
if (isRoot())
{
return 0;
}
else
{
return 1 + parent()->level();
}
}
size_t height() const
{
if (isLeaf())
{
return 0;
}
else
{
size_t maxHeight = 0;
for (const Partitioner<DIMENSION> *child : children())
{
maxHeight = std::max(maxHeight, child->height());
}
return 1 + maxHeight;
}
}
/**
* @brief Find the leaf which contains the point
* @param point
* Point to which the leaf will be searched upon
* @return
* The leaf which contains the point
*/
const Partitioner<DIMENSION>* findNearestLeaf(const Vector &point) const
{
if (isLeaf())
{
return this;
}
else
{
const Partitioner<DIMENSION>* nearest = NULL;
float nearestDist = std::numeric_limits<float>::max();
for (const Partitioner<DIMENSION> *child : children())
{
if (child != NULL)
{
float dist = (point - child->extension().center()).squaredNorm();
if (dist < nearestDist)
{
nearestDist = dist;
nearest = child;
}
}
}
return nearest->findNearestLeaf(point);
}
}
virtual const Partitioner<DIMENSION>* getContainingLeaf(size_t index) const = 0;
virtual void partition(size_t levels, size_t minNumPoints, float minSize) = 0;
virtual std::vector<const Partitioner<DIMENSION>*> children() const = 0;
virtual const Partitioner<DIMENSION>* parent() const = 0;
virtual bool isRoot() const = 0;
virtual bool isLeaf() const = 0;
virtual Rect<DIMENSION> extension() const = 0;
virtual std::vector<size_t> points() const = 0;
virtual size_t numPoints() const = 0;
private:
const PointCloud<DIMENSION>* mPointCloud;
};
template class Partitioner<2>;
template class Partitioner<3>;
typedef Partitioner<2> Partitioner2d;
typedef Partitioner<3> Partitioner3d;
#endif // PARTITIONER_H