PCL--pcl::copyPointCloud 使用方法

部分copy

pcl 1.8.0 库中函数说明:

void pcl::copyPointCloud (const pcl::PointCloud< PointInT > & cloud_in, 
const std::vector< int, Eigen::aligned_allocator< int > > & indices, 
pcl::PointCloud< PointOutT > & cloud_out 
)
**Extract the indices of a given point cloud as a new point cloud.** 
Parameters
[in]cloud_in     the input point cloud dataset 
[in]indices      the vector of indices representing the points to be copied from cloud_in 
[out]cloud_out   the resultant output point cloud dataset 

使用方法:

//-------------------------------------------------------
//---如果知道需要保存点的索引,如何从原点云中拷贝点到新点云?
#include 
#include 
#include 
#include 

pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
pcl::io::loadPCDFile("your_pcd_file.pcd", *cloud);
pcl::PointCloud::Ptr cloudOut(new pcl::PointCloud);
std::vector<int > indexs = { 1, 2, 5 }; //索引
pcl::copyPointCloud(*cloud, indexs, *cloudOut);
//--------------------------------------------------------

全部copy

pcl 1.8.0 库中函数说明:

void pcl::copyPointCloud (const pcl::PointCloud< PointInT > & cloud_in, 
pcl::PointCloud< PointOutT > & cloud_out 
)

**Copy all the fields from a given point cloud into a new point cloud.** 
Parameters
[in]cloud_in      the input point cloud dataset 
[out]cloud_out    the resultant output point cloud dataset 

使用方法

//将一个点云A全部复制到另一个点云B中,不需要将点云B中点清空,直接复制就会将云完全覆盖掉
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/cloud_viewer.h>

#include <iostream>
#include <string>
using namespace std;
void main()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_Block(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("F:\\常用的三维点云数据\\Block.pcd", *cloud_Block);
    cout <<"cloud_Block:  "<< cloud_Block->points.size() << endl;

    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_bunny(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("F:\\常用的三维点云数据\\bunny.pcd", *cloud_bunny);
    cout <<"cloud_bunny:  "<< cloud_bunny->points.size() << endl;

    pcl::copyPointCloud(*cloud_bunny, *cloud_Block); //复制
    cout <<"cloud_Block:  "<< cloud_Block->points.size() << endl;
    system("pause");
}

pcl::copyPointCloud还有很多重载方法,以后慢慢探索。

你可能感兴趣的:(PCL)