SRBA: Sparser Relative Bundle Adjustment
srba/impl/make_ordered_list_base_kfs.h
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 namespace srba {
00013 namespace internal {
00014 
00015 template <class traits_t,class rba_problem_state_t>
00016 void make_ordered_list_base_kfs(
00017     const typename traits_t::new_kf_observations_t & obs,
00018     const rba_problem_state_t & rba_state,
00019     base_sorted_lst_t            & obs_for_each_base_sorted,
00020     std::map<TKeyFrameID,size_t>       *out_obs_for_each_base = NULL )
00021 {
00022     using namespace std;
00023     // Make a first pass to make a sorted list of base KFs, ordered by # of observations so we prefer edges to
00024     // strongly connected base KFs:
00025     map<TKeyFrameID,size_t> obs_for_each_base;
00026 
00027     for (typename traits_t::new_kf_observations_t::const_iterator itObs=obs.begin();itObs!=obs.end();++itObs)
00028     {
00029         const TLandmarkID lm_id = itObs->obs.feat_id;
00030         if (lm_id>=rba_state.all_lms.size()) continue; // It's a new LM
00031 
00032         const typename landmark_traits<typename traits_t::original_landmark_t>::TLandmarkEntry &lme = rba_state.all_lms[lm_id];
00033         if (!lme.rfp) continue; // It's a new LM.
00034 
00035         const TKeyFrameID base_id = lme.rfp->id_frame_base;
00036         obs_for_each_base[base_id]++; // vote for this.
00037     }
00038 
00039     // Sort map<> by values:
00040     for (map<TKeyFrameID,size_t>::const_iterator it=obs_for_each_base.begin();it!=obs_for_each_base.end();++it)
00041         obs_for_each_base_sorted.insert( make_pair(it->second,it->first) );
00042 
00043     if (out_obs_for_each_base)
00044         out_obs_for_each_base->swap(obs_for_each_base);
00045 }
00046 
00047 } } // End of namespaces
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends