CGAL 最小点数约束的体素滤波

一、概述

  在CGAL 5.5版本中,grid_simplify_point_set()中添加了一个新的可选命名参数min_points_per_cell。通过在单元格中添加最小数量的点以便保留一个点,还可以过滤掉低密度区域和异常值:在密集采样点云的情况下,这比使用网格简化然后异常值去除产生更好的结果。

二、代码实现

#include <vector>
#include <fstream>
#include <CGAL/grid_simplify_point_set.h> // 体素滤波
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>


#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
// types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

int main(int argc, char* argv[])
{
	// ------------------------------加载点云---------------------------------
	std::vector<Kernel::Point_3> points;
	if (CGAL::IO::read_points("cgal//CSite.xyz", std::back_inserter(points)) == -1)
	{
		std::cerr << "Error: cannot read file" << std::endl;
		return -1;
	}

	std::cout << "从文件中读取" << points.size() << "个点。" << std::endl;
	
	// ------------------------最小点约束的体素滤波--------------------------
	double gridSize = 0.5;      // 体素大小
	unsigned int minPoints = 2;// 每个体素内要求的最小点数

	auto iterator_to_first_to_remove
		= CGAL::grid_simplify_point_set
		(points, gridSize,
			CGAL::parameters::min_points_per_cell(minPoints)); // optional

	points.erase(iterator_to_first_to_remove, points.end());
	CGAL::IO::write_points("cgal//CSite1_min_voxel.xyz", points, CGAL::parameters::stream_precision(14));
	std::cout << "采样后的点:" << points.size() << std::endl;
	// shrink_to_fit() 是 C++ STL 中的内置函数,它减少容器的容量以适应其大小并销毁超出容量的所有元素
	points.shrink_to_fit();
	
	return 0;
}

三、结果展示

1、原始点云
在这里插入图片描述
2、滤波后
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

点云侠

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

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

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

打赏作者

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

抵扣说明:

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

余额充值