ndtLikelihoodTester.cc
Go to the documentation of this file.
00001 #include <NDTMap.hh>
00002 #include <OctTree.hh>
00003 #include <AdaptiveOctTree.hh>
00004 #include <PointCloudUtils.hh>
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 <LazzyGrid.hh>
00013 
00014 #include <fstream>
00015 #include <sstream>
00016 
00017 using namespace std;
00018 
00019 static int ctr = 0;
00020 int
00021 main (int argc, char** argv)
00022 {
00023 
00024     if(argc!=4)
00025     {
00026         //cout<<"usage: likelihood_test full_point_cloud laser_point_cloud_name tof_pointcloud \n";
00027         cout<<"usage: ./likelihood_test [full_point_cloud] [path_to_save_data] [path_to_save_CSV]\n";
00028         return(-1);
00029     }
00030     pcl::PointCloud<pcl::PointXYZ> cloud;
00031     pcl::PointCloud<pcl::PointXYZ> laserCloud;
00032     pcl::PointCloud<pcl::PointXYZ> tofCloud;
00033     pcl::PointCloud<pcl::PointXYZI> outCloudLaser;
00034     pcl::PointCloud<pcl::PointXYZI> outCloudTOF;
00035 
00036     cloud = lslgeneric::readVRML(argv[1]);
00037     //laserCloud = lslgeneric::readVRML(argv[2]);
00038     //tofCloud = lslgeneric::readVRML(argv[3]);
00039     string path= argv[2];
00040     string ValidationData = argv[3];
00041     ofstream out;
00042     out.open (ValidationData.c_str());
00043     if (!out.is_open())
00044     {
00045         cout<<"file not open";
00046     }
00047 
00048     for (int k=0; k<10; k++)
00049     {
00050         char fname[100];
00051         snprintf(fname,99,"%s/SR4000_%d.wrl",path.c_str(),k);
00052         tofCloud = lslgeneric::readVRML(fname);
00053 
00054         snprintf(fname,99,"%s/LaserScanner_%d.wrl",path.c_str(),k);
00055         laserCloud = lslgeneric::readVRML(fname);
00056 
00057 
00058         //   lslgeneric::NDTMap nd(new lslgeneric::AdaptiveOctTree());
00059         lslgeneric::NDTMap nd(new lslgeneric::LazzyGrid(0.2));
00060         nd.loadPointCloud(cloud);
00061 
00062         nd.computeNDTCells();
00063         snprintf(fname,99,"%s/ndt_map.wrl",path.c_str());
00064         nd.writeToVRML(fname);
00065 
00066 
00067         double maxLikelihood = INT_MIN;
00068         double sumLikelihoods = 0;
00069 
00070         outCloudLaser.points.resize(laserCloud.points.size());
00071         outCloudTOF.points.resize(tofCloud.points.size());
00072 
00073         //loop through points and compute likelihoods LASER
00074         for(int i=0; i<laserCloud.points.size(); i++)
00075         {
00076             pcl::PointXYZ thisPt = laserCloud.points[i];
00077             double likelihood = nd.getLikelihoodForPointWithInterpolation(thisPt);
00078             //double likelihood = nd.getLikelihoodForPoint(thisPt);
00079             pcl::PointXYZI outPt;
00080             outPt.x = thisPt.x;
00081             outPt.y = thisPt.y;
00082             outPt.z = thisPt.z;
00083             outPt.intensity = likelihood;
00084             sumLikelihoods += likelihood;
00085             maxLikelihood = (likelihood > maxLikelihood) ?
00086                             likelihood : maxLikelihood;
00087             outCloudLaser.points[i] = outPt;
00088         }
00089         cout<<"LASER max likelihood "<<maxLikelihood<<endl;
00090         cout<<"LASER sum likelihoods "<<sumLikelihoods<<endl;
00091         cout<<"LASER average likelihood "<<sumLikelihoods/laserCloud.points.size()<<endl;
00092         out<<sumLikelihoods<<","<<sumLikelihoods/laserCloud.points.size()<<","<<maxLikelihood<<endl;
00093         //normalize for display
00094         //compute standart deviation
00095         for(int i=0; i<laserCloud.points.size(); i++)
00096         {
00097             outCloudLaser.points[i].intensity /= maxLikelihood;
00098 
00099         }
00100         snprintf(fname,99,"%s/likelihood_LASER_%d.wrl",path.c_str(),k);
00101         lslgeneric::writeToVRML(fname,outCloudLaser);
00102 
00103 
00104         maxLikelihood = INT_MIN;
00105         sumLikelihoods = 0;
00106         //loop through points and compute likelihoods TOF
00107         for(int i=0; i<tofCloud.points.size(); i++)
00108         {
00109             pcl::PointXYZ thisPt = tofCloud.points[i];
00110             double likelihood = nd.getLikelihoodForPointWithInterpolation(thisPt);
00111             //double likelihood = nd.getLikelihoodForPoint(thisPt);
00112             pcl::PointXYZI outPt;
00113             outPt.x = thisPt.x;
00114             outPt.y = thisPt.y;
00115             outPt.z = thisPt.z;
00116             outPt.intensity = likelihood;
00117             sumLikelihoods += likelihood;
00118             maxLikelihood = (likelihood > maxLikelihood) ?
00119                             likelihood : maxLikelihood;
00120             outCloudTOF.points[i] = outPt;
00121         }
00122         cout<<"TOF max likelihood "<<maxLikelihood<<endl;
00123         cout<<"TOF sum likelihoods "<<sumLikelihoods<<endl;
00124         cout<<"TOF average likelihood "<<sumLikelihoods/tofCloud.points.size()<<endl;
00125         out<<sumLikelihoods<<","<<sumLikelihoods/tofCloud.points.size()<<","<<maxLikelihood<<endl;
00126         //normalize for display
00127         //compute standart deviation
00128         for(int i=0; i<tofCloud.points.size(); i++)
00129         {
00130             outCloudTOF.points[i].intensity /= maxLikelihood;
00131 
00132         }
00133         snprintf(fname,99,"%s/likelihood_TOF_%d.wrl",path.c_str(),k);
00134         lslgeneric::writeToVRML(fname,outCloudTOF);
00135     }
00136 
00137     return (0);
00138 }
00139 
00140 
00141 


ndt_map
Author(s): Todor Stoyanov, Jari Saarinen, Henrik Andreasson
autogenerated on Mon Jan 6 2014 11:31:57