首页 > 解决方案 > 退出 PCL 查看器:即使窗口关闭,wasStopped() 也不会改变值

问题描述

我一直在尝试根据PCL 网站上的本教程使用 PCL Visualizer,并使用以下方法来可视化点云:

boost::shared_ptr<pcl::visualization::PCLVisualizer> createViewer (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud, std::string& viewerName) 
{ 
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer (viewerName)); 

    viewer->setBackgroundColor (0, 0, 0); 
    viewer->addPointCloud<pcl::PointXYZ> (cloud, viewerName); 
    viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, viewerName); 
    viewer->addCoordinateSystem (1.0); 
    viewer->initCameraParameters (); 

    return viewer; 
} 

void visualizePointCloud (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud) 
{ 
    std::string viewerName = "3D Viewer: Cloud"; 

    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer; 
    viewer = createViewer(cloud, viewerName); 

    while (!viewer->wasStopped()) 
    { 
        viewer->spinOnce(100); 
        boost::this_thread::sleep (boost::posix_time::microseconds (100000)); 
    } 
} 

一切都很好,但我似乎无法摆脱循环!如果您通过单击“x”关闭查看器窗口,则没有任何反应,wasStopped()仍然返回false,并且程序卡住了。

有人知道如何正确终止查看器,以便程序可以继续执行其余代码吗?我只是愚蠢吗?提前谢谢了!

PS:我在 Mac OS 10.13.6 上使用 PCL 1.8.1(通过 Homebrew 安装)。

标签: c++visualizationpoint-cloud-library

解决方案


我有点尴尬,但答案真的很简单……在尝试了 Flumenque 的解决方案后偶然发现了它……事实证明一切都按预期进行,我太简单了以至于无法意识到:

可以通过按键盘上的“q”来终止查看器。但是,您必须先在可视化区域内单击,即使窗口已经具有焦点!

以为我会写下来以防万一其他人与我的愚蠢相匹配... ;)


推荐阅读