Main MRPT website > C++ reference
MRPT logo
spantree_update_numeric.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 namespace mrpt { namespace srba {
13 
14 using namespace std;
15 
16 #define UPDATE_NUM_ST_VERBOSE 0
17 #define DEBUG_GARBAGE_FILL_ALL_NUMS 0
18 
19 /** Updates all the numeric SE(3) poses from a given entry from \a sym.all_edges[i] */
20 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
22  const typename all_edges_maps_t::const_iterator & it,
23  bool skip_marked_as_uptodate)
24 {
25  // num[SOURCE] |--> map[TARGET] = CPose3D of TARGET as seen from SOURCE
26  const TKeyFrameID id_from = it->first;
27  frameid2pose_map_t &frameid2pose_map = num[id_from]; // O(1) with map_as_vector
28 
29  for (typename std::map<TKeyFrameID, k2k_edge_vector_t >::const_iterator itE = it->second.begin();itE != it->second.end();++itE)
30  {
31  const TKeyFrameID id_to = itE->first;
32 
33  pose_flag_t & i2j = frameid2pose_map[id_to];
34  pose_flag_t & j2i = num[id_to][id_from]; // O(1) with map_as_vector
35 
36  if (skip_marked_as_uptodate && i2j.updated && j2i.updated)
37  continue;
38 
39  // Go recompute this pose:
40  const k2k_edge_vector_t &ev = itE->second;
41 
42  // Accumulate inverse poses in the order established by the path:
43  pose_t accum;
44  TKeyFrameID curKF = id_from;
45 
46 #if UPDATE_NUM_ST_VERBOSE
47  std::cout << "ST.NUM["<<id_from<<"]["<<id_to<<"] : ";
48 #endif
49  for (size_t k=0;k<ev.size();k++)
50  {
51  if(ev[k]->to==curKF) // Inverse poses means we should face all arcs by the "head" (arrow) side
52  {
53  accum.composeFrom(accum, ev[k]->inv_pose );
54  curKF = ev[k]->from;
55 #if UPDATE_NUM_ST_VERBOSE
56  std::cout << "->"<<curKF;
57 #endif
58  }
59  else
60  {
61  accum.composeFrom(accum, -ev[k]->inv_pose ); // unary "-" operator inverts SE(3) poses
62  curKF = ev[k]->to;
63 #if UPDATE_NUM_ST_VERBOSE
64  std::cout << "<-"<<curKF;
65 #endif
66  }
67  }
68 
69  // Save in map:
70  i2j.pose = accum;
71  i2j.updated = true;
72 
73  // And also symmetric (inverse) pose:
74  j2i.pose = -accum;
75  j2i.updated = true;
76 
77 #if UPDATE_NUM_ST_VERBOSE
78  std::cout << " "<< accum.asString() << std::endl;
79 #endif
80  }
81 
82  return it->second.size();
83 }
84 
85 #if DEBUG_GARBAGE_FILL_ALL_NUMS
86 
87 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
89 {
90  // Mark all numeric values to trash so we detect if some goes un-initialized.
91  for (typename kf2kf_pose_traits<KF2KF_POSE_TYPE>::TRelativePosesForEachTarget::iterator it=st.num.begin();it!=st.num.end();++it)
92  {
94  for (typename kf2kf_pose_traits<KF2KF_POSE_TYPE>::frameid2pose_map_t::iterator it2=m.begin();it2!=m.end();++it2)
95  it2->second.pose.setToNaN();
96  }
97 }
98 #endif
99 
100 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
102 {
103 #if DEBUG_GARBAGE_FILL_ALL_NUMS
104  setAllNumericToGarbage<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>(*this);
105 #endif
106  size_t pose_count = 0;
107  for (typename all_edges_maps_t::const_iterator it=sym.all_edges.begin();it!=sym.all_edges.end();++it)
108  pose_count += update_numeric_only_all_from_node(it, skip_marked_as_uptodate);
109  return pose_count;
110 }
111 
112 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
113 size_t TRBA_Problem_state<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::TSpanningTree::update_numeric(const std::set<TKeyFrameID> & kfs_to_update,bool skip_marked_as_uptodate)
114 {
115 #if DEBUG_GARBAGE_FILL_ALL_NUMS
116  setAllNumericToGarbage<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>(*this);
117 #endif
118 
119  size_t pose_count = 0;
120  for (std::set<TKeyFrameID>::const_iterator it=kfs_to_update.begin();it!=kfs_to_update.end();++it)
121  {
122  typename all_edges_maps_t::const_iterator it_edge=sym.all_edges.find( *it );
123  if (it_edge!=sym.all_edges.end())
124  {
125  pose_count += update_numeric_only_all_from_node(it_edge, skip_marked_as_uptodate);
126  }
127  }
128  return pose_count;
129 }
130 
131 } } // end NS
kf2kf_pose_traits< KF2KF_POSE_TYPE >::pose_flag_t pose_flag_t
Definition: srba_types.h:480
kf2kf_pose_traits< KF2KF_POSE_TYPE >::frameid2pose_map_t frameid2pose_map_t
Definition: srba_types.h:479
kf2kf_pose_traits< KF2KF_POSE_TYPE >::k2k_edge_vector_t k2k_edge_vector_t
Definition: srba_types.h:478
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
The argument "POSE_TRAITS" can be any of those defined in srba/models/kf2kf_poses.h (typically, either kf2kf_poses::SE3 or kf2kf_poses::SE2).
Definition: srba_types.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
size_t update_numeric_only_all_from_node(const typename all_edges_maps_t::const_iterator &it, bool skip_marked_as_uptodate=false)
Updates all the numeric SE(3) poses from a given entry from sym.all_edges[i].
kf2kf_pose_traits< KF2KF_POSE_TYPE >::TRelativePosesForEachTarget num
"Numeric" spanning tree: the SE(3) pose of each node wrt to any other: num[SOURCE] |–> map[TARGET] =...
Definition: srba_types.h:550
size_t update_numeric(bool skip_marked_as_uptodate=false)
Updates all the numeric SE(3) poses from ALL the sym.all_edges.
KF2KF_POSE_TYPE::pose_t pose_t
Definition: srba_types.h:476
uint64_t TKeyFrameID
Numeric IDs for key-frames (KFs)
Definition: srba_types.h:31



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014