一、 Open3D中根据点云的高程度信息为点云中的每个点附上颜色,并保存颜色渲染结果!
#include<iostream>
#include<open3d/Open3D.h>
using namespace std;
int main()
{
//-------------------------------读取点云---------------------------------
auto cloud = std::make_shared<open3d::geometry::PointCloud>();
if (open3d::io::ReadPointCloud("hand.pcd", *cloud) == 0)
{
open3d::utility::LogInfo("点云读取失败!!!");
return -1;
}
// ---------------------------计算高程取值范围----------------------------
double maxZvalue = cloud->GetMaxBound()[2];
double minZvalue = cloud->GetMinBound()[2];
cout << "最大值为:: " << maxZvalue << ",最小值为: " << minZvalue << endl;
// ----------------------根据高程对点云进行颜色渲染-----------------------
cloud->colors_.resize(cloud->points_.size());
open3d::visualization::ColorMapJet colormap;
for (size_t i = 0; i < cloud->points_.size(); ++i)
{
// 高程归一化
double normZvalue = (cloud->points_[i][2] - minZvalue) / (maxZvalue - minZvalue);
cloud->colors_[i] = colormap.GetColor(normZvalue); // 颜色渲染
}
open3d::io::WritePointCloudToPCD("Elevation.pcd", *cloud, false);
// ------------------------------结果可视化------------------------------
open3d::visualization::DrawGeometries({ cloud }, u8"点云按高程赋色", 800, 600);
return 0;
}
二、测试结果为: