CGAL学习记录——点云体素采样

点云体素采样


点云体素采样,参考PCL点云体素

方法一

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/grid_simplify_point_set.h>
#include <CGAL/property_map.h>
#include <vector>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;


int main(int argc, char** argv)
{
	std::vector<Point> points;
	std::vector<Vector> normals;
	std::ifstream stream(argv[1]);
	
	Point p;
	Vector v;
	while (stream >> p >> v)
	{
		points.push_back(p);
		normals.push_back(v);
	}

	//点的数量
	std::cout << points.size() << std::endl;
	std::vector<std::size_t>indices(points.size());//创建索引

	for (std::size_t i=0;i<points.size();i++)
	{
		indices[i] = i;
	}
	std::vector<std::size_t>::iterator end;//定义迭代器
	end = CGAL::grid_simplify_point_set(indices,0.5,CGAL::parameters::point_map(CGAL::make_property_map(points)));
	std::size_t k = end - indices.begin();
	std::cerr << "Keep" << k <<"points" << std::endl;

	{
		std::vector<Point>tmp_points(k);
		std::vector<Vector> tmp_normals(k);

		for (std::size_t i = 0; i < k; i++)
		{
			tmp_points[i] = points[indices[i]];
			tmp_normals[i] = normals[indices[i]];

		}
		points.swap(tmp_points);
		normals.swap(tmp_normals);
	}
	std::cout << "体素滤波后点的个数" << points.size() << std::endl;

	system("pause");
	return 0;
}


在这里插入图片描述


方法二

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/grid_simplify_point_set.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;

int main(int argc, char** argv)
{
    std::vector<Point>cloud;
    CGAL::IO::read_points(argv[1], std::back_inserter(cloud));
    
    std::cout << "采样前的点:" << cloud.size() << std::endl;
    cloud.erase(CGAL::grid_simplify_point_set(cloud, 2), cloud.end());
    std::cout << "采样后的点:" << cloud.size() << std::endl;
    CGAL::IO::write_XYZ("test_copy",cloud, CGAL::parameters::stream_precision(17));

}

在这里插入图片描述

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片