CGAL 基于曲面拟合的点云平滑

一、算法原理

  基于曲面拟合的方法,实现对点云的平滑处理。

1、主要函数

头文件

#include <CGAL/jet_smooth_point_set.h>

函数

void CGAL::jet_smooth_point_set  ( PointRange &  points,  
  unsigned int  k,  
  const NamedParameters &  np = parameters::default_values()  
 )  

  使用射流拟合在最近的邻居和重新投影到射流上的点的范围平滑。由于此方法会改变点的位置,因此不适用于进行过排序处理的点云。

  • points:点云
  • k: 隐式曲面拟合的邻域点数。值越大,结果越平滑。
  • np:下面列出的命名参数中的一个可选序列。

在这里插入图片描述

二、代码实现

#include <vector>
#include <iostream>    // io
#include <pcl/io/pcd_io.h>          // PCL读取PCD
#include <pcl/point_types.h>        // PCL点类型
#include <CGAL/Point_set_3/IO/XYZ.h>// CGAL保存点为.xyz

#include <CGAL/jet_smooth_point_set.h>
#include <CGAL/Simple_cartesian.h>

typedef CGAL::Simple_cartesian<float> Kernel;

int main()
{
	//-------------------------加载PCD点云数据------------------------------
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

	if (pcl::io::loadPCDFile<pcl::PointXYZ>("cgal//cloud.pcd", *cloud) == -1)
	{
		PCL_ERROR("Could not read file\n");
		return -1;
	}
	// ----------------------转为CGAL支持的格式------------------------------
	std::vector<Kernel::Point_3> points;
	for (size_t i = 0; i < cloud->size(); ++i)
	{
		float px = cloud->points[i].x;
		float py = cloud->points[i].y;
		float pz = cloud->points[i].z;
		points.push_back(Kernel::Point_3(px, py, pz));
	}

	// ---------------------------Smoothing----------------------------------
	const unsigned int nb_neighbors = 24; // 邻域点的个数
	CGAL::jet_smooth_point_set<CGAL::Parallel_if_available_tag>(points, nb_neighbors);
	//CGAL::IO::write_XYZ("cgal//smooth.xyz", points);

	pcl::PointCloud<pcl::PointXYZ>::Ptr smoothed(new pcl::PointCloud<pcl::PointXYZ>);
	smoothed->resize(points.size());
	smoothed->reserve(points.size());

	for (size_t i = 0; i < points.size(); ++i)
	{
		smoothed->points[i].x = points[i].hx();
		smoothed->points[i].y = points[i].hy();
		smoothed->points[i].z = points[i].hz();
	}
	pcl::io::savePCDFileBinary("cgal//jet_smooth.pcd", *smoothed); 
	
	return 0;
}

三、结果展示

在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

点云侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值