PCL viewer is blank until interacted with/Camera position bug

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PCL viewer is blank until interacted with/Camera position bug

llee
I'm currently trying to automate rendering a point cloud, setting the camera position, and taking a screenshot.

Using the code from http://pointclouds.org/documentation/tutorials/pcl_visualizer.php#pcl-visualizer, I created a viewer object, then called the set camera position method. However, when the viewer window actually appears, it remains black until I interact with it in some way (dragging the mouse around). Therefore, when I remove the while loop that keeps the window active and then call saveScreenshot, the screenshot is all black with just the FPS in the bottom left corner. Is there any way to make the window render without the user having to interact with it?

Additionally, the camera position and angle that I'm setting never seems to be consistent between runs. I'm using the same point cloud each time, but whenever I set the camera position the displayed point cloud always seems to have shifted a bit so that I need to manually readjust the camera again before I take the screenshot. Any advice? Relevant code below:

boost::shared_ptr<pcl::visualization::PCLVisualizer> pcd::pcdVisualizer::simpleVis (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
    viewer->setBackgroundColor (0, 0, 0);
    viewer->addPointCloud<pcl::PointXYZ> (cloud, "sample cloud");
    viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
    viewer->addCoordinateSystem (1.0);
    viewer->initCameraParameters ();
    return (viewer);
}

outputCloud->width = (int) outputCloud->points.size();
    outputCloud->height = 1;
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = simpleVis(outputCloud);
    std::string outName = generateOutputName("cross");
    viewer->setCameraPosition(3283.64, 4997.91, 2367.14, 0, -.3, 1);
    while (!viewer->wasStopped()) {
        viewer->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }
    viewer->saveScreenshot(outName);