首页 > 编程学习 > 使用visualization_msgs::Marker可视化

使用visualization_msgs::Marker可视化

发布时间:2022/1/17 11:44:41

介绍:

visualization_msgs::Marker格式如下:

//各种标志物类型的定义,每一个的具体介绍和形状可以到这里查看:http://wiki.ros.org/rviz/DisplayTypes/Marker
uint8 ARROW=0//箭头
uint8 CUBE=1//立方体
uint8 SPHERE=2//球
uint8 CYLINDER=3//圆柱体
uint8 LINE_STRIP=4//线条(点的连线)
uint8 LINE_LIST=5//线条序列
uint8 CUBE_LIST=6//立方体序列
uint8 SPHERE_LIST=7//球序列
uint8 POINTS=8//点集
uint8 TEXT_VIEW_FACING=9//显示3D的文字
uint8 MESH_RESOURCE=10//网格?
uint8 TRIANGLE_LIST=11//三角形序列
//对标记的操作
uint8 ADD=0
uint8 MODIFY=0
uint8 DELETE=2
uint8 DELETEALL=3
 
Header header
string ns   //命名空间namespace,就是你理解的那样
int32 id    //与命名空间联合起来,形成唯一的id,这个唯一的id可以将各个标志物区分开来,使得程序可以对指定的标志物进行操作
int32 type  //类型
int32 action 	//操作,是添加还是修改还是删除
geometry_msgs/Pose pose       # Pose of the object
geometry_msgs/Vector3 scale   # Scale of the object 1,1,1 means default (usually 1 meter square)
std_msgs/ColorRGBA color      # Color [0.0-1.0]
duration lifetime             # How long the object should last before being automatically deleted.  0 means forever
bool frame_locked             # If this marker should be frame-locked, i.e. retransformed into its frame every timestep
 
#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
geometry_msgs/Point[] points//这个是在序列、点集中才会用到,指明序列中每个点的位置
#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
#number of colors must either be 0 or equal to the number of points
#NOTE: alpha is not yet used
std_msgs/ColorRGBA[] colors
 
# NOTE: only used for text markers
string text
 
# NOTE: only used for MESH_RESOURCE markers
string mesh_resource
bool mesh_use_embedded_materials

示例代码:

根据起始点和终点,可视化多条直线

/*
typedef struct _generate_line
{
	//first point
	double x1;
	double y1;
	//end point
	double x2;
	double y2;
}gline;
*/
void LaserFeatureROS::publishMarkerMsg(const std::vector<gline> &m_gline,visualization_msgs::Marker &marker_msg)
{
	marker_msg.ns = "line_extraction";
	marker_msg.id = 0;
	marker_msg.type = visualization_msgs::Marker::LINE_LIST;
	marker_msg.scale.x = 0.1;
	marker_msg.color.r = 1.0;
	marker_msg.color.g = 0.0;
	marker_msg.color.b = 0.0;
	marker_msg.color.a = 1.0;
  

	for (std::vector<gline>::const_iterator cit = m_gline.begin(); cit != m_gline.end(); ++cit)
	{
		geometry_msgs::Point p_start;
		p_start.x = cit->x1;
	    p_start.y = cit->y1;
	    p_start.z = 0;
	    marker_msg.points.push_back(p_start);
	    geometry_msgs::Point p_end;
	    p_end.x = cit->x2;
	    p_end.y = cit->y2;
	    p_end.z = 0;
	    marker_msg.points.push_back(p_end);
	}
	marker_msg.header.frame_id = "laser";
	marker_msg.header.stamp = ros::Time::now();
}
int main()
{
    visualization_msgs::Marker marker_msg;
    publishMarkerMsg(glines, marker_msg);
    marker_publisher_.publish(marker_msg);
}

Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000