16 #ifndef PSEN_SCAN_V2_ZONESET_TO_MARKER_CONVERSION_H
17 #define PSEN_SCAN_V2_ZONESET_TO_MARKER_CONVERSION_H
22 #include <fmt/format.h>
24 #include <geometry_msgs/Point.h>
25 #include <geometry_msgs/Point32.h>
26 #include <std_msgs/ColorRGBA.h>
27 #include <visualization_msgs/Marker.h>
29 #include "psen_scan_v2/ZoneSet.h"
31 #define TO_MARKER(zoneset_obj, polygon_type, polygon_index, tf_frame) \
32 createMarker(fmt::format("active zoneset {}{} {}", #polygon_type, #polygon_index, getRangeInfo(zoneset_obj)), \
33 createRGBA(strcmp(#polygon_type, "muting") != 0, \
34 strcmp(#polygon_type, "warn") == 0, \
35 strcmp(#polygon_type, "muting") == 0, \
38 zoneset_obj.polygon_type##polygon_index.points, \
39 0.01 * (strcmp(#polygon_type, "warn") == 0) + 0.02 * (strcmp(#polygon_type, "muting") == 0))
43 geometry_msgs::Point
createPoint(
const double& x,
const double& y,
const double& z)
45 geometry_msgs::Point p;
52 std_msgs::ColorRGBA
createRGBA(
const float& r,
const float& g,
const float& b,
const float& a)
54 std_msgs::ColorRGBA color;
63 const std_msgs::ColorRGBA& color,
64 const std::string& frame_id,
65 const std::vector<geometry_msgs::Point32>& points,
66 const double& z_offset = 0)
68 visualization_msgs::Marker marker;
69 marker.header.frame_id = frame_id;
72 marker.type = marker.TRIANGLE_LIST;
73 marker.action = marker.ADD;
84 marker.pose.orientation.x = 0.0;
85 marker.pose.orientation.y = 0.0;
86 marker.pose.orientation.z = 0.0;
87 marker.pose.orientation.w = 1.0;
88 marker.pose.position.x = 0.0;
89 marker.pose.position.y = 0.0;
90 marker.pose.position.z = z_offset;
92 marker.points.reserve(3 * (points.size() - 1));
93 marker.colors.reserve(points.size() - 1);
95 for (std::size_t i = 1; i < points.size(); ++i)
97 marker.points.push_back(
createPoint(0.0, 0.0, 0.0));
98 marker.points.push_back(
createPoint(points.at(i - 1).x, points.at(i - 1).y, 0.0));
99 marker.points.push_back(
createPoint(points.at(i).x, points.at(i).y, 0.0));
100 marker.colors.push_back(color);
107 std::string range_info =
"";
108 if (zoneset.speed_lower != 0 || zoneset.speed_upper != 0)
110 range_info = fmt::format(
"min:{:+} max:{:+}", zoneset.speed_lower, zoneset.speed_upper);
115 std::vector<visualization_msgs::Marker>
toMarkers(
const ZoneSet& zoneset)
117 std::vector<visualization_msgs::Marker> return_vec;
120 if (!zoneset.safety1.points.empty())
122 return_vec.push_back(
TO_MARKER(zoneset, safety, 1,
"laser_1"));
124 if (!zoneset.safety2.points.empty())
126 return_vec.push_back(
TO_MARKER(zoneset, safety, 2,
"laser_1"));
128 if (!zoneset.safety3.points.empty())
130 return_vec.push_back(
TO_MARKER(zoneset, safety, 3,
"laser_1"));
132 if (!zoneset.warn1.points.empty())
134 return_vec.push_back(
TO_MARKER(zoneset, warn, 1,
"laser_1"));
136 if (!zoneset.warn2.points.empty())
138 return_vec.push_back(
TO_MARKER(zoneset, warn, 2,
"laser_1"));
140 if (!zoneset.muting1.points.empty())
142 return_vec.push_back(
TO_MARKER(zoneset, muting, 1,
"laser_1"));
144 if (!zoneset.muting2.points.empty())
146 return_vec.push_back(
TO_MARKER(zoneset, muting, 2,
"laser_1"));
150 if (!zoneset.safety1_Sub0.points.empty())
152 return_vec.push_back(
TO_MARKER(zoneset, safety, 1_Sub0,
"laser_1_Subscriber0"));
154 if (!zoneset.safety2_Sub0.points.empty())
156 return_vec.push_back(
TO_MARKER(zoneset, safety, 2_Sub0,
"laser_1_Subscriber0"));
158 if (!zoneset.safety3_Sub0.points.empty())
160 return_vec.push_back(
TO_MARKER(zoneset, safety, 3_Sub0,
"laser_1_Subscriber0"));
162 if (!zoneset.warn1_Sub0.points.empty())
164 return_vec.push_back(
TO_MARKER(zoneset, warn, 1_Sub0,
"laser_1_Subscriber0"));
166 if (!zoneset.warn2_Sub0.points.empty())
168 return_vec.push_back(
TO_MARKER(zoneset, warn, 2_Sub0,
"laser_1_Subscriber0"));
170 if (!zoneset.muting1_Sub0.points.empty())
172 return_vec.push_back(
TO_MARKER(zoneset, muting, 1_Sub0,
"laser_1_Subscriber0"));
174 if (!zoneset.muting2_Sub0.points.empty())
176 return_vec.push_back(
TO_MARKER(zoneset, muting, 2_Sub0,
"laser_1_Subscriber0"));
180 if (!zoneset.safety1_Sub1.points.empty())
182 return_vec.push_back(
TO_MARKER(zoneset, safety, 1_Sub1,
"laser_1_Subscriber1"));
184 if (!zoneset.safety2_Sub1.points.empty())
186 return_vec.push_back(
TO_MARKER(zoneset, safety, 2_Sub1,
"laser_1_Subscriber1"));
188 if (!zoneset.safety3_Sub1.points.empty())
190 return_vec.push_back(
TO_MARKER(zoneset, safety, 3_Sub1,
"laser_1_Subscriber1"));
192 if (!zoneset.warn1_Sub1.points.empty())
194 return_vec.push_back(
TO_MARKER(zoneset, warn, 1_Sub1,
"laser_1_Subscriber1"));
196 if (!zoneset.warn2_Sub1.points.empty())
198 return_vec.push_back(
TO_MARKER(zoneset, warn, 2_Sub1,
"laser_1_Subscriber1"));
200 if (!zoneset.muting1_Sub1.points.empty())
202 return_vec.push_back(
TO_MARKER(zoneset, muting, 1_Sub1,
"laser_1_Subscriber1"));
204 if (!zoneset.muting2_Sub1.points.empty())
206 return_vec.push_back(
TO_MARKER(zoneset, muting, 2_Sub1,
"laser_1_Subscriber1"));
210 if (!zoneset.safety1_Sub2.points.empty())
212 return_vec.push_back(
TO_MARKER(zoneset, safety, 1_Sub2,
"laser_1_Subscriber2"));
214 if (!zoneset.safety2_Sub2.points.empty())
216 return_vec.push_back(
TO_MARKER(zoneset, safety, 2_Sub2,
"laser_1_Subscriber2"));
218 if (!zoneset.safety3_Sub2.points.empty())
220 return_vec.push_back(
TO_MARKER(zoneset, safety, 3_Sub2,
"laser_1_Subscriber2"));
222 if (!zoneset.warn1_Sub2.points.empty())
224 return_vec.push_back(
TO_MARKER(zoneset, warn, 1_Sub2,
"laser_1_Subscriber2"));
226 if (!zoneset.warn2_Sub2.points.empty())
228 return_vec.push_back(
TO_MARKER(zoneset, warn, 2_Sub2,
"laser_1_Subscriber2"));
230 if (!zoneset.muting1_Sub2.points.empty())
232 return_vec.push_back(
TO_MARKER(zoneset, muting, 1_Sub2,
"laser_1_Subscriber2"));
234 if (!zoneset.muting2_Sub2.points.empty())
236 return_vec.push_back(
TO_MARKER(zoneset, muting, 2_Sub2,
"laser_1_Subscriber2"));
244 #endif // PSEN_SCAN_V2_ZONESET_TO_MARKER_CONVERSION_H