Main MRPT website > C++ reference
MRPT logo
export_opengl_landmark_renderers.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
15 #include <mrpt/opengl/CEllipsoid.h>
16 #include <mrpt/opengl/CText3D.h>
19 
20 namespace mrpt { namespace srba {
21 
22 // Specializations for rendering each kind of landmark:
23 template <class LM_TYPE>
25 
26 /** Landmark renderer for: landmark_rendering_as_point */
28 {
29  template <class RBA>
30  static void render(
31  const RBA &rba,
32  const srba::TKeyFrameID root_keyframe,
33  const typename RBA::frameid2pose_map_t &spantree,
34  const typename RBA::TOpenGLRepresentationOptions &options,
36  {
37  using namespace mrpt::math;
40 
41  // For each fixed known LM, add a point to a point cloud
42  // and a text label with the landmark ID:
43  mrpt::opengl::CPointCloudPtr gl_lms = mrpt::opengl::CPointCloud::Create();
44  gl_lms->setPointSize(5);
45  gl_lms->setColor(0,0,1);
46 
47  scene.insert(gl_lms);
48 
49  vector<typename RBA::TRelativeLandmarkPosMap::const_iterator> lms_to_draw;
50  vector<const typename RBA::hessian_traits_t::TSparseBlocksHessian_f::matrix_t *> lms_to_draw_inf_covs;
51 
52  for (typename RBA::TRelativeLandmarkPosMap::const_iterator itLM = rba.get_rba_state().known_lms.begin();itLM != rba.get_rba_state().known_lms.end();++itLM)
53  {
54  lms_to_draw.push_back(itLM);
55  lms_to_draw_inf_covs.push_back( NULL );
56  }
57 
58  const size_t nKnown = lms_to_draw.size();
59 
60  if (options.draw_unknown_feats)
61  {
62  for (typename RBA::TRelativeLandmarkPosMap::const_iterator itLM = rba.get_rba_state().unknown_lms.begin();itLM != rba.get_rba_state().unknown_lms.end();++itLM)
63  {
64  lms_to_draw.push_back(itLM);
65 
66  typename RBA::hessian_traits_t::landmarks2infmatrix_t::const_iterator it_inf = rba.get_rba_state().unknown_lms_inf_matrices.find(itLM->first);
67 
68  if (it_inf != rba.get_rba_state().unknown_lms_inf_matrices.end())
69  lms_to_draw_inf_covs.push_back( &it_inf->second );
70  else lms_to_draw_inf_covs.push_back(NULL);
71  }
72  }
73 
74  const mrpt::utils::TColorf col_known_lms(1.f,1.f,0.f);
75  const mrpt::utils::TColorf col_unknown_lms(1.f,0.f,0.f);
76 
77  for (size_t i=0;i<lms_to_draw.size();i++)
78  {
79  const typename RBA::TRelativeLandmarkPosMap::const_iterator &itLM = lms_to_draw[i];
80  const bool is_known = (i<nKnown);
81 
82  // Don't draw those unknown LMs which hasn't been estimated not even once:
83  //if (!is_known && lms_to_draw_inf_covs[i]==NULL) continue;
84 
85  mrpt::poses::CPose3D base_pose;
86  if (itLM->second.id_frame_base!=root_keyframe)
87  {
88  typename RBA::frameid2pose_map_t::const_iterator itBaseNode = spantree.find(itLM->second.id_frame_base);
89  if(itBaseNode==spantree.end())
90  continue;
91  base_pose = itBaseNode->second.pose; // Inverse!
92  }
93  else
94  {
95  // It's the origin.
96  }
97 
98  // If LM_TYPE defines this kind of renderer, we
99  mrpt::math::TPoint3D p_wrt_base;
100  RBA::lm_type::relativeEuclideanLocation(itLM->second.pos, p_wrt_base);
101 
102  mrpt::math::TPoint3D p_global;
103  base_pose.composePoint(p_wrt_base,p_global);
104 
105  gl_lms->insertPoint(p_global.x,p_global.y,p_global.z);
106 
107  if( options.show_unknown_feats_ids )
108  {
109  // Add text label:
110  mrpt::opengl::CText3DPtr gl_txt = mrpt::opengl::CText3D::Create(
111  mrpt::format("%u",static_cast<unsigned int>( itLM->first)),
112  "mono", 0.15,
114  gl_txt->setPose(CPose3D(p_global.x,p_global.y,p_global.z,DEG2RAD(-90),DEG2RAD(0),DEG2RAD(90)));
115  gl_txt->setColor( is_known ? col_known_lms : col_unknown_lms );
116 
117  scene.insert(gl_txt);
118  }
119 
120  // Uncertainty ellipse?
121  if (options.draw_unknown_feats_ellipses && lms_to_draw_inf_covs[i] )
122  {
123  double min_inf_diag=std::numeric_limits<double>::max();
124  for (size_t k=0;k<RBA::LM_DIMS;k++)
125  mrpt::utils::keep_min(min_inf_diag, (*lms_to_draw_inf_covs[i])(k,k));
126  if (min_inf_diag<1e-5) continue; // Too large covariance!
127 
129  lms_to_draw_inf_covs[i]->inv(cov);
130 
131  mrpt::opengl::CEllipsoidPtr gl_ellip = mrpt::opengl::CEllipsoid::Create();
132  gl_ellip->setQuantiles( options.draw_unknown_feats_ellipses_quantiles );
133  gl_ellip->enableDrawSolid3D(false);
134 
135  gl_ellip->setCovMatrix(cov);
136  CPose3D ellip_pose = base_pose;
137  ellip_pose.x(p_global.x);
138  ellip_pose.y(p_global.y);
139  ellip_pose.z(p_global.z);
140 
141  gl_ellip->setPose(ellip_pose);
142  scene.insert(gl_ellip);
143  }
144  }
145  }
146 };
147 
148 /** Landmark renderer for: landmark_rendering_as_pose_constraints */
150 {
151  template <class RBA>
152  static void render(
153  const RBA &rba,
154  const srba::TKeyFrameID root_keyframe,
155  const typename RBA::frameid2pose_map_t &spantree,
156  const typename RBA::TOpenGLRepresentationOptions &options,
158  {
159  MRPT_UNUSED_PARAM(options);
160  MRPT_UNUSED_PARAM(root_keyframe);
161  using namespace mrpt::math;
162 
163  mrpt::opengl::CSetOfLinesPtr gl_edges = mrpt::opengl::CSetOfLines::Create();
164  gl_edges->setLineWidth(1);
165  gl_edges->setColor(0,0,1);
166 
167  scene.insert(gl_edges);
168 
169  // For each KF: check all its "observations"
170  for (typename RBA::frameid2pose_map_t::const_iterator it=spantree.begin();it!=spantree.end();++it)
171  {
172  const TKeyFrameID kf_id = it->first;
173  const typename RBA::pose_flag_t & pf = it->second;
174 
175  const typename RBA::keyframe_info &kfi = rba.get_rba_state().keyframes[kf_id];
176 
177  for (size_t i=0;i<kfi.adjacent_k2f_edges.size();i++)
178  {
179  const typename RBA::k2f_edge_t * k2f = kfi.adjacent_k2f_edges[i];
180  const TKeyFrameID other_kf_id = k2f->feat_rel_pos->id_frame_base;
181  if (kf_id==other_kf_id)
182  continue; // It's not an constraint with ANOTHER keyframe
183 
184  // Is the other KF in the spanning tree?
185  typename RBA::frameid2pose_map_t::const_iterator other_it=spantree.find(other_kf_id);
186  if (other_it==spantree.end()) continue;
187 
188  const typename RBA::pose_flag_t & other_pf = other_it->second;
189 
190  // Add edge between the two KFs to represent the pose constraint:
191  mrpt::poses::CPose3D p1 = mrpt::poses::CPose3D(pf.pose); // Convert to 3D
192  mrpt::poses::CPose3D p2 = mrpt::poses::CPose3D(other_pf.pose);
193 
194  gl_edges->appendLine( p1.x(),p1.y(),p1.z()+0.10, p2.x(),p2.y(),p2.z()+0.10 );
195  }
196 
197  } // end for each KF
198  }
199 };
200 
201 /** Landmark renderer for: landmark_rendering_none */
203 {
204  template <class RBA>
205  static void render(
206  const RBA &rba,
207  const srba::TKeyFrameID root_keyframe,
208  const typename RBA::frameid2pose_map_t &spantree,
209  const typename RBA::TOpenGLRepresentationOptions &options,
211  {
212  MRPT_UNUSED_PARAM(rba);
213  MRPT_UNUSED_PARAM(root_keyframe);
214  MRPT_UNUSED_PARAM(spantree);
215  MRPT_UNUSED_PARAM(options);
216  MRPT_UNUSED_PARAM(scene);
217  // Nothing to render
218  }
219 };
220 
221 } } // end namespaces
static CEllipsoidPtr Create()
double DEG2RAD(const double x)
Degrees to radians.
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:32
static void render(const RBA &rba, const srba::TKeyFrameID root_keyframe, const typename RBA::frameid2pose_map_t &spantree, const typename RBA::TOpenGLRepresentationOptions &options, mrpt::opengl::CSetOfObjects &scene)
const Scalar * const_iterator
Definition: eigen_plugins.h:24
double z
X,Y,Z coordinates.
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
static CSetOfLinesPtr Create()
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArray.h:18
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:113
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
Definition: ops_matrices.h:135
static CText3DPtr Create()
#define DEG2RAD
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Render "fake graph-slam-like landmarks" as keyframe-to-keyframe constraints.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static void render(const RBA &rba, const srba::TKeyFrameID root_keyframe, const typename RBA::frameid2pose_map_t &spantree, const typename RBA::TOpenGLRepresentationOptions &options, mrpt::opengl::CSetOfObjects &scene)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
void insert(const CRenderizablePtr &newObject)
Insert a new object to the list.
renders glyphs filled with antialiased outlines
Definition: opengl_fonts.h:40
static void render(const RBA &rba, const srba::TKeyFrameID root_keyframe, const typename RBA::frameid2pose_map_t &spantree, const typename RBA::TOpenGLRepresentationOptions &options, mrpt::opengl::CSetOfObjects &scene)
A RGB color - floats in the range [0,1].
Definition: TColor.h:52
static CPointCloudPtr Create()
Lightweight 3D point.
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