getApproximateIndices():得到给定点云的一组近似索引到参考点云
void pcl::getApproximateIndices (const typename pcl::PointCloud< PointT >::ConstPtr & cloud_in,const typename pcl::PointCloud< PointT>::ConstPtr & cloud_ref,std::vector< int > & indices )
Get a set of approximate indices for a given point cloud into a reference point cloud.
The coordinates of the two point clouds can differ. The method uses an internal KdTree for finding the closest neighbors from cloud_in in cloud_ref.
Parameters:
[in] cloud_in :the input point cloud dataset;
[in] cloud_ref :the reference point cloud dataset;
[out] indices :the resultant set of nearest neighbor indices of cloud_in in cloud_ref.
code:
// get_index_of_overlap.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "stdafx.h"
#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include<pcl/point_cloud.h>
#include<pcl/kdtree/kdtree_flann.h>
#include<pcl/kdtree/io.h>
#include<vector>
#include<fstream>
using namespace std;
int main()
{
ofstream test;
test.open("test.txt");
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudA(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudB(new pcl::PointCloud<pcl::PointXYZ>);
//读取pcd文档
if (pcl::io::loadPCDFile<pcl::PointXYZ>("pointA.pcd", *cloudA) == -1)
{
PCL_ERROR("Couldn't read file cloudA.pcd\n");
return -1;
}
if (pcl::io::loadPCDFile<pcl::PointXYZ>("pointB.pcd", *cloudB) == -1)
{
PCL_ERROR("Couldn't read file cloudB.pcd\n");
return -1;
}
//为点云A中的每个点在点云B中找到一个最邻近点,但是无法设置阈值
vector<int>vec;
pcl::getApproximateIndices<pcl::PointXYZ>(cloudA, cloudB, vec);
test.close();
return 0;
}