check_reg.cc
Go to the documentation of this file.
00001 
00010 #include "pcl/io/pcd_io.h"
00011 #include "pcl/point_cloud.h"
00012 #include <Eigen/Geometry> // for eulerAngles
00013 #include <iostream>
00014 #include <ndt_registration/ndt_matcher_d2d.h>
00015 #include <ndt_registration/ndt_matcher_p2d.h>
00016 #include <string>
00017 //#include <boost/program_options.hpp>
00018 //#include <cstdlib>
00019 
00020 
00021 using namespace std;
00022 using namespace lslgeneric;
00023 
00024 int main( int argc, char** argv )
00025 {
00026   if (argc < 8+1)
00027   {
00028     std::cerr << "Usage: " << argv[0] << " <pc1> <pc2> <3xtranslation> <3xrotation>\n";
00029     return -1;
00030   }
00031   int i = 1;
00032   std::string file_fixed  (argv[i++]);
00033   std::string file_offset (argv[i++]);
00034 
00035   double tx (atof(argv[i++]));
00036   double ty (atof(argv[i++]));
00037   double tz (atof(argv[i++]));
00038   double rx (atof(argv[i++]));
00039   double ry (atof(argv[i++]));
00040   double rz (atof(argv[i++]));
00041 
00042   Eigen::Transform<double,3,Eigen::Affine> T;
00043   T = Eigen::Translation3d( tx, ty, tz );
00044    //Eigen::AngleAxisd( 0.0, Eigen::Vector3d( 1.0, 0.0, 0.0 ) );
00045   //  Eigen::eulerAngles( rx, ry, rz );
00046     //  T.setIdentity();
00047 
00048   pcl::PointCloud<pcl::PointXYZ> cloud_fixed;
00049   if (pcl::io::loadPCDFile (file_fixed, cloud_fixed) == -1)
00050   {
00051     cerr << "Was not able to open file \"" << file_fixed << "\".\n";
00052     return 1;
00053   }
00054   pcl::PointCloud<pcl::PointXYZ> cloud_offset;
00055   if (pcl::io::loadPCDFile (file_offset, cloud_offset) == -1)
00056   {
00057     cerr << "Was not able to open file \"" << file_offset << "\".\n";
00058     return 1;
00059   }
00060 
00061   lslgeneric::transformPointCloudInPlace( T, cloud_offset );
00062   
00063   std::vector<double> resolutions;
00064   resolutions.push_back( 1 );
00065   NDTMatcherP2D matcherP2D(resolutions);
00066   NDTMatcherD2D matcherD2D(false, false, resolutions);
00067 
00068   Eigen::Matrix<double,6,6> covP2D;
00069   Eigen::MatrixXd covD2D(6,6);
00070   Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double,6,6> > Sol ;
00071   //Eigen::SelfAdjointEigenSolver<Eigen::Matrix6d > Sol ();
00072   Eigen::Matrix<double,6,1> evals;
00073   
00074   // Check the alignment before registration
00075   //matcherP2D.check( cloud_fixed, cloud_offset, T );
00076   matcherP2D.covariance( cloud_fixed, cloud_offset, T, covP2D );
00077   cout << "Cov(P2D)\n" << covP2D << "\n";
00078   Sol.compute( covP2D );
00079   evals = Sol.eigenvalues().real();
00080   cout << "Cov(P2D) eigenvalues "
00081        << evals[0] << " "
00082        << evals[1] << " "
00083        << evals[2] << " "
00084        << evals[3] << " "
00085        << evals[4] << " "
00086        << evals[5] << " "
00087        << "\n";
00088   matcherD2D.covariance( cloud_fixed, cloud_offset, T, covD2D );
00089   Sol.compute( covD2D );
00090   evals = Sol.eigenvalues().real();
00091   cout << "Cov(D2D) eigenvalues "
00092        << evals[0] << " "
00093        << evals[1] << " "
00094        << evals[2] << " "
00095        << evals[3] << " "
00096        << evals[4] << " "
00097        << evals[5] << " "
00098        << "\n";
00099 
00100   // (optionally) perform registration
00101   matcherP2D.ITR_MAX = 0;
00102   matcherP2D.subsample_size = 0.4;
00103   bool converged = matcherP2D.match( cloud_fixed, cloud_offset, T );
00104   if (not converged)
00105     cerr << "warning: matcher terminated before convergence\n";
00106 
00107   cout << "Result T: " << T.matrix() << "\n";
00108   
00109   // Now check the alignment
00110   //matcherP2D.check( cloud_fixed, cloud_offset, T );
00111   matcherP2D.covariance( cloud_fixed, cloud_offset, T, covP2D );
00112   cout << "Cov(P2D)\n" << covP2D << "\n";
00113   Sol.compute(covP2D);
00114   evals = Sol.eigenvalues().real();
00115   cout << "Cov(P2D) eigenvalues "
00116        << evals[0] << " "
00117        << evals[1] << " "
00118        << evals[2] << " "
00119        << evals[3] << " "
00120        << evals[4] << " "
00121        << evals[5] << " "
00122        << "\n";
00123   matcherD2D.covariance( cloud_fixed, cloud_offset, T, covD2D );
00124   Sol.compute( covD2D );
00125   evals = Sol.eigenvalues().real();
00126   cout << "Cov(D2D) eigenvalues "
00127        << evals[0] << " "
00128        << evals[1] << " "
00129        << evals[2] << " "
00130        << evals[3] << " "
00131        << evals[4] << " "
00132        << evals[5] << " "
00133        << "\n";
00134 
00135   // pcl::io::savePCDFile ("test_pcd_fixed.pcd", cloud_fixed);
00136   // pcl::io::savePCDFile ("test_pcd_trans.pcd", cloud_trans);
00137   
00138   return 0;
00139 }
00140 
00141 


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