Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef opengl_graph_tools_impl_H
00029 #define opengl_graph_tools_impl_H
00030
00031 namespace mrpt
00032 {
00033 namespace opengl
00034 {
00035 namespace graph_tools
00036 {
00037 template<class GRAPH_T>
00038 CSetOfObjectsPtr graph_visualize(
00039 const GRAPH_T &g,
00040 const mrpt::utils::TParametersDouble &extra_params)
00041 {
00042 MRPT_TRY_START
00043
00044
00045 typedef typename GRAPH_T::constraint_t constraint_t;
00046
00047 const bool is_3D_graph = constraint_t::is_3D();
00048
00049 CSetOfObjectsPtr ret = CSetOfObjects::Create();
00050
00051 const bool show_ID_labels = 0!=extra_params.getWithDefaultVal("show_ID_labels", 0);
00052 const bool show_ground_grid = 0!=extra_params.getWithDefaultVal("show_ground_grid", 1);
00053 const bool show_edges = 0!=extra_params.getWithDefaultVal("show_edges", 1);
00054 const bool show_node_corners = 0!=extra_params.getWithDefaultVal("show_node_corners", 1);
00055 const double nodes_point_size = extra_params.getWithDefaultVal("nodes_point_size", 0. );
00056 const double nodes_corner_scale = extra_params.getWithDefaultVal("nodes_corner_scale", 0.7 );
00057 const unsigned int nodes_point_color = extra_params.getWithDefaultVal("nodes_point_color", (unsigned int)0xA0A0A0 );
00058 const unsigned int edge_color = extra_params.getWithDefaultVal("edge_color", (unsigned int)0x400000FF );
00059 const double edge_width = extra_params.getWithDefaultVal("edge_width", 2. );
00060
00061 if (show_ground_grid)
00062 {
00063
00064 TPoint3D BB_min(-10.,-10.,0.), BB_max(10.,10.,0.);
00065
00066 for (typename GRAPH_T::global_poses_t::const_iterator itNod = g.nodes.begin();itNod!=g.nodes.end();++itNod)
00067 {
00068 const CPose3D p = CPose3D(itNod->second);
00069
00070 keep_min( BB_min.x, p.x() );
00071 keep_min( BB_min.y, p.y() );
00072 keep_min( BB_min.z, p.z() );
00073
00074 keep_max( BB_max.x, p.x() );
00075 keep_max( BB_max.y, p.y() );
00076 keep_max( BB_max.z, p.z() );
00077 }
00078
00079
00080 const double grid_frequency = 5.0;
00081 CGridPlaneXYPtr grid = CGridPlaneXY::Create(BB_min.x, BB_max.x, BB_min.y, BB_max.y, BB_min.z, grid_frequency);
00082 grid->setColor(0.3,0.3,0.3);
00083 ret->insert( grid );
00084 }
00085
00086
00087 if (nodes_point_size!=0)
00088 {
00089 ASSERT_(nodes_point_size>=0);
00090
00091 CPointCloudPtr pnts = CPointCloud::Create();
00092 pnts->setColor( TColorf(TColor(nodes_point_color)) );
00093 pnts->setPointSize(nodes_point_size);
00094
00095
00096 for (typename GRAPH_T::global_poses_t::const_iterator itNod = g.nodes.begin();itNod!=g.nodes.end();++itNod)
00097 {
00098 const CPose3D p = CPose3D(itNod->second);
00099 pnts->insertPoint(p.x(),p.y(), p.z() );
00100 }
00101
00102 pnts->enablePointSmooth();
00103
00104 ret->insert(pnts);
00105 }
00106
00107
00108 if (show_node_corners || show_ID_labels)
00109 {
00110 for (typename GRAPH_T::global_poses_t::const_iterator itNod = g.nodes.begin();itNod!=g.nodes.end();++itNod)
00111 {
00112 const CPose3D p = CPose3D(itNod->second);
00113 CSetOfObjectsPtr gl_corner = show_node_corners ?
00114 (is_3D_graph ? stock_objects::CornerXYZSimple(nodes_corner_scale, 1.0 ) : stock_objects::CornerXYSimple(nodes_corner_scale, 1.0 ))
00115 : CSetOfObjects::Create();
00116 gl_corner->setPose( p );
00117 if (show_ID_labels)
00118 {
00119 gl_corner->setName(format("%u",static_cast<unsigned int>(itNod->first) ));
00120 gl_corner->enableShowName();
00121 }
00122 ret->insert( gl_corner );
00123 }
00124 }
00125
00126 if (show_edges)
00127 {
00128 CSetOfLinesPtr gl_edges = CSetOfLines::Create();
00129 const TColor col8bit(edge_color & 0xffffff);
00130 const uint8_t col_alpha = edge_color >> 24;
00131
00132 gl_edges->setColor( col8bit.R*(1./255), col8bit.G*(1./255), col8bit.B*(1./255), col_alpha*(1./255) );
00133 gl_edges->setLineWidth( edge_width );
00134
00135 for (typename GRAPH_T::const_iterator itEd = g.begin();itEd!=g.end();++itEd)
00136 {
00137 const TNodeID id1 = itEd->first.first;
00138 const TNodeID id2 = itEd->first.second;
00139
00140
00141 typename GRAPH_T::global_poses_t::const_iterator itNod1 = g.nodes.find(id1);
00142 typename GRAPH_T::global_poses_t::const_iterator itNod2 = g.nodes.find(id2);
00143 if (itNod1!=g.nodes.end() && itNod2!=g.nodes.end())
00144 {
00145 const CPose3D p1 = CPose3D(itNod1->second);
00146 const CPose3D p2 = CPose3D(itNod2->second);
00147 gl_edges->appendLine( TPoint3D(p1.x(),p1.y(),p1.z()), TPoint3D(p2.x(),p2.y(),p2.z()) );
00148 }
00149 }
00150 ret->insert( gl_edges );
00151
00152 }
00153
00154 return ret;
00155
00156 MRPT_TRY_END
00157
00158 }
00159
00160 }
00161 }
00162 }
00163
00164 #endif