publisher.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: publisher.h 33238 2010-03-11 00:46:58Z rusu $
00035  *
00036  */
00045 #ifndef PCL_ROS_PUBLISHER_H_
00046 #define PCL_ROS_PUBLISHER_H_
00047 
00048 #include <ros/ros.h>
00049 #include "pcl/ros/conversions.h"
00050 
00051 namespace pcl_ros 
00052 {
00053   class BasePublisher
00054   {
00055     public:
00056       void 
00057         advertise (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00058       {
00059         pub_ = nh.advertise<sensor_msgs::PointCloud2>(topic, queue_size);
00060       }
00061 
00062       std::string 
00063         getTopic ()
00064       {
00065         return (pub_.getTopic ());
00066       }
00067 
00068       uint32_t 
00069         getNumSubscribers () const
00070       {
00071         return (pub_.getNumSubscribers ());
00072       }
00073 
00074       void 
00075         shutdown ()
00076       {
00077         pub_.shutdown ();
00078       }
00079 
00080       operator void*() const
00081       {
00082         return (pub_) ? (void*)1 : (void*)0; 
00083       }
00084 
00085     protected:
00086       ros::Publisher pub_;
00087   };
00088 
00089   template <typename PointT>
00090   class Publisher : public BasePublisher
00091   {
00092     public:
00093       Publisher () {}
00094 
00095       Publisher (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00096       {
00097         advertise (nh, topic, queue_size);
00098       }
00099 
00100       ~Publisher () {}
00101 
00102       inline void 
00103         publish (const boost::shared_ptr<const pcl::PointCloud<PointT> > &point_cloud) const
00104       {
00105         publish (*point_cloud);
00106       }
00107 
00108       inline void 
00109         publish (const pcl::PointCloud<PointT>& point_cloud) const
00110       {
00111         // Fill point cloud binary data
00112         sensor_msgs::PointCloud2 msg;
00113         pcl::toROSMsg (point_cloud, msg);
00114         pub_.publish (boost::make_shared<const sensor_msgs::PointCloud2> (msg));
00115       }
00116   };
00117 
00118   template <>
00119   class Publisher<sensor_msgs::PointCloud2> : public BasePublisher
00120   {
00121     public:
00122       Publisher () {}
00123 
00124       Publisher (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00125       {
00126         advertise (nh, topic, queue_size);
00127       }
00128 
00129       ~Publisher () {}
00130 
00131       void 
00132         publish (const sensor_msgs::PointCloud2Ptr& point_cloud) const
00133       {
00134         pub_.publish (point_cloud);
00135         //pub_.publish (*point_cloud);
00136       }
00137 
00138       void 
00139         publish (const sensor_msgs::PointCloud2& point_cloud) const
00140       {
00141         pub_.publish (boost::make_shared<const sensor_msgs::PointCloud2> (point_cloud));
00142         //pub_.publish (point_cloud);
00143       }
00144   };
00145 }
00146 #endif  //#ifndef PCL_ROS_PUBLISHER_H_


pcl_ros
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:22:23