当前位置: 首页 > news >正文

pcl源码分析之计算凸包

文章目录

  • 前言
  • 一、应用案例
  • 二、源码分析
    • 1.ConvexHull类
    • 2.reconstruct函数
    • 3.performReconstruction 函数
    • 4.calculateInputDimension 函数
  • 总结


前言

本文分析一下pcl里凸包的源码。什么是凸包以及怎么求解,可以了解一下概念。


一、应用案例

#include <pcl/surface/convex_hull.h>pcl::ConvexHull<pcl::PointXYZ> convex_hull;convex_hull.setInputCloud(cloud_in);//输入点云//convex_hull.setDimension(3);//设置维数,当然不设置,内部算法也会自己计算//pcl::PointCloud<pcl::PointXYZ>::Ptr hull_out(new pcl::PointCloud<pcl::PointXYZ>);convex_hull.reconstruct(*cloud_out);//输出凸包(点)convex_hull.getHullPointIndices(Indices);//输出凸包(点)在输入点云中的id

二、源码分析

1.ConvexHull类

  template<typename PointInT>class ConvexHull : public MeshConstruction<PointInT>{...//构造函数中dimension_(数据的维数) 默认是0//x_axis_ , y_axis_ , z_axis_ 坐标轴三个参数也在这里确定/** \brief Empty constructor. */ConvexHull () : compute_area_ (false), total_area_ (0), total_volume_ (0), dimension_ (0), projection_angle_thresh_ (cos (0.174532925) ), qhull_flags ("qhull "),x_axis_ (1.0, 0.0, 0.0), y_axis_ (0.0, 1.0, 0.0), z_axis_ (0.0, 0.0, 1.0){};...//输出凸包接口/** \brief Compute a convex hull for all points given.* \param[out] points the resultant points lying on the convex hull.*/voidreconstruct (PointCloud &points);...//设置维数接口(这里如果不设置具体的维数,则会维数默认值是构造函数里的值0,并且算法里会自行计算真实的维数)void setDimension (int dimension){if ((dimension == 2) || (dimension == 3))dimension_ = dimension;elsePCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());}...//获取凸包点在输入点云中的idvoidgetHullPointIndices (pcl::PointIndices &hull_point_indices) const;...}

2.reconstruct函数

template <typename PointInT> void
pcl::ConvexHull<PointInT>::reconstruct (PointCloud &points)
{points.header = input_->header;//初始化,这里initCompute 实际上是PCLBase这个基类的初始化函数,前文有讲过,这里不再赘述if (!initCompute () || input_->points.empty () || indices_->empty ()){points.points.clear ();return;}// Perform the actual surface reconstruction//这里就是真正的凸包计算接口std::vector<pcl::Vertices> polygons;performReconstruction (points, polygons, false);points.width = static_cast<uint32_t> (points.points.size ());points.height = 1;points.is_dense = true;deinitCompute ();
}

3.performReconstruction 函数

对于Qhull,有兴趣可以了解学习一下:
3.1 什么是Qhull
3.2 怎么下载编译Qhull
3.2 Qhull官网地址

template <typename PointInT> void
pcl::ConvexHull<PointInT>::performReconstruction (PointCloud &hull, std::vector<pcl::Vertices> &polygons,bool fill_polygon_data)
{//如上面所说,如果没有在维度设置接口中设置维度,则默认维度是0,也即会执行calculateInputDimension if (dimension_ == 0)calculateInputDimension ();//后面这两函数就是具体的调用哦个Ahull库来实现凸包的计算//具体怎么实现的,后续有空再研究吧,毕竟又涉及到另一个开源库,need more time~~if (dimension_ == 2)performReconstruction2D (hull, polygons, fill_polygon_data);else if (dimension_ == 3)performReconstruction3D (hull, polygons, fill_polygon_data);elsePCL_ERROR ("[pcl::%s::performReconstruction] Error: invalid input dimension requested: %d\n",getClassName ().c_str (),dimension_);
}

4.calculateInputDimension 函数

template <typename PointInT> void
pcl::ConvexHull<PointInT>::calculateInputDimension ()
{PCL_DEBUG ("[pcl::%s::calculateInputDimension] WARNING: Input dimension not specified.  Automatically determining input dimension.\n", getClassName ().c_str ());//计算输入点云质心Eigen::Vector4d xyz_centroid;compute3DCentroid (*input_, *indices_, xyz_centroid);EIGEN_ALIGN16 Eigen::Matrix3d covariance_matrix;//计算每个点的协方差矩阵//这里原理就是://1.将原始点云坐标减去中心点坐标//2.再对这些数据构造协方差矩阵,协方差矩阵具体构造原理看前文harris3d源码分析,就不再详细分析//3.有一点要说明,这个部分构造协方差矩阵的开源代码,比harris3d里协方差矩阵开源代码要清晰很多computeCovarianceMatrixNormalized (*input_, *indices_, xyz_centroid, covariance_matrix);//求协方差矩阵的特征值//主法向量是协方差矩阵的最小特征值对应的特征向量EIGEN_ALIGN16 Eigen::Vector3d eigen_values;pcl::eigen33 (covariance_matrix, eigen_values);//对于二维的数据,主法向量就是0或者近似于0if (std::abs (eigen_values[0]) < std::numeric_limits<double>::epsilon () || std::abs (eigen_values[0] / eigen_values[2]) < 1.0e-3)dimension_ = 2;elsedimension_ = 3;
}

总结

分析了下pcl里求解凸包的整体流程,有一些收获~~

http://www.lryc.cn/news/514789.html

相关文章:

  • 在K8S中,Pod请求另一个Pod偶尔出现超市或延迟,如何排查?
  • 3blue1brow线代笔记
  • 【前端系列】优化axios响应拦截器
  • SQL使用视图
  • 在Windows计算机上打开 HEIC 文件的 6 种有效方法
  • 开源数据集成平台白皮书重磅发布《Apache SeaTunnel 2024用户案例合集》!
  • C# delegate 委托使用教程
  • 《机器学习》——数据标准化(0~1标准化,z标准化)
  • 如何监控和管理API接口的调用频率和并发量?
  • springboot+vue使用EasyCaptcha实现简单验证码
  • “善弈者”也需妙手,Oclean欧可林:差异化不是说说而已
  • Lianwei 安全周报|2025.1.2
  • 吐卡机开发——指令合集—未来之窗行业应用跨平台架构
  • C# 设计模式(创建型模式):单例模式
  • 使用WebSocket 获取实时数据
  • 阿里云服务器上安装配置Logtail日志收集客户端
  • Java实现下载excel模板,并实现自定义下拉框
  • postgres docker安装
  • 数据库原理与应用期末复习
  • 数据库知识汇总2
  • CS·GO搬砖流程详细版
  • 《长寿养生报》是科普报刊吗?参与评选的科普作品需要注意什么?
  • React native 原生环境搭建(最新版本RN环境搭建,不是expo)
  • Unity Excel转Json编辑器工具
  • XML结构快捷转JSON结构API集成指南
  • 数据挖掘——支持向量机分类器
  • ImageNet 2.0?自动驾驶数据集迎来自动标注新时代
  • 智能工厂的设计软件 应用场景的一个例子:为AI聊天工具添加一个知识系统 之11 方案再探之2 项目文件(修改稿1)
  • 详解MySQL SQL删除(超详,7K,含实例与分析)
  • uniapp:跳转第三方地图