C++代码优化:使用双层循环查找最小值并插入点云数据
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++)
{
// 设置点云颜色为红色
planes[i][j].r = 255;
planes[i][j].g = 0;
planes[i][j].b = 0;
pts_pipeishiyan[i].insert(planes[i][j]);
}
}
这段代码首先使用双层循环遍历二维数组 dis_centroid_LidarToPhoto,找出每一行的最小值及其索引。然后,根据 angle_LidarToPhoto 的值判断是否需要将对应索引的点云数据插入到 planes 中。最后,将插入的点云数据设置为红色,并将其复制到 pts_pipeishiyan 中。
该代码使用了 PCL 库进行点云操作。其中,Point_set 表示一个点云数据,它包含点的坐标和颜色信息。可以通过设置点的 RGB 值来改变点云的颜色。
代码中注释掉的代码块是可选的,可以根据实际需求进行修改。
希望以上内容能够帮助您理解代码并进行优化。
原文地址: https://www.cveoy.top/t/topic/jXdN 著作权归作者所有。请勿转载和采集!