dlut_dtbc.cpp
Go to the documentation of this file.
00001 /*************************************************************************
00002   > File Name: dlut_hash_icp.cpp
00003   > Author: 吴乃亮
00004   > Mail: wunailiang@gmail.com
00005   > Created Time: Wed 21 May 2014 10:13:53 AM CST
00006  ************************************************************************/
00007 
00008 #include "ros/ros.h"
00009 //用于打开pcd
00010 #include <pcl/filters/voxel_grid.h>
00011 #include <pcl/filters/filter.h>
00012 
00013 #include "src/icp.h"
00014 #include "boost/thread.hpp"
00015 #include <queue>
00016 #include "src/net_transfor.h"
00017 
00018 using namespace std;
00019 boost::mutex io_mutex;
00020 typedef boost::unordered_map<unordered_map_voxel,un_key> umap;
00021 
00022 void getdata(std::queue<pcl::PointCloud<pcl::PointXYZ> > *p_q)
00023 {
00024     Net_transfor n1(0);
00025 
00026     while(ros::ok())
00027     {
00028         pcl::PointCloud<pcl::PointXYZ> cloud_copy;
00029         cout <<"in thread\n";
00030         //cloud->clear();
00031         if(n1.receive(cloud_copy)==false)
00032             break;
00033 
00034         {
00035             boost::mutex::scoped_lock lock(io_mutex);
00036             p_q->push(cloud_copy);
00037         }
00038         cout <<"p_q.size="<<p_q->size()<<endl;
00039     }
00040     n1.close_receive();
00041     cout <<"exit thread\n";
00042 }
00043 
00044 int main(int argc,char** argv)
00045 {
00046     ros::init(argc,argv,"dlut_dtbc");
00047     ros::NodeHandle n;
00048     double voxel_size,filter_voxel_size;
00049     n.param("voxel_size",voxel_size,0.3);
00050     n.param("filter_voxel_size",filter_voxel_size,0.03);
00051 
00052     Voxelize* voxelize1;
00053     voxelize1 = new Voxelize;
00054     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
00055     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_local(new pcl::PointCloud<pcl::PointXYZ>);
00056     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_local_temp(new pcl::PointCloud<pcl::PointXYZ>);
00057     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_global(new pcl::PointCloud<pcl::PointXYZ>);
00058     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_global_raw(new pcl::PointCloud<pcl::PointXYZ>);
00059     std::queue<pcl::PointCloud<pcl::PointXYZ> > point_queue;
00060     boost::thread get_data(boost::bind(getdata,&point_queue));
00061     int marker = 0;
00062     int num_of_scan = 0;
00063     boost::unordered_map<unordered_map_voxel,un_key> m1;
00064     boost::unordered_map<unordered_map_voxel,un_key> m2;
00065     Eigen::Matrix4f tf_sum;
00066     tf_sum<<1,0,0,0,
00067         0,1,0,0,
00068         0,0,1,0,
00069         0,0,0,0;
00070     while(ros::ok())
00071     {
00072         if(point_queue.empty())
00073         {
00074             continue;
00075         }
00076         //live time
00077         {
00078             boost::mutex::scoped_lock lock(io_mutex);
00079             *cloud = point_queue.front();
00080             point_queue.pop();
00081         }
00082 
00083         if(marker==0)
00084         {
00085             marker=1;
00086 
00087             pcl::copyPointCloud(*cloud,*cloud_global);
00088             pcl::copyPointCloud(*cloud,*cloud_global_raw);
00089             swap(*cloud,*cloud_local);
00090             cloud->clear();
00091             voxelize1->generateUmap(*cloud_local,voxel_size,m2);
00092             continue;
00093         }
00094         *cloud_global_raw += *cloud;
00095         m1.clear();
00096 
00097         voxelize1->generateUmap(*cloud,voxel_size,m1);
00098         Icp icp(m1,m2,*cloud,voxel_size);
00099         Eigen::Matrix4f tf_mat;
00100         tf_mat = icp.icpFit();
00101         tf_sum+=tf_mat;
00102 
00103         num_of_scan++;
00104         pcl::transformPointCloud(*cloud,*cloud,tf_mat);
00105         *cloud_local_temp += *cloud;
00106         cloud_local->swap(*cloud_local_temp);
00107         cloud_local_temp->clear();
00108         m2.clear();
00109         voxelize1->generateUmap(*cloud_local,voxel_size,m2);
00110         *cloud_global += *cloud;
00111 
00112     }
00113 
00114     pcl::PCDWriter writer;
00115     if(cloud_global->size()!=0)
00116     {
00117         writer.write("global_map.pcd",*cloud_global);
00118         writer.write("global_map_raw.pcd",*cloud_global_raw);
00119     }
00120     delete voxelize1;
00121     return 0;
00122 }


dlut_hash_icp
Author(s): Zhuang Yan , Yan Fei, Wu Nai Liang
autogenerated on Thu Jun 6 2019 18:56:21