0
$\begingroup$

Rosanswers logo

Hey there,

I have a problem creating a CUBE_LIST with different colors for each cube. Below is my code. The strange thing is, that when setColor is set to true, all cubes are drawn in the same color (as expected in green), but when it is set to false, nothing is shown at all. How exactly is the use of the markerMsg attribute colors? Do you see the mistake I made? In the documentation it states "In visualization 1.1+ will also optionally use the colors member for per-vertex color.". How can I find out which version of visualization I am using? I have ros fuerte installed.

ros::Publisher pubTrackMarkers;
pubTrackMarkers = n.advertise<visualization_msgs::Marker>("/track_markers",queue_size, true);
visualization_msgs::Marker markerMsg;

markerMsg.header.frame_id  = "/trackMarkers_frame";
markerMsg.ns = "trackMarkers";
markerMsg.action = visualization_msgs::Marker::ADD;
markerMsg.pose.orientation.w = 1.0;
markerMsg.type = visualization_msgs::Marker::CUBE_LIST;
markerMsg.scale.x = 0.8f;
markerMsg.scale.y = 0.8f;
markerMsg.scale.z = 0.8f;
if (setColor){
    markerMsg.color.r = 0;
    markerMsg.color.g = 1;
    markerMsg.color.b = 0;
    markerMsg.color.a = 1;
}

for (int i=0; i<10; i++){
    geometry_msgs::Point temp;
    temp.x = i;
    temp.y = 1;
    temp.z = 0.5;
    markerMsg.points.push_back(temp);
    std_msgs::ColorRGBA c;
    c.r = (float)i/10.0;
    c.g = 0;
    c.b = 0;
    c.a = 1;
    markerMsg.colors.push_back(c);
}

pubTrackMarkers.publish(markerMsg);
markerMsg->points.clear();
markerMsg->colors.clear();

Thank you so much for your help! Jens

edit: solved! added the line "markerMsg->colors.clear();" now the number of color values and points is the same and it works. Thanks everyone!


Originally posted by tuxware on ROS Answers with karma: 11 on 2013-08-29

Post score: 1


Original comments

Comment by JonW on 2013-09-03:
Since i is in the range of zero to nine, could the value you are setting in the red channel be rounding down to zero?

Comment by tuxware on 2013-09-04:
Good point, but that's not it. Changed it to a switch case statement with 5 "hard coded" colors, still not working. Shouldn't the boxes still be drawn but black then? I just added clearing the colors vector in the markerMsg, as I forget that earlier. That was it!! Thanks everybody for the helpt!

Comment by RobustControl on 2020-11-15:
I have some problem about with CUBE_LIST marker. I use your code, set setColor=true, and I only get 10 points in the RVIZ, not ten cube.

I tried to write my own code to display CUBE_LIST, but still can't get correct result. Is there something error with my RVIZ?

Comment by OzzieTheHead on 2021-08-12:
@RobustControl This question is very old and most answers you see might be outdated. Are you setting the scale field for your cubes?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

One problem is that you are not using a Marker Array. For more than one Marker always use Marker Array. If you are not using Marker Array then push pubTrackMarkers.publish(markerMsg); inside the for loop. If you change to MarkerArray then use publisher of type <visualization_msgs::MarkerArray> Change this and tell me if you still have some problem


Originally posted by Gudjohnson with karma: 100 on 2013-08-29

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Gudjohnson on 2013-08-29:
are you really getting more than one marker on your screen in rviz?

Comment by tuxware on 2013-08-29:
Yes, I am getting more than one. Why shouldn't I use CUBE_LIST, if I am ok with all cubes having the same size and attributes except for color ans position? This should be working with CUBE_LIST, or not? http://www.ros.org/wiki/rviz/DisplayTypes/Marker#Cube_List_.28CUBE_LIST.3D6.29

Comment by tuxware on 2013-08-29:
By the way, I am having the same issue using LINE_LIST. Why should the publish method be called within the for loop? That really makes no sense to me... The msg is filled with 10 cubes and then published at the end. It is working if setColor is set to true!

Comment by OzzieTheHead on 2021-08-11:
Why is this marked as the correct answer?

First of all the message type is *_LIST. And the DisplayTypes/Marker page clearly states that marker lists will utilize batch-up rendering and perform better than MarkerArrays. You can see that in the code by looking at how context_->queueRender(); is called

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.