test_ndt_histogram.cc
Go to the documentation of this file.
00001 #include <ndt_map/ndt_histogram.h>
00002 //#include <ndt_map/oc_tree.h>
00003 #include <ndt_map/pointcloud_utils.h>
00004 #include <ndt_map/lazy_grid.h>
00005 
00006 #include "pcl/point_cloud.h"
00007 #include "sensor_msgs/PointCloud2.h"
00008 #include "pcl/io/pcd_io.h"
00009 #include "pcl/features/feature.h"
00010 #include <cstdio>
00011 
00012 #include <fstream>
00013 
00014 //#define FULLTESTER
00015 
00016 using namespace std;
00017 
00018 int main (int argc, char** argv) {
00019 
00020     if(argc!=3){
00021         cout<<"usage: histTest point_cloud1 point_cloud2\n";
00022         return(-1);
00023     }
00024     pcl::PointCloud<pcl::PointXYZ> cloud, cloud2, cloud3;
00025     pcl::PointCloud<pcl::PointXYZI> outCloud;
00026 
00027     // lslgeneric::OctTree<pcl::PointXYZ> tr;
00028     // tr.BIG_CELL_SIZE = 2;
00029     // tr.SMALL_CELL_SIZE = 0.2;
00030     lslgeneric::LazyGrid tr(0.5);
00031 
00032 #ifdef FULLTESTER
00033     // std::string fname_str = argv[1];
00034     // int nclouds = atoi(argv[2]);
00035     // //lslgeneric::AdaptiveOctTree::MIN_CELL_SIZE = 0.01;
00036 
00037     // ofstream logger ("similarity.m");
00038     // logger<< "S = [";
00039     // struct timeval tv_start, tv_end;
00040     // gettimeofday(&tv_start,NULL);
00041     // lslgeneric::NDTHistogram *array  = new lslgeneric::NDTHistogram[nclouds];
00042     // for(int i=0; i<nclouds; i++){
00043     //     char cloudname [500];
00044         
00045     //     lslgeneric::NDTMap nd(&tr);
00046     //     nd.loadPointCloud(cloud);
00047     //     nd.computeNDTCells();
00048     //     array[i] = lslgeneric::NDTHistogram(nd);
00049     // }
00050     // gettimeofday(&tv_end,NULL);
00051     // double avg_build = (tv_end.tv_sec-tv_start.tv_sec)*1000.+(tv_end.tv_usec-tv_start.tv_usec)/1000.;
00052     // avg_build = avg_build/nclouds;
00053     // cout<<"building histograms took "<<avg_build<<" msec per scan\n";
00054 
00055     // gettimeofday(&tv_start,NULL);
00056     // for(int i=0; i<nclouds; i++)
00057     // {
00058     //     for(int j=0; j<nclouds; j++)
00059     //     {
00060     //         logger<<array[j].getSimilarity(array[i])<<" ";
00061     //     }
00062     //     logger<<";\n";
00063     //     cout<<" I "<<i<<endl;
00064     // }
00065 
00066     // gettimeofday(&tv_end,NULL);
00067     // double avg_match = (tv_end.tv_sec-tv_start.tv_sec)*1000.+(tv_end.tv_usec-tv_start.tv_usec)/1000.;
00068     // avg_match = avg_match/(nclouds*nclouds);
00069     // cout<<"matching histograms took "<<avg_match<<" msec per scan\n";
00070 
00071     // logger<<"];\n";
00072 #else
00073 
00074     pcl::io::loadPCDFile<pcl::PointXYZ> (argv[1], cloud);
00075     pcl::io::loadPCDFile<pcl::PointXYZ> (argv[2], cloud2);
00076     //lslgeneric::NDTMap nd(new lslgeneric::LazzyGrid(5));
00077     lslgeneric::NDTMap nd(&tr);
00078     nd.loadPointCloud(cloud);
00079     //lslgeneric::NDTMap nd2(new lslgeneric::LazzyGrid(5));
00080     lslgeneric::NDTMap nd2(&tr);
00081     nd2.loadPointCloud(cloud2);
00082 
00083     nd.computeNDTCells();
00084     nd2.computeNDTCells();
00085 
00086     lslgeneric::NDTHistogram nh(nd);
00087     lslgeneric::NDTHistogram nh2(nd2);
00088     cout<<"1 =========== \n";
00089     nh.printHistogram(true);
00090     cout<<"2 =========== \n";
00091     nh2.printHistogram(true);
00092 
00093     Eigen::Transform<double,3,Eigen::Affine,Eigen::ColMajor> T;
00094 
00095     nh2.bestFitToHistogram(nh,T,true);
00096     cout<<" ==================== \n Transform R "<<T.rotation()<<"\nt "<<T.translation().transpose()<<endl;
00097 
00098     cout<<"scan similarity is "<<nh2.getSimilarity(nh)<<endl;
00099     cloud3 = lslgeneric::transformPointCloud(T,cloud2);
00100     //lslgeneric::NDTMap nd3(new lslgeneric::LazzyGrid(5));
00101     lslgeneric::NDTMap nd3(&tr);
00102     nd3.loadPointCloud(cloud3);
00103     nd3.computeNDTCells();
00104 
00105     lslgeneric::NDTHistogram nh3(nd3);
00106     cout<<"3 =========== \n";
00107     nh3.printHistogram(true);
00108 
00109 
00110     char fname[50];
00111   
00112     std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> > directions = nh.directions;
00113     cout<<"direction = [";
00114     for(int i=0; i<directions.size(); i++)
00115     {
00116         cout<<directions[i].transpose()<<";";
00117     }
00118     cout<<"];\n";
00119 #endif
00120 
00121 
00122 
00123     return (0);
00124 }
00125 
00126 
00127 


ndt_map
Author(s): Todor Stoyanov, Jari Saarinen, Henrik Andreasson
autogenerated on Wed Aug 26 2015 15:24:41