Main MRPT website > C++ reference
MRPT logo
spantree_create_complete.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 #include <queue>
13 
14 namespace mrpt { namespace srba {
15 
16 // This is used mainly for 3D rendering
17 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
19  const TKeyFrameID root_id,
20  frameid2pose_map_t & span_tree,
21  const size_t max_depth,
22  std::vector<bool> * aux_ws
23  ) const
24 {
25  using namespace std;
26  MRPT_UNUSED_PARAM(aux_ws);
27  span_tree.clear();
28 
29  set<TKeyFrameID> visited;
30  queue<TKeyFrameID> pending;
31  map<TKeyFrameID,TBFSEntryEdges> preceding;
32 
33  // ----------------------------------------------------------------------------------------------------------------
34  // (1) Do a BFS to build a spanning tree, storing the shortest path and its depth for each KF within max_depth:
35  // ----------------------------------------------------------------------------------------------------------------
36  // Insert:
37  pending.push(root_id);
38  visited.insert(root_id);
39  preceding[root_id].dist = 0;
40 
41  while (!pending.empty())
42  {
43  const TKeyFrameID next_kf = pending.front();
44  pending.pop();
45 
46  const topo_dist_t cur_dist = preceding[next_kf].dist;
47 
48  if (cur_dist>=max_depth)
49  continue;
50 
51  // Get all connections of this node:
52  ASSERTDEB_(next_kf < rba_state.keyframes.size())
53  const keyframe_info & kfi = rba_state.keyframes[next_kf];
54 
55  for (size_t i=0;i<kfi.adjacent_k2k_edges.size();i++)
56  {
57  const k2k_edge_t* ed = kfi.adjacent_k2k_edges[i];
58  const TKeyFrameID new_kf = getTheOtherFromPair2(next_kf, *ed);
59  if (!visited.count(new_kf))
60  {
61  pending.push(new_kf);
62  visited.insert(new_kf);
63 
64  TBFSEntryEdges & p = preceding[new_kf];
65 
66  if (p.dist>cur_dist+1)
67  {
68  p.dist = cur_dist+1;
69  p.prev = next_kf;
70  p.edge = ed;
71  }
72  }
73  }
74  }
75 
76  // ----------------------------------------------------------------------------------------------------------------
77  // (2) Sort all KFs in range by hiearchy, i.e. by increasing depth:
78  // ----------------------------------------------------------------------------------------------------------------
79  multimap<topo_dist_t,pair<TKeyFrameID,TBFSEntryEdges> > kfs_by_depth;
80 
81  for (typename map<TKeyFrameID,TBFSEntryEdges>::const_iterator it=preceding.begin();it!=preceding.end();++it)
82  kfs_by_depth.insert( make_pair( it->second.dist, *it ) );
83 
84 
85  // ----------------------------------------------------------------------------------------------------------------
86  // (3) Construct the pose of each KF by composing the poses along the tree, from the root to the leaves:
87  // ----------------------------------------------------------------------------------------------------------------
88  for (typename multimap<topo_dist_t,pair<TKeyFrameID,TBFSEntryEdges> >::const_iterator it=kfs_by_depth.begin();it!=kfs_by_depth.end();++it)
89  {
90  const topo_dist_t kf_depth = it->first;
91  const TKeyFrameID kf_id = it->second.first;
92  const TBFSEntryEdges & bfs_data = it->second.second;
93 
94 
95  if (kf_depth==0)
96  {
97  // Root:
98  span_tree[ kf_id ].pose = pose_t(); // Default: origin.
99  }
100  else
101  {
102  // All leaves:
103  ASSERT_(bfs_data.edge!=NULL)
104 
105  // The pose of my parent KF:
106  const pose_t & parent_pose = span_tree[ bfs_data.prev ].pose;
107 
108  // A ref to the placeholder for my pose:
109  pose_t & my_pose = span_tree[ kf_id ].pose;
110 
111  // Is the edge direct or inverted?
112  if (bfs_data.edge->to==kf_id)
113  {
114  // Edge: parent -> me
115  // "inv_pose" in edge is really the inverse pose of me w.r.t. my parent:
116  my_pose.composeFrom(parent_pose, -bfs_data.edge->inv_pose );
117  }
118  else
119  {
120  // Edge: me -> parent
121  // "inv_pose" in edge is directly the pose of me w.r.t. my parent:
122  my_pose.composeFrom(parent_pose, bfs_data.edge->inv_pose );
123  }
124  }
125  }
126 
127 }
128 
129 
130 } } // end NS
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
KF2KF_POSE_TYPE::pose_t pose_t
The type of relative poses (e.g. mrpt::poses::CPose3D)
Definition: RbaEngine.h:87
Keyframe-to-keyframe edge: an unknown of the problem.
Definition: srba_types.h:82
uint64_t topo_dist_t
Unsigned integral type for topological distances in a graph/tree.
Definition: srba_types.h:33
TKeyFrameID prev
Definition: RbaEngine.h:643
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Private aux structure for BFS searches.
Definition: RbaEngine.h:638
topo_dist_t dist
Definition: RbaEngine.h:644
const k2k_edge_t * edge
Definition: RbaEngine.h:645
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
pose_t inv_pose
Inverse pose: pose_from (-) pose_to , that is: "from" as seen from "to".
Definition: srba_types.h:86
kf2kf_pose_traits_t::frameid2pose_map_t frameid2pose_map_t
Definition: RbaEngine.h:95
void create_complete_spanning_tree(const TKeyFrameID root_id, frameid2pose_map_t &span_tree, const size_t max_depth=std::numeric_limits< size_t >::max(), std::vector< bool > *aux_ws=NULL) const
Creates a numeric spanning tree between a given root keyframe and the entire graph, returning it into a user-supplied data structure Note that this method does NOT use the depth-limited spanning trees which are built incrementally with the graph.
#define ASSERT_(f)
Information per key-frame needed for RBA.
Definition: srba_types.h:453
V getTheOtherFromPair2(const V one, const K2K_EDGE &p)
For usage with K2K_EDGE = typename kf2kf_pose_traits::k2k_edge_t.
Definition: srba_types.h:191
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