Main MRPT website > C++ reference
MRPT logo
eval_overall_error.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 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
16 {
17  using namespace std;
18  using namespace mrpt::utils;
19 
20  m_profiler.enter("eval_overall_squared_error");
21 
22  double sqerr = 0;
23 
24  // ---------------------------------------------------------------------------
25  // Make a list of all the observing & base KFs needed by all observations:
26  // ---------------------------------------------------------------------------
27  vector<bool> base_ids(rba_state.keyframes.size(), false);
28  map<TKeyFrameID, set<TKeyFrameID> > ob_pairs; // Minimum ID first index.
29 
30  for (typename rba_problem_state_t::all_observations_deque_t::const_iterator itO=rba_state.all_observations.begin();itO!=rba_state.all_observations.end();++itO)
31  {
32 #ifdef SRBA_WORKAROUND_MSVC9_DEQUE_BUG
33  const TKeyFrameID obs_id = (*itO)->obs.kf_id;
34  const TKeyFrameID base_id = (*itO)->feat_rel_pos->id_frame_base;
35 #else
36  const TKeyFrameID obs_id = itO->obs.kf_id;
37  const TKeyFrameID base_id = itO->feat_rel_pos->id_frame_base;
38 #endif
39 
40  base_ids[base_id] = true;
41  ob_pairs[ std::min(obs_id,base_id) ].insert( std::max(obs_id,base_id) );
42  }
43 
44  // ---------------------------------------------------------------------------
45  // Build all the needed shortest paths:
46  // ---------------------------------------------------------------------------
47  // all_rel_poses[SOURCE] |--> map[TARGET] = CPose3D of TARGET as seen from SOURCE
48  TRelativePosesForEachTarget all_rel_poses;
49  for (map<TKeyFrameID, set<TKeyFrameID> >::const_iterator it1=ob_pairs.begin();it1!=ob_pairs.end();++it1)
50  {
51  const TKeyFrameID root = it1->first;
52 
53  // Build S.T. from this root:
54  m_profiler.enter("eval_overall_squared_error.complete_ST");
55 
56  frameid2pose_map_t span_tree;
57  this->create_complete_spanning_tree(root,span_tree);
58 
59  m_profiler.leave("eval_overall_squared_error.complete_ST");
60 
61  // Look for the "set_intersection":
62  typename frameid2pose_map_t::const_iterator it_have = span_tree.begin();
63  const typename frameid2pose_map_t::const_iterator it_have_end = span_tree.end();
64 
65  set<TKeyFrameID>::const_iterator it_want = it1->second.begin();
66  const set<TKeyFrameID>::const_iterator it_want_end = it1->second.end();
67 
68  while (it_have!=it_have_end && it_want!=it_want_end)
69  {
70  if (it_have->first<*it_want)
71  ++it_have;
72  else if (*it_want<it_have->first)
73  ++it_want;
74  else
75  {
76  // This means we need 1 or both of the poses:
77  // root -> *it_want
78  // *it_want -> root
79  all_rel_poses[root][*it_want] = it_have->second;
80  all_rel_poses[*it_want][root] = pose_flag_t(-it_have->second.pose, it_have->second.updated);
81 
82  ++it_have;
83  ++it_want;
84  }
85  }
86  }
87 
88  // ---------------------------------------------------------------------------
89  // Evaluate errors:
90  // ---------------------------------------------------------------------------
91  for (typename rba_problem_state_t::all_observations_deque_t::const_iterator itO=rba_state.all_observations.begin();itO!=rba_state.all_observations.end();++itO)
92  {
93  // Actually measured pixel coords: observations[i]->obs.px
94 
95 #ifdef SRBA_WORKAROUND_MSVC9_DEQUE_BUG
96  const TKeyFrameID obs_frame_id = (*itO)->obs.kf_id;
97  const TKeyFrameID base_id = (*itO)->feat_rel_pos->id_frame_base;
98  const TRelativeLandmarkPos *feat_rel_pos = (*itO)->feat_rel_pos;
99 #else
100  const TKeyFrameID obs_frame_id = itO->obs.kf_id;
101  const TKeyFrameID base_id = itO->feat_rel_pos->id_frame_base;
102  const TRelativeLandmarkPos *feat_rel_pos = itO->feat_rel_pos;
103 #endif
104  ASSERTDEB_(feat_rel_pos!=NULL)
105 
106  pose_t const * base_pose_wrt_observer=NULL;
107 
108  // This case can occur with feats with unknown rel.pos:
109  if (base_id==obs_frame_id)
110  {
111  base_pose_wrt_observer = &aux_null_pose;
112  }
113  else
114  {
115  // num[SOURCE] |--> map[TARGET] = CPose3D of TARGET as seen from SOURCE
116  const typename TRelativePosesForEachTarget::const_iterator itPoseMap_for_base_id = all_rel_poses.find(obs_frame_id);
117  ASSERT_( itPoseMap_for_base_id != all_rel_poses.end() )
118 
119  const typename frameid2pose_map_t::const_iterator itRelPose = itPoseMap_for_base_id->second.find(base_id);
120  ASSERT_( itRelPose != itPoseMap_for_base_id->second.end() )
121 
122  base_pose_wrt_observer = &itRelPose->second.pose;
123  }
124 
125  // Sensor pose: base_pose_wrt_sensor = robot_pose (+) sensor_pose_on_the_robot
127  RBA_OPTIONS::sensor_pose_on_robot_t::robot2sensor( *base_pose_wrt_observer, base_pose_wrt_sensor, this->parameters.sensor_pose );
128 
129  // Stored observation:
130  const array_obs_t & z_real = itO->obs.obs_arr;
131 
132  // Predict observation and compare to real obs:
133  residual_t delta;
134  sensor_model_t::observe_error(
135  delta,
136  z_real,
137  base_pose_wrt_sensor,
138  feat_rel_pos->pos, // Position of LM wrt its base_id
139  this->parameters.sensor
140  );
141 
142  sqerr+= delta.squaredNorm();
143  }
144 
145  m_profiler.leave("eval_overall_squared_error");
146 
147  return sqerr;
148 }
149 
150 } } // end namespaces
A STL-like container which looks and behaves (almost exactly) like a std::map<> but is implemented as...
Definition: map_as_vector.h:46
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
Typedefs for determining whether the result of combining a KF pose (+) a sensor pose leads to a SE(2)...
vec_t::const_iterator const_iterator
Definition: map_as_vector.h:56
iterator find(const size_t i)
Constant-time find, returning an iterator to the pair or to end() if not found (that is...
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
kf2kf_pose_traits_t::pose_flag_t pose_flag_t
Definition: RbaEngine.h:94
KF2KF_POSE_TYPE::pose_t pose_t
The type of relative poses (e.g. mrpt::poses::CPose3D)
Definition: RbaEngine.h:87
landmark_traits_t::TRelativeLandmarkPos TRelativeLandmarkPos
One landmark position (relative to its base KF)
Definition: RbaEngine.h:98
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.
kf2kf_pose_traits_t::frameid2pose_map_t frameid2pose_map_t
Definition: RbaEngine.h:95
#define ASSERT_(f)
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:74
double eval_overall_squared_error() const
Evaluates the quality of the overall map/landmark estimations, by computing the sum of the squared er...
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