来源:《点云库PCL从入门到精通》P42-55;
PCL库中提供许多预定义的点类型,在一般情况下足够满足用户需求。同时PCL库也允许用户定义自己的点类型。
上图截选了pcl1.8.1版本中预定义的部分点类型 ,完整目录可在point_types.hpp中查看。在定义自己的点类型前,需要了解已有的类型,如果需要的点类型在PCL中已经存在,就不需要重复定义。(有时候点类型的名字并没有将成员包含的那么全,不能望文生义。比如PointXYZINormal这个类型,其成员变量就包含float x,y,z,intensity,normal[3],curvature;除了包括三维坐标xyz、强度信息、曲面法向量外,还可以存储曲率信息。)
#define PCL_NO_PRECOMPILE //没加这句话之前会报一个错误,没报错可以不加
#include <iostream>
#include <fstream>
#include <pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include <pcl/point_cloud.h>
using namespace std;
using namespace pcl;
struct MyPointType
{
PCL_ADD_POINT4D; // 添加pcl里xyz+padding
float test01; //定义你自己想要的属性,以及属性的数据类型
float test02;
float test03;
float test04;
float test05;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // 确保定义新类型点云内存与SSE对齐
} EIGEN_ALIGN16; // 强制SSE填充以正确对齐内存
POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType,
(float, x, x)
(float, y, y)
(float, z, z)
(float, test01, test01)
(float, test02, test02)
(float, test03, test03)
(float, test04, test04)
(float, test05, test05)
)
int main()
{
//所有的操作都和pcl预定义的点类型一样
pcl::PointCloud<MyPointType>::Ptr cloud(new pcl::PointCloud<MyPointType>);//定义一个装载自定义点类型的点云容器
MyPointType p1;//自定义点类型 对象实例化
system("pause");
return 0;
}