open3d 中点云按id信息染色,并保存到pcd文件
#include<iostream>
#include<open3d/Open3D.h>
using namespace std;
int main()
{
auto cloud = std::make_shared<open3d::geometry::PointCloud>();
if (open3d::io::ReadPointCloud("E://data//b9.pcd", *cloud) == 0)
{
open3d::utility::LogInfo("点云读取失败!!!");
return -1;
}
double maxID = cloud->points_.size();
double minID = 0.0;
cout << "最大值为:: " << maxID << ",最小值为: " << minID << endl;
cloud->colors_.resize(cloud->points_.size());
open3d::visualization::ColorMapJet colormap;
for (size_t i = 0; i < cloud->points_.size(); ++i)
{
double normID = (i - minID) / (maxID - minID);
cloud->colors_[i] = colormap.GetColor(normID);
}
open3d::io::WritePointCloudToPCD("RenderByIndinces.pcd", *cloud, false);
open3d::visualization::DrawGeometries({ cloud }, u8"点云按ID赋色", 800, 600);
return 0;
}