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
00028 #include <ros/ros.h>
00029 #include <pcl_ros/transforms.h>
00030 #include <pcl/ros/conversions.h>
00031 #include <pcl/point_cloud.h>
00032 #include <pcl/point_types.h>
00033 #include <laser_geometry/laser_geometry.h>
00034 #include <sensor_msgs/PointCloud2.h>
00035 #include <sensor_msgs/LaserScan.h>
00036 #include <tf/transform_listener.h>
00037 #include <nav_msgs/Odometry.h>
00038
00039
00054 using namespace std;
00055 class pc_accumulation
00056 {
00057 public:
00058
00059 tf::TransformListener *p_listener;
00060 ros::NodeHandle* p_n;
00061 double voxel_size;
00062 std::string _acc_frame_id;
00063
00064 nav_msgs::Odometry odometry_;
00065 ros::Time time_msg;
00066
00067 sensor_msgs::PointCloud2 msg_cloud;
00068
00069 pcl::PointCloud<pcl::PointXYZRGB> pcl_pc_acc;
00070
00077 int pointcloud_accumulated(sensor_msgs::LaserScan& scan_in,std::string acc_frame_id)
00078 {
00079
00080 laser_geometry::LaserProjection projector_;
00081 pcl::PointCloud<pcl::PointXYZ> pc_tmp;
00082 pcl::PointCloud<pcl::PointXYZRGB> pc_laser;
00083 sensor_msgs::PointCloud2 poincloud_in;
00084
00085 projector_.transformLaserScanToPointCloud(scan_in.header.frame_id,scan_in,poincloud_in,*p_listener);
00086
00087
00088 pcl::fromROSMsg(poincloud_in,pc_tmp);
00089
00090
00091 pc_laser.points.resize(pc_tmp.size());
00092
00093 for (size_t i = 0; i < pc_laser.points.size(); i++)
00094 {
00095
00096 pc_laser.points[i].x = pc_tmp.points[i].x;
00097 pc_laser.points[i].y = pc_tmp.points[i].y;
00098 pc_laser.points[i].z = pc_tmp.points[i].z;
00099 pc_laser.points[i].r = 0.0;
00100 pc_laser.points[i].g = 0.0;
00101 pc_laser.points[i].b = 0.0;
00102 }
00103 pc_laser.header.frame_id = scan_in.header.frame_id;
00104 pc_laser.header.stamp = scan_in.header.stamp;
00105 return pointcloud_accumulated(pc_laser,acc_frame_id);
00106 };
00107
00114 int pointcloud_accumulated(sensor_msgs::PointCloud2& pc_in,std::string acc_frame_id)
00115 {
00116 pcl::PointCloud<pcl::PointXYZRGB> pcl_pc;
00117 for (size_t i=0; i <pc_in.fields.size();i++)
00118 {
00119 if (pc_in.fields[i].name=="rgb")
00120 {
00121 ROS_ERROR("TEM RGB");
00122
00123 pcl::fromROSMsg(pc_in,pcl_pc);
00124 }
00125 else
00126 {
00127
00128 pcl::PointCloud<pcl::PointXYZ> pcl_tmp;
00129 pcl::fromROSMsg(pc_in,pcl_tmp);
00130 pcl_pc.points.resize(pcl_tmp.size());
00131 for (size_t i = 0; i < pcl_pc.points.size(); i++)
00132 {
00133 pcl_pc.points[i].x = pcl_tmp.points[i].x;
00134 pcl_pc.points[i].y = pcl_tmp.points[i].y;
00135 pcl_pc.points[i].z = pcl_tmp.points[i].z;
00136 pcl_pc.points[i].r = 0.0;
00137 pcl_pc.points[i].g = 0.0;
00138 pcl_pc.points[i].b = 0.0;
00139 }
00140
00141 }
00142 }
00143 pcl_pc.header.frame_id=pc_in.header.frame_id;
00144 return pointcloud_accumulated(pcl_pc,acc_frame_id);
00145
00146 };
00147 int pointcloud_accumulated(pcl::PointCloud<pcl::PointXYZRGB> pcl_pc,std::string acc_frame_id);
00148
00149
00157 int remove_points_from_pointcloud(pcl::PointCloud<pcl::PointXYZRGB> pcl_pc,float dist,std::string frame_id)
00158 {
00159 tf::StampedTransform transform;
00160
00161 try
00162 {
00163 p_listener->lookupTransform(frame_id,_acc_frame_id , pcl_pc.header.stamp, transform);
00164 }
00165 catch (tf::TransformException ex)
00166 {
00167 ROS_ERROR("%s",ex.what());
00168 return 0;
00169 }
00170
00171 double X0 = transform.getOrigin().x();
00172 double Y0 = transform.getOrigin().y();
00173 double Z0 = transform.getOrigin().z();
00174
00175 return remove_points_from_pointcloud(pcl_pc,dist, X0, Y0, Z0);
00176 }
00177
00178 int remove_points_from_pointcloud(pcl::PointCloud<pcl::PointXYZRGB> pcl_pc,float dist, float X0, float Y0, float Z0);
00179
00180 private:
00181
00182 };