3 #include "visualization_msgs/Marker.h" 4 #include "visualization_msgs/MarkerArray.h" 11 void emitRow(
const std::string type_name, uint32_t type, int32_t x_pos,
float r,
float g,
float b,
13 float sx = 1.0,
float sy = 1.0,
float sz = 1.0)
15 static uint32_t count = 0;
16 for (
int i = -5; i < 5; ++i)
18 visualization_msgs::Marker marker;
19 marker.header.frame_id = frame_id;
22 marker.header.stamp = ros_time;
23 marker.ns =
"marker_test_" + type_name;
26 marker.action = visualization_msgs::Marker::ADD;
27 marker.pose.position.x = x_pos;
28 marker.pose.position.y = (i * 2);
29 marker.pose.position.z = 0;
30 marker.pose.orientation.x = 0.0;
31 marker.pose.orientation.y = 0.0;
32 marker.pose.orientation.z = 0.0;
33 marker.pose.orientation.w = 1.0;
40 marker.color.a = float(i+5) / 10.0;
42 marker.lifetime = lifetime;
43 marker.frame_locked = frame_locked;
44 marker.text =
"This is some text\nthis is a new line\nthis is another line\nand another adfoije owijeoiwej\na really really really really really really really really really really long one";
45 marker.mesh_resource =
"package://pr2_description/meshes/base_v0/base.dae";
46 marker.mesh_use_embedded_materials = (i > int((count / 12) % 5));
55 static uint32_t counter = 0;
59 emitRow(
"arrows", visualization_msgs::Marker::ARROW, x_pos, 1.0, 0.0, 0.0,
ros::Duration(), g_marker_pub);
61 emitRow(
"cubes", visualization_msgs::Marker::CUBE, x_pos, 0.0, 1.0, 0.0,
ros::Duration(), g_marker_pub);
63 emitRow(
"cubes_frame_locked", visualization_msgs::Marker::CUBE, x_pos, 1.0, 1.0, 0.0,
ros::Duration(), g_marker_pub,
true,
"/my_link");
65 emitRow(
"spheres", visualization_msgs::Marker::SPHERE, x_pos, 0.0, 0.0, 1.0,
ros::Duration(), g_marker_pub);
67 emitRow(
"cylinder", visualization_msgs::Marker::CYLINDER, x_pos, 1.0, 0.0, 0.0,
ros::Duration(), g_marker_pub);
69 emitRow(
"arrows_with_lifetime", visualization_msgs::Marker::ARROW, x_pos, 0.0, 1.0, 0.0,
ros::Duration(0.6),
72 emitRow(
"cubes_with_lifetime", visualization_msgs::Marker::CUBE, x_pos, 0.0, 0.0, 1.0,
ros::Duration(0.7),
75 emitRow(
"spheres_with_lifetime", visualization_msgs::Marker::SPHERE, x_pos, 1.0, 0.0, 0.0,
ros::Duration(0.8),
78 emitRow(
"cylinder_with_lifetime", visualization_msgs::Marker::CYLINDER, x_pos, 0.0, 1.0, 0.0,
ros::Duration(0.9),
81 emitRow(
"text_view_facing", visualization_msgs::Marker::TEXT_VIEW_FACING, x_pos, 1.0, 1.0, 1.0,
ros::Duration(),
82 g_marker_pub,
false,
"/base_link", 1.0, 1.0, 0.2);
84 emitRow(
"mesh_resource", visualization_msgs::Marker::MESH_RESOURCE, x_pos, 0.0, 1.0, 1.0,
ros::Duration(),
88 emitRow(
"invalid_scales", visualization_msgs::Marker::CUBE, x_pos, 0.0, 1.0, 1.0,
ros::Duration(), g_marker_pub,
false,
"/base_link", 0.0, 1.0, 1.0);
92 for (
int i = -5; i < 5; ++i)
94 visualization_msgs::Marker marker;
95 marker.header.frame_id =
"/base_link";
97 marker.ns =
"marker_test_arrow_by_points";
99 marker.type = visualization_msgs::Marker::ARROW;
100 marker.action = visualization_msgs::Marker::ADD;
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;
105 marker.pose.position.x = x_pos;
106 marker.pose.position.y = i * 2;
107 marker.scale.x = 0.25;
108 marker.scale.y = 0.5;
109 marker.color.r = 0.0;
110 marker.color.g = 1.0;
111 marker.color.b = 1.0;
112 marker.color.a = 1.0;
113 marker.frame_locked =
true;
115 if (counter % 2 == 0)
117 marker.points.resize(1);
118 marker.points[0].x = 0.0f;
119 marker.points[0].y = 0.0f;
120 marker.points[0].z = 0.0f;
124 marker.points.resize(2);
125 marker.points[0].x = 0.0f;
126 marker.points[0].y = 0.0f;
127 marker.points[0].z = 0.0f;
128 marker.points[1].x = 1.0f;
129 marker.points[1].y = 0.0f;
130 marker.points[1].z = 0.0f;
139 visualization_msgs::Marker marker;
140 marker.header.frame_id =
"/base_link";
142 marker.ns =
"marker_test_cube_list";
144 marker.type = visualization_msgs::Marker::CUBE_LIST;
145 marker.action = visualization_msgs::Marker::ADD;
146 marker.pose.orientation.x = 0.0;
147 marker.pose.orientation.y = 0.0;
148 marker.pose.orientation.z = 0.0;
149 marker.pose.orientation.w = 1.0;
150 marker.pose.position.x = x_pos;
151 marker.scale.x = 0.05;
152 marker.scale.y = 0.05;
153 marker.scale.z = 0.05;
154 marker.color.r = 1.0;
155 marker.color.g = 1.0;
156 marker.color.b = 0.0;
157 marker.color.a = 1.0;
158 marker.frame_locked =
true;
160 for (
int x = 0;
x < 10; ++
x)
162 for (
int y = 0;
y < 10; ++
y)
164 for (
int z = 0;
z < 10; ++
z)
166 geometry_msgs::Point p;
171 marker.points.push_back(p);
181 visualization_msgs::Marker marker;
182 marker.header.frame_id =
"/base_link";
184 marker.ns =
"marker_test_cube_list_color_per";
186 marker.type = visualization_msgs::Marker::CUBE_LIST;
187 marker.action = visualization_msgs::Marker::ADD;
188 marker.pose.orientation.x = 0.0;
189 marker.pose.orientation.y = 0.0;
190 marker.pose.orientation.z = 0.0;
191 marker.pose.orientation.w = 1.0;
192 marker.pose.position.x = x_pos;
193 marker.scale.x = 0.05;
194 marker.scale.y = 0.05;
195 marker.scale.z = 0.05;
196 marker.color.r = 1.0;
197 marker.color.g = 1.0;
198 marker.color.b = 0.0;
199 marker.color.a = 1.0;
200 marker.frame_locked =
true;
202 for (
int x = 0;
x < 10; ++
x)
204 for (
int y = 0;
y < 10; ++
y)
206 for (
int z = 0;
z < 10; ++
z)
208 geometry_msgs::Point p;
213 marker.points.push_back(p);
215 std_msgs::ColorRGBA c;
220 marker.colors.push_back(c);
230 visualization_msgs::Marker marker;
231 marker.header.frame_id =
"/base_link";
233 marker.ns =
"marker_test_point_list_alpha_per";
235 marker.action = visualization_msgs::Marker::ADD;
236 marker.pose.orientation.x = 0.0;
237 marker.pose.orientation.y = 0.0;
238 marker.pose.orientation.z = 0.0;
239 marker.pose.orientation.w = 1.0;
240 marker.pose.position.x = x_pos;
241 marker.scale.x = 0.05;
242 marker.scale.y = 0.05;
243 marker.scale.z = 0.05;
244 marker.color.r = 1.0;
245 marker.color.g = 1.0;
246 marker.color.b = 0.0;
247 marker.color.a = 1.0;
248 marker.frame_locked =
true;
250 for(
int type = visualization_msgs::Marker::CUBE_LIST; type <= visualization_msgs::Marker::POINTS; type++ )
253 marker.pose.position.x += 0.5;
256 for (
int y = 0;
y < 10; ++
y)
258 geometry_msgs::Point p;
263 marker.points.push_back(p);
265 std_msgs::ColorRGBA c;
269 c.a = (float)
y * 0.1 + 0.1;
270 marker.colors.push_back(c);
279 visualization_msgs::Marker marker;
280 marker.header.frame_id =
"/base_link";
282 marker.ns =
"marker_test_sphere_list";
284 marker.type = visualization_msgs::Marker::SPHERE_LIST;
285 marker.action = visualization_msgs::Marker::ADD;
286 marker.pose.orientation.x = 0.0;
287 marker.pose.orientation.y = 0.0;
288 marker.pose.orientation.z = 0.0;
289 marker.pose.orientation.w = 1.0;
290 marker.pose.position.x = x_pos;
291 marker.scale.x = 0.05;
292 marker.scale.y = 0.05;
293 marker.scale.z = 0.05;
294 marker.color.r = 1.0;
295 marker.color.g = 1.0;
296 marker.color.b = 1.0;
297 marker.color.a = 1.0;
298 marker.frame_locked =
true;
300 for (
int x = 0;
x < 10; ++
x)
302 for (
int y = 0;
y < 10; ++
y)
304 for (
int z = 0;
z < 1; ++
z)
306 geometry_msgs::Point p;
311 marker.points.push_back(p);
313 std_msgs::ColorRGBA c;
318 marker.colors.push_back(c);
328 visualization_msgs::Marker marker;
329 marker.header.frame_id =
"/base_link";
331 marker.ns =
"marker_test_points";
333 marker.type = visualization_msgs::Marker::POINTS;
334 marker.action = visualization_msgs::Marker::ADD;
335 marker.pose.orientation.x = 0.0;
336 marker.pose.orientation.y = 0.0;
337 marker.pose.orientation.z = 0.0;
338 marker.pose.orientation.w = 1.0;
339 marker.pose.position.x = x_pos;
340 marker.scale.x = 0.02;
341 marker.scale.y = 0.02;
342 marker.scale.z = 0.02;
343 marker.color.r = 1.0;
344 marker.color.g = 0.0;
345 marker.color.b = 1.0;
346 marker.color.a = 1.0;
347 marker.frame_locked =
true;
349 for (
int x = 0;
x < 10; ++
x)
351 for (
int y = 0;
y < 10; ++
y)
353 for (
int z = 0;
z < 10; ++
z)
355 geometry_msgs::Point p;
360 marker.points.push_back(p);
370 visualization_msgs::Marker marker;
371 marker.header.frame_id =
"/base_link";
373 marker.ns =
"marker_test_points_color_per";
375 marker.type = visualization_msgs::Marker::POINTS;
376 marker.action = visualization_msgs::Marker::ADD;
377 marker.pose.orientation.x = 0.0;
378 marker.pose.orientation.y = 0.0;
379 marker.pose.orientation.z = 0.0;
380 marker.pose.orientation.w = 1.0;
381 marker.pose.position.x = x_pos;
382 marker.scale.x = 0.02;
383 marker.scale.y = 0.02;
384 marker.scale.z = 0.02;
385 marker.color.r = 1.0;
386 marker.color.g = 0.0;
387 marker.color.b = 1.0;
388 marker.color.a = 1.0;
389 marker.frame_locked =
true;
391 for (
int x = 0;
x < 10; ++
x)
393 for (
int y = 0;
y < 10; ++
y)
395 for (
int z = 0;
z < 10; ++
z)
397 geometry_msgs::Point p;
402 marker.points.push_back(p);
404 std_msgs::ColorRGBA c;
409 marker.colors.push_back(c);
420 visualization_msgs::Marker marker;
421 marker.header.frame_id =
"/base_link";
423 marker.ns =
"marker_test_line_list";
425 marker.type = visualization_msgs::Marker::LINE_LIST;
426 marker.action = visualization_msgs::Marker::ADD;
427 marker.pose.position.x = 0.0;
428 marker.pose.position.y = 0.0;
429 marker.pose.position.z = 0.0;
430 marker.pose.orientation.x = 0.0;
431 marker.pose.orientation.y = 0.0;
432 marker.pose.orientation.z = 0.0;
433 marker.pose.orientation.w = 1.0;
434 marker.pose.position.x = x_pos;
435 marker.scale.x = 0.1;
436 marker.color.r = 1.0;
437 marker.color.a = 1.0;
438 marker.frame_locked =
true;
440 for (
int i = 0; i < count; ++i)
442 geometry_msgs::Point p1, p2;
444 p1.y = (i - count / 2) * 2;
447 p2.y = (i - count / 2) * 2;
449 marker.points.push_back(p1);
450 marker.points.push_back(p2);
459 visualization_msgs::Marker marker;
460 marker.header.frame_id =
"/base_link";
462 marker.ns =
"marker_test_line_list_color_per";
464 marker.type = visualization_msgs::Marker::LINE_LIST;
465 marker.action = visualization_msgs::Marker::ADD;
466 marker.pose.position.x = 0.0;
467 marker.pose.position.y = 0.0;
468 marker.pose.position.z = 0.0;
469 marker.pose.orientation.x = 0.0;
470 marker.pose.orientation.y = 0.0;
471 marker.pose.orientation.z = 0.0;
472 marker.pose.orientation.w = 1.0;
473 marker.pose.position.x = x_pos;
474 marker.scale.x = 0.1;
475 marker.color.r = 1.0;
476 marker.color.a = 1.0;
477 marker.frame_locked =
true;
479 for (
int i = 0; i < count; ++i)
481 geometry_msgs::Point p1, p2;
483 p1.y = (i - count / 2) * 2;
486 p2.y = (i - count / 2) * 2;
488 marker.points.push_back(p1);
489 marker.points.push_back(p2);
491 std_msgs::ColorRGBA c;
492 float pct = (float)i / (
float)count;
493 c.r = pct * 1.0 + (1 - pct) * 0.0;
494 c.g = pct * 0.0 + (1 - pct) * 0.0;
495 c.b = pct * 0.0 + (1 - pct) * 1.0;
498 marker.colors.push_back(c);
499 marker.colors.push_back(c);
507 visualization_msgs::Marker marker;
508 marker.header.frame_id =
"/base_link";
510 marker.ns =
"marker_test_line_strip";
512 marker.type = visualization_msgs::Marker::LINE_STRIP;
513 marker.action = visualization_msgs::Marker::ADD;
514 marker.pose.position.x = 0.0;
515 marker.pose.position.y = 0.0;
516 marker.pose.position.z = 0.0;
517 marker.pose.orientation.x = 0.0;
518 marker.pose.orientation.y = 0.0;
519 marker.pose.orientation.z = 0.0;
520 marker.pose.orientation.w = 1.0;
521 marker.pose.position.x = x_pos;
522 marker.scale.x = 0.1;
523 marker.color.g = 1.0;
524 marker.color.a = 1.0;
525 marker.frame_locked =
true;
527 for (
int i = -5; i < 5; ++i)
529 geometry_msgs::Point p;
533 marker.points.push_back(p);
542 visualization_msgs::Marker marker;
543 marker.header.frame_id =
"/base_link";
545 marker.ns =
"marker_test_line_strip_color_per";
547 marker.type = visualization_msgs::Marker::LINE_STRIP;
548 marker.action = visualization_msgs::Marker::ADD;
549 marker.pose.position.x = 0.0;
550 marker.pose.position.y = 0.0;
551 marker.pose.position.z = 0.0;
552 marker.pose.orientation.x = 0.0;
553 marker.pose.orientation.y = 0.0;
554 marker.pose.orientation.z = 0.0;
555 marker.pose.orientation.w = 1.0;
556 marker.pose.position.x = x_pos;
557 marker.scale.x = 0.1;
558 marker.color.g = 1.0;
559 marker.color.a = 1.0;
560 marker.frame_locked =
true;
562 for (
int i = -5; i < 5; ++i)
564 geometry_msgs::Point p;
568 marker.points.push_back(p);
570 std_msgs::ColorRGBA c;
571 float pct = (i + 5) / 10.0;
572 c.r = pct * 0.0 + (1 - pct) * 0.0;
573 c.g = pct * 1.0 + (1 - pct) * 0.0;
574 c.b = pct * 0.0 + (1 - pct) * 1.0;
577 marker.colors.push_back(c);
586 visualization_msgs::Marker marker;
587 marker.header.frame_id =
"/base_link";
589 marker.ns =
"marker_test_triangle_list";
591 marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
592 marker.action = visualization_msgs::Marker::ADD;
593 marker.pose.position.x = 0.0;
594 marker.pose.position.y = 0.0;
595 marker.pose.position.z = 0.0;
596 marker.pose.orientation.x = 0.0;
597 marker.pose.orientation.y = 0.0;
598 marker.pose.orientation.z = 0.0;
599 marker.pose.orientation.w = 1.0;
600 marker.pose.position.x = x_pos;
601 marker.scale.x = 1.0;
602 marker.scale.y = 1.0;
603 marker.scale.z = 1.0;
604 marker.color.g = 1.0;
605 marker.color.a = 1.0;
606 marker.frame_locked =
true;
608 for (
int x = 0;
x < 10; ++
x)
610 for (
int y = 0;
y < 10; ++
y)
612 for (
int z = 0;
z < 10; ++
z)
614 geometry_msgs::Point p;
619 geometry_msgs::Point p2 = p;
622 geometry_msgs::Point p3 = p;
626 marker.points.push_back(p);
627 marker.points.push_back(p2);
628 marker.points.push_back(p3);
630 std_msgs::ColorRGBA c;
635 marker.colors.push_back(c);
636 marker.colors.push_back(c);
637 marker.colors.push_back(c);
648 visualization_msgs::Marker marker;
649 marker.header.frame_id =
"/base_link";
651 marker.ns =
"marker_test_mesh_color_change";
653 marker.type = visualization_msgs::Marker::MESH_RESOURCE;
654 marker.action = visualization_msgs::Marker::ADD;
655 marker.pose.position.x = 0.0;
656 marker.pose.position.y = 0.0;
657 marker.pose.position.z = 0.0;
658 marker.pose.orientation.x = 0.0;
659 marker.pose.orientation.y = 0.0;
660 marker.pose.orientation.z = 0.0;
661 marker.pose.orientation.w = 1.0;
662 marker.pose.position.x = x_pos;
663 marker.scale.x = 1.0;
664 marker.scale.y = 1.0;
665 marker.scale.z = 1.0;
666 marker.color.r = float(counter % 255) / 255;
667 marker.color.g = float((counter*3) % 255) / 255;
668 marker.color.b = float((counter*10) % 255) / 255;
669 marker.color.a = 1.0;
670 marker.frame_locked =
true;
671 marker.mesh_resource =
"package://pr2_description/meshes/base_v0/base.dae";
672 marker.mesh_use_embedded_materials =
false;
682 static uint32_t counter = 0;
698 int main(
int argc,
char** argv)
703 g_marker_pub = n.
advertise<visualization_msgs::Marker> (
"visualization_marker", 0);
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
void publish(const boost::shared_ptr< M > &message) const
void frameCallback(const ros::TimerEvent &)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TFSIMD_FORCE_INLINE const tfScalar & y() const
ROSCPP_DECL void spin(Spinner &spinner)
ros::Publisher g_marker_pub
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TFSIMD_FORCE_INLINE const tfScalar & z() const
int main(int argc, char **argv)
void publishCallback(const ros::TimerEvent &)
void emitRow(const std::string type_name, uint32_t type, int32_t x_pos, float r, float g, float b, ros::Duration lifetime, ros::Publisher &pub, bool frame_locked=true, std::string frame_id=std::string("/base_link"), float sx=1.0, float sy=1.0, float sz=1.0)