如何增加新的PointT类型

博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=286

为了增加新的point类型,首先需要进行定义,例如:

struct MyPointType
{
float test;
};

然后,你得确保你的代码包含了PCL中特定的类/算法的模板头文件的实现,它将和你的新point类型MyPointType共同使用,例如,你想使用pcl::PassThrough。你只需要使用下面的代码即可:

#include <pcl/filters/passthrough.h>
#include <pcl/filters/impl/passthrough.hpp>
// the rest of the code goes here

如果你的代码是库的一部分,可以被他人使用,需要为你自己的MyPointType类型进行显示实例化。

实例

下面的代码段创建了包含XYZ数据的新point类型,连同一个的test的浮点型数据,这样满足存储对齐。

#include <pcl/point_types.h>
 #include <pcl/point_cloud.h>
 #include <pcl/io/pcd_io.h>
 
struct MyPointType              //定义点类型结构
{
PCL_ADD_POINT4D;                // 该点类型有4个元素
float test;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW// 确保new操作符对齐操作
}EIGEN_ALIGN16;// 强制SSE对齐
 
POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType,// 注册点类型宏
(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.points[0].test=1;
cloud.points[1].test=2;
cloud.points[0].x=cloud.points[0].y=cloud.points[0].z=0;
cloud.points[1].x=cloud.points[1].y=cloud.points[1].z=3;
 
pcl::io::savePCDFile("test.pcd",cloud);
}

 敬请关注PCL(Point Cloud Learning)中国更多的点云库PCL(Point Cloud Library)相关官方教程。

参考文献:

1.朱德海、郭浩、苏伟.点云库PCL学习教程(ISBN 978-7-5124-0954-5)北京航空航天出版

原文地址:https://www.cnblogs.com/flyinggod/p/8596172.html