ndt_fuser.cpp
Go to the documentation of this file.
00001 #include <ndt_fuser/ndt_fuser.h>
00002 
00003 namespace lslgeneric {
00004     void NDTFuser::initialize(Eigen::Affine3d initPos, pcl::PointCloud<pcl::PointXYZ> &cloud)
00005     {
00006         std::cout<<"Initializing NDT FUSER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
00008         lslgeneric::transformPointCloudInPlace(sensor_pose, cloud);
00009         lslgeneric::transformPointCloudInPlace(initPos, cloud);
00010         Tnow = initPos;
00011         map->initialize(Tnow.translation()(0),Tnow.translation()(1),Tnow.translation()(2),map_size_x,map_size_y,map_size_z);
00012         map->addPointCloud(Tnow.translation(),cloud, 0.1, 100.0, 0.1);
00013         map->computeNDTCells(CELL_UPDATE_MODE_SAMPLE_VARIANCE, 1e5, 255, Tnow.translation(), 0.1);
00014         isInit = true;
00015         Tlast_fuse = Tnow;
00016         if(visualize) 
00017         {
00018 #ifndef NO_NDT_VIZ
00019             viewer->plotNDTSAccordingToOccupancy(-1,map); 
00020             //viewer->plotLocalNDTMap(cloud,resolution); 
00021 #endif
00022         }
00023     }
00024     Eigen::Affine3d NDTFuser::update(Eigen::Affine3d Tmotion, pcl::PointCloud<pcl::PointXYZ> &cloud){
00025         if(!isInit){
00026             fprintf(stderr,"NDT-Fuser: Call Initialize first!!\n");
00027             return Tnow;
00028         }
00029         double t1,t2,t3,t4;
00031         lslgeneric::transformPointCloudInPlace(sensor_pose, cloud);
00032         t1 = getDoubleTime();
00034         lslgeneric::NDTMap ndlocal(new lslgeneric::LazyGrid(resolution));
00035         //ndlocal.guessSize(Tnow.translation()(0),Tnow.translation()(1),Tnow.translation()(2),sensor_range,sensor_range,sensor_range);
00036         ndlocal.addPointCloudSimple(cloud);
00037         ndlocal.computeNDTCells(CELL_UPDATE_MODE_SAMPLE_VARIANCE);
00038         t2 = getDoubleTime();
00039         t3 = t4 = t2;
00040         //Tmotion.setIdentity();        
00041         Eigen::Affine3d Tinit = Tnow * Tmotion;
00042         if(be2D) {
00043             if(matcher2D.match( *map, ndlocal,Tinit,true)){
00044                 Eigen::Affine3d diff = (Tnow * Tmotion).inverse() * Tinit;
00045                 if((diff.translation().norm() > max_translation_norm || 
00046                             diff.rotation().eulerAngles(0,1,2).norm() > max_rotation_norm) && checkConsistency){
00047                     fprintf(stderr,"****  NDTFuser -- ALMOST DEFINATELY A REGISTRATION FAILURE *****\n");
00048                     Tnow = Tnow * Tmotion;
00049                 }else{
00050                     Tnow = Tinit;
00051                     lslgeneric::transformPointCloudInPlace(Tnow, cloud);
00052                     Eigen::Affine3d spose = Tnow*sensor_pose;
00053                     Eigen::Affine3d diff_fuse = Tlast_fuse.inverse()*Tnow;
00054 
00055                     if(diff_fuse.translation().norm() > translation_fuse_delta ||
00056                             diff_fuse.rotation().eulerAngles(0,1,2).norm() > rotation_fuse_delta)
00057                     {
00058                         t3 = getDoubleTime();
00059                         map->addPointCloud(spose.translation(),cloud, 0.06, 2.5);
00060                         t4 = getDoubleTime();
00061                         map->computeNDTCells(CELL_UPDATE_MODE_SAMPLE_VARIANCE, 1e5, 255, spose.translation(), 0.1);
00062                         Tlast_fuse = Tnow;
00063                         if(visualize) 
00064                         {
00065 #ifndef NO_NDT_VIZ
00066                             viewer->plotNDTSAccordingToOccupancy(-1,map); 
00067                             //viewer->plotLocalNDTMap(cloud,resolution); 
00068 #endif
00069                         }
00070                     }
00071                 }
00072                 /*
00073                    std::cout<<"load: "<<t2-t1<<" match: "<<t3-t2<<" fuse: "<<t4-t3<<" total: "<<t4-t1<<std::endl;
00074                    FILE *ftmp = fopen("tmp.txt","a");
00075                    fprintf(ftmp,"%lf, ",t4-t3);
00076                    fclose(ftmp);*/
00077             }else{
00078                 Tnow = Tnow * Tmotion;
00079             }
00080 
00081         }
00082         else
00083         {
00084             if(matcher.match( *map, ndlocal,Tinit,true)){
00085                 Eigen::Affine3d diff = (Tnow * Tmotion).inverse() * Tinit;
00086                 if((diff.translation().norm() > max_translation_norm || 
00087                             diff.rotation().eulerAngles(0,1,2).norm() > max_rotation_norm) && checkConsistency){
00088                     fprintf(stderr,"****  NDTFuser -- ALMOST DEFINATELY A REGISTRATION FAILURE *****\n");
00089                     Tnow = Tnow * Tmotion;
00090                     //save offending map:
00091                     //map->writeToJFF("map.jff");
00092                     //ndlocal.writeToJFF("local.jff");
00093                 }else{
00094                     Tnow = Tinit;
00095                     lslgeneric::transformPointCloudInPlace(Tnow, cloud);
00096                     std::cout<<"Tnow :" << Tnow.matrix()<<std::endl;
00097                     Eigen::Affine3d spose = Tnow*sensor_pose;
00098                     Eigen::Affine3d diff_fuse = Tlast_fuse.inverse()*Tnow;
00099 
00100                     if(diff_fuse.translation().norm() > translation_fuse_delta ||
00101                             diff_fuse.rotation().eulerAngles(0,1,2).norm() > 2*rotation_fuse_delta)
00102                     {
00103                         t3 = getDoubleTime();
00104                         map->addPointCloud(spose.translation(),cloud, 0.06, 2.5);
00105                         t4 = getDoubleTime();
00106                         map->computeNDTCells(CELL_UPDATE_MODE_SAMPLE_VARIANCE, 1e5, 255, spose.translation(), 0.1);
00107                         Tlast_fuse = Tnow;
00108                         if(visualize) 
00109                         {
00110 #ifndef NO_NDT_VIZ
00111                             viewer->plotNDTSAccordingToOccupancy(-1,map); 
00112                             //viewer->plotLocalNDTMap(cloud,resolution); 
00113 #endif
00114                         }
00115 
00116                     }
00117                 }
00118                 std::cout<<"load: "<<t2-t1<<" match: "<<t3-t2<<" fuse: "<<t4-t3<<" total: "<<t4-t1<<std::endl;
00119                 /*FILE *ftmp = fopen("tmp.txt","a");
00120                   fprintf(ftmp,"%lf, ",t4-t3);
00121                   fclose(ftmp);*/
00122             }else{
00123                 Tnow = Tnow * Tmotion;
00124             }
00125         }
00126 
00127         return Tnow;
00128     }
00129 }


ndt_fuser
Author(s): Todor Stoyanov, Jari Saarinen
autogenerated on Wed Aug 26 2015 15:25:16