PCL 新增点云类型
【摘要】
PCL 新增自定义点云类型
CMakeList.txtCode所有代码
测试
pcl 库自身定义了很多中类型的 点云类型变量 。
但是在使用时 如果 希望 使用 自己定义的 点云...
PCL 新增自定义点云类型
pcl 库自身定义了很多中类型的 点云类型变量 。
但是在使用时 如果 希望 使用 自己定义的 点云类型 ,可以 通过 特定的 类 /算法 的模板文件实现
具体代码方法如下:
CMakeList.txt
首先构建 编译文件
使用PCL就这么搞就行了
# 声明要求的 cmake 最低版本
cmake_minimum_required(VERSION 2.8 )
# 添加c++ 11 标准支持
set(CMAKE_CXX_FLAGS "-std=c++11")
# 寻找PCL的库
find_package(PCL REQUIRED COMPONENT common io)
# 添加头文件
include_directories(${PCL_INCLUDE_DIRS})
add_definitions( ${PCL_DEFINITIONS} )
#添加一个可执行程序
add_executable(AddPointStyle_test AddPointStyle.cpp)
#链接PCL 库
target_link_libraries(AddPointStyle_test ${PCL_LIBRARIES})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
Code
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
- 1
- 2
- 3
需要包换的头文件
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%、
struct MyPointType //定义点类型结构
{
PCL_ADD_POINT4D; //该点类型有4个元素
/*尝试新增一个自定义*/
float JoneAdd; //定义自己新增的类型名称
//测试了添加这么多个也没问题
float JoneAdd1;
float JoneAdd2;
float JoneAdd3;
float JoneAdd4;
float JoneAdd5;
float JoneAdd6;
float JoneAdd7;
float JoneAdd8;
float JoneAdd9;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW //确保new操作符对齐操作
}EIGEN_ALIGN16; //强制SSE 对齐
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
定义一个结构体 为 自己定义的点 的 结构
点类型的名称
PCL_ADD_POINT4D 宏定义(pcl库的) 里面分别有 x、y、z 还有一个对齐变量
自己定义的 点里包含的变量名称
测试了可以添加这么多变量也没问题
pcl的宏定义 直接用就行了
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType, //注册点类型宏
(float ,x,x)
(float ,y,y)
(float ,z,z)
(float ,JoneAdd,JoneAdd)
(float ,JoneAdd,JoneAdd1)
(float ,JoneAdd,JoneAdd2)
(float ,JoneAdd,JoneAdd3)
(float ,JoneAdd,JoneAdd4)
(float ,JoneAdd,JoneAdd5)
(float ,JoneAdd,JoneAdd6)
(float ,JoneAdd,JoneAdd7)
(float ,JoneAdd,JoneAdd8)
(float ,JoneAdd,JoneAdd9)
)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
注册点类型宏
固定步骤
按照上的格式 ,先是上面定义的结构体的名称。后面时点的各变量
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main(int argc, char const *argv[])
{
pcl::PointCloud <MyPointType> cloud;
cloud.points.resize(2);
cloud.width=2;
cloud.height=1;
cloud.points[0].x=cloud.points[0].y=cloud.points[0].z=1;
cloud.points[1].x=cloud.points[1].y=cloud.points[1].z=3;
cloud.points[0].JoneAdd = 1.2;
cloud.points[1].JoneAdd = 3.4;
pcl::io::savePCDFile("test.pcd",cloud);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
声明自己定义的点云 变量
设置点云大小
赋值点里面的变量,其中包含了常规的 x,y,z
还有自己定义的 JoneAdd
保存成pcd文件
所有代码
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
struct MyPointType //定义点类型结构
{
PCL_ADD_POINT4D; //该点类型有4个元素
/*尝试新增一个自定义*/
float JoneAdd; //定义自己新增的类型名称
//测试了添加这么多个也没问题
float JoneAdd1;
float JoneAdd2;
float JoneAdd3;
float JoneAdd4;
float JoneAdd5;
float JoneAdd6;
float JoneAdd7;
float JoneAdd8;
float JoneAdd9;
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 ,JoneAdd,JoneAdd)
(float ,JoneAdd,JoneAdd1)
(float ,JoneAdd,JoneAdd2)
(float ,JoneAdd,JoneAdd3)
(float ,JoneAdd,JoneAdd4)
(float ,JoneAdd,JoneAdd5)
(float ,JoneAdd,JoneAdd6)
(float ,JoneAdd,JoneAdd7)
(float ,JoneAdd,JoneAdd8)
(float ,JoneAdd,JoneAdd9)
)
int main(int argc, char const *argv[])
{
pcl::PointCloud <MyPointType> cloud;
cloud.points.resize(2);
cloud.width=2;
cloud.height=1;
cloud.points[0].x=cloud.points[0].y=cloud.points[0].z=1;
cloud.points[1].x=cloud.points[1].y=cloud.points[1].z=3;
cloud.points[0].JoneAdd = 1.2;
cloud.points[1].JoneAdd = 3.4;
pcl::io::savePCDFile("test.pcd",cloud);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
测试
文章来源: blog.csdn.net,作者:月照银海似蛟龙,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_32761549/article/details/117221920
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)