PointCloud Minimum Spanning Tree Visualization with Node Appearance Count and Highlighted Point
#include
// Find the point with maximum y value among the points that appear at least 3 times
int findMaxPoint(std::unordered_map<int, int>& pointCount, PointCloudT::Ptr cloud)
{
int maxPoint = -1;
int maxCount = 0;
for (const auto& pair : pointCount)
{
if (pair.second >= 3)
{
const auto& point = cloud->points[pair.first];
if (point.y > maxPoint)
{
maxPoint = point.y;
maxCount = pair.second;
}
}
}
return maxPoint;
}
};
...
int main()
{
...
// Perform Kruskal's algorithm to find the minimum spanning tree
std::vector
// Find the point with maximum y value among the points that appear at least 3 times
int maxPoint = graph.findMaxPoint(pointCount, cloud);
// Visualize the point cloud and color the point with maximum y value in green
pcl::visualization::PCLVisualizer viewer("Point Cloud Viewer");
viewer.setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 255, 255, 255);
viewer.addPointCloud<pcl::PointXYZ>(cloud, single_color, "cloud");
// Color the point with maximum y value in green
for (int i = 0; i < cloud->size(); ++i)
{
if (cloud->points[i].y == maxPoint)
{
cloud->points[i].r = 0;
cloud->points[i].g = 255;
cloud->points[i].b = 0;
}
}
// Update the point cloud in the viewer
viewer.updatePointCloud<pcl::PointXYZ>(cloud, single_color, "cloud");
viewer.spin();
...
}
原文地址: https://www.cveoy.top/t/topic/pQ0t 著作权归作者所有。请勿转载和采集!