PCL学习笔记——多组点云数据拼接和字段拼接

本文详细介绍了使用PCL库进行点云数据(PointXYZ和Normal)的官方合并方法,以及自定义方式实现数据拼接,并展示了如何结合点云和法向量。通过实例展示了两种操作,有助于理解PCL中数据结构的连接和字段扩展。
摘要由CSDN通过智能技术生成

本文包括pcl官方实现的字段拼接和数据拼接以及自实现两种拼接的代码。

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;
int main()
{
    pcl::PointCloud<pcl::PointXYZ> cloud_a,cloud_b,cloud_c,cloud_c_op;
    pcl::PointCloud<pcl::Normal> n_cloud_b;
    pcl::PointCloud<pcl::PointNormal> n_cloud_b_normal,n_cloud_b_normal_op;

    for(size_t i = 0;i<3;i++)
    {
        pcl::PointXYZ tmp;
        tmp.x = 1024*rand()/(RAND_MAX+1.0f);
        tmp.y = 1024*rand()/(RAND_MAX+1.0f);
        tmp.z = 1024*rand()/(RAND_MAX+1.0f);
        cloud_a.push_back(tmp);
    }
    for(size_t i = 0;i<cloud_a.points.size();i++)
    {
        cout<<"cloud_a:x="<<cloud_a.points[i].x<<",y="<<cloud_a.points[i].y<<",z="<<cloud_a.points[i].z<<endl;
    }

    for(size_t i = 0;i<3;i++)
    {
        pcl::PointXYZ tmp;
        tmp.x = 1024*rand()/(RAND_MAX+1.0f);
        tmp.y = 1024*rand()/(RAND_MAX+1.0f);
        tmp.z = 1024*rand()/(RAND_MAX+1.0f);
        cloud_b.push_back(tmp);
    }
    for(size_t i = 0;i<cloud_b.points.size();i++)
    {
        cout<<"cloud_b:x="<<cloud_b.points[i].x<<",y="<<cloud_b.points[i].y<<",z="<<cloud_b.points[i].z<<endl;
    }


    for(size_t i = 0;i<3;i++)
    {
        pcl::Normal tmp_normal;
        tmp_normal.normal_x = 1024*rand()/(RAND_MAX+1.0f);
        tmp_normal.normal_y = 1024*rand()/(RAND_MAX+1.0f);
        tmp_normal.normal_z = 1024*rand()/(RAND_MAX+1.0f);
        n_cloud_b.push_back(tmp_normal);
    }
    for(size_t i = 0;i<n_cloud_b.points.size();i++)
    {
        cout<<"n_cloud_b:normal_x="<<n_cloud_b.points[i].normal_x<<",normal_y="<<n_cloud_b.points[i].normal_y<<",normal_z="<<n_cloud_b.points[i].normal_z<<endl;
    }

    //数据连接-----------------
    //pcl官方操作
    cloud_c =cloud_a;
    cloud_c += cloud_b;
//    for(size_t i = 0;i<cloud_c.points.size();i++)
//    {
//        cout<<"cloud_c:x="<<cloud_c.points[i].x<<",y="<<cloud_c.points[i].y<<",z="<<cloud_c.points[i].z<<endl;
//    }

    //自定义操作
    for(size_t i = 0; i<cloud_a.points.size()+cloud_b.points.size();i++)
    {
        if(i<cloud_a.points.size())
        {
            pcl::PointXYZ tmp;
            tmp.x = cloud_a.points[i].x;
            tmp.y = cloud_a.points[i].y;
            tmp.z = cloud_a.points[i].z;
            cloud_c_op.push_back(tmp);
        }
        else
        {
            pcl::PointXYZ tmp;
            tmp.x = cloud_b.points[i-cloud_a.points.size()].x;
            tmp.y = cloud_b.points[i-cloud_a.points.size()].y;
            tmp.z = cloud_b.points[i-cloud_a.points.size()].z;
            cloud_c_op.push_back(tmp);
        }
    }
//    for(size_t i = 0;i<cloud_c_op.points.size();i++)
//    {
//        cout<<"cloud_c_op:x="<<cloud_c_op.points[i].x<<",y="<<cloud_c_op.points[i].y<<",z="<<cloud_c_op.points[i].z<<endl;
//    }
    //-----------------


    //字段拼接---------------
    //pcl官方操作
    pcl::concatenateFields(cloud_b,n_cloud_b,n_cloud_b_normal);
    for(size_t i = 0;i<n_cloud_b_normal.points.size();i++)
    {
        cout<<"n_cloud_b_normal:x="<<n_cloud_b_normal.points[i].x<<",y="<<n_cloud_b_normal.points[i].y<<",z="<<n_cloud_b_normal.points[i].z<<",normal_x:"<<n_cloud_b_normal.points[i].normal_x<<",normal_y"<<n_cloud_b_normal.points[i].normal_y<<",normal_z"<<n_cloud_b_normal.points[i].normal_z<<endl;
    }

    //自定义操作
    for(size_t i = 0; i<cloud_b.points.size();i++)
    {
        pcl::PointNormal tmp;
        tmp.x = cloud_b.points[i].x;
        tmp.y = cloud_b.points[i].y;
        tmp.z = cloud_b.points[i].z;
        tmp.normal_x = n_cloud_b.points[i].normal_x;
        tmp.normal_y = n_cloud_b.points[i].normal_y;
        tmp.normal_z = n_cloud_b.points[i].normal_z;
        n_cloud_b_normal_op.push_back(tmp);
    }
    for(size_t i = 0;i<n_cloud_b_normal_op.points.size();i++)
    {
        cout<<"n_cloud_b_normal_op:x="<<n_cloud_b_normal_op.points[i].x<<",y="<<n_cloud_b_normal_op.points[i].y<<",z="<<n_cloud_b_normal_op.points[i].z<<",normal_x:"<<n_cloud_b_normal_op.points[i].normal_x<<",normal_y"<<n_cloud_b_normal_op.points[i].normal_y<<",normal_z"<<n_cloud_b_normal_op.points[i].normal_z<<endl;
    }


    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值