C++ 使用 CGAL 插入点云并设置颜色
使用 CGAL 插入点云并设置颜色
以下代码示例展示了如何使用 CGAL 插入点云并设置颜色,实现点云可视化。
double indexa = 100000000;
double indexb = 100000000;
double indexa1 = 100000000;
double indexb1 = 100000000;
for (int j = 0; j < dis_centroid_LidarToPhoto.size(); j++)
{
for (int k = 0; k < dis_centroid_LidarToPhoto[j].size(); k++)
{
if (dis_centroid_LidarToPhoto[j][k] < indexa)
{
indexa = dis_centroid_LidarToPhoto[j][k];
indexb = k;
}
/*if (angle_LidarToPhoto[j][k] < indexa1)
{
indexa1 = angle_LidarToPhoto[j][k];
indexb1 = k;
}*/
}
/*if (indexb == indexb1)
{
planes[j].insert(planes[j].end(), planes1[indexb].begin(), planes1[indexb].end());
}*/
//planes[j].insert(planes[j].end(), planes1[indexb].begin(), planes1[indexb].end());
if (angle_LidarToPhoto[j][indexb] < 3.1416 / 20 || angle_LidarToPhoto[j][indexb]>3)
{
planes[j].insert(planes[j].end(), planes1[indexb].begin(), planes1[indexb].end());
}
indexa = 100000000;
indexb = 100000000;
}
std::vector<Point_set> pts_pipeishiyan;
pts_pipeishiyan.resize(planes.size());
for (int i = 0; i < planes.size(); i++)
{
for (int j = 0; j < planes[i].size(); j++)
{
pts_pipeishiyan[i].insert(planes[i][j]);
}
}
// 定义点类型
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
// 定义点集类型
typedef CGAL::Point_set_3<Point_3> Point_set;
// 创建新的点集
Point_set pts_pipeishiyan;
// 将点插入点集
for (int i = 0; i < planes.size(); i++)
{
for (int j = 0; j < planes[i].size(); j++)
{
// 将点转换为 CGAL 点
Point_3 p(planes[i][j].x, planes[i][j].y, planes[i][j].z);
// 将点插入点集
pts_pipeishiyan.insert(p);
}
}
// 将点集颜色设置为红色
pts_pipeishiyan.color(CGAL::Color(255, 0, 0));
这段代码首先定义了点类型和点集类型,并创建了一个新的点集 pts_pipeishiyan。然后,它将点数据从 planes 数组中插入到点集。最后,它使用 pts_pipeishiyan.color() 方法将点集的颜色设置为红色。
这段代码展示了使用 CGAL 插入点云并设置颜色的基本步骤,您可以根据自己的需要修改代码以实现更复杂的功能。
原文地址: https://www.cveoy.top/t/topic/jXku 著作权归作者所有。请勿转载和采集!