-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathkdtree.h
More file actions
executable file
·50 lines (43 loc) · 1.27 KB
/
kdtree.h
File metadata and controls
executable file
·50 lines (43 loc) · 1.27 KB
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
#ifndef KDTREE_H
#define KDTREE_H
#include <vector>
#include <cmath>
#include "3dKDtree.h"
#include "Point.h"
namespace td
{
class KdTree
{
kdTree t_;
int numberOfNeighbours_; //按最近邻域点个数搜索
double radius_; //按半径搜索
PointCloud pnts_; //存放最近邻域点
public:
KdTree(PointCloud &_p) :t_(_p.size()) //建立Kdtree,传如的参数是list数据,继承自Point类,其中有xyz值
{
std::vector<td::Point>::iterator it;
it = _p.begin();
for (int i = 0; it != _p.end(); ++it, ++i)
{
t_.store(it->x, it->y, it->z, i);
}
t_.treeBalance(); //调整树
}
void setNumberOfNeighbours(int _num) //按最近邻域点搜索
{
numberOfNeighbours_ = _num;
radius_ = 5.0; //默认1.0米,具有500+个点,搜索半径太大没意义
}
void setNeighboursRadius(double _radius) //按半径搜索
{
radius_ = _radius;
numberOfNeighbours_ = 1000; //1平米点数约有700+点
}
int kNearestNeighbor(double &_x, double &_y, double &_z); //搜索最近n个邻域点,其本身也被包括在内&返回最临近点个数
std::vector<td::Point>& getNearestNeighbor() //取最临近值
{
return pnts_;
}
};
}
#endif