变量是:
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_k_upper std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_k_lower std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_underk_upper std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>> clusters_underk_lower# 变量填充
1. 直接使用(非函数)
// 创建一个 PCLVisualizer 对象
pcl::visualization::PCLVisualizer viewer("Point Cloud Visualization");
for (size_t i = 0; i < clusters_k_upper.size(); ++i) {
// 创建不同的颜色处理器
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler_k_upper(clusters_k_upper[i], 255, 0, 0); // 红色
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler_k_lower(clusters_k_lower[i], 0, 255, 0); // 绿色
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler_underk_upper(clusters_underk_upper[i], 0, 0, 255); // 蓝色
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_handler_underk_lower(clusters_underk_lower[i], 255, 255, 0); // 黄色
// 为每个点云生成唯一的ID
std::string id_k_upper = "upper k " + std::to_string(i);
std::string id_k_lower = "lower k " + std::to_string(i);
std::string id_underk_upper = "upper underk " + std::to_string(i);
std::string id_underk_lower = "lower underk " + std::to_string(i);
// 添加点云到可视化对象
viewer.addPointCloud<pcl::PointXYZRGB>(clusters_k_upper[i], color_handler_k_upper, id_k_upper);
viewer.addPointCloud<pcl::PointXYZRGB>(clusters_k_lower[i], color_handler_k_lower, id_k_lower);
viewer.addPointCloud<pcl::PointXYZRGB>(clusters_underk_upper[i], color_handler_underk_upper, id_underk_upper);
viewer.addPointCloud<pcl::PointXYZRGB>(clusters_underk_lower[i], color_handler_underk_lower, id_underk_lower);
// 可以选择设置点大小
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, id_k_upper);
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, id_k_lower);
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, id_underk_upper);
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, id_underk_lower);
}
// 设置视窗的背景颜色
viewer.setBackgroundColor(0, 0, 0);
// 循环直到视窗关闭
while (!viewer.wasStopped()) {
viewer.spinOnce();
}