Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00041
00042 #include <ros/ros.h>
00043
00044 #include <sensor_msgs/Image.h>
00045 #include <sensor_msgs/PointCloud2.h>
00046
00047 #include <pcl/io/pcd_io.h>
00048
00049 #include <pcl_conversions/pcl_conversions.h>
00050
00051 #include <string>
00052
00053 class PointCloudToImage
00054 {
00055 public:
00056 void
00057 cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud)
00058 {
00059 if (cloud->height <= 1)
00060 {
00061 ROS_ERROR("Input point cloud is not organized, ignoring!");
00062 return;
00063 }
00064 try
00065 {
00066 pcl::toROSMsg (*cloud, image_);
00067 image_.header = cloud->header;
00068 image_pub_.publish (image_);
00069 }
00070 catch (std::runtime_error &e)
00071 {
00072 ROS_ERROR_STREAM("Error in converting cloud to image message: "
00073 << e.what());
00074 }
00075 }
00076 PointCloudToImage () : cloud_topic_("input"),image_topic_("output")
00077 {
00078 sub_ = nh_.subscribe (cloud_topic_, 30,
00079 &PointCloudToImage::cloud_cb, this);
00080 image_pub_ = nh_.advertise<sensor_msgs::Image> (image_topic_, 30);
00081
00082
00083 std::string r_ct = nh_.resolveName (cloud_topic_);
00084 std::string r_it = nh_.resolveName (image_topic_);
00085 ROS_INFO_STREAM("Listening for incoming data on topic " << r_ct );
00086 ROS_INFO_STREAM("Publishing image on topic " << r_it );
00087 }
00088 private:
00089 ros::NodeHandle nh_;
00090 sensor_msgs::Image image_;
00091 std::string cloud_topic_;
00092 std::string image_topic_;
00093 ros::Subscriber sub_;
00094 ros::Publisher image_pub_;
00095 };
00096
00097 int
00098 main (int argc, char **argv)
00099 {
00100 ros::init (argc, argv, "convert_pointcloud_to_image");
00101 PointCloudToImage pci;
00102 ros::spin ();
00103 return 0;
00104 }