尝试对原始las文件的点进行修改的需求包括点云着色、点云分类等,参考官网的例程发现,点云着色和点云简单分类都是需要新建一个las文件,对原始文件的点进行修改后写入到新文件中:
例如,官网中点云简单分类示例代码中的点云遍历部分:(lasexample_simple_classification.cpp)
// loop over the points
while (lasreader->read_point())
{
xpos = I32_FLOOR((lasreader->point.get_x() - lasreader->header.min_x)/step);
ypos = I32_FLOOR((lasreader->point.get_y() - lasreader->header.min_y)/step);
pos = ypos*xdim + xpos;
if (grid_minz[pos] < R)
{
lasreader->point.set_classification(8);
count++;
}
laswriter->write_point(&lasreader->point);
laswriter->update_inventory(&lasreader->point);
}
例如,官网中点云着色示例代码中的点云遍历部分:(lasexample_add_rgb.cpp)
// loop over points and modify them
// where there is a point to read
while (lasreader->read_point())
{
// copy the point
point = lasreader->point;
// change RGB
point.rgb[0] = point.rgb[1] = point.rgb[2] = U16_QUANTIZE(((point.get_z() - header.min_z)*65535.0)/(header.max_z - header.min_z));
if (lasreader->point.get_classification() == 12) lasreader->point.set_classification(1);
// write the modified point
laswriter->write_point(&point);
}
感觉LASLib用不够爽快,不是全部开源,PDAL貌似一直在更新,下一步尝试一下PDAL,希望能像GDAL一样开源。