PCL自定义点类型

来源:互联网 发布:上海浦东软件协会朱 编辑:程序博客网 时间:2024/05/18 04:57

除了pcl已定义点类型,参考http://www.cnblogs.com/li-yao7758258/p/6433445.html

很多时候都需要自定义所需点类型,定义方法如下

以下例子是创建新的点类型,数据中包含X,Y,Z,PC1,PC2,meanPC(平均曲率),作为参考


step 1 新建myPointType.h

#define PCL_NO_PRECOMPILE#ifndef MYPOINTTYPE_H#define MYPOINTTYPE_H#include <pcl/point_types.h>struct XYZ_CURVA{PCL_ADD_POINT4D;union{float coordinate[3];struct{float x;float y;float z;};};float pc1;float pc2;float mean_pc;EIGEN_MAKE_ALIGNED_OPERATOR_NEW;}EIGEN_ALIGN16;POINT_CLOUD_REGISTER_POINT_STRUCT(XYZ_CURVA,// 注册点类型宏(float, x, x)(float, y, y)(float, z, z)(float, pc1, pc1)(float, pc2, pc2)(float, mean_pc, mean_pc))#endif


step 2 cpp中使用
法线和曲率计算参见官网法线例子,曲率计算例子如下(并不是真正数学意义上的曲率

pcl::PointCloud<pcl::Normal>::Ptr cloud_with_normals;pcl::PointCloud<pcl::PrincipalCurvatures>::Ptr principal_curvatures;pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimation;
normal_estimation.setInputCloud(cloud);pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);normal_estimation.setSearchMethod(tree);//适合本实验数据的k值normal_estimation.setKSearch(60);normal_estimation.compute(*cloud_with_normals);// Setup the principal curvatures computationpcl::PrincipalCurvaturesEstimation<pcl::PointXYZ, pcl::Normal, pcl::PrincipalCurvatures> principal_curvatures_estimation;// Provide the original point cloud (without normals)principal_curvatures_estimation.setInputCloud(cloud);// Provide the point cloud with normalsprincipal_curvatures_estimation.setInputNormals(cloud_with_normals);// Use the same KdTree from the normal estimationprincipal_curvatures_estimation.setSearchMethod(tree);principal_curvatures_estimation.setKSearch(60);// Actually compute the principal curvaturesprincipal_curvatures_estimation.compute(*principal_curvatures);pcl::io::savePCDFile("temp/curva_out.pcd", *principal_curvatures);pcl::io::savePCDFile("temp/normal_out.pcd", *cloud_with_normals);

将每个点坐标以及计算好的数据保存至新文件

int size = cloud->size();pcl::PointCloud<XYZ_CURVA> xyz_curva;xyz_curva.points.resize(size);xyz_curva.width = size;xyz_curva.height = 1;for (int i = 0; i < size; i++){xyz_curva.points[i].x = cloud->points[i].x;xyz_curva.points[i].y = cloud->points[i].y;xyz_curva.points[i].z = cloud->points[i].z;xyz_curva.points[i].pc1 = principal_curvatures->points[i].pc1;xyz_curva.points[i].pc2 = principal_curvatures->points[i].pc2;xyz_curva.points[i].mean_pc = (principal_curvatures->points[i].pc1 + principal_curvatures->points[i].pc2)/2;}pcl::io::savePCDFile("temp/test.pcd", xyz_curva);

存在问题:

IntelliSense:  常量表达式中不允许该运算符 myPointType.h (但是最终结果不受影响,编译器或者版本的问题maybe)


1 0
原创粉丝点击