SRBA: Sparser Relative Bundle Adjustment
srba/impl/alloc_kf2kf_edge.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 
00011 #pragma once
00012 
00013 namespace srba {
00014 
00015 // See header & papers for docs
00016 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
00017 size_t TRBA_Problem_state<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::alloc_kf2kf_edge(
00018     const TPairKeyFrameID &ids,
00019     const pose_t &init_inv_pose_val )
00020 {
00021     // Create edge:
00022     k2k_edges.push_back(k2k_edge_t());         // O(1)
00023     k2k_edge_t & new_edge = *k2k_edges.rbegin();
00024 
00025     new_edge.from = ids.first;
00026     new_edge.to   = ids.second;
00027 
00028     ASSERT_(new_edge.from!=new_edge.to)
00029 
00030     new_edge.inv_pose = init_inv_pose_val;
00031 
00032     new_edge.id = k2k_edges.size()-1; // For convenience, save index within the same structure.
00033 
00034 #ifdef _DEBUG
00035     {
00036         // Security consistency check for user introducing duplicated edges:
00037         std::deque<k2k_edge_t*> &edges = keyframes[ids.first ].adjacent_k2k_edges;
00038         for (size_t i=0;i<edges.size();++i)
00039         {
00040             const k2k_edge_t &e = *edges[i];
00041             if ( (e.to==ids.first && e.from==ids.second) ||
00042                  (e.from==ids.first && e.to==ids.second) )
00043             {
00044                 throw std::runtime_error( mrpt::format("[alloc_kf2kf_edge] ERROR: Edge already exists between %u -> %u",static_cast<unsigned int>(ids.first),static_cast<unsigned int>(ids.second) ) );
00045             }
00046         }
00047     }
00048 #endif
00049 
00050     // Update adjacency lists:  O(1)
00051     keyframes[ids.first ].adjacent_k2k_edges.push_back(&new_edge);
00052     keyframes[ids.second].adjacent_k2k_edges.push_back(&new_edge);
00053 
00054     // Expand dh_dAp Jacobian to make room for a new column for this new edge:
00055     const size_t remapIdx = new_edge.id;
00056     //TSparseBlocksJacobians_dh_dAp::col_t & col =
00057     lin_system.dh_dAp.appendCol(remapIdx);         // O(1) with map_as_vector
00058 
00059     return new_edge.id;
00060 
00061 } // end of alloc_kf2kf_edge
00062 
00063 } // end NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends