PCLVisualizer within a ROS node does not respond
Dear all,
I want to visualize my pointcloud data and some objects within a ROS node. The node receives the data via a ROS Topic. The problem I have is how to integrate the viewer properly. In the main class I am using a member variable for the viewer and one thread which should update the view.
boost::shared_ptr<boost::thread> visualizer_thread_;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_;
In the constructor of my class (basically a segmentation class) I initialize the viewer and start the thread to do the update.
viewer_= boost::make_shared<pcl::visualization::PCLVisualizer>("Cylinder Viewer");
visualizer_thread_.reset(new boost::thread(boost::bind(&CylinderSegmentation::visualize,this)));
In the visualization thread I do basically an spin operation on the view
/** Visualizer Thread for the objects
*
*/
void visualize(){
ros::Rate r(40);
viewer_->setBackgroundColor(10.5,0.5,1.0);
viewer_->addCoordinateSystem(1.0);
while (!viewer_->wasStopped()){
viewer_->spinOnce();
r.sleep();
}
std::cout<<"Stopped the Viewer"<<std::endl;
}
When I close the viewer window, I receive the message "Stopped the Viewer" but the window does not close. I cannot even add something to the window to be shown. Is there something wrong I do about the usage of the PCLViewer?
Cheers,
Markus