GroundGrid.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
11 #include <mvsim/World.h>
12 #include "xml_utils.h"
13 
14 #include <mrpt/opengl/COpenGLScene.h>
15 #include <rapidxml.hpp>
16 
17 using namespace rapidxml;
18 using namespace mvsim;
19 using namespace std;
20 
21 GroundGrid::GroundGrid(World* parent, const rapidxml::xml_node<char>* root)
22  : WorldElementBase(parent),
23  m_is_floating(true),
24  m_x_min(-25.0),
25  m_x_max(25.0),
26  m_y_min(-25.0),
27  m_y_max(25.0),
28  m_interval(5.0),
29  m_color(0xe0, 0xe0, 0xe0, 0xff),
30  m_line_width(1.0)
31 {
32  // Create opengl object: in this class, we'll store most state data directly
33  // in the mrpt::opengl object.
34  loadConfigFrom(root);
35 }
36 
39 {
40  if (!root) return; // Assume defaults
41 
42  std::map<std::string, TParamEntry> params;
43  params["floating"] = TParamEntry("%bool", &m_is_floating);
44  params["floating_focus"] =
46  params["color"] = TParamEntry("%color", &m_color);
47  params["line_width"] = TParamEntry("%lf", &m_line_width);
48 
49  params["x_min"] = TParamEntry("%lf", &m_x_min);
50  params["x_max"] = TParamEntry("%lf", &m_x_max);
51  params["y_min"] = TParamEntry("%lf", &m_y_min);
52  params["y_max"] = TParamEntry("%lf", &m_y_max);
53  params["interval"] = TParamEntry("%lf", &m_interval);
54 
55  parse_xmlnode_children_as_param(*root, params);
56 
57  // If a vehicle name is given, setting "is_floating=true" by the user is
58  // optional:
59  if (!m_float_center_at_vehicle_name.empty()) m_is_floating = true;
60 }
61 
62 void GroundGrid::gui_update(mrpt::opengl::COpenGLScene& scene)
63 {
64  using namespace mrpt::math;
65 
66  // 1st call OR gridmap changed?
67  if (!m_gl_groundgrid)
68  {
69  m_gl_groundgrid = mrpt::opengl::CGridPlaneXY::Create();
70  m_gl_groundgrid->setPlaneLimits(m_x_min, m_x_max, m_y_min, m_y_max);
71  m_gl_groundgrid->setGridFrequency(m_interval);
72  m_gl_groundgrid->setColor(TColorf(m_color));
73  m_gl_groundgrid->setLineWidth(m_line_width);
74 
76  }
77 
78  // Update:
79  mrpt::math::TPoint3D center_offset(.0, .0, .0);
80  if (m_is_floating)
81  {
82  // Centered at a vehicle:
84  // Look for the vehicle by its name:
85  World::TListVehicles::const_iterator it_veh =
87  // not found -> error:
88  if (!m_float_center_at_vehicle_name.empty() && it_veh == vehs.end())
89  throw std::runtime_error(
90  mrpt::format(
91  "[GroundGrid] *ERROR* Cannot find vehicle named '%s' to "
92  "focus on.",
94 
95  // If the user didn't specify any name, assume it's the first vehicle,
96  // or ignore it if none exists:
97  if (it_veh == vehs.end()) it_veh = vehs.begin();
98 
99  if (it_veh != vehs.end())
100  {
101  const mrpt::math::TPose3D& pose = it_veh->second->getPose();
102  center_offset.x = pose.x;
103  center_offset.y = pose.y;
104  }
105  }
106 
107  // "Discretize" offset for a better visual impact:
108  ASSERT_(m_interval > .0);
109  center_offset.x = m_interval *
110  ::floor(std::abs(center_offset.x) / m_interval) *
111  (center_offset.x < 0 ? -1. : 1.);
112  center_offset.y = m_interval *
113  ::floor(std::abs(center_offset.y) / m_interval) *
114  (center_offset.y < 0 ? -1. : 1.);
115  m_gl_groundgrid->setLocation(center_offset);
116 }
This file contains rapidxml parser and DOM implementation.
virtual ~GroundGrid()
Definition: GroundGrid.cpp:37
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root)
See docs in base class.
Definition: GroundGrid.cpp:38
std::multimap< std::string, VehicleBase * > TListVehicles
Definition: World.h:167
std::string m_float_center_at_vehicle_name
Definition: GroundGrid.h:43
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > &params, const char *function_name_context="")
Definition: xml_utils.cpp:196
#define SCENE_INSERT_Z_ORDER(_SCENE, _ZORDER_INDEX, _OBJ_TO_INSERT)
Definition: VisualObject.h:37
virtual void gui_update(mrpt::opengl::COpenGLScene &scene)
See docs in base class.
Definition: GroundGrid.cpp:62
const TListVehicles & getListOfVehicles() const
Definition: World.h:181
mrpt::opengl::CGridPlaneXY::Ptr m_gl_groundgrid
Definition: GroundGrid.h:48
double m_line_width
Definition: GroundGrid.h:46


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40