c++ - 退出 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 安装)。
解决方案
我有点尴尬,但答案真的很简单……在尝试了 Flumenque 的解决方案后偶然发现了它……事实证明一切都按预期进行,我太简单了以至于无法意识到:
可以通过按键盘上的“q”来终止查看器。但是,您必须先在可视化区域内单击,即使窗口已经具有焦点!
以为我会写下来以防万一其他人与我的愚蠢相匹配... ;)
推荐阅读
- python - 从 AWS Lambda (Python) 连接到 IBM MQ(on-perm)
- python - Python,范围(),双循环,
- c++ - 将值作为参数传递时出现“类型名称不允许指定存储类”错误
- html - 我怎样才能让 Chrome 尊重“scroll-snap-stop:always”?
- c - 检查动态分配的二维数组中的相邻单元格
- javascript - 在后台表单字段中将数据传递给 post.php
- reactjs - @typeform/embed 打破 Gatsby Netlify 构建
- javascript - 如何附加 SVG
元素 - javascript - 打印数组javascript对象的数组
- python - 删除/编辑数据框中条目不符合条件的行