44 static std_msgs::ColorRGBA
color(
float r,
float g,
float b,
float a = 0.5f)
46 std_msgs::ColorRGBA
color;
54 static std_msgs::ColorRGBA
red(
void)
59 static std_msgs::ColorRGBA
green(
void)
64 static std_msgs::ColorRGBA
blue(
void)
69 static std_msgs::ColorRGBA
yellow(
void)
74 static std_msgs::ColorRGBA
gray(
void)
80 : m_scan_mon_fieldset(0), m_marker_output_legend_offset_x(-0.5)
84 m_frame_id = marker_frame_id.empty() ?
"/cloud" : marker_frame_id;
100 std::vector<FieldInfo> default_fields = {
FieldInfo(0,0,
"-",
"3",
gray()),
FieldInfo(1,0,
"-",
"2",
gray()),
FieldInfo(2,0,
"-",
"1",
gray())};
119 int num_devices = std::min(msg.output_count.size(), msg.output_state.size());
120 std::vector<std::string> output_state(num_devices);
121 std::vector<std::string> output_count(num_devices);
122 std::vector<std_msgs::ColorRGBA> output_colors(num_devices);
123 for(
int field_idx = 0; field_idx < num_devices; field_idx++)
125 int count = msg.output_count[field_idx];
126 int state = msg.output_state[field_idx];
127 output_state[field_idx] = std::to_string(state);
128 output_count[field_idx] = std::to_string(count);
131 output_state[field_idx] =
"[ON]";
132 output_colors[field_idx] =
yellow();
136 output_state[field_idx] =
"[OFF]";
137 output_colors[field_idx] =
gray();
140 std::stringstream dbg_info;
141 dbg_info <<
"SickScanMarker::updateMarker(): LIDoutputstateMsg (state,count) = { ";
142 for(
int field_idx = 0; field_idx < num_devices; field_idx++)
143 dbg_info << ((field_idx > 0) ?
", (" :
"(") << output_state[field_idx] <<
"," << output_count[field_idx] <<
")";
161 std::vector<FieldInfo> field_info(msg.fields.size());
162 for(
int field_idx = 0; field_idx < msg.fields.size(); field_idx++)
165 field_info[field_idx].field_index_scan_mon = msg.fields[field_idx].field_index - 1 + msg.fields.size() *
m_scan_mon_fieldset;
166 field_info[field_idx].field_result = msg.fields[field_idx].field_result_mrs;
167 if(field_info[field_idx].field_result == 1)
169 field_info[field_idx].field_status =
"Clear";
170 field_info[field_idx].field_color =
green();
172 else if(field_info[field_idx].field_result == 2)
174 field_info[field_idx].field_status =
"Infringed";
175 field_info[field_idx].field_color =
yellow();
179 field_info[field_idx].field_status =
"Incorrect";
180 field_info[field_idx].field_color =
gray();
183 field_info[field_idx].field_name = std::to_string(field_info.size() - field_idx);
185 field_info[field_idx].field_name = std::to_string(msg.fields[field_idx].field_index);
187 std::stringstream dbg_info;
188 dbg_info <<
"SickScanMarker::updateMarker(): LFErec states={";
189 for(
int field_idx = 0; field_idx < msg.fields.size(); field_idx++)
190 dbg_info << ((field_idx > 0) ?
"," :
"") << (
int)msg.fields[field_idx].field_index <<
":" << (int)msg.fields[field_idx].field_result_mrs;
191 dbg_info <<
"}, mon_field_point_cnt={";
193 dbg_info << ((field_idx > 0) ?
"," :
"") <<
m_scan_mon_fields[field_idx].getPointCount();
205 visualization_msgs::MarkerArray marker_array;
218 static void appendTrianglePoints(
int point_count,
const std::vector<float>& points_x,
const std::vector<float>& points_y,
219 visualization_msgs::Marker& marker_point,
int& triangle_idx,
int nr_triangles, std_msgs::ColorRGBA field_color)
221 for(
int point_idx = 2; point_idx < point_count && triangle_idx < nr_triangles; point_idx++, triangle_idx++)
224 marker_point.points[3 * triangle_idx + 0].x = points_x[0];
225 marker_point.points[3 * triangle_idx + 0].y = points_y[0];
226 marker_point.points[3 * triangle_idx + 0].z = 0;
228 marker_point.points[3 * triangle_idx + 1].x = points_x[point_idx - 1];
229 marker_point.points[3 * triangle_idx + 1].y = points_y[point_idx - 1];
230 marker_point.points[3 * triangle_idx + 1].z = 0;
232 marker_point.points[3 * triangle_idx + 2].x = points_x[point_idx];
233 marker_point.points[3 * triangle_idx + 2].y = points_y[point_idx];
234 marker_point.points[3 * triangle_idx + 2].z = 0;
236 marker_point.colors[3 * triangle_idx + 0] = field_color;
237 marker_point.colors[3 * triangle_idx + 1] = field_color;
238 marker_point.colors[3 * triangle_idx + 2] = field_color;
244 int nr_triangles = 0;
245 for(
int field_info_idx = 0; field_info_idx < field_info.size(); field_info_idx++)
247 int field_idx = field_info[field_info_idx].field_index_scan_mon;
250 nr_triangles += 2 * std::max(0,
m_scan_mon_fields[field_idx].getPointCount()/2 - 2);
256 visualization_msgs::Marker marker_point;
259 marker_point.ns =
"sick_scan";
261 marker_point.type = visualization_msgs::Marker::TRIANGLE_LIST;
262 marker_point.scale.x = 1;
263 marker_point.scale.y = 1;
264 marker_point.scale.z = 1;
265 marker_point.pose.position.x = 0.0;
266 marker_point.pose.position.y = 0.0;
267 marker_point.pose.position.z = 0.0;
268 marker_point.pose.orientation.x = 0.0;
269 marker_point.pose.orientation.y = 0.0;
270 marker_point.pose.orientation.z = 0.0;
271 marker_point.pose.orientation.w = 1.0;
272 marker_point.action = visualization_msgs::Marker::ADD;
273 marker_point.color =
gray();
276 marker_point.points.resize(3 * nr_triangles);
277 marker_point.colors.resize(3 * nr_triangles);
278 std::vector<geometry_msgs::Point> triangle_centroids;
279 triangle_centroids.reserve(field_info.size());
280 for(
int field_info_idx = 0, triangle_idx = 0; field_info_idx < field_info.size() && triangle_idx < nr_triangles; field_info_idx++)
282 int field_idx = field_info[field_info_idx].field_index_scan_mon;
283 std_msgs::ColorRGBA field_color = field_info[field_info_idx].field_color;
285 const std::vector<float>& points_x =
m_scan_mon_fields[field_idx].getFieldPointsX();
286 const std::vector<float>& points_y =
m_scan_mon_fields[field_idx].getFieldPointsY();
290 std::vector<float> field1_points_x(point_count/2), field1_points_y(point_count/2), field2_points_x(point_count/2), field2_points_y(point_count/2);
291 for(
int n = 0; n < point_count/2; n++)
293 field1_points_x[n] = points_x[n];
294 field1_points_y[n] = points_y[n];
295 field2_points_x[n] = points_x[n + point_count/2];
296 field2_points_y[n] = points_y[n + point_count/2];
298 std_msgs::ColorRGBA field1_color = field_color, field2_color = field_color;
299 field1_color.r *= 0.5;
300 field1_color.g *= 0.5;
301 field1_color.b *= 0.5;
302 appendTrianglePoints(point_count/2, field1_points_x, field1_points_y, marker_point, triangle_idx, nr_triangles, field1_color);
303 appendTrianglePoints(point_count/2, field2_points_x, field2_points_y, marker_point, triangle_idx, nr_triangles, field2_color);
307 appendTrianglePoints(point_count, points_x, points_y, marker_point, triangle_idx, nr_triangles, field_color);
311 std::vector<visualization_msgs::Marker> marker_array;
312 marker_array.reserve(1 + field_info.size());
313 marker_array.push_back(marker_point);
316 for(
int field_info_idx = 0; field_info_idx < field_info.size(); field_info_idx++)
318 int field_idx = field_info[field_info_idx].field_index_scan_mon;
321 geometry_msgs::Point triangle_centroid;
322 triangle_centroid.x = 0;
323 triangle_centroid.y = 0;
324 triangle_centroid.z = 0;
325 const std::vector<float>& points_x =
m_scan_mon_fields[field_idx].getFieldPointsX();
326 const std::vector<float>& points_y =
m_scan_mon_fields[field_idx].getFieldPointsY();
327 for(
int point_idx = 0; point_idx <
m_scan_mon_fields[field_idx].getPointCount(); point_idx++)
329 triangle_centroid.x += points_x[point_idx];
330 triangle_centroid.y += points_y[point_idx];
334 visualization_msgs::Marker marker_field_name;
336 marker_field_name.header.frame_id =
m_frame_id;
337 marker_field_name.ns =
"sick_scan";
338 marker_field_name.id = 2 + field_info_idx;
339 marker_field_name.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
340 marker_field_name.scale.z = 0.1;
341 marker_field_name.pose.position.x = triangle_centroid.x;
342 marker_field_name.pose.position.y = triangle_centroid.y;
343 marker_field_name.pose.position.z = triangle_centroid.z;
344 marker_field_name.pose.orientation.x = 0.0;
345 marker_field_name.pose.orientation.y = 0.0;
346 marker_field_name.pose.orientation.z = 0.0;
347 marker_field_name.pose.orientation.w = 1.0;
348 marker_field_name.action = visualization_msgs::Marker::ADD;
349 marker_field_name.color = field_info[field_info_idx].field_color;
350 marker_field_name.color.a = 1;
352 marker_field_name.text = field_info[field_info_idx].field_name;
353 marker_array.push_back(marker_field_name);
357 visualization_msgs::Marker marker_field_name;
359 marker_field_name.header.frame_id =
m_frame_id;
360 marker_field_name.ns =
"sick_scan";
361 marker_field_name.id = 2 + field_info_idx;
362 marker_field_name.action = visualization_msgs::Marker::DELETE;
364 marker_array.push_back(marker_field_name);
374 std::vector<visualization_msgs::Marker> marker_array;
375 marker_array.reserve(2 * field_info.size());
376 for(
int loop_cnt = 0; loop_cnt < 2; loop_cnt++)
378 for(
int field_info_idx = 0, triangle_idx = 0; field_info_idx < field_info.size(); field_info_idx++)
380 int field_idx = field_info[field_info_idx].field_index_scan_mon;
381 visualization_msgs::Marker marker_point;
384 marker_point.ns =
"sick_scan";
386 marker_point.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
387 marker_point.scale.z = 0.1;
388 marker_point.pose.position.x = -0.1 * field_info_idx - 0.1;
389 marker_point.pose.position.y = ((loop_cnt == 0) ? 0.3 : -0.2);
390 marker_point.pose.position.z = 0.0;
391 marker_point.pose.orientation.x = 0.0;
392 marker_point.pose.orientation.y = 0.0;
393 marker_point.pose.orientation.z = 0.0;
394 marker_point.pose.orientation.w = 1.0;
395 marker_point.action = visualization_msgs::Marker::ADD;
396 marker_point.color = field_info[field_info_idx].field_color;
397 marker_point.color.a = 1;
399 std::stringstream marker_text;
402 marker_text <<
"Detection field " << (field_info[field_info_idx].field_name) <<
" : ";
404 marker_text << field_info[field_info_idx].field_status;
405 marker_point.text = marker_text.str();
406 marker_array.push_back(marker_point);
416 std::vector<visualization_msgs::Marker> marker_array;
417 marker_array.reserve(2);
418 for(
int loop_cnt = 0; loop_cnt < 2; loop_cnt++)
420 visualization_msgs::Marker marker_point;
423 marker_point.ns =
"sick_scan";
424 marker_point.id = 500 + loop_cnt;
425 marker_point.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
426 marker_point.scale.z = 0.1;
427 marker_point.pose.position.x = -0.4;
428 marker_point.pose.position.y = ((loop_cnt == 0) ? 0.16 : -0.2);
429 marker_point.pose.position.z = 0.0;
430 marker_point.pose.orientation.x = 0.0;
431 marker_point.pose.orientation.y = 0.0;
432 marker_point.pose.orientation.z = 0.0;
433 marker_point.pose.orientation.w = 1.0;
434 marker_point.action = visualization_msgs::Marker::ADD;
435 marker_point.color =
green();
436 marker_point.color.a = 1;
438 std::stringstream marker_text;
440 marker_text <<
"Fieldset :";
442 marker_text << std::to_string(fieldset + 1);
443 marker_point.text = marker_text.str();
444 marker_array.push_back(marker_point);
452 std::vector<visualization_msgs::Marker> marker_array;
453 marker_array.reserve(2 * output_count.size());
454 for(
int loop_cnt = 0; loop_cnt < 2; loop_cnt++)
456 for(
int field_idx = 0; field_idx < output_count.size(); field_idx++)
458 visualization_msgs::Marker marker_point;
461 marker_point.ns =
"sick_scan";
462 marker_point.id = 400 + loop_cnt * output_count.size() + field_idx;
463 marker_point.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
464 marker_point.scale.z = 0.1;
466 marker_point.pose.position.y = ((loop_cnt == 0) ? 0.16 : -0.3);
467 marker_point.pose.position.z = 0.0;
468 marker_point.pose.orientation.x = 0.0;
469 marker_point.pose.orientation.y = 0.0;
470 marker_point.pose.orientation.z = 0.0;
471 marker_point.pose.orientation.w = 1.0;
472 marker_point.action = visualization_msgs::Marker::ADD;
473 marker_point.color = output_colors[field_idx];
474 marker_point.color.a = 1;
476 std::stringstream marker_text;
477 int output_device = field_idx + 1;
479 marker_text <<
"Output " << output_device <<
" : ";
481 marker_text << (field_idx < output_state.size() ? (output_state[field_idx]) :
"") <<
" Count:" << output_count[field_idx];
482 marker_point.text = marker_text.str();
483 marker_array.push_back(marker_point);
std::vector< visualization_msgs::Marker > createMonFieldsetLegend(int fieldset)
std::vector< visualization_msgs::Marker > m_scan_outputstate_legend
SickScanMarker(ros::NodeHandle *nh=0, const std::string &marker_topic="", const std::string &marker_frame_id="")
void publish(const boost::shared_ptr< M > &message) const
void updateMarker(const std::vector< SickScanMonField > &fields, int fieldset, int eval_field_logic)
static std_msgs::ColorRGBA red(void)
std::vector< visualization_msgs::Marker > m_scan_mon_field_marker
virtual ~SickScanMarker()
std::vector< sick_scan::SickScanMonField > m_scan_mon_fields
static void appendTrianglePoints(int point_count, const std::vector< float > &points_x, const std::vector< float > &points_y, visualization_msgs::Marker &marker_point, int &triangle_idx, int nr_triangles, std_msgs::ColorRGBA field_color)
static std_msgs::ColorRGBA gray(void)
int getActiveFieldset(void)
static SickScanFieldMonSingleton * getInstance()
std::vector< visualization_msgs::Marker > createMonFieldLegend(const std::vector< FieldInfo > &field_info)
static std_msgs::ColorRGBA blue(void)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static std_msgs::ColorRGBA color(float r, float g, float b, float a=0.5f)
#define ROS_DEBUG_STREAM(args)
std::vector< visualization_msgs::Marker > createMonFieldMarker(const std::vector< FieldInfo > &field_info)
static std_msgs::ColorRGBA green(void)
std::vector< visualization_msgs::Marker > createOutputStateLegend(const std::vector< std::string > &output_state, const std::vector< std::string > &output_count, const std::vector< std_msgs::ColorRGBA > &output_colors)
static std_msgs::ColorRGBA yellow(void)
std::vector< visualization_msgs::Marker > m_scan_mon_field_legend
float m_marker_output_legend_offset_x
std::vector< visualization_msgs::Marker > m_scan_fieldset_legend
ros::Publisher m_marker_publisher