用flann实现K近邻查找的例子

 //KDTreeSingleIndexParams(适合低维的情况) When passing an object of this type the index will contain a single kd-tree optimized for searching lower dimensionality data (for example 3D point clouds)
 //KDTreeIndexParams When passing an object of this type the index constructed will consist of a set of randomized kd-trees which will be searched in parallel.


        flann::Matrix<float> dataset(new float[N*dim], N, dim);
	TriMesh::Point p;


	for (TriMesh::VertexIter vit = mesh.vertices_begin(); vit != mesh.vertices_end(); vit++)
	{
		p = mesh.point(*vit);
		dataset[vit->idx()][0] = p[0];
		dataset[vit->idx()][1] = p[1];
		dataset[vit->idx()][2] = p[2];
	}

        //L2----欧氏距离的平方
	flann::Index< L2<float> > flann_index(dataset, flann::KDTreeSingleIndexParams(10));
	flann_index.buildIndex();


	std::vector<std::vector<int>>indices;
	std::vector<std::vector<float>>dists;


	flann_index.radiusSearch(dataset, indices, dists, radius, flann::SearchParams(128)); //搜索该半径范围以内所有的点的索引
 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值