复制点云
- 添加点的方式到新的点云
cloud->push_back(point);
- 通过索引添加
template <typename PointT> void copyPoints(const pcl::PointCloud<PointT> &cloud_in, const std::vector<int> &indices, pcl::PointCloud<PointT> &cloud_out) { if (indices.size() == cloud_in.points.size()) { cloud_out = cloud_in; return; } cloud_out.points.resize(indices.size()); cloud_out.header = cloud_in.header; cloud_out.width = static_cast<uint32_t>(indices.size()); cloud_out.height = 1; cloud_out.is_dense = cloud_in.is_dense; cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_; cloud_out.sensor_origin_ = cloud_in.sensor_origin_; for (size_t i = 0; i < indices.size(); ++i) { cloud_out[i] = cloud_in[indices[i]]; } }
- 函数调用
这种方式还可用于点云格式转换,如source为XYZI,result为XYZ.pcl::copyPointCloud(*source, *result);
- 两个点云叠加在一块
*cloud_c = *cloud_a + *cloud_b;
用时对比
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/shadowpoints.h>
#include <pcl/features/normal_3d.h>
#include <pcl/common/common.h>
#include <mutex>
#include <time.h>
#include <omp.h>
using namespace std;
int main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr source(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr t1(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr t2(new pcl::PointCloud<pcl::PointXYZ>);
int point_num = 20000000;
for (int i=0;i<point_num;i++)
{
pcl::PointXYZ point;
point.x = rand();
point.y = rand();
point.z = rand();
source->points.push_back(point);
}
clock_t start = clock();
pcl::copyPointCloud(*source,*t1);
clock_t end = clock();
cout << end - start << endl;
mutex push_lock;
//#pragma omp parallel for
for (int i = 0; i < point_num; i++)
{
push_lock.lock();
t2->points.push_back(source->points[i]);
push_lock.unlock();
Sleep(1);
}
clock_t end2 = clock();
cout << end2 - end << endl;
return 0;
}
pcl::copyPointCloud()方法更快。
pcl学习资料:https://zhuanlan.zhihu.com/p/268524083
pcl常用数据集: https://blog.csdn.net/qq_27816785/article/details/124856990