lanelet2_map_server v1.2.3
Loading...
Searching...
No Matches
lanelet2_lichtblick_display.hpp
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
4#pragma once
5
6#include <atomic>
7#include <cmath>
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include <tf2/LinearMath/Quaternion.h>
14#include <rclcpp/rclcpp.hpp>
15#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
16
17#include "geometry_msgs/msg/point.hpp"
18#include "visualization_msgs/msg/marker_array.hpp"
19
21
23
24template <typename C>
25struct is_vector : std::false_type {};
26template <typename T, typename A>
27struct is_vector<std::vector<T, A>> : std::true_type {};
28template <typename C>
29inline constexpr bool is_vector_v = is_vector<C>::value;
30
34class Lanelet2LichtblickDisplay : public rclcpp::Node {
35 public:
40
41 private:
56 template <typename T>
57 void declareAndLoadParameter(const std::string& name,
58 T& param,
59 const std::string& description,
60 const bool add_to_auto_reconfigurable_params = true,
61 const bool is_required = false,
62 const bool read_only = false,
63 const std::optional<double>& from_value = std::nullopt,
64 const std::optional<double>& to_value = std::nullopt,
65 const std::optional<double>& step_value = std::nullopt,
66 const std::string& additional_constraints = "");
67
74 rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector<rclcpp::Parameter>& parameters);
75
79 void setup();
80
90 void checkMapStatus();
91
99 void hexToRgb(const std::string& hex, float& r, float& g, float& b);
100
110 void publishMarker(const lanelet::LaneletMapConstPtr& lanelet_map);
111
120 static geometry_msgs::msg::Point toRos(const Eigen::Vector3d& point);
121
128 void clearAllMarkers();
129
144 void addLineStripMarker(visualization_msgs::msg::MarkerArray& marker_array_msg,
145 int& current_marker_id,
146 const std::string& ns,
147 double line_width,
148 const std::string& color_hex,
149 double opacity,
150 const std_msgs::msg::Header& header,
151 const std::vector<geometry_msgs::msg::Point>& points);
152
170 static void addMeshMarker(visualization_msgs::msg::MarkerArray& marker_array_msg,
171 int& current_marker_id,
172 const std::string& ns,
173 const std::string& mesh_resource,
174 const geometry_msgs::msg::Point& position,
175 double scale,
176 double z_offset,
177 double opacity,
178 const std_msgs::msg::Header& header,
179 double yaw_ref_line,
180 const geometry_msgs::msg::Point& middle_point);
181
191 static std::optional<std::array<geometry_msgs::msg::Point, 2>> regulatoryElementReferenceLine(
192 const std::shared_ptr<const lanelet::RegulatoryElement>& regulatory_element);
193
202 static std::vector<geometry_msgs::msg::Point> regulatoryElementPositions(
203 const std::shared_ptr<const lanelet::RegulatoryElement>& regulatory_element);
204
208 std::vector<std::tuple<std::string, std::function<void(const rclcpp::Parameter&)>>> auto_reconfigurable_params_;
209
213 OnSetParametersCallbackHandle::SharedPtr parameters_callback_;
214
218 rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr marker_array_publisher_;
219
220 rclcpp::TimerBase::SharedPtr timer_;
221
222 std::atomic<bool> need_republish_{false};
223
224 std::shared_ptr<Lanelet2MapInterface> lanelet2_map_interface_;
225 lanelet::LaneletMapConstPtr last_map_ptr_;
226 std::string map_frame_id;
227
228 rclcpp::Time current_timestamp;
229
230 // Parameters
232 std::string left_bound_color_hex_ = "#0000FF";
234
236 std::string right_bound_color_hex_ = "#FF0000";
238
240 std::string centerline_color_hex_ = "#008000";
242
244 std::string lanelet_text_color_hex_ = "#000000";
246
248 std::string reference_line_color_hex_ = "#FFFF00";
250
255
257 double yield_sign_scale_ = 1.0;
260};
261
262} // namespace lanelet2_lichtblick_display
static void addMeshMarker(visualization_msgs::msg::MarkerArray &marker_array_msg, int &current_marker_id, const std::string &ns, const std::string &mesh_resource, const geometry_msgs::msg::Point &position, double scale, double z_offset, double opacity, const std_msgs::msg::Header &header, double yaw_ref_line, const geometry_msgs::msg::Point &middle_point)
Creates and adds a MESH_RESOURCE marker for regulatory elements.
void checkMapStatus()
Check for a new or changed Lanelet2 map and publish markers if present.
static geometry_msgs::msg::Point toRos(const Eigen::Vector3d &point)
Converts an Eigen::Vector3d into a ROS geometry_msgs::msg::Point.
void hexToRgb(const std::string &hex, float &r, float &g, float &b)
Convert a hex color string into normalized RGB float components.
void clearAllMarkers()
Publishes a DELETEALL action to clear all markers from the topic.
void publishMarker(const lanelet::LaneletMapConstPtr &lanelet_map)
Converts a Lanelet2 map into a MarkerArray and publishes it.
Lanelet2LichtblickDisplay()
Creates the Lichtblick visualization node and declares its rendering parameters.
static std::optional< std::array< geometry_msgs::msg::Point, 2 > > regulatoryElementReferenceLine(const std::shared_ptr< const lanelet::RegulatoryElement > &regulatory_element)
Extracts the reference/effect line of a regulatory element.
OnSetParametersCallbackHandle::SharedPtr parameters_callback_
Callback handle for dynamic parameter reconfiguration.
void addLineStripMarker(visualization_msgs::msg::MarkerArray &marker_array_msg, int &current_marker_id, const std::string &ns, double line_width, const std::string &color_hex, double opacity, const std_msgs::msg::Header &header, const std::vector< geometry_msgs::msg::Point > &points)
Creates and adds a LINE_STRIP marker to a marker array.
static std::vector< geometry_msgs::msg::Point > regulatoryElementPositions(const std::shared_ptr< const lanelet::RegulatoryElement > &regulatory_element)
Extracts the sign/signal positions of a regulatory element.
rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Handles reconfiguration when a parameter value is changed.
void setup()
Sets up subscribers, publishers, etc. to configure the node.
void declareAndLoadParameter(const std::string &name, T &param, const std::string &description, const bool add_to_auto_reconfigurable_params=true, const bool is_required=false, const bool read_only=false, const std::optional< double > &from_value=std::nullopt, const std::optional< double > &to_value=std::nullopt, const std::optional< double > &step_value=std::nullopt, const std::string &additional_constraints="")
Declares and loads a ROS parameter.
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr marker_array_publisher_
Publisher Marker Array.
std::vector< std::tuple< std::string, std::function< void(const rclcpp::Parameter &)> > > auto_reconfigurable_params_
Auto-reconfigurable parameters for dynamic reconfiguration.