test_ndt_mapper.cc
Go to the documentation of this file.
00001 #include <ndt_map_builder/ndt_map_builder.h>
00002 //#include <ndt_map/oc_tree.h>
00003 #include <ndt_registration/ndt_matcher_d2d.h>
00004 #include <ndt_map/pointcloud_utils.h>
00005 #include <pcl/io/pcd_io.h>
00006 
00007 using namespace std;
00008 using namespace lslgeneric;
00009 
00010 int main(int argc, char**argv)
00011 {
00012 
00013     if(argc != 7)
00014     {
00015         cout<<"Usage: "<<argv[0]<<" N_CLOUDS clouds_prefix (bKinect|bLaser) (doHistogram=0|1) (bD2D|bP2D|bICP) offset\n \
00016             \t bKinect -> use settings more suitable for a kinect\n \
00017             \t bLaser -> use settings more suitable for a kinect\n \
00018             \t bD2D . p2D ICP -> choice of registration algorithm\n";
00019         return -1;
00020     }
00021 
00022     bool bKinect = (strncmp(argv[3],"bKinect",7) == 0);
00023     bool doHistogram = (atoi(argv[4]) == 1);
00024     bool bICP = (strncmp(argv[5],"bICP",4) == 0);
00025     bool bP2D = (strncmp(argv[5],"bP2D",4) == 0);
00026     bool bD2D = ((strncmp(argv[5],"bD2D",4) == 0) || !(bICP || bP2D));
00027     int offset = atoi(argv[6]);
00028 
00029     //    lslgeneric::LazyGrid *histogramPrototype;
00030     std::vector<double> resolutions;
00031     double res;
00032 
00033     double __res1[] = {0.5, 1, 2};
00034     double __res2[] = {0.1,0.2,1,2,4};
00035     if(!bKinect){
00036         resolutions = std::vector<double>(__res1, __res1+sizeof(__res1)/sizeof(double));
00037         //histogramPrototype = new LazyGrid(2);
00038         res=2;
00039     }
00040     else{
00041         resolutions = std::vector<double>(__res2, __res2+sizeof(__res2)/sizeof(double));
00042         //  histogramPrototype=new LazyGrid(0.5);
00043         res=0.5;
00044     }
00045 
00046     lslgeneric::NDTMatcherD2D matcherF2F(false, false, resolutions);
00047     lslgeneric::NDTMatcherP2D matcherP2F(resolutions);
00048 
00049     NDTMapBuilder mapper(res,doHistogram);
00050     if(bD2D)
00051     {
00052         mapper.setMatcherF2F(&matcherF2F);
00053         cout<<"setting to D2D matcher\n";
00054     }
00055     else if(bP2D)
00056     {
00057         mapper.setMatcherP2F(&matcherP2F);
00058         cout<<"setting to P2D matcher\n";
00059     }
00060     // else
00061     // {
00062     //     mapper.setICP();
00063     //     cout<<"setting to ICP matcher\n";
00064     // }
00065 
00066     //mapper.tr = histogramPrototype;
00067 
00068     int N_CLOUDS = atoi(argv[1]);
00069     char fname[600];
00070 
00071     double MAX_DIST = 26;
00072 
00073     if(bKinect) MAX_DIST = 5;
00074 
00075     for (int i=offset; i<N_CLOUDS; i++)
00076     {
00077         snprintf(fname,600,"%s%03d.pcd",argv[2],i);
00078         pcl::PointCloud<pcl::PointXYZ> cl;
00079         pcl::io::loadPCDFile<pcl::PointXYZ> (fname, cl);
00080 
00081         pcl::PointCloud<pcl::PointXYZ> filtered;
00082         for(int q=0; q<cl.points.size(); q++)
00083         {
00084             double dist = sqrt(pow(cl.points[q].x,2)+pow(cl.points[q].y,2)+pow(cl.points[q].z,2));
00085             if(dist<MAX_DIST)
00086             {
00087                 if(!bKinect)
00088                 {
00089                     filtered.points.push_back(cl.points[q]);
00090                 }
00091                 else
00092                 {
00093                     pcl::PointXYZ pNew;
00094                     pNew.x = cl.points[q].z;
00095                     pNew.y = cl.points[q].x;
00096                     pNew.z = -cl.points[q].y;
00097                     filtered.points.push_back(pNew);
00098                 }
00099 
00100             }
00101         }
00102 
00103         cout<<"adding cloud number "<<i<<endl;
00104         mapper.addScan(filtered);
00105     }
00106 
00107     snprintf(fname,600,"%s.g2o",argv[2]);
00108     mapper.saveG2OlogFile(fname);
00109 
00110     snprintf(fname,600,"%s.dat",argv[2]);
00111     mapper.saveDatlogFile(fname);
00112 
00113     //    snprintf(fname,600,"%s_COMPLETE.wrl",argv[2]);
00114     // mapper.theMotherOfAllPointClouds(fname);
00115 
00116     return 0;
00117 }


ndt_map_builder
Author(s): Todor Stoyanov
autogenerated on Wed Aug 26 2015 15:25:12