lanelet2_map_server v1.2.3
Loading...
Searching...
No Matches
lanelet2_display.cpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
5
6#include <cstdint>
7#include <memory>
8#include <string>
9
10#include <OgreSceneManager.h>
11#include <OgreSceneNode.h>
12
13#include "rviz_common/display_context.hpp"
14#include "rviz_common/frame_manager_iface.hpp"
15#include "rviz_common/interaction/selection_manager.hpp"
16#include "rviz_common/properties/parse_color.hpp"
17#include "rviz_common/properties/property.hpp"
18
19using rviz_common::properties::BoolProperty;
20using rviz_common::properties::ColorProperty;
21using rviz_common::properties::FloatProperty;
22using rviz_common::properties::qtToOgre;
23using rviz_common::properties::StringProperty;
24
25namespace lanelet2_rviz_display {
26
28 // RViz properties are parent-owned by Qt/RViz once constructed with this display as parent.
29 // NOLINTBEGIN(cppcoreguidelines-owning-memory)
30 // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
32 new StringProperty(QString::fromStdString("Name of lanelet2_map_server"), QString::fromStdString("lanelet2_map_server"),
33 QString::fromStdString("Global name of lanelet2_map_server node"), this, SLOT(updateServerName()));
34
36 new FloatProperty("Alpha", 1.0F, "The amount of transparency to apply to the Map.", this, SLOT(updateColor()), this);
37 alpha_property_->setMin(0.0F);
38 alpha_property_->setMax(1.0F);
39
41 new BoolProperty("Show Map in 3D", true, "Toggles wether to display the lanelet map with or without its z coordinates.",
42 this, SLOT(update3D()));
43
45 new BoolProperty("Visualize Lanelet-Linestrings", true, "Activate the visualization of Lanelet-Linestrings.", this,
47
48 ll_left_col_property_ = new ColorProperty("LL Color Left", Qt::white, "Color of left Lanelet-Linestring.",
50
51 ll_right_col_property_ = new ColorProperty("LL Color Right", Qt::white, "Color of right Lanelet-Linestring.",
53
54 linestring_width_property_ = new FloatProperty("Linestring Width", 0.1F, "The width, in meters, of each linestring.",
56 linestring_width_property_->setMin(0.01F);
57
59 new BoolProperty("Visualize Lanelet-Separators", false, "Activate the visualization of Lanelet-Separators.", this,
61
62 separators_col_property_ = new ColorProperty("Separators Color", QColor{25, 25, 230}, "Color of Lanelet Separators.",
64
65 separators_width_property_ = new FloatProperty("Linestring Width", 0.2F, "The width, in meters, of each linestring.",
67 separators_width_property_->setMin(0.01F);
68
69 viz_stop_line_property_ = new BoolProperty("Visualize Stop lines", true, "Activate the visualization of Stop-Lines.", this,
71
72 stop_line_col_property_ = new ColorProperty("Stop Line Color", QColor{255, 25, 25}, "Color of Stop-Lines.",
74
75 stop_line_width_property_ = new FloatProperty("Stop Line Width", 0.2F, "The width, in meters, of each stop line.",
77 stop_line_width_property_->setMin(0.01F);
78
80 new BoolProperty("Visualize Traffic Lights", true, "Activate the visualization of Traffic-Lights.", this,
82
83 traffic_light_col_property_ = new ColorProperty("Traffic Light Color", QColor{102, 102, 102}, "Color of Traffic-Lights.",
85
87 new FloatProperty("Traffic Light Height", 3.0F, "The height, in meters, of each traffic light.",
89 traffic_light_height_property_->setMin(0.01F);
90
92 new BoolProperty("Visualize Areas", true, "Activate the visualization of Areas.", this, SLOT(updateAreaRendering()));
93
95 new ColorProperty("Area Color", QColor{230, 127, 25}, "Color of Areas.", viz_area_property_, SLOT(updateColor()), this);
96
98 new FloatProperty("Area Width", 0.3F, "The width, in meters, of each area.", viz_area_property_, SLOT(updateStyle()), this);
99 area_width_property_->setMin(0.01F);
100
101 fill_area_property_ = new BoolProperty("Fill Areas", false, "Toggles wether to fill the areas with color or not.",
102 viz_area_property_, SLOT(updateStyle()), this);
103
105 new BoolProperty("Visualize Parking", true, "Activate the visualization of Parking.", this, SLOT(updateParkingRendering()));
106
107 parking_col_property_ = new ColorProperty("Parking Color", QColor{0, 179, 76}, "Color of Parking.", viz_parking_property_,
108 SLOT(updateColor()), this);
109
110 parking_width_property_ = new FloatProperty("Parking Width", 0.3F, "The width, in meters, of each parking.",
111 viz_parking_property_, SLOT(updateStyle()), this);
112 parking_width_property_->setMin(0.01F);
113
114 fill_parking_property_ = new BoolProperty("Fill Parking", true, "Toggles wether to fill the parking with color or not.",
115 viz_parking_property_, SLOT(updateStyle()), this);
116
117 // Lane fills (road surface)
118 viz_lane_fill_property_ = new BoolProperty("Fill Lanelets (Road)", true, "Render road surface as filled polygons.", this,
120 lane_fill_col_property_ = new ColorProperty("Road Color", QColor{56, 56, 56}, "Color of road fill.", viz_lane_fill_property_,
121 SLOT(updateColor()), this);
122
123 // Pedestrian features
124 viz_sidewalk_property_ = new BoolProperty("Visualize Sidewalks", true, "Render sidewalk areas as filled polygons.", this,
126 sidewalk_col_property_ = new ColorProperty("Sidewalk Color", QColor{191, 191, 191}, "Color of sidewalks.",
127 viz_sidewalk_property_, SLOT(updateColor()), this);
128
129 viz_crosswalk_property_ = new BoolProperty("Visualize Crosswalks", true, "Render crosswalk areas as filled polygons.", this,
131 crosswalk_col_property_ = new ColorProperty("Crosswalk Color", QColor{255, 255, 255}, "Color of crosswalks.",
132 viz_crosswalk_property_, SLOT(updateColor()), this);
133
134 viz_id_property_ = new BoolProperty("Visualize Lanelet-IDs", false, "Activate the visualization of Lanelet-IDs.", this,
135 SLOT(updateIdRendering()));
136
138 new ColorProperty("ID Color", Qt::white, "Color of Lanelet-IDs.", viz_id_property_, SLOT(updateColor()), this);
139
141 new FloatProperty("Character Height", 1.0F, "The height of each character.", viz_id_property_, SLOT(updateStyle()), this);
142 // NOLINTEND(cppcoreguidelines-owning-memory)
143}
144
146
147void Lanelet2Display::initializeMapInterface(rclcpp::Node& parent_node) {
148 std::string name = ll2_server_name_property_->getStdString();
149 if (!name.empty()) {
150 if (name[0] != '/') {
151 name = '/' + name;
152 }
153 lanelet2_map_interface_ = std::make_unique<Lanelet2MapInterface>(parent_node, name);
154 }
155}
156
158 auto nodeAbstraction = context_->getRosNodeAbstraction().lock();
159 rviz_node_ = nodeAbstraction->get_raw_node();
161}
162
163void Lanelet2Display::update(float dt, float ros_dt) {
164 if (lanelet2_map_interface_->map_loaded_) {
165 if (!viz_init_) {
167 lanelet2_map_interface_->update_pending_ = false;
168 }
169
170 if (lanelet2_map_interface_->update_pending_) {
172 }
173
174 if (viz_init_) {
175 Q_UNUSED(dt);
176 Q_UNUSED(ros_dt);
177
178 Ogre::Vector3 position;
179 Ogre::Quaternion orientation;
180 if (context_->getFrameManager()->getTransform(lanelet2_map_interface_->map_frame_id_, position, orientation)) {
181 scene_node_->setPosition(position);
182 scene_node_->setOrientation(orientation);
183 setTransformOk();
184 } else {
185 setMissingTransformToFixedFrame(lanelet2_map_interface_->map_frame_id_);
186 map_->getSceneNode()->setVisible(false);
187 }
188 }
189 }
190}
191
197
199 map_ = std::make_unique<rviz_rendering::Lanelet2Map>(scene_manager_, scene_node_, rendering_options_,
200 lanelet2_map_interface_->getMapPtr());
201 return true;
202}
203
205 if (viz_init_) {
206 map_->updateMap(rendering_options_, lanelet2_map_interface_->getMapPtr());
207 lanelet2_map_interface_->update_pending_ = false;
208 }
209}
210
212 if (viz_init_) {
213 map_->updateVisibility(rendering_options_);
214 }
215}
216
224
227 for (uint16_t i = 0; i < viz_separators_property_->numChildren(); i++) {
229 }
231}
232
235 for (uint16_t i = 0; i < viz_stop_line_property_->numChildren(); i++) {
236 viz_stop_line_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderStopLines);
237 }
239}
240
248
251 for (uint16_t i = 0; i < viz_area_property_->numChildren(); i++) {
252 viz_area_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderAreas);
253 }
255}
256
259 for (uint16_t i = 0; i < viz_parking_property_->numChildren(); i++) {
260 viz_parking_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderParking);
261 }
263}
264
267 for (uint16_t i = 0; i < viz_lane_fill_property_->numChildren(); i++) {
268 viz_lane_fill_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderLaneletFills);
269 }
271}
272
275 for (uint16_t i = 0; i < viz_sidewalk_property_->numChildren(); i++) {
276 viz_sidewalk_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderSidewalks);
277 }
279}
280
283 for (uint16_t i = 0; i < viz_crosswalk_property_->numChildren(); i++) {
284 viz_crosswalk_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderCrosswalks);
285 }
287}
288
291 for (uint16_t i = 0; i < viz_id_property_->numChildren(); i++) {
292 viz_id_property_->childAtUnchecked(i)->setHidden(!rendering_options_.renderLaneletIds);
293 }
295}
296
298 // Linestrings
299 QColor color_left = ll_left_col_property_->getColor();
300 QColor color_right = ll_right_col_property_->getColor();
301 color_left.setAlphaF(alpha_property_->getFloat());
302 color_right.setAlphaF(alpha_property_->getFloat());
303 rendering_options_.colorLeft = qtToOgre(color_left);
304 rendering_options_.colorRight = qtToOgre(color_right);
305
306 // Separators
307 QColor color_sep = separators_col_property_->getColor();
308 color_sep.setAlphaF(alpha_property_->getFloat());
309 rendering_options_.colorSeperator = qtToOgre(color_sep);
310
311 // Traffic lights
312 QColor color_tl = traffic_light_col_property_->getColor();
313 color_tl.setAlphaF(alpha_property_->getFloat());
314 rendering_options_.colorTrafficLight = qtToOgre(color_tl);
315
316 // Stop lines
317 QColor color_sl = stop_line_col_property_->getColor();
318 color_sl.setAlphaF(alpha_property_->getFloat());
319 rendering_options_.colorStopLine = qtToOgre(color_sl);
320
321 // Areas
322 QColor color_area = area_col_property_->getColor();
323 color_area.setAlphaF(alpha_property_->getFloat());
324 rendering_options_.colorArea = qtToOgre(color_area);
325
326 // Parking
327 QColor color_parking = parking_col_property_->getColor();
328 color_parking.setAlphaF(alpha_property_->getFloat());
329 rendering_options_.colorParking = qtToOgre(color_parking);
330
331 // Lane fill (road)
332 QColor color_lane_fill = lane_fill_col_property_->getColor();
333 color_lane_fill.setAlphaF(alpha_property_->getFloat());
334 rendering_options_.colorLaneFill = qtToOgre(color_lane_fill);
335
336 // Sidewalk
337 QColor color_sidewalk = sidewalk_col_property_->getColor();
338 color_sidewalk.setAlphaF(alpha_property_->getFloat());
339 rendering_options_.colorSidewalk = qtToOgre(color_sidewalk);
340
341 // Crosswalk
342 QColor color_crosswalk = crosswalk_col_property_->getColor();
343 color_crosswalk.setAlphaF(alpha_property_->getFloat());
344 rendering_options_.colorCrosswalk = qtToOgre(color_crosswalk);
345
346 // IDs
347 QColor color_id = id_col_property_->getColor();
348 color_id.setAlphaF(alpha_property_->getFloat());
349 rendering_options_.colorLaneletId = qtToOgre(color_id);
350
352}
353
355 // Linestrings
357
358 // Separators
360
361 // Stop lines
363
364 // Traffic lights
366
367 // IDs
369
370 // Areas
372
373 // Parking
375
377}
378
385
386} // namespace lanelet2_rviz_display
387
388#include <pluginlib/class_list_macros.hpp> // NOLINT
389// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
390PLUGINLIB_EXPORT_CLASS(lanelet2_rviz_display::Lanelet2Display, rviz_common::Display)
rviz_common::properties::ColorProperty * parking_col_property_
void onInitialize() override
Initializes the display once RViz has provided the rendering context.
bool visualizeMap()
Creates the RViz rendering object for the currently loaded map.
rviz_common::properties::StringProperty * ll2_server_name_property_
rviz_common::properties::BoolProperty * viz_sidewalk_property_
rviz_common::properties::BoolProperty * viz_lane_fill_property_
rviz_common::properties::BoolProperty * fill_parking_property_
rviz_common::properties::ColorProperty * stop_line_col_property_
rviz_common::properties::ColorProperty * ll_right_col_property_
rviz_common::properties::FloatProperty * area_width_property_
std::unique_ptr< Lanelet2MapInterface > lanelet2_map_interface_
rviz_common::properties::BoolProperty * viz_separators_property_
rviz_common::properties::FloatProperty * char_height_property_
rviz_common::properties::ColorProperty * sidewalk_col_property_
rviz_common::properties::BoolProperty * viz_traffic_light_property_
rviz_common::properties::ColorProperty * area_col_property_
rviz_common::properties::ColorProperty * separators_col_property_
void initializeMapInterface(rclcpp::Node &parent_node)
Creates the map interface used to fetch map data from the server node.
rviz_common::properties::BoolProperty * viz_id_property_
~Lanelet2Display() override
Destroys the RViz display and releases its map visualization resources.
rviz_common::properties::FloatProperty * stop_line_width_property_
rviz_common::properties::BoolProperty * viz_crosswalk_property_
std::unique_ptr< rviz_rendering::Lanelet2Map > map_
void updateVisibility()
Applies visibility toggles to the existing rendered map objects.
rviz_common::properties::BoolProperty * viz_stop_line_property_
void update(float dt, float ros_dt) override
Periodically updates the display and refreshes the rendered map when needed.
rviz_common::properties::FloatProperty * traffic_light_height_property_
rviz_common::properties::ColorProperty * traffic_light_col_property_
rviz_common::properties::FloatProperty * linestring_width_property_
rviz_common::properties::FloatProperty * alpha_property_
rviz_common::properties::FloatProperty * separators_width_property_
rviz_common::properties::ColorProperty * id_col_property_
rviz_common::properties::ColorProperty * lane_fill_col_property_
rviz_common::properties::ColorProperty * ll_left_col_property_
rviz_common::properties::FloatProperty * parking_width_property_
Lanelet2Display()
Creates the RViz display and initializes its configurable properties.
rviz_common::properties::BoolProperty * viz_parking_property_
void updateVisualization()
Rebuilds the rendered map using the current rendering options.
rviz_rendering::Lanelet2Map::RenderingOptions rendering_options_
rviz_common::properties::BoolProperty * three_d_property_
rviz_common::properties::BoolProperty * viz_linestring_property_
rviz_common::properties::BoolProperty * fill_area_property_
rviz_common::properties::BoolProperty * viz_area_property_
rviz_common::properties::ColorProperty * crosswalk_col_property_