CGAL 读取.las格式的点云

一、概述

1、只读取坐标值

头文件

#include <CGAL/IO/read_las_points.h>

read_LAS() [1/2]

bool CGAL::IO::read_LAS  ( std::istream &  is,  
  PointOutputIterator  output,  
  const NamedParameters &  np = parameters::default_values()  
 ) 

从las文件中读取点的坐标,忽略其他属性。

  • OutputIteratorValueType :可以放在PointOutputIterator中的对象类型。它必须是一个DefaultConstructible模型,默认值为value_type_traits<PointOutputIterator>::type。当默认值合适时,可以省略它。
  • PointOutputIterator :输出点上的迭代器。
  • NamedParameters:命名参数序列

read_LAS() [2/2]

bool CGAL::IO::read_LAS  ( const std::string &  filename,  
  PointOutputIterator  output,  
  const NamedParameters &  np = parameters::default_values()  
 ) 

与第一个函数的唯一的区别在于:const std::string & filename

2、读取全部属性信息

头文件

#include <CGAL/IO/read_las_points.h>

read_LAS_with_properties()

bool CGAL::IO::read_LAS_with_properties  ( std::istream &  is,  
  PointOutputIterator  output,  
  PropertyHandler &&...  properties  
 ) 

从.las或.laz流中读取用户选择的点属性。属性通过可变参数属性处理程序列表进行处理。PropertyHandler可以是:
在这里插入图片描述

二、代码实现

#include <utility>
#include <vector>
#include <fstream>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_las_points.h> // 读取las点云
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
// types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point; // 三维点坐标
typedef std::array<unsigned short, 4> Color; // 存储点云的RGB和强度
typedef std::pair<Point, Color> PointWithColor;

int main(int argc, char* argv[])
{
	// ----------------------------------文件名------------------------------------------
	const char* fname =  "cgal//pig_points.las";

	// --------------------------从las中读取点坐标和颜色---------------------------------
	std::ifstream in(fname, std::ios_base::binary);
	std::vector<PointWithColor> points; // 存储点
	if (!CGAL::IO::read_LAS_with_properties(in, std::back_inserter(points),
		CGAL::IO::make_las_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
		std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
			CGAL::Construct_array(),
			CGAL::IO::LAS_property::R(),
			CGAL::IO::LAS_property::G(),
			CGAL::IO::LAS_property::B(),
			CGAL::IO::LAS_property::I())))
	{
		std::cerr << "文件读取失败!!! " << fname << std::endl;
		return -1;
	}
	// ------------------------------输出点的坐标信息------------------------------------
	for (std::size_t i = 0; i < points.size(); ++i)
		std::cout << points[i].first << std::endl;

	return 0;

}

三、结果展示

0.175183 0.070269 -0.003253
0.234583 -0.001111 -0.39657
-0.110455 -0.178169 0.151965
0.058809 -0.206985 0.375651
-0.129126 0.050437 -0.192177
0.002745 0.18951 0.110554
-0.14196 0.217696 0.26906
-0.171035 0.078014 -0.296062
0.035744 -0.100524 0.501598
0.006477 0.08389 0.414722
0.14916 0.094349 0.37183
0.069491 0.149561 0.32208
-0.172832 -0.114168 0.232984
-0.00648 -0.15797 0.476349
-0.166571 0.125111 -0.100292
-0.006127 0.202885 -0.09991
0.119563 0.095019 0.38983
-0.021609 -0.223013 0.367699
0.199056 0.193772 0.195561
-0.039805 0.227673 -0.260155
0.146068 0.119123 -0.117735
0.066526 0.21461 -0.467774
-0.091801 -0.05396 -0.282808
0.177088 -0.010878 -0.417488
0.12899 0.122892 -0.393541
-0.03911 -0.233486 0.287357
0.099947 0.20789 0.255911
0.046513 0.085855 -0.431266
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
CGAL(Computational Geometry Algorithms Library)是一个用于计算几何学算法的开源库,而PCL(Point Cloud Library)是一个用于点云处理的开源库。要在CGAL读取PCL库中的点云数据,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了CGAL和PCL库,并且配置正确。 2. 在你的代码中引入CGAL和PCL的相关头文件。例如: ```cpp #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/point_generators_3.h> #include <CGAL/Polygon_mesh_processing/measure.h> #include <pcl/io/pcd_io.h> ``` 3. 使用PCL的点云读取函数加载点云数据。例如,使用`pcl::io::loadPCDFile`函数加载一个PCD文件: ```cpp pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::io::loadPCDFile("path/to/your/pointcloud.pcd", *cloud); ``` 这将把读取点云数据存储在`cloud`变量中。 4. 将PCL的点云数据转换为CGAL的点类型。CGAL使用自定义的点类型来表示点云数据。你需要将PCL的点云数据转换为CGAL的点类型以便进行进一步的计算。例如,假设你使用的是三维点云数据: ```cpp typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::Point_3 CGAL_Point; std::vector<CGAL_Point> cgal_points; for (const pcl::PointXYZ& pcl_point : cloud->points) { CGAL_Point cgal_point(pcl_point.x, pcl_point.y, pcl_point.z); cgal_points.push_back(cgal_point); } ``` 这将把PCL的点云数据转换为CGAL的点类型,并存储在`cgal_points`向量中。 现在你可以使用CGAL算法点云数据进行处理了。请注意,上述代码只是一个简单的示例,具体的实现可能因你的需求而有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

点云侠

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

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

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

打赏作者

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

抵扣说明:

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

余额充值