title: Point Cloud Library (PCL) wait/delay/sleep function in C++
body: <p>Is there a way I can make the PCL library wait for a while when visualizing point clouds? I have a series of point clouds and want to "animate" these in PCLVisualizer (by either updating a single point cloud or by showing+removing new point cloud in a loop).</p>
  
  <p>I am using C++ and have set up the <a href="http://pointclouds.org/documentation/tutorials/cloud_viewer.php" rel="nofollow">CloudViewer example</a>. So far I can only reach some degree of a delay by cross-compiling with OpenCV and using its waitKey(milliseconds) function. I am on Ubuntu 14.04 LTS. Made example work with OpenCV:</p>
  
  <pre><code>#include &lt;opencv2/opencv.hpp&gt;
  using namespace cv;
  </code></pre>
  
  <p>However the waitKey only works within a simple use in the very end of the viewerPsycho function where it really delays the counter in that function:</p>
  
  <pre><code>void viewerPsycho (pcl::visualization::PCLVisualizer&amp; viewer)
  {
      static unsigned count = 0;
      std::stringstream ss;
      ss &lt;&lt; "Once per viewer loop: " &lt;&lt; count++;
      viewer.removeShape ("text", 0);
      viewer.addText (ss.str(), 200, 300, "text", 0);
  
      // this will delay counter but shows nothing
      waitKey(1000);
      viewer.addPointCloud(point_cloud_ptr, "first");
      waitKey(1000);
      viewer.removePointCloud("first");
  }
  </code></pre>
  
  <p>My code is richer than the original example and the method addPointCloud works properly when not trying the delay. Method removePointCloud probably works too since nothing is displayed (waitKey ignored?).</p>
  
  <p>The waitKey also seems to be ignored in the viewerOneOff function when used same way with addPointCloud and removePointCloud like this (in the end of function):</p>
  
  <p>works (only shows):</p>
  
  <pre><code>viewer.addPointCloud(point_cloud_ptr, "first");
  </code></pre>
  
  <p>does not work (shows nothing):</p>
  
  <pre><code>viewer.addPointCloud(point_cloud_ptr, "first");
  waitKey(5000);
  viewer.removePointCloud("first");
  </code></pre>
  
  <p>My CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
  
  project(opencv_pcl)
  
  find_package(PCL 1.2 REQUIRED)
  find_package(OpenCV REQUIRED)
  
  include_directories(${PCL_INCLUDE_DIRS})
  include_directories(${OpenCV_INCLUDE_DIRS})
  link_directories(${PCL_LIBRARY_DIRS})
  add_definitions(${PCL_DEFINITIONS})
  
  add_executable (opencv_pcl opencv_pcl.cpp)    
  target_link_libraries (opencv_pcl ${PCL_LIBRARIES} ${OpenCV_LIBS})
  </code></pre>
  
  <p>I will appreciate any help.</p>