用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 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 > flann_index(dataset, flann::KDTreeSingleIndexParams(10));
	flann_index.buildIndex();


	std::vector>indices;
	std::vector>dists;


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


你可能感兴趣的:(编程)