CGAL 计算点云的最值

一、概述

  CGAL中CGAL::bbox_3可以用来计算三维点云坐标的最值。

二、代码实现

#include <pcl/io/pcd_io.h>          // PCL读取PCD
#include <pcl/point_types.h>        // PCL点类型

#include <CGAL/Point_set_3.h>
#include <CGAL/Simple_cartesian.h>
//#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
//using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Kernel = CGAL::Simple_cartesian<double>;
using Point_2 = Kernel::Point_2;
using Point_3 = Kernel::Point_3;

using namespace std;

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

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

	// --------------------------计算点云最值--------------------------------
	CGAL::Bbox_3 bbox = CGAL::bbox_3(points.points().begin(), points.points().end());
	
	cout << "Min x: " << bbox.xmin() << endl;
	cout << "Min y: " << bbox.ymin() << endl;
	cout << "Min z: " << bbox.zmin() << endl;
	cout << "Max x: " << bbox.xmax() << endl;
	cout << "Max y: " << bbox.ymax() << endl;
	cout << "Max z: " << bbox.zmax() << endl;
	
	return 0;
}

三、结果展示

Min x: -0.0946899
Min y: 0.0329874
Min z: -0.0618736
Max x: 0.0610091
Max y: 0.187321
Max z: 0.0587997
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

点云侠

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

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

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

打赏作者

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

抵扣说明:

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

余额充值