rviz中根据可视化不同的值

// 渐变色函数
vector<int> getColor(int value){
	vector<int> startColor{0,255,0};
	vector<int> endColor{255,255,0};	
	if(value >= 255)
		return endColor;
	else if(value <= 0)
		return startColor;

	int r_gap=endColor[0]-startColor[0];
	int g_gap=endColor[1]-startColor[1];
	int b_gap=endColor[2]-startColor[2];
	
	// int nSteps = max(abs(r), max(abs(g), abs(b)));
	// if (nSteps < 1) nSteps = 1;
	int nSteps = 255;
	// Calculate the step size for each color
	float rStep=r_gap/(float)nSteps;
	float gStep=g_gap/(float)nSteps;
	float bStep=b_gap/(float)nSteps;

	// Reset the colors to the starting position
	float rStart=startColor[0];
	float gStart=startColor[1];
	float bStart=startColor[2];	

	// float step = (value - 255)/255;
	int step = value;
	int r = rStart + r_gap * value / 255;
	int g = gStart + g_gap * value / 255;
	int b = bStart + b_gap * value / 255;
	float a = value / 255;
	cout << r << " " << g << " " << b << endl;
	return vector<int>{r,g,b,a};
	// return vector<int>{(int)(rStart+rStep*step+0.5),(int)(gStart+gStep*step+0.5),(int)(bStart+bStep*step+0.5)};
}

后来发现在rviz中只有绿黄两种颜色,应该是rviz不支持渐变色。
解决方案:
1.用点云pointcloud

	sensor_msgs::PointCloud cloud;
	int num_points = cost_map.size[0]*cost_map.size[1]*cost_map.size[2];
	cloud.header.stamp = ros::Time::now();
    	cloud.header.frame_id = "map";//填充 PointCloud 消息的头:frame 和 timestamp.
    	cloud.points.resize(num_points);//设置点云的数量.
 
    	//增加信道 "intensity" 并设置其大小,使与点云数量相匹配.
    	cloud.channels.resize(1);
    	cloud.channels[0].name = "intensities";
    	cloud.channels[0].values.resize(num_points);
 
	//使用虚拟数据填充 PointCloud 消息.同时,使用虚拟数据填充 intensity 信道.
	int i = 0;
    	for (int row = 0; row < cost_map.size[0]; ++row)
		for (int col = 0; col < cost_map.size[1]; ++col)
                        for (int hei = 0;hei < cost_map.size[2]; ++ hei){
				cloud.points[i].x = camera_pose.position.x + (row - cam_posid[0]) * resolution;
				cloud.points[i].y = camera_pose.position.y + (col - cam_posid[1]) * resolution;
				cloud.points[i].z = camera_pose.position.z + (hei - cam_posid[2]) * resolution;
				int cur_cost =  cost_map.at<float>(row, col, hei);
				cloud.channels[0].values[i] = cur_cost;
				i++;
    			}
    costcloud_pub.publish(cloud);

2.渐变色中加入更多颜色变化,value值的变化表现在marker.color.alpha上

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值