point_cloud_aggregator.cpp
Go to the documentation of this file.
00001 
00002 #include <ros/ros.h>
00003 #include <pluginlib/class_list_macros.h>
00004 #include <nodelet/nodelet.h>
00005 
00006 #include <pcl/point_cloud.h>
00007 #include <pcl/point_types.h>
00008 #include <pcl_conversions/pcl_conversions.h>
00009 
00010 #include <tf/transform_listener.h>
00011 
00012 #include <sensor_msgs/PointCloud2.h>
00013 
00014 #include <image_transport/image_transport.h>
00015 #include <image_transport/subscriber_filter.h>
00016 
00017 #include <message_filters/sync_policies/approximate_time.h>
00018 #include <message_filters/subscriber.h>
00019 #include <message_filters/sync_policies/approximate_time.h>
00020 
00021 #include <rtabmap_ros/MsgConversion.h>
00022 
00023 namespace rtabmap_ros
00024 {
00025 
00026 class PointCloudAggregator : public nodelet::Nodelet
00027 {
00028 public:
00029         PointCloudAggregator() : sync(NULL)
00030         {}
00031 
00032         virtual ~PointCloudAggregator()
00033         {
00034             if (sync!=NULL) delete sync;
00035         }
00036 
00037 private:
00038         void clouds_callback(const sensor_msgs::PointCloud2ConstPtr & cloudMsg_1,
00039                              const sensor_msgs::PointCloud2ConstPtr & cloudMsg_2,
00040                              const sensor_msgs::PointCloud2ConstPtr & cloudMsg_3)
00041         {
00042                 if(cloudPub_.getNumSubscribers())
00043                 {
00044                         pcl::fromROSMsg(*cloudMsg_1, cloud1);
00045                         pcl::fromROSMsg(*cloudMsg_2, cloud2);
00046                         pcl::fromROSMsg(*cloudMsg_3, cloud3);
00047                     pcl::PointCloud<pcl::PointXYZ> totalCloud;
00048                     totalCloud = cloud1 + cloud2;
00049                     totalCloud += cloud3;
00050                     sensor_msgs::PointCloud2 rosCloud;
00051                     pcl::toROSMsg(totalCloud, rosCloud);
00052                     rosCloud.header.stamp = cloudMsg_1->header.stamp;
00053                     rosCloud.header.frame_id = cloudMsg_1->header.frame_id;
00054                     cloudPub_.publish(rosCloud);
00055                 }
00056         }
00057 
00058     typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> MySyncPolicy;
00059         virtual void onInit()
00060         {
00061                 ros::NodeHandle & nh = getNodeHandle();
00062                 ros::NodeHandle & pnh = getPrivateNodeHandle();
00063 
00064                 int queueSize = 5;
00065                 pnh.param("queue_size", queueSize, queueSize);
00066 
00067                 cloudSub_1_.subscribe(nh, "cloud1", 1);
00068                 cloudSub_2_.subscribe(nh, "cloud2", 1);
00069                 cloudSub_3_.subscribe(nh, "cloud3", 1);
00070 
00071         sync = new message_filters::Synchronizer<MySyncPolicy>(MySyncPolicy(queueSize), cloudSub_1_, cloudSub_2_, cloudSub_3_);
00072         sync->registerCallback(boost::bind(&rtabmap_ros::PointCloudAggregator::clouds_callback, this, _1, _2, _3));
00073 
00074                 cloudPub_ = nh.advertise<sensor_msgs::PointCloud2>("combined_cloud", 1);
00075         }
00076 
00077     message_filters::Synchronizer<MySyncPolicy>* sync;
00078         message_filters::Subscriber<sensor_msgs::PointCloud2> cloudSub_1_;
00079         message_filters::Subscriber<sensor_msgs::PointCloud2> cloudSub_2_;
00080         message_filters::Subscriber<sensor_msgs::PointCloud2> cloudSub_3_;
00081         pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2, cloud3;
00082 
00083         ros::Publisher cloudPub_;
00084 };
00085 
00086 PLUGINLIB_EXPORT_CLASS(rtabmap_ros::PointCloudAggregator, nodelet::Nodelet);
00087 }
00088 


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Sun Jul 24 2016 03:49:08