difference_segmentation.cpp
Go to the documentation of this file.
00001 
00064 //##################
00065 //#### includes ####
00066 
00067 // ROS includes
00068 //#include <ros/ros.h>
00069 #include <ros/console.h>
00070 //#include <pcl/io/pcd_io.h>
00071 //#include <pcl/point_types.h>
00072 
00073 #include <nodelet/nodelet.h>
00074 #include <pcl_ros/point_cloud.h>
00075 #include <pcl/io/io.h>
00076 #include <pluginlib/class_list_macros.h>
00077 #include <pcl_conversions/pcl_conversions.h>
00078 
00079 #include <message_filters/subscriber.h>
00080 #include <message_filters/synchronizer.h>
00081 #include <message_filters/sync_policies/exact_time.h>
00082 //#include <message_filters/sync_policies/approximate_time.h>
00083 #include <pcl/segmentation/segment_differences.h>
00084 #include <pcl/kdtree/kdtree_flann.h>
00085 #include <pcl/conversions.h>
00086 
00087 
00091 class DifferenceSegmentation : public nodelet::Nodelet//, protected Reconfigurable_Node<cob_3d_mapping_point_map::point_map_nodeletConfig>
00092 {
00093   typedef pcl::PointXYZRGB Point;
00094   typedef pcl::PointCloud<Point> PointCloud;
00095   typedef message_filters::sync_policies::ExactTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2 > MySyncPolicy;
00096 
00097 public:
00098   // Constructor
00099   DifferenceSegmentation()
00100   {
00101   }
00102 
00103   // Destructor
00104   ~DifferenceSegmentation()
00105   {
00107   }
00108 
00116   void
00117   onInit()
00118   {
00119     n_ = getNodeHandle();
00120 
00121     map_diff_pub_ = n_.advertise<PointCloud>("output",1);
00122     map_sub_.subscribe(n_,"target",10);
00123     pc_aligned_sub_.subscribe(n_,"input",10);
00124     sync_.reset(new message_filters::Synchronizer<MySyncPolicy>(MySyncPolicy(10), map_sub_, pc_aligned_sub_));
00125     sync_->registerCallback(boost::bind(&DifferenceSegmentation::pointCloudSubCallback, this, _1, _2));
00126 
00127     pcl::search::KdTree<Point>::Ptr tree (new pcl::search::KdTree<Point> ());
00128     sd_.setSearchMethod(tree);
00129     //TODO: set to a value derived from the map resolution
00130     sd_.setDistanceThreshold(0.01);
00131   }
00132 
00143   void
00144   pointCloudSubCallback(const sensor_msgs::PointCloud2::ConstPtr& map_msg, const sensor_msgs::PointCloud2::ConstPtr& pc_aligned_msg)
00145   {
00146     if(pc_aligned_msg->header.frame_id != map_msg->header.frame_id)
00147     {
00148       ROS_ERROR("Frame ID of incoming point cloud does not match map frame ID, aborting...");
00149       return;
00150     }
00151     PointCloud::Ptr pc_diff(new PointCloud);
00152     PointCloud::Ptr pc_aligned(new PointCloud);
00153     PointCloud::Ptr map(new PointCloud);
00154 
00155     pcl::PCLPointCloud2 pc_aligned2;
00156     pcl_conversions::toPCL(*pc_aligned_msg, pc_aligned2);
00157     pcl::fromPCLPointCloud2(pc_aligned2, *pc_aligned);
00158     pcl::PCLPointCloud2 map2;
00159     pcl_conversions::toPCL(*map_msg, map2);
00160     pcl::fromPCLPointCloud2(map2, *map);
00161 
00162     sd_.setTargetCloud(map_.makeShared());
00163     sd_.setInputCloud(pc_aligned);
00164     sd_.segment(*pc_diff);
00165     pc_diff->header = map->header;
00166     std::cout << pc_diff->size() << std::endl;
00167     if(pc_diff->size()>0)
00168     {
00169       map_diff_pub_.publish(pc_diff);
00170     }
00171     pcl::copyPointCloud(*map, map_);
00172   }
00173 
00174 protected:
00175   ros::NodeHandle n_;
00176   message_filters::Subscriber<sensor_msgs::PointCloud2 > map_sub_;
00177   message_filters::Subscriber<sensor_msgs::PointCloud2 > pc_aligned_sub_;
00178   ros::Publisher map_diff_pub_;         //publisher for map
00179   boost::shared_ptr<message_filters::Synchronizer<MySyncPolicy> > sync_;
00180 
00181   pcl::PointCloud<Point> map_;
00182   pcl::SegmentDifferences<Point> sd_;
00183 };
00184 
00185 PLUGINLIB_DECLARE_CLASS(cob_3d_mapping_point_map, DifferenceSegmentation, DifferenceSegmentation, nodelet::Nodelet)
00186 


cob_3d_mapping_point_map
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:02:48