Main MRPT website > C++ reference
MRPT logo
export_opengl.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 
14 #include <mrpt/opengl/CDisk.h>
16 
17 #include "export_opengl_landmark_renderers.h" // Declare LandmarkRendererBase<> specializations
18 
19 namespace mrpt { namespace srba {
20 //
21 // RbaEngine<>::build_opengl_representation
22 //
23 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
25  const srba::TKeyFrameID root_keyframe,
26  const TOpenGLRepresentationOptions &options,
27  mrpt::opengl::CSetOfObjectsPtr out_scene,
28  mrpt::opengl::CSetOfObjectsPtr out_root_tree
29  ) const
30 {
31  using namespace std;
32  using namespace mrpt::utils;
34 
35  // Generate 3D scene:
36  // ------------------------------
37  if (out_scene)
38  {
39  out_scene->clear();
40 
41  if (!rba_state.keyframes.empty())
42  {
43  // Use a spanning tree to estimate the global pose of every node
44  // starting (root) at the given keyframe:
45 
46  frameid2pose_map_t spantree;
47  create_complete_spanning_tree(root_keyframe,spantree, options.span_tree_max_depth );
48 
49  // For each key-frame, add a 3D corner:
50  for (typename frameid2pose_map_t::const_iterator itP = spantree.begin();itP!=spantree.end();++itP)
51  {
52  if (root_keyframe==itP->first) continue;
53 
54  const CPose3D p = itP->second.pose;
55 
56  mrpt::opengl::CSetOfObjectsPtr o = mrpt::opengl::stock_objects::CornerXYZSimple(0.75,2.0);
57  o->setPose(p);
58  o->setName( mrpt::format("%d",int(itP->first)).c_str() );
59  o->enableShowName();
60  out_scene->insert(o);
61  }
62  // And a bigger one for the root:
63  {
64  mrpt::opengl::CSetOfObjectsPtr o = mrpt::opengl::stock_objects::CornerXYZSimple(1.0,4.0);
65  //o->setPose(...); // At the origin
66  out_scene->insert(o);
67  }
68 
69  // Draw all edges between frames:
70  mrpt::opengl::CSetOfLinesPtr gl_edges = mrpt::opengl::CSetOfLines::Create();
71  gl_edges->setColor(1,0,1); // Magenta, in order to not confuse them with the standard lines of a grid plane
72 #ifdef SRBA_WORKAROUND_MSVC9_DEQUE_BUG
73  for (typename rba_problem_state_t::k2k_edges_deque_t::const_iterator itEdge2 = rba_state.k2k_edges.begin();itEdge2!=rba_state.k2k_edges.end();++itEdge2)
74  {
75  const k2k_edge_t * itEdge = itEdge2->pointer();
76 #else
77  for (typename rba_problem_state_t::k2k_edges_deque_t::const_iterator itEdge = rba_state.k2k_edges.begin();itEdge!=rba_state.k2k_edges.end();++itEdge)
78  {
79 #endif
80  CPose3D p1;
81  if (itEdge->from!=root_keyframe)
82  {
83  typename frameid2pose_map_t::const_iterator itN1 = spantree.find(itEdge->from);
84  if(itN1==spantree.end())
85  continue;
86  p1 = itN1->second.pose;
87  }
88  CPose3D p2;
89  if (itEdge->to!=root_keyframe)
90  {
91  typename frameid2pose_map_t::const_iterator itN2 = spantree.find(itEdge->to);
92  if(itN2==spantree.end())
93  continue;
94  p2 = itN2->second.pose;
95  }
96  gl_edges->appendLine(p1.x(),p1.y(),p1.z(), p2.x(),p2.y(),p2.z());
97  }
98  out_scene->insert(gl_edges);
99 
100  // Render landmarks:
101  LandmarkRendererBase<typename LM_TYPE::render_mode_t>::render(*this,root_keyframe,spantree, options,*out_scene);
102 
103  } // end if graph is not empty
104 
105  } // end of "out_scene"
106 
107 
108  // Generate 2D tree:
109  // ------------------------------
110  if (out_root_tree)
111  {
112  out_root_tree->clear();
113 
114  const float NODE_RADIUS = 1;
115  const float ROW_HEIGHT = 4*NODE_RADIUS;
116  const float COL_WIDTH = 3*NODE_RADIUS;
117 
118  typename rba_problem_state_t::TSpanningTree::next_edge_maps_t::const_iterator it_st_root = rba_state.spanning_tree.sym.next_edge.find(root_keyframe);
119  ASSERT_(it_st_root != rba_state.spanning_tree.sym.next_edge.end())
120 
121  const std::map<TKeyFrameID,TSpanTreeEntry> & st_root = it_st_root->second;
122 
123  std::map<TKeyFrameID,topo_dist_t> children_depths;
124  std::map<topo_dist_t,std::vector<TKeyFrameID> > children_by_depth;
125 
126  // roots are not in spanning trees ("spanning_tree.sym.next_edge")
127  children_depths[root_keyframe]=0;
128  children_by_depth[0].push_back(root_keyframe);
129 
130  // Go thru the tree to realize of its size:
131  //size_t max_nodes_per_level = 1;
132  size_t max_depth = 0;
133  for (std::map<TKeyFrameID,TSpanTreeEntry>::const_iterator it=st_root.begin();it!=st_root.end();++it)
134  {
135  const topo_dist_t depth = it->second.distance;
136  children_depths[it->first] = depth;
137  mrpt::utils::keep_max(max_depth, depth);
138 
139  std::vector<TKeyFrameID> & v = children_by_depth[depth];
140  v.push_back(it->first);
141  //mrpt::utils::keep_max(max_nodes_per_level, v.size());
142  }
143 
144  // Generate (x,y) coords for each node:
145  std::map<TKeyFrameID, mrpt::math::TPoint3Df> node_coords;
146 
147  for (size_t d=0;d<=max_depth;d++)
148  {
149  const float y = -(d*ROW_HEIGHT);
150 
151  std::vector<TKeyFrameID> & v = children_by_depth[d];
152  const float row_width = v.size()*COL_WIDTH;
153 
154  for (size_t i=0;i<v.size();i++)
155  {
156  const float x = - 0.5f*row_width + COL_WIDTH*i;
157  node_coords[v[i]] = mrpt::math::TPoint3Df(x,y,0);
158  }
159  }
160 
161  // Draw edges in tree:
162  mrpt::opengl::CSetOfLinesPtr gl_edges = mrpt::opengl::CSetOfLines::Create();
163  gl_edges->setLineWidth(1.5);
164  gl_edges->setColor_u8(mrpt::utils::TColor(0xff,0xff,0x00));
165  out_root_tree->insert(gl_edges);
166 
167  typename rba_problem_state_t::TSpanningTree::all_edges_maps_t::const_iterator it_edges_from_root = rba_state.spanning_tree.sym.all_edges.find(root_keyframe);
168  ASSERT_(it_edges_from_root != rba_state.spanning_tree.sym.all_edges.end())
169 
170  const std::map<TKeyFrameID, typename rba_problem_state_t::k2k_edge_vector_t> edges_from_root = it_edges_from_root->second;
171 
172  for (typename std::map<TKeyFrameID, typename rba_problem_state_t::k2k_edge_vector_t>::const_iterator it=edges_from_root.begin();it!=edges_from_root.end();++it)
173  {
174  const typename rba_problem_state_t::k2k_edge_vector_t & edges_to_j = it->second;
175  for (size_t k=0;k<edges_to_j.size();k++)
176  {
177  const TKeyFrameID id1 = edges_to_j[k]->from;
178  const TKeyFrameID id2 = edges_to_j[k]->to;
179 
180  gl_edges->appendLine(node_coords[id1], node_coords[id2]);
181  }
182  }
183 
184  // And on the top, draw the nodes:
185  for (std::map<TKeyFrameID, mrpt::math::TPoint3Df>::const_iterator it=node_coords.begin();it!=node_coords.end();++it)
186  gl_aux_draw_node(*out_root_tree, mrpt::format("%u", static_cast<unsigned int>(it->first) ), it->second.x, it->second.y);
187 
188  } // end render "2D tree"
189 
190 }
191 
192 
193 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
194 void RbaEngine<KF2KF_POSE_TYPE,LM_TYPE,OBS_TYPE,RBA_OPTIONS>::gl_aux_draw_node(mrpt::opengl::CSetOfObjects &soo, const std::string &label, const float x, const float y) const
195 {
196  {
197  mrpt::opengl::CDiskPtr obj = mrpt::opengl::CDisk::Create();
198  obj->setDiskRadius(1,0);
199  obj->setColor_u8(mrpt::utils::TColor(0x00,0x00,0x00, 0xa0));
200  obj->setLocation(x,y,0);
201  soo.insert(obj);
202  }
203 
204  {
205  mrpt::opengl::CText3DPtr obj = mrpt::opengl::CText3D::Create(label);
206  obj->setFont("sans");
207  obj->setColor_u8(mrpt::utils::TColor(0xff,0xff,0xff));
208  obj->setScale(0.9);
209  obj->setLocation(x-0.5,y-0.5,0);
210  soo.insert(obj);
211  }
212 
213 }
214 
215 } } // end namespaces
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:32
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
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
static CSetOfLinesPtr Create()
static CDiskPtr Create()
Lightweight 3D point (float version).
A RGB color - 8bit.
Definition: TColor.h:25
static CText3DPtr Create()
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
CSetOfObjectsPtr OPENGL_IMPEXP CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
Returns three arrows representing a X,Y,Z 3D corner (just thick lines instead of complex arrows for f...
size_t span_tree_max_depth
Maximum spanning tree depth for reconstructing relative poses (default=-1 : infinity) ...
Definition: RbaEngine.h:231
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
kf2kf_pose_traits_t::frameid2pose_map_t frameid2pose_map_t
Definition: RbaEngine.h:95
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.
void build_opengl_representation(const srba::TKeyFrameID root_keyframe, const TOpenGLRepresentationOptions &options, mrpt::opengl::CSetOfObjectsPtr out_scene, mrpt::opengl::CSetOfObjectsPtr out_root_tree=mrpt::opengl::CSetOfObjectsPtr()) const
Build an opengl representation of the current state of this RBA problem One of different representati...
Definition: export_opengl.h:24
#define ASSERT_(f)
void gl_aux_draw_node(mrpt::opengl::CSetOfObjects &soo, const std::string &label, const float x, const float y) const
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
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