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 <sensor_msgs/PointCloud2.h>
00050 #include <pcl/conversions.h>
00051 
00052 #include <pcl_conversions/pcl_conversions.h>
00053 
00054 namespace pcl_ros 
00055 {
00056   class BasePublisher
00057   {
00058     public:
00059       void 
00060         advertise (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00061       {
00062         pub_ = nh.advertise<sensor_msgs::PointCloud2>(topic, queue_size);
00063       }
00064 
00065       std::string 
00066         getTopic ()
00067       {
00068         return (pub_.getTopic ());
00069       }
00070 
00071       uint32_t 
00072         getNumSubscribers () const
00073       {
00074         return (pub_.getNumSubscribers ());
00075       }
00076 
00077       void 
00078         shutdown ()
00079       {
00080         pub_.shutdown ();
00081       }
00082 
00083       operator void*() const
00084       {
00085         return (pub_) ? (void*)1 : (void*)0; 
00086       }
00087 
00088     protected:
00089       ros::Publisher pub_;
00090   };
00091 
00092   template <typename PointT>
00093   class Publisher : public BasePublisher
00094   {
00095     public:
00096       Publisher () {}
00097 
00098       Publisher (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00099       {
00100         advertise (nh, topic, queue_size);
00101       }
00102 
00103       ~Publisher () {}
00104 
00105       inline void 
00106         publish (const boost::shared_ptr<const pcl::PointCloud<PointT> > &point_cloud) const
00107       {
00108         publish (*point_cloud);
00109       }
00110 
00111       inline void 
00112         publish (const pcl::PointCloud<PointT>& point_cloud) const
00113       {
00114         // Fill point cloud binary data
00115         sensor_msgs::PointCloud2 msg;
00116         pcl::toROSMsg (point_cloud, msg);
00117         pub_.publish (boost::make_shared<const sensor_msgs::PointCloud2> (msg));
00118       }
00119   };
00120 
00121   template <>
00122   class Publisher<sensor_msgs::PointCloud2> : public BasePublisher
00123   {
00124     public:
00125       Publisher () {}
00126 
00127       Publisher (ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size)
00128       {
00129         advertise (nh, topic, queue_size);
00130       }
00131 
00132       ~Publisher () {}
00133 
00134       void 
00135         publish (const sensor_msgs::PointCloud2Ptr& point_cloud) const
00136       {
00137         pub_.publish (point_cloud);
00138         //pub_.publish (*point_cloud);
00139       }
00140 
00141       void 
00142         publish (const sensor_msgs::PointCloud2& point_cloud) const
00143       {
00144         pub_.publish (boost::make_shared<const sensor_msgs::PointCloud2> (point_cloud));
00145         //pub_.publish (point_cloud);
00146       }
00147   };
00148 }
00149 #endif  //#ifndef PCL_ROS_PUBLISHER_H_


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Thu May 5 2016 04:16:43