GroundGrid.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mvsim/World.h>
12 #include "xml_utils.h"
13 
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 
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 
63  mrpt::opengl::COpenGLScene& scene, bool childrenOnly)
64 {
65  using namespace mrpt::math;
66 
67  // 1st call OR gridmap changed?
68  if (!m_gl_groundgrid)
69  {
71  m_gl_groundgrid->setPlaneLimits(m_x_min, m_x_max, m_y_min, m_y_max);
72  m_gl_groundgrid->setGridFrequency(m_interval);
73  m_gl_groundgrid->setColor_u8(m_color);
74  m_gl_groundgrid->setLineWidth(m_line_width);
75 
76  scene.insert(m_gl_groundgrid);
77  }
78 
79  // Update:
80  mrpt::math::TPoint3D center_offset(.0, .0, .0);
81  if (m_is_floating)
82  {
83  // Centered at a vehicle:
85  // Look for the vehicle by its name:
86  World::VehicleList::const_iterator it_veh =
88  // not found -> error:
89  if (!m_float_center_at_vehicle_name.empty() && it_veh == vehs.end())
90  throw std::runtime_error(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
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions &params, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
Definition: xml_utils.cpp:179
const VehicleList & getListOfVehicles() const
Definition: World.h:195
std::multimap< std::string, VehicleBase::Ptr > VehicleList
Definition: World.h:173
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root) override
Definition: GroundGrid.cpp:38
void insert(const CRenderizablePtr &newObject, const std::string &viewportName=std::string("main"))
std::string m_float_center_at_vehicle_name
Definition: GroundGrid.h:34
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
static CGridPlaneXYPtr Create(float xMin, float xMax, float yMin, float yMax, float z=0, float frequency=1, float lineWidth=1.3f, bool antiAliasing=true)
#define ASSERT_(f)
GLfloat * params
virtual void internalGuiUpdate(mrpt::opengl::COpenGLScene &scene, bool childrenOnly) override
Definition: GroundGrid.cpp:62
mrpt::opengl::CGridPlaneXY::Ptr m_gl_groundgrid
Definition: GroundGrid.h:39
mrpt::img::TColor m_color
Definition: GroundGrid.h:36
double m_line_width
Definition: GroundGrid.h:37


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51