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-2015, 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 #define UPDATE_NUM_ST_VERBOSE 0
15 #define DEBUG_GARBAGE_FILL_ALL_NUMS 0
16 
17 /** Updates all the numeric SE(3) poses from a given entry from \a sym.all_edges[i] */
18 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
20  const typename all_edges_maps_t::const_iterator & it,
21  bool skip_marked_as_uptodate)
22 {
23  // num[SOURCE] |--> map[TARGET] = CPose3D of TARGET as seen from SOURCE
24  const TKeyFrameID id_from = it->first;
25  frameid2pose_map_t &frameid2pose_map = num[id_from]; // O(1) with map_as_vector
26 
27  for (typename std::map<TKeyFrameID, k2k_edge_vector_t >::const_iterator itE = it->second.begin();itE != it->second.end();++itE)
28  {
29  const TKeyFrameID id_to = itE->first;
30 
31  pose_flag_t & i2j = frameid2pose_map[id_to];
32  pose_flag_t & j2i = num[id_to][id_from]; // O(1) with map_as_vector
33 
34  if (skip_marked_as_uptodate && i2j.updated && j2i.updated)
35  continue;
36 
37  // Go recompute this pose:
38  const k2k_edge_vector_t &ev = itE->second;
39 
40  // Accumulate inverse poses in the order established by the path:
41  pose_t accum;
42  TKeyFrameID curKF = id_from;
43 
44 #if UPDATE_NUM_ST_VERBOSE
45  std::cout << "ST.NUM["<<id_from<<"]["<<id_to<<"] : ";
46 #endif
47  for (size_t k=0;k<ev.size();k++)
48  {
49  if(ev[k]->to==curKF) // Inverse poses means we should face all arcs by the "head" (arrow) side
50  {
51  accum.composeFrom(accum, ev[k]->inv_pose );
52  curKF = ev[k]->from;
53 #if UPDATE_NUM_ST_VERBOSE
54  std::cout << "->"<<curKF;
55 #endif
56  }
57  else
58  {
59  accum.composeFrom(accum, -ev[k]->inv_pose ); // unary "-" operator inverts SE(3) poses
60  curKF = ev[k]->to;
61 #if UPDATE_NUM_ST_VERBOSE
62  std::cout << "<-"<<curKF;
63 #endif
64  }
65  }
66 
67  // Save in map:
68  i2j.pose = accum;
69  i2j.updated = true;
70 
71  // And also symmetric (inverse) pose:
72  j2i.pose = -accum;
73  j2i.updated = true;
74 
75 #if UPDATE_NUM_ST_VERBOSE
76  std::cout << " "<< accum.asString() << std::endl;
77 #endif
78  }
79 
80  return it->second.size();
81 }
82 
83 #if DEBUG_GARBAGE_FILL_ALL_NUMS
84 
85 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
87 {
88  // Mark all numeric values to trash so we detect if some goes un-initialized.
89  for (typename kf2kf_pose_traits<KF2KF_POSE_TYPE>::TRelativePosesForEachTarget::iterator it=st.num.begin();it!=st.num.end();++it)
90  {
92  for (typename kf2kf_pose_traits<KF2KF_POSE_TYPE>::frameid2pose_map_t::iterator it2=m.begin();it2!=m.end();++it2)
93  it2->second.pose.setToNaN();
94  }
95 }
96 #endif
97 
98 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
100 {
101 #if DEBUG_GARBAGE_FILL_ALL_NUMS
102  setAllNumericToGarbage<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>(*this);
103 #endif
104  size_t pose_count = 0;
105  for (typename all_edges_maps_t::const_iterator it=sym.all_edges.begin();it!=sym.all_edges.end();++it)
106  pose_count += update_numeric_only_all_from_node(it, skip_marked_as_uptodate);
107  return pose_count;
108 }
109 
110 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
111 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)
112 {
113 #if DEBUG_GARBAGE_FILL_ALL_NUMS
114  setAllNumericToGarbage<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>(*this);
115 #endif
116 
117  size_t pose_count = 0;
118  for (std::set<TKeyFrameID>::const_iterator it=kfs_to_update.begin();it!=kfs_to_update.end();++it)
119  {
120  typename all_edges_maps_t::const_iterator it_edge=sym.all_edges.find( *it );
121  if (it_edge!=sym.all_edges.end())
122  {
123  pose_count += update_numeric_only_all_from_node(it_edge, skip_marked_as_uptodate);
124  }
125  }
126  return pose_count;
127 }
128 
129 } } // 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
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.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015