PCL 自定义点云类型的读写问题

10 篇文章 11 订阅

自定义点云类型

struct EIGEN_ALIGN32 MyPointType    // 强制 SSE 填充以获得正确的内存对齐
{
  PCL_ADD_POINT4D;                  // 添加 XYZ+padding
  PCL_ADD_RGB;						// 添加 RGBA
  uint8_t intensity;				// 自定义变量
  uint8_t return_number;
  PCL_MAKE_ALIGNED_OPERATOR_NEW     // 确保我们的新分配器对齐
};

POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType,           // 注册点类型宏 (type, name, tag) (类型(不符合不会载入), 变量名, 文件中的变量名(不符合会报错))
                                   (float, x, x)
                                   (float, y, y)
                                   (float, z, z)
                                   (float, rgb, rgb)
								   (uint8_t, intensity, scalar_Intensity)
								   (uint8_t, return_number, scalar_ReturnNumber))

上述代码定义了一个 xyzrgbi(intensity)r(return_number) 的点云.
其中PCL_ADD_POINT4D定义了xyz, 其具体实现可参考如下代码:

#define PCL_ADD_UNION_POINT4D \
  union EIGEN_ALIGN16 { \
    float data[4]; \
    struct { \
      float x; \
      float y; \
      float z; \
    }; \
  };

同理PCL_ADD_RGB定义了rgba, a我们用不到, 可参考:

#define PCL_ADD_UNION_RGB \
  union \
  { \
    union \
    { \
      struct \
      { \
        std::uint8_t b; \
        std::uint8_t g; \
        std::uint8_t r; \
        std::uint8_t a; \
      }; \
      float rgb; \
    }; \
    std::uint32_t rgba; \
  };

POINT_CLOUD_REGISTER_POINT_STRUCT

POINT_CLOUD_REGISTER_POINT_STRUCT 用于注册点类型, 参数中的 (type, name, tag) 分别填入某个变量的类型, 名称和标签. 这里的名称是指结构体中对应的变量名, 标签是指文件中写入的变量名.

上述代码对应的pcd文件结构如下:

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z rgb scalar_Intensity scalar_ReturnNumber
SIZE 4 4 4 4 1 1
TYPE F F F U U U
COUNT 1 1 1 1 1 1
WIDTH 174097
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 174097
DATA ascii
-1.174494e+29 -1.8729781 7.6664328e-25 4010034017 191 189
-1.174494e+29 -7.6053216e+28 1.0537315e-38 29212655 42 239
-1.8729781 -7.7143658e+28 225.7412 4022190063 191 189
...

读取pcd文件:

pcl::PointCloud<MyPointType> cloud;
pcl::io::loadPCDFile("./test.pcd", cloud);

读入pcd文件时可能会遇到如下错误

可能出现的错误

Failed to find match for field ‘xxx’

xxx 为你代码中注册了但是文件中没有的 tag, 有可能是因为文件中颜色相关的tag为rgb, 但是注册却写了

	(uint8_t, r, r)
	(uint8_t, g, g)
	(uint8_t, b, b)

无报错, 但是没读入

可能是由于变量类型不匹配导致的, 如文件中对应的 intensity 类型为 U , 但是代码中却注册了(float, intensity, scalar_Intensity)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值