未执行spin()函数后的额外代码 我正在研究一个C++项目,需要把PCL和VTK结合起来。 但是,我在使用旋转函数更新场景时遇到了一个问题。 我知道spin函数在无限循环中调用spinOnce进行更新 pcl Visualizer中的场景。。 但是我正在做一个项目,在使用完之后我需要执行一些代码 自旋函数。 此代码可能类似于: void addBoundingBox() { // add vtkBoxWidget2 to the pcl visualizer. m_label = new BoundingBoxLabel(m_pclViewer, ia::annotalight::common::AnnnotationKinds::CAR); m_label->addLabel(*m_labelingService); m_pclViewer->spin(); // i need to execute this code to add the vtkBox to a QTreeWidget. setAllLabels(m_labelingService); initLabelsList(); }

未执行spin()函数后的额外代码 我正在研究一个C++项目,需要把PCL和VTK结合起来。 但是,我在使用旋转函数更新场景时遇到了一个问题。 我知道spin函数在无限循环中调用spinOnce进行更新 pcl Visualizer中的场景。。 但是我正在做一个项目,在使用完之后我需要执行一些代码 自旋函数。 此代码可能类似于: void addBoundingBox() { // add vtkBoxWidget2 to the pcl visualizer. m_label = new BoundingBoxLabel(m_pclViewer, ia::annotalight::common::AnnnotationKinds::CAR); m_label->addLabel(*m_labelingService); m_pclViewer->spin(); // i need to execute this code to add the vtkBox to a QTreeWidget. setAllLabels(m_labelingService); initLabelsList(); },c++,vtk,point-cloud-library,C++,Vtk,Point Cloud Library,tl;博士-没有别的办法了 正如您已经意识到的,PCLVisualizer::spin是一种阻塞方法。如果希望在不破坏窗口的情况下执行代码,则需要立即开始使用PCLVisualizer::spinOnce。如果希望保持场景刷新并处理输入事件,则需要将其保持在此类循环中 while (!viewer->wasStopped ()) { viewer->spinOnce (100); // (optional) boost::this_thread::sleep (boost::

tl;博士-没有别的办法了

正如您已经意识到的,PCLVisualizer::spin是一种阻塞方法。如果希望在不破坏窗口的情况下执行代码,则需要立即开始使用PCLVisualizer::spinOnce。如果希望保持场景刷新并处理输入事件,则需要将其保持在此类循环中

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

您添加或修改的所有内容都需要在该循环内部或该线程外部完成。只需确保在spinOnce运行时避免修改渲染窗口的内容。

听起来您已经发现了问题?也许您可以考虑添加另一个线程,或者可能在无限循环之前运行代码?感谢您的快速回复,我正在尝试使用另一个线程,但我希望这将是另一种方法。