3#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
11#include "rclcpp/clock.hpp"
12#include "rclcpp/rclcpp.hpp"
13#include "std_msgs/msg/color_rgba.hpp"
14#include "visualization_msgs/msg/marker.hpp"
15#include "visualization_msgs/msg/marker_array.hpp"
17using K = CGAL::Exact_predicates_inexact_constructions_kernel;
21inline const std::map<std::string, std::array<float, 4>, std::less<>>&
marker_color_map() {
22 static const std::map<std::string, std::array<float, 4>, std::less<>> map = {
23 {
"blue", {0.0f, 0.0f, 1.0f, 1.0f}}, {
"yellow", {1.0f, 1.0f, 0.0f, 1.0f}},
24 {
"orange", {1.0f, 0.5f, 0.0f, 1.0f}}, {
"red", {1.0f, 0.0f, 0.0f, 1.0f}},
25 {
"green", {0.0f, 1.0f, 0.0f, 1.0f}}, {
"white", {1.0f, 1.0f, 1.0f, 1.0f}},
26 {
"grey", {0.5f, 0.5f, 0.5f, 1.0f}},
32 static const std::map<std::string, int, std::less<>> map = {
33 {
"cylinder", visualization_msgs::msg::Marker::CYLINDER},
34 {
"cube", visualization_msgs::msg::Marker::CUBE},
35 {
"sphere", visualization_msgs::msg::Marker::SPHERE},
36 {
"line", visualization_msgs::msg::Marker::LINE_STRIP},
37 {
"cone", visualization_msgs::msg::Marker::MESH_RESOURCE},
38 {
"arrow", visualization_msgs::msg::Marker::ARROW},
50template <
typename T,
typename =
void>
62 std::enable_if_t<std::is_arithmetic_v<decltype(std::declval<T>().position.x)> &&
63 std::is_arithmetic_v<decltype(std::declval<T>().position.y)>>>
64 :
public std::true_type {};
80 const std::vector<T>& structure_array,
const std::string& name_space,
81 const std::string& frame_id,
const std::string& color =
"red",
82 const std::string& shape =
"cylinder",
float scale = 0.5,
83 int action = visualization_msgs::msg::Marker::MODIFY) {
86 "Template argument T must have a data member named 'position' with 'x' and 'y' sub-members");
88 visualization_msgs::msg::MarkerArray marker_array;
91 for (
size_t i = 0; i < structure_array.size(); ++i) {
92 visualization_msgs::msg::Marker marker;
94 marker.header.frame_id = frame_id;
95 marker.header.stamp = rclcpp::Clock().now();
96 marker.ns = name_space;
97 marker.id =
static_cast<int>(i);
99 marker.action = action;
101 marker.pose.orientation.x = 0.0;
102 marker.pose.orientation.y = 0.0;
103 marker.pose.orientation.z = 0.0;
104 marker.pose.orientation.w = 1.0;
106 marker.pose.position.x = structure_array[i].position.x;
107 marker.pose.position.y = structure_array[i].position.y;
108 marker.pose.position.z = 0;
110 marker.scale.x = scale;
111 marker.scale.y = scale;
112 marker.scale.z = scale;
114 marker.color.r = color_array[0];
115 marker.color.g = color_array[1];
116 marker.color.b = color_array[2];
117 marker.color.a = color_array[3];
129 if (shape ==
"cone") {
130 marker.pose.orientation.x = 0.7071;
131 marker.pose.orientation.y = 0.0;
132 marker.pose.orientation.z = 0.0;
133 marker.pose.orientation.w = -0.7071;
134 marker.scale.x = scale * 0.03;
135 marker.scale.y = scale * 0.03;
136 marker.scale.z = scale * 0.03;
137 marker.mesh_resource =
"https://paginas.fe.up.pt/~up202109860/FormulaStudent/FSGConev2.obj";
139 marker_array.markers.push_back(marker);
159 const std::vector<T>& structure_array,
const std::string& name_space,
160 const std::string& frame_id,
const int id,
const std::string& color =
"red",
161 const std::string& shape =
"line",
float scale = 0.1f,
162 int action = visualization_msgs::msg::Marker::MODIFY) {
165 "Template argument T must have a data member named 'position' with 'x' and 'y' sub-members");
169 visualization_msgs::msg::Marker marker;
171 marker.header.frame_id = frame_id;
172 marker.header.stamp = rclcpp::Clock().now();
173 marker.ns = name_space;
176 marker.action = action;
178 marker.pose.orientation.x = 0.0;
179 marker.pose.orientation.y = 0.0;
180 marker.pose.orientation.z = 0.0;
181 marker.pose.orientation.w = 1.0;
183 marker.pose.position.x = 0;
184 marker.pose.position.y = 0;
185 marker.pose.position.z = 0;
187 marker.scale.x = scale;
188 marker.scale.y = scale;
189 marker.scale.z = scale;
191 marker.color.r = color_array[0];
192 marker.color.g = color_array[1];
193 marker.color.b = color_array[2];
194 marker.color.a = color_array[3];
196 for (
size_t i = 0; i < structure_array.size(); ++i) {
197 geometry_msgs::msg::Point point;
198 point.x = structure_array[i].position.x;
199 point.y = structure_array[i].position.y,
201 marker.points.push_back(point);
222 const std::string& color =
"red",
float scale = 0.5,
const std::string& frame_id =
"map",
223 const std::string& shape =
"sphere",
int action = visualization_msgs::msg::Marker::ADD);
238 const std::vector<std::pair<Point, Point>>& triangulations,
const std::string& name_space,
239 const std::string& frame_id,
int id,
const std::string& color,
float scale,
int action);
253 const std::vector<common_lib::structures::PathPoint>& path_array,
const std::string& name_space,
254 const std::string& frame_id,
float scale = 0.2f,
int every_nth = 1);
CGAL::Exact_predicates_inexact_constructions_kernel K
const std::map< std::string, std::array< float, 4 >, std::less<> > & marker_color_map()
visualization_msgs::msg::Marker line_marker_from_structure_array(const std::vector< T > &structure_array, const std::string &name_space, const std::string &frame_id, const int id, const std::string &color="red", const std::string &shape="line", float scale=0.1f, int action=visualization_msgs::msg::Marker::MODIFY)
Converts a vector of cones to a marker array.
visualization_msgs::msg::MarkerArray marker_array_from_structure_array(const std::vector< T > &structure_array, const std::string &name_space, const std::string &frame_id, const std::string &color="red", const std::string &shape="cylinder", float scale=0.5, int action=visualization_msgs::msg::Marker::MODIFY)
Converts a vector of cones to a marker array.
visualization_msgs::msg::MarkerArray velocity_hover_markers(const std::vector< common_lib::structures::PathPoint > &path_array, const std::string &name_space, const std::string &frame_id, float scale=0.2f, int every_nth=1)
Creates sphere markers at each path point with velocity in the marker namespace When you hover over t...
const std::map< std::string, int, std::less<> > & marker_shape_map()
visualization_msgs::msg::Marker marker_from_position(const common_lib::structures::Position &position, const std::string &name_space, const int id, const std::string &color="red", float scale=0.5, const std::string &frame_id="map", const std::string &shape="sphere", int action=visualization_msgs::msg::Marker::ADD)
Converts a position to a marker.
visualization_msgs::msg::Marker lines_marker_from_triangulations(const std::vector< std::pair< Point, Point > > &triangulations, const std::string &name_space, const std::string &frame_id, int id, const std::string &color, float scale, int action)
Converts a vector of triangulation edges to a marker.
A helper struct to check if a type T has a member named 'position'.