Search code examples
c++delaysleepwaitpoint-cloud-library

Point Cloud Library (PCL) wait/delay/sleep function in C++


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).

I am using C++ and have set up the CloudViewer example. 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:

#include <opencv2/opencv.hpp>
using namespace cv;

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:

void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << 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");
}

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?).

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):

works (only shows):

viewer.addPointCloud(point_cloud_ptr, "first");

does not work (shows nothing):

viewer.addPointCloud(point_cloud_ptr, "first");
waitKey(5000);
viewer.removePointCloud("first");

My CMakeLists.txt:

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})

I will appreciate any help.


Solution

  • Do you have a spin() or spinOnce() method anywhere in your code?

    viewer->spinOnce (100);
    

    This updates the renderer and processes all interactions (http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_p_c_l_visualizer.html#a896556f91ba6b45b12a9543a2b397193).