#include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace rtabmap_ros { class PointCloudAggregator : public nodelet::Nodelet { public: PointCloudAggregator() : sync(NULL) {} virtual ~PointCloudAggregator() { if (sync!=NULL) delete sync; } private: void clouds_callback(const sensor_msgs::PointCloud2ConstPtr & cloudMsg_1, const sensor_msgs::PointCloud2ConstPtr & cloudMsg_2, const sensor_msgs::PointCloud2ConstPtr & cloudMsg_3) { if(cloudPub_.getNumSubscribers()) { pcl::fromROSMsg(*cloudMsg_1, cloud1); pcl::fromROSMsg(*cloudMsg_2, cloud2); pcl::fromROSMsg(*cloudMsg_3, cloud3); pcl::PointCloud totalCloud; totalCloud = cloud1 + cloud2; totalCloud += cloud3; sensor_msgs::PointCloud2 rosCloud; pcl::toROSMsg(totalCloud, rosCloud); rosCloud.header.stamp = cloudMsg_1->header.stamp; rosCloud.header.frame_id = cloudMsg_1->header.frame_id; cloudPub_.publish(rosCloud); } } typedef message_filters::sync_policies::ApproximateTime MySyncPolicy; virtual void onInit() { ros::NodeHandle & nh = getNodeHandle(); ros::NodeHandle & pnh = getPrivateNodeHandle(); int queueSize = 5; pnh.param("queue_size", queueSize, queueSize); cloudSub_1_.subscribe(nh, "cloud1", 1); cloudSub_2_.subscribe(nh, "cloud2", 1); cloudSub_3_.subscribe(nh, "cloud3", 1); sync = new message_filters::Synchronizer(MySyncPolicy(queueSize), cloudSub_1_, cloudSub_2_, cloudSub_3_); sync->registerCallback(boost::bind(&rtabmap_ros::PointCloudAggregator::clouds_callback, this, _1, _2, _3)); cloudPub_ = nh.advertise("combined_cloud", 1); } message_filters::Synchronizer* sync; message_filters::Subscriber cloudSub_1_; message_filters::Subscriber cloudSub_2_; message_filters::Subscriber cloudSub_3_; pcl::PointCloud cloud1, cloud2, cloud3; ros::Publisher cloudPub_; }; PLUGINLIB_EXPORT_CLASS(rtabmap_ros::PointCloudAggregator, nodelet::Nodelet); }