Go to the documentation of this file.00001 #include "cloud_visualizer.h"
00002 #include <ros/ros.h>
00003
00004 namespace rc
00005 {
00006
00007 CloudVisualizer::CloudVisualizer(const char* name) : viewer_(new visualizer_t(name))
00008 {
00009 viewer_->setBackgroundColor(0.2, 0.2, 0.2);
00010 viewer_->addCoordinateSystem(0.1);
00011 viewer_->initCameraParameters();
00012 viewer_->setCameraPosition(-1,0,0,
00013 0,0,0,
00014 0,0,1);
00015 }
00016
00017 void CloudVisualizer::stop(){ stop_ = true; }
00018
00019 void CloudVisualizer::operator()()
00020 {
00021 while(!viewer_->wasStopped() && ros::ok())
00022 {
00023 boost::this_thread::sleep(boost::posix_time::microseconds(100000));
00024 if(!ros::ok()) break;
00025 boost::mutex::scoped_lock guard(viewer_mutex_);
00026 viewer_->spinOnce();
00027 }
00028 }
00029
00030 void CloudVisualizer::addCloudToViewer(const pointcloud_t::Ptr pointcloud)
00031 {
00032 boost::mutex::scoped_lock guard(viewer_mutex_);
00033 viewer_->removeAllPointClouds();
00034 pcl::visualization::PointCloudColorHandlerRGBField<point_t> rgb(pointcloud);
00035 viewer_->addPointCloud<point_t>(pointcloud, rgb);
00036 viewer_->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3);
00037 }
00038
00039 void CloudVisualizer::updateCloudInViewer(const pointcloud_t::Ptr pointcloud)
00040 {
00041 boost::mutex::scoped_lock guard(viewer_mutex_);
00042 pcl::visualization::PointCloudColorHandlerRGBField<point_t> rgb(pointcloud);
00043 viewer_->updatePointCloud<point_t>(pointcloud, rgb);
00044 }
00045
00046 }
00047