00001 #include <NDTMatcherF2F.hh>
00002 #include <NDTMap.hh>
00003 #include <NDTHistogram.hh>
00004 #include <OctTree.hh>
00005 #include <AdaptiveOctTree.hh>
00006 #include "ros/ros.h"
00007 #include "pcl/point_cloud.h"
00008 #include "sensor_msgs/PointCloud2.h"
00009 #include "pcl/io/pcd_io.h"
00010 #include "pcl/features/feature.h"
00011 #include "pcl/registration/icp.h"
00012 #include "pcl/filters/voxel_grid.h"
00013 #include <LazzyGrid.hh>
00014
00015 #include <cstdio>
00016 #include <Eigen/Eigen>
00017 #include <PointCloudUtils.hh>
00018 #include <fstream>
00019
00020 using namespace std;
00021
00022 int
00023 main (int argc, char** argv)
00024 {
00025
00026 std::ofstream logger ("/home/tsv/ndt_tmp/results_histogram.txt");
00027
00028
00029 pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2, cloud3, cloud4, cloud5, cloud6, cloud7 ;
00030 double __res[] = {0.5, 1, 2, 4};
00031 std::vector<double> resolutions (__res, __res+sizeof(__res)/sizeof(double));
00032 lslgeneric::NDTMatcherF2F matcherF2F(false, false, false, resolutions);
00033
00034 Eigen::Transform<double,3,Eigen::Affine,Eigen::ColMajor> Tin, Tout, Tndt;
00035
00036 struct timeval tv_start, tv_end;
00037
00038 double bestscore = INT_MAX;
00039
00040 Tout.setIdentity();
00041 bool succ = false;
00042 if(argc == 3)
00043 {
00044
00045
00046 cloud1 = lslgeneric::readVRML(argv[1]);
00047 cloud2 = lslgeneric::readVRML(argv[2]);
00048
00049
00050 lslgeneric::OctTree tr;
00051
00052 lslgeneric::OctTree::BIG_CELL_SIZE = 1;
00053 lslgeneric::OctTree::SMALL_CELL_SIZE = 0.2;
00054 double finalscore;
00055
00056 gettimeofday(&tv_start,NULL);
00057
00058 lslgeneric::NDTMap fixed(&tr);
00059 fixed.loadPointCloud(cloud1);
00060 lslgeneric::NDTMap moving(&tr);
00061 moving.loadPointCloud(cloud2);
00062 lslgeneric::NDTMap moved(&tr);
00063
00064
00065 fixed.computeNDTCells();
00066 moving.computeNDTCells();
00067
00068 lslgeneric::NDTHistogram fixedH(fixed);
00069 lslgeneric::NDTHistogram movingH(moving);
00070
00071
00072
00073
00074
00075
00076 Eigen::Transform<double,3,Eigen::Affine,Eigen::ColMajor> T;
00077
00078 movingH.bestFitToHistogram(fixedH,T);
00079
00080
00081
00082 for(int q=0; q<1; q++)
00083 {
00084 if(q!=3)
00085 {
00086 movingH.getTransform(q,T);
00087 }
00088 else
00089 {
00090 T.setIdentity();
00091 }
00092 cout<<"T init "<<T.translation().transpose()<<" r "<<T.rotation().eulerAngles(0,1,2).transpose()<<endl;
00093 Tndt.setIdentity();
00094 cloud3 = lslgeneric::transformPointCloud(T,cloud2);
00095 bool ret = matcherF2F.match(cloud1,cloud3,Tndt);
00096 finalscore = matcherF2F.finalscore;
00097 cout<<"final score at "<<q<<" is "<<finalscore<<endl;
00098 if(finalscore < bestscore)
00099 {
00100 Tout = Tndt*T;
00101 bestscore = finalscore;
00102 cout<<"score = "<<bestscore<<"best is "<<q<<endl;
00103 }
00104 cout<<"T fin "<<Tout.translation().transpose()<<" r "<<Tout.rotation().eulerAngles(0,1,2).transpose()<<endl;
00105 }
00106
00107 cloud4 = lslgeneric::transformPointCloud(Tout,cloud2);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 gettimeofday(&tv_end,NULL);
00163
00164 cout<<" TIME: "<<
00165 (tv_end.tv_sec-tv_start.tv_sec)*1000.+(tv_end.tv_usec-tv_start.tv_usec)/1000.<<endl;
00166
00167 char fname[50];
00168 snprintf(fname,49,"/home/tsv/ndt_tmp/c_offset.wrl");
00169 FILE *fout = fopen(fname,"w");
00170 fprintf(fout,"#VRML V2.0 utf8\n");
00171
00172 lslgeneric::writeToVRML(fout,cloud1,Eigen::Vector3d(0,1,0));
00173
00174 lslgeneric::writeToVRML(fout,cloud2,Eigen::Vector3d(1,0,0));
00175
00176
00177
00178 {
00179 Eigen::Vector3d out = Tout.rotation().eulerAngles(0,1,2);
00180 cout<<"rot: "<<out.transpose()<<endl;
00181 cout<<"translation "<<Tout.translation().transpose()<<endl;
00182 logger<<"rot: "<<out.transpose()<<endl;
00183 logger<<"translation "<<Tout.translation()<<endl;
00184
00185 lslgeneric::writeToVRML(fout,cloud4,Eigen::Vector3d(1,1,1));
00186
00187
00188
00189 }
00190
00191 fclose(fout);
00192
00193 succ = true;
00194 }
00195 return 0;
00196 }
00197
00198
00199