Go to the documentation of this file.00001 #ifndef NDT_FUSER_HMT_HH
00002 #define NDT_FUSER_HMT_HH
00003 #ifndef NO_NDT_VIZ
00004 #include <ndt_visualisation/ndt_viz.h>
00005 #endif
00006 #include <ndt_map/ndt_map.h>
00007 #include <ndt_map/ndt_map_hmt.h>
00008 #include <ndt_registration/ndt_matcher_d2d_2d.h>
00009 #include <ndt_registration/ndt_matcher_d2d.h>
00010 #include <ndt_map/pointcloud_utils.h>
00011
00012 #include <Eigen/Eigen>
00013 #include <pcl/point_cloud.h>
00014 #include <sys/time.h>
00015
00016
00017
00018 namespace lslgeneric {
00024 class NDTFuserHMT{
00025 public:
00026 Eigen::Affine3d Tnow, Tlast_fuse, Todom;
00027 lslgeneric::NDTMap *map;
00028 bool checkConsistency;
00029 double max_translation_norm, max_rotation_norm;
00030 double sensor_range;
00031 bool be2D, doMultires, fuseIncomplete, beHMT, disableRegistration;
00032 int ctr;
00033 std::string prefix;
00034 std::string hmt_map_dir;
00035 #ifndef NO_NDT_VIZ
00036 NDTViz *viewer;
00037 #endif
00038 FILE *fAddTimes, *fRegTimes;
00039
00040 NDTFuserHMT(double map_resolution, double map_size_x_, double map_size_y_, double map_size_z_, double sensor_range_ = 3,
00041 bool visualize_=false, bool be2D_=false, bool doMultires_=false, bool fuseIncomplete_=false, int max_itr=30,
00042 std::string prefix_="", bool beHMT_=true, std::string hmt_map_dir_="map", bool _step_control=true){
00043 isInit = false;
00044 disableRegistration=false;
00045 resolution = map_resolution;
00046 sensor_pose.setIdentity();
00047 checkConsistency = false;
00048 visualize = true;
00049 translation_fuse_delta = 0.0;
00050 rotation_fuse_delta = 0.0;
00051
00052
00053 max_translation_norm = 1.;
00054 max_rotation_norm = M_PI/4;
00055 map_size_x = map_size_x_;
00056 map_size_y = map_size_y_;
00057 map_size_z = map_size_z_;
00058 visualize = visualize_;
00059 be2D = be2D_;
00060 sensor_range = sensor_range_;
00061 prefix = prefix_;
00062 doMultires = doMultires_;
00063 ctr =0;
00064 #ifndef NO_NDT_VIZ
00065 if(visualize_){
00066 viewer = new NDTViz(visualize);
00067 viewer->win3D->start_main_loop_own_thread();
00068 }
00069 #endif
00070 localMapSize<<sensor_range_,sensor_range_,map_size_z_;
00071 fuseIncomplete = fuseIncomplete_;
00072 matcher.ITR_MAX = max_itr;
00073 matcher2D.ITR_MAX = max_itr;
00074 matcher.step_control=_step_control;
00075 matcher2D.step_control=_step_control;
00076 beHMT = beHMT_;
00077 hmt_map_dir=hmt_map_dir_;
00078
00079
00080 char fname[1000];
00081 snprintf(fname,999,"%s_addTime.txt",prefix.c_str());
00082 fAddTimes = fopen(fname,"w");
00083
00084 std::cout<<"MAP: resolution: "<<resolution<<" size "<<map_size_x<<" "<<map_size_y<<" "<<map_size_z<<" sr "<<sensor_range<<std::endl;
00085 }
00086 ~NDTFuserHMT()
00087 {
00088 delete map;
00089 #ifndef NO_NDT_VIZ
00090 delete viewer;
00091 #endif
00092 if(fAddTimes!=NULL) fclose(fAddTimes);
00093 if(fRegTimes!=NULL) fclose(fRegTimes);
00094 }
00095
00096 double getDoubleTime()
00097 {
00098 struct timeval time;
00099 gettimeofday(&time,NULL);
00100 return time.tv_sec + time.tv_usec * 1e-6;
00101 }
00102 void setSensorPose(Eigen::Affine3d spose){
00103 sensor_pose = spose;
00104 }
00105
00106 bool wasInit()
00107 {
00108 return isInit;
00109 }
00110
00111 bool saveMap() {
00112 if(!isInit) return false;
00113 if(map == NULL) return false;
00114 if(beHMT) {
00115 lslgeneric::NDTMapHMT *map_hmt = dynamic_cast<lslgeneric::NDTMapHMT*> (map);
00116 if(map_hmt==NULL) return false;
00117 return (map_hmt->writeTo()==0);
00118 } else {
00119 char fname[1000];
00120 snprintf(fname,999,"%s/%s_map.jff",hmt_map_dir.c_str(),prefix.c_str());
00121 return (map->writeToJFF(fname) == 0);
00122 }
00123 }
00124
00128 void initialize(Eigen::Affine3d initPos, pcl::PointCloud<pcl::PointXYZ> &cloud, bool preLoad=false);
00129
00134 Eigen::Affine3d update(Eigen::Affine3d Tmotion, pcl::PointCloud<pcl::PointXYZ> &cloud);
00135
00136 private:
00137 bool isInit;
00138
00139 double resolution;
00140 double map_size;
00141
00142 double translation_fuse_delta, rotation_fuse_delta;
00143 double map_size_x;
00144 double map_size_y;
00145 double map_size_z;
00146 bool visualize;
00147
00148 Eigen::Affine3d sensor_pose;
00149 lslgeneric::NDTMatcherD2D matcher;
00150 lslgeneric::NDTMatcherD2D_2D matcher2D;
00151 Eigen::Vector3d localMapSize;
00152
00153 public:
00154 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00155
00156 };
00157 }
00158 #endif