Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <strstream>
00008 #include "ros/ros.h"
00009
00010 #include <pcl/filters/voxel_grid.h>
00011 #include <pcl/filters/filter.h>
00012
00013 #include "src/icp.h"
00014 #include "src/net_transfor.h"
00015 #include "boost/thread.hpp"
00016 #include <queue>
00017
00018 using namespace std;
00019 boost::mutex io_mutex;
00020 typedef boost::unordered_map<unordered_map_voxel,un_key> umap;
00021 std::queue<pcl::PointCloud<pcl::PointXYZ> > point_queue;
00022 pcl::PCDWriter writer;
00023
00024 void pointCloud2Callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
00025 {
00026 cout<<"into callback"<<endl;
00027 static int i = 0;
00028 std::string temp_filename;
00029 strstream ss;
00030 ss << i;
00031 ss >> temp_filename;
00032 temp_filename+=".pcd";
00033 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_robot(new pcl::PointCloud<pcl::PointXYZ>);
00034 pcl::fromROSMsg(*msg,*cloud_robot);
00035 writer.write(temp_filename, *cloud_robot);
00036 {
00037 boost::mutex::scoped_lock lock(io_mutex);
00038 point_queue.push(*cloud_robot);
00039 }
00040 i++;
00041 }
00042
00043 void get_data()
00044 {
00045 Voxelize* voxelize1 = new Voxelize;
00046 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
00047 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_local(new pcl::PointCloud<pcl::PointXYZ>);
00048 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_local_temp(new pcl::PointCloud<pcl::PointXYZ>);
00049 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_global(new pcl::PointCloud<pcl::PointXYZ>);
00050 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_global_raw(new pcl::PointCloud<pcl::PointXYZ>);
00051
00052 int marker = 0;
00053 int num_of_scan = 0;
00054 boost::unordered_map<unordered_map_voxel,un_key> m1;
00055 boost::unordered_map<unordered_map_voxel,un_key> m2;
00056 Eigen::Matrix4f tf_sum;
00057 tf_sum<<1,0,0,0,
00058 0,1,0,0,
00059 0,0,1,0,
00060 0,0,0,0;
00061 while(ros::ok())
00062 {
00063 if(point_queue.empty())
00064 {
00065 continue;
00066 }
00067
00068 {
00069 boost::mutex::scoped_lock lock(io_mutex);
00070 *cloud = point_queue.front();
00071 point_queue.pop();
00072 }
00073
00074 if(marker==0)
00075 {
00076 marker=1;
00077
00078 pcl::copyPointCloud(*cloud,*cloud_global);
00079 pcl::copyPointCloud(*cloud,*cloud_global_raw);
00080 swap(*cloud,*cloud_local);
00081 cloud->clear();
00082 voxelize1->generateUmap(*cloud_local,0.3,m2);
00083 continue;
00084 }
00085 *cloud_global_raw += *cloud;
00086 m1.clear();
00087
00088 voxelize1->generateUmap(*cloud,0.3,m1);
00089 Icp icp(m1,m2,*cloud,0);
00090 Eigen::Matrix4f tf_mat;
00091 tf_mat = icp.icpFit();
00092 tf_sum+=tf_mat;
00093 num_of_scan++;
00094 pcl::transformPointCloud(*cloud,*cloud,tf_mat);
00095 *cloud_local_temp += *cloud;
00096
00097 cloud_local->swap(*cloud_local_temp);
00098 cloud_local_temp->clear();
00099 m2.clear();
00100 voxelize1->generateUmap(*cloud_local,0.3,m2);
00101 *cloud_global += *cloud;
00102
00103 }
00104
00105 pcl::PCDWriter writer;
00106 if(cloud_global->size()!=0)
00107 {
00108 writer.write("global_map.pcd",*cloud_global);
00109 writer.write("global_map_raw.pcd",*cloud_global_raw);
00110 }
00111 delete voxelize1;
00112 }
00113
00114
00115 int main(int argc,char** argv)
00116 {
00117 ros::init(argc,argv,"dlut_align");
00118 ros::NodeHandle n;
00119 ros::Subscriber sub;
00120 sub = n.subscribe("hokuyo_point_cloud2", 10, pointCloud2Callback);
00121
00122 boost::thread getdata(&get_data);
00123
00124 ros::spin();
00125 sleep(4);
00126 cout << "hello icp" <<endl;
00127 return 0;
00128 }