1. 程式人生 > >PCL學習筆記——getApproximateIndices()函式的呼叫

PCL學習筆記——getApproximateIndices()函式的呼叫

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;
}