cloud_visualizer.cc
Go to the documentation of this file.
1 #include "cloud_visualizer.h"
2 #include <ros/ros.h>
3 
4 namespace rc
5 {
6 
7 CloudVisualizer::CloudVisualizer(const char* name) : viewer_(new visualizer_t(name))
8 {
9  viewer_->setBackgroundColor(0.2, 0.2, 0.2);//dark gray
10  viewer_->addCoordinateSystem(0.1);//make a small coordinate system where the world pose is
11  viewer_->initCameraParameters();
12  viewer_->setCameraPosition(-1,0,0, //1m behind the origin (x is the viewing direction).
13  0,0,0, //look towards the origin.
14  0,0,1); //Z is up
15 }
16 
17 void CloudVisualizer::stop(){ stop_ = true; }
18 
20 {
21  while(!viewer_->wasStopped() && ros::ok())
22  {
23  boost::this_thread::sleep(boost::posix_time::microseconds(100000));
24  if(!ros::ok()) break;
25  boost::mutex::scoped_lock guard(viewer_mutex_);
26  viewer_->spinOnce();
27  }
28 }
29 
30 void CloudVisualizer::addCloudToViewer(const pointcloud_t::Ptr pointcloud)
31 {
32  boost::mutex::scoped_lock guard(viewer_mutex_);
33  viewer_->removeAllPointClouds();
34  pcl::visualization::PointCloudColorHandlerRGBField<point_t> rgb(pointcloud);
35  viewer_->addPointCloud<point_t>(pointcloud, rgb);
36  viewer_->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3);
37 }
38 
39 void CloudVisualizer::updateCloudInViewer(const pointcloud_t::Ptr pointcloud)
40 {
41  boost::mutex::scoped_lock guard(viewer_mutex_);
42  pcl::visualization::PointCloudColorHandlerRGBField<point_t> rgb(pointcloud);
43  viewer_->updatePointCloud<point_t>(pointcloud, rgb);
44 }
45 
46 }//namespace rc
47 
pcl::visualization::PCLVisualizer visualizer_t
boost::mutex viewer_mutex_
CloudVisualizer(const char *name)
Creates the viewer object.
pcl::PointXYZRGB point_t
ROSCPP_DECL bool ok()
void operator()()
Viewer update loop, will be called when viewer thread is started.
void addCloudToViewer(const pointcloud_t::Ptr pointcloud)
Thread-safe addition/replacement of the cloud.
void updateCloudInViewer(const pointcloud_t::Ptr pointcloud)
Thread-safe update to the cloud.
visualizer_ptr_t viewer_
void stop()
Signal thread to stop the visualization loop.


rc_cloud_accumulator
Author(s): Felix Endres
autogenerated on Thu Jun 6 2019 20:08:45