SRBA: Sparser Relative Bundle Adjustment
|
00001 /* +---------------------------------------------------------------------------+ 00002 | Mobile Robot Programming Toolkit (MRPT) | 00003 | http://www.mrpt.org/ | 00004 | | 00005 | Copyright (c) 2005-2015, Individual contributors, see AUTHORS file | 00006 | See: http://www.mrpt.org/Authors - All rights reserved. | 00007 | Released under BSD License. See details in http://www.mrpt.org/License | 00008 +---------------------------------------------------------------------------+ */ 00009 00010 #pragma once 00011 00012 #include <mrpt/utils/CConfigFileBase.h> // MRPT_LOAD_CONFIG_VAR 00013 #include <mrpt/math/ops_containers.h> // meanAndStd() 00014 00015 namespace srba { 00016 00018 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00019 RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::RbaEngine() : 00020 m_verbose_level(1), 00021 rba_state(), 00022 m_profiler(true) 00023 { 00024 clear(); 00025 } 00026 00028 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00029 void RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::clear() 00030 { 00031 this->rba_state.clear(); 00032 } 00033 00034 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00035 RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::TSRBAParameters::TSRBAParameters() : 00036 // ------------------------------- 00037 max_tree_depth ( 4 ), 00038 max_optimize_depth ( 4 ), 00039 // ------------------------------- 00040 optimize_new_edges_alone (true), 00041 use_robust_kernel ( false ), 00042 use_robust_kernel_stage1 ( false ), 00043 kernel_param ( 3. ), 00044 max_iters ( 20 ), 00045 max_error_per_obs_to_stop ( 1e-6 ), 00046 max_rho ( 10.0 ), 00047 max_lambda ( 1e20 ), 00048 min_error_reduction_ratio_to_relinearize ( 0.01 ), 00049 numeric_jacobians ( false ), 00050 feedback_user_iteration(NULL), 00051 compute_condition_number(false), 00052 compute_sparsity_stats (false), 00053 max_rmse_show_red_warning(0.5), 00054 cov_recovery ( crpLandmarksApprox ) 00055 { 00056 } 00057 00059 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00060 void RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::TSRBAParameters::loadFromConfigFile(const mrpt::utils::CConfigFileBase & source,const std::string & section) 00061 { 00062 MRPT_LOAD_CONFIG_VAR(max_tree_depth,uint64_t,source,section) 00063 MRPT_LOAD_CONFIG_VAR(max_optimize_depth,uint64_t,source,section) 00064 00065 MRPT_LOAD_CONFIG_VAR(optimize_new_edges_alone,bool,source,section) 00066 MRPT_LOAD_CONFIG_VAR(use_robust_kernel,bool,source,section) 00067 MRPT_LOAD_CONFIG_VAR(use_robust_kernel_stage1,bool,source,section) 00068 MRPT_LOAD_CONFIG_VAR(max_rho,double,source,section) 00069 MRPT_LOAD_CONFIG_VAR(max_lambda,double,source,section) 00070 MRPT_LOAD_CONFIG_VAR(kernel_param,double,source,section) 00071 MRPT_LOAD_CONFIG_VAR(max_iters,uint64_t,source,section) 00072 MRPT_LOAD_CONFIG_VAR(max_error_per_obs_to_stop,double,source,section) 00073 00074 cov_recovery = source.read_enum(section, "cov_recovery", cov_recovery); 00075 } 00076 00078 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00079 void RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::TSRBAParameters::saveToConfigFile(mrpt::utils::CConfigFileBase & out,const std::string & section) const 00080 { 00081 out.write(section,"max_tree_depth",max_tree_depth, /* text width */ 30, 30, "Maximum depth of all spanning trees"); 00082 out.write(section,"max_optimize_depth",max_optimize_depth, /* text width */ 30, 30, "Max. local optimization distance"); 00083 00084 out.write(section,"optimize_new_edges_alone",optimize_new_edges_alone, /* text width */ 30, 30, "Optimize new edges alone before optimizing the entire local area?"); 00085 out.write(section,"use_robust_kernel",use_robust_kernel, /* text width */ 30, 30, "Use pseudo-Huber kernel?"); 00086 out.write(section,"use_robust_kernel_stage1",use_robust_kernel_stage1, /* text width */ 30, 30, "Use pseudo-Huber kernel at stage1?"); 00087 out.write(section,"kernel_param",kernel_param, /* text width */ 30, 30, "robust kernel parameter"); 00088 out.write(section,"max_rho",max_rho, /* text width */ 30, 30, "Lev-Marq optimization: maximum rho value to stop"); 00089 out.write(section,"max_lambda",max_lambda, /* text width */ 30, 30, "Lev-Marq optimization: maximum lambda to stop"); 00090 out.write(section,"max_iters",static_cast<uint64_t>(max_iters), /* text width */ 30, 30, "Max. iterations for optimization"); 00091 out.write(section,"max_error_per_obs_to_stop",max_error_per_obs_to_stop, /* text width */ 30, 30, "Another criterion for stopping optimization"); 00092 out.write(section,"cov_recovery", mrpt::utils::TEnumType<TCovarianceRecoveryPolicy>::value2name(cov_recovery) , /* text width */ 30, 30, "Covariance recovery policy"); 00093 } 00094 00095 00097 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00098 void TRBA_Problem_state<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::compute_all_node_degrees( 00099 double &out_mean_degree, 00100 double &out_std_degree, 00101 double &out_max_degree) const 00102 { 00103 out_mean_degree = 0; 00104 out_std_degree = 0; 00105 out_max_degree = 0; 00106 00107 const size_t nKFs = keyframes.size(); 00108 00109 std::vector<size_t> degs; 00110 degs.reserve(nKFs); 00111 00112 for(size_t i=0;i<nKFs;i++) 00113 degs.push_back( keyframes[i].adjacent_k2k_edges.size() ); 00114 00115 mrpt::math::meanAndStd(degs,out_mean_degree,out_std_degree); 00116 out_max_degree = mrpt::math::maximum(degs); 00117 00118 } 00119 00122 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS> 00123 bool TRBA_Problem_state<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::are_keyframes_connected(const TKeyFrameID id1, const TKeyFrameID id2) const 00124 { 00125 ASSERT_BELOW_(id1, keyframes.size()) 00126 ASSERT_BELOW_(id2, keyframes.size()) 00127 00128 const std::deque<k2k_edge_t*> & id1_adj = keyframes[id1].adjacent_k2k_edges; 00129 00130 for (size_t i=0;i<id1_adj.size();i++) 00131 if ( id2== getTheOtherFromPair2(id1, *id1_adj[i]) ) 00132 return true; 00133 00134 return false; 00135 } 00136 00137 } // end NS