Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <mvsim/WorldElements/GroundGrid.h>
00011 #include <mvsim/World.h>
00012 #include "xml_utils.h"
00013
00014 #include <mrpt/opengl/COpenGLScene.h>
00015 #include <rapidxml.hpp>
00016
00017 using namespace rapidxml;
00018 using namespace mvsim;
00019 using namespace std;
00020
00021 GroundGrid::GroundGrid(World* parent, const rapidxml::xml_node<char>* root)
00022 : WorldElementBase(parent),
00023 m_is_floating(true),
00024 m_x_min(-25.0),
00025 m_x_max(25.0),
00026 m_y_min(-25.0),
00027 m_y_max(25.0),
00028 m_interval(5.0),
00029 m_color(0xe0, 0xe0, 0xe0, 0xff),
00030 m_line_width(1.0)
00031 {
00032
00033
00034 loadConfigFrom(root);
00035 }
00036
00037 GroundGrid::~GroundGrid() {}
00038 void GroundGrid::loadConfigFrom(const rapidxml::xml_node<char>* root)
00039 {
00040 if (!root) return;
00041
00042 std::map<std::string, TParamEntry> params;
00043 params["floating"] = TParamEntry("%bool", &m_is_floating);
00044 params["floating_focus"] =
00045 TParamEntry("%s", &m_float_center_at_vehicle_name);
00046 params["color"] = TParamEntry("%color", &m_color);
00047 params["line_width"] = TParamEntry("%lf", &m_line_width);
00048
00049 params["x_min"] = TParamEntry("%lf", &m_x_min);
00050 params["x_max"] = TParamEntry("%lf", &m_x_max);
00051 params["y_min"] = TParamEntry("%lf", &m_y_min);
00052 params["y_max"] = TParamEntry("%lf", &m_y_max);
00053 params["interval"] = TParamEntry("%lf", &m_interval);
00054
00055 parse_xmlnode_children_as_param(*root, params);
00056
00057
00058
00059 if (!m_float_center_at_vehicle_name.empty()) m_is_floating = true;
00060 }
00061
00062 void GroundGrid::gui_update(mrpt::opengl::COpenGLScene& scene)
00063 {
00064 using namespace mrpt::math;
00065
00066
00067 if (!m_gl_groundgrid)
00068 {
00069 m_gl_groundgrid =
00070 mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>();
00071 m_gl_groundgrid->setPlaneLimits(m_x_min, m_x_max, m_y_min, m_y_max);
00072 m_gl_groundgrid->setGridFrequency(m_interval);
00073 m_gl_groundgrid->setColor(mrpt::utils::TColorf(m_color));
00074 m_gl_groundgrid->setLineWidth(m_line_width);
00075
00076 SCENE_INSERT_Z_ORDER(scene, 0, m_gl_groundgrid);
00077 }
00078
00079
00080 mrpt::math::TPoint3D center_offset(.0, .0, .0);
00081 if (m_is_floating)
00082 {
00083
00084 const World::TListVehicles& vehs = m_world->getListOfVehicles();
00085
00086 World::TListVehicles::const_iterator it_veh =
00087 vehs.find(m_float_center_at_vehicle_name);
00088
00089 if (!m_float_center_at_vehicle_name.empty() && it_veh == vehs.end())
00090 throw std::runtime_error(
00091 mrpt::format(
00092 "[GroundGrid] *ERROR* Cannot find vehicle named '%s' to "
00093 "focus on.",
00094 m_float_center_at_vehicle_name.c_str()));
00095
00096
00097
00098 if (it_veh == vehs.end()) it_veh = vehs.begin();
00099
00100 if (it_veh != vehs.end())
00101 {
00102 const mrpt::math::TPose3D& pose = it_veh->second->getPose();
00103 center_offset.x = pose.x;
00104 center_offset.y = pose.y;
00105 }
00106 }
00107
00108
00109 ASSERT_(m_interval > .0)
00110 center_offset.x = m_interval *
00111 ::floor(std::abs(center_offset.x) / m_interval) *
00112 (center_offset.x < 0 ? -1. : 1.);
00113 center_offset.y = m_interval *
00114 ::floor(std::abs(center_offset.y) / m_interval) *
00115 (center_offset.y < 0 ? -1. : 1.);
00116 m_gl_groundgrid->setLocation(center_offset);
00117 }