PCL:自定义点云PointT数据类型及字段信息

PCL点云自定义数据类型

PCL官方例子

PCL官方链接
The following code snippet example creates a new point type that contains XYZ data (SSE padded), together with a test float.


#define PCL_NO_PRECOMPILE
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>

struct MyPointType
{
  PCL_ADD_POINT4D;                  // preferred way of adding a XYZ+padding
  float test;
  PCL_MAKE_ALIGNED_OPERATOR_NEW     // make sure our new allocators are aligned
} EIGEN_ALIGN16;                    // enforce SSE padding for correct memory alignment

POINT_CLOUD_REGISTER_POINT_STRUCT (MyPointType,           // here we assume a XYZ + "test" (as fields)
                                   (float, x, x)
                                   (float, y, y)
                                   (float, z, z)
                                   (float, test, test)
)

int
main (int argc, char** argv)
{
  pcl::PointCloud<MyPointType> cloud;
  cloud.points.resize (2);
  cloud.width = 2;
  cloud.height = 1;

  cloud[0].test = 1;
  cloud[1].test = 2;
  cloud[0].x = cloud[0].y = cloud[0].z = 0;
  cloud[1].x = cloud[1].y = cloud[1].z = 3;

  pcl::io::savePCDFile ("test.pcd", cloud);
}

自定义示例

参考官方是咧,可以根据自己的需求添加想要的字段信息,下面给出一个例子

struct PointXYZIRT {
 PCL_ADD_POINT4D;
 uint8_t intensity;
 uint16_t ring;
 double timestamp;
 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 }EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZIRT,
 (float, x, x)
 (float, y, y)
 (float, z, z)
 (uint8_t, intensity, intensity)
 (uint16_t, ring, ring)
 (double, timestamp, timestamp) 
) 

转成PointXYZI

void PointXYZIRT2PointXYZI(const pcl::PointCloud<PointXYZIRT>::Ptr in_cloud_xyzirt,
pcl::PointCloud<pcl::PointXYZI>::Ptr in_cloud)
{        
  in_cloud->header = in_cloud_xyzirt->header;
  in_cloud->width = in_cloud_xyzirt->width;
  in_cloud->height = in_cloud_xyzirt->height;
  in_cloud->is_dense = in_cloud_xyzirt->is_dense;
  for(size_t i=0;i<in_cloud_xyzirt->points.size();i++)
  {         
    pcl::PointXYZI p = in_cloud_xyzirt->at(i);;
    p.x = in_cloud_xyzirt->points.x;
    p.y = in_cloud_xyzirt->points.y;
    p.z = in_cloud_xyzirt->points.z;
    p.intensity = in_cloud_xyzirt->points.intensity;
    in_cloud->points.push_back(p);
  }
  
}
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ywfwyht

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值