pcl源码分析之法向量


前言

点云处理中,法向量是一个很重要的参数,这里分析下pcl计算法向量的源码,加深对原理的理解。大概原理和流程可以参考这篇博文


一、应用实例

#include <pcl/features/normal_3d_omp.h>//使用OMP需要添加的头文件

	pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> n;//OMP加速
	//pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
	//建立kdtree来进行近邻点集搜索
	pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
	n.setNumberOfThreads(10);//设置openMP的线程数
	n.setViewPoint(0, 0, 0);//设置视点,默认为(0,0,0)
	n.setInputCloud(cloud);
	n.setSearchMethod(tree);

	if(is_radius)
		n.setRadiusSearch(radius);//半径搜素
	else
		n.setKSearch(sum);//点云法向计算时,需要所搜的近邻点大小
	
	n.compute(*normals);//开始进行法向计

二、NormalEstimationOMP类

在NormalEstimationOMP类中,核心函数是computeFeature。

三、computeFeature函数

该函数有两个个需要注意的地方:

  1. for循环的多线程运行——#pragma omp parallel for;
  2. 置nan值——std::numeric_limits::quiet_NaN ();
//模板函数
template <typename PointInT, typename PointOutT> void
pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
{
   
  // Allocate enough space to hold the results
  // \note This resize is irrelevant for a radiusSearch ().
  std::vector<int> nn_indices (k_);
  std::vector<float> nn_dists (k_);

  output.is_dense = true;

  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
  if (input_->is_dense)
  {
   
#ifdef _OPENMP
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
    // Iterating over the entire index vector
    for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
    {
   
      //如果找不到近邻点,则将参数置为nan值
      //这里还是用到了kdtree,kdtree在pcl源码里的使用率非常高
      if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
      {
   
        output.points[idx].normal[0] = output.points[idx].normal[1] = output.points[idx].normal[2] = output.points[idx].curvature = std::numeric_limits<float>::<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值