一、概述
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