ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

making LINE_LIST lines different colors?

asked 2012-04-18 03:58:49 -0500

liquidmonkey gravatar image

updated 2014-04-20 14:09:32 -0500

ngrennan gravatar image

hi,

very quick summary -- how can you make each line when using LINE_LIST a different color? --

more specific: i'm using Rviz to create a bounding box around found clusters within a pointcloud. i have created the points and by using LINE_LIST, joined each pair together, giving me a bounding box around each cluster.

ideally i would like each bounding box to be a different color but i am unable to get this working. in my code below, i tried using 'j' to change the colors but only the last clusters color is chosen and that color is applied to all bounding box.

i also noticed there is a 'marker.colors' option but i was unable to get that working. there is very little documentation on it and i was not able to find any examples.

any ideas? thanks in advance for any suggestions :)

Eigen::Vector4f min_point;
Eigen::Vector4f max_point;
geometry_msgs::Point32 min_pt;
geometry_msgs::Point32 max_pt;

visualization_msgs::Marker lines;
lines.header.frame_id = "base_link";
lines.header.stamp = ros::Time::now();
lines.type = visualization_msgs::Marker::LINE_LIST;
lines.action = visualization_msgs::Marker::ADD;
lines.scale.x = 0.01;
lines.scale.y = 0.01;
lines.color.a = 1.0;
lines.ns = "my lines";
lines.id = 1;

int j = 1;
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin();
                                                   it != cluster_indices.end(); ++it)
{
  pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_cluster (new pcl::PointCloud<pcl::PointXYZI>);
  for (std::vector<int>::const_iterator pit = it->indices.begin(); pit != it->indices.end(); pit++)
       cloud_cluster->points.push_back (inCld->points[*pit]);

  cloud_cluster->width = cloud_cluster->points.size();
  cloud_cluster->height = 1;
  cloud_cluster->is_dense = true;

  pcl::getMinMax3D (*cloud_cluster, min_point, max_point);

  //minimum side face points
  geometry_msgs::Point pt1;
  pt1.x = max_point.x(); pt1.y = min_point.y(); pt1.z = max_point.z();

  geometry_msgs::Point pt2;
  pt2.x = min_point.x(); pt2.y = min_point.y(); pt2.z = max_point.z();

  geometry_msgs::Point pt3;
  pt3.x = max_point.x(); pt3.y = min_point.y(); pt3.z = min_point.z();


  lines.points.push_back(pt1); lines.points.push_back(pt2);
  lines.points.push_back(pt1); lines.points.push_back(pt3);

  lines.color.r = 1.0f / j;
  lines.color.g = 1.0f / j;
  lines.color.b = 1.0f / j;      

  pub_Bbox.publish (lines);
  j++;
 }
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-12-07 18:16:34 -0500

atp gravatar image

lines.color determines the color for all lines in visualization_msgs::Marker::LINE_LIST. You could use a MarkerArray instead of a Marker, and give each line list in the array a different color.

Also, you only need to do pub_Bbox.publish (lines); once. It should be after the for-loop.

edit flag offensive delete link more
0

answered 2017-04-18 10:15:07 -0500

Sagexs gravatar image

change the ns value like:

void draw_box(PointT min_point, PointT max_point, int number) {
    static ros::Publisher pub_marker = nh_.advertise<visualization_msgs::Marker>("/seg_box",1);
    visualization_msgs::Marker lines;
    lines.header.frame_id = MAIN_FRAME_ID;
    lines.header.stamp = ros::Time::now();
    lines.type = visualization_msgs::Marker::LINE_LIST;
    lines.action = visualization_msgs::Marker::ADD;
    lines.scale.x = 0.01;
    lines.scale.y = 0.01;
    lines.color.a = 1.0;

    std::stringstream ss;
    ss << number;

    lines.ns = "my lines_" + ss.str();
    lines.id = 1;

    geometry_msgs::Point pt1;
    pt1.x = min_point.x;
    pt1.y = min_point.y;
    pt1.z = min_point.z;

    geometry_msgs::Point pt2;
    pt2.x = min_point.x;
    pt2.y = min_point.y;
    pt2.z = max_point.z;

    geometry_msgs::Point pt3;
    pt3.x = max_point.x;
    pt3.y = min_point.y;
    pt3.z = min_point.z;

    geometry_msgs::Point pt4;
    pt4.x = max_point.x;
    pt4.y = min_point.y;
    pt4.z = max_point.z;

    geometry_msgs::Point pt5;
    pt5.x = min_point.x;
    pt5.y = max_point.y;
    pt5.z = min_point.z;

    geometry_msgs::Point pt6;
    pt6.x = min_point.x;
    pt6.y = max_point.y;
    pt6.z = max_point.z;

    geometry_msgs::Point pt7;
    pt7.x = max_point.x;
    pt7.y = max_point.y;
    pt7.z = min_point.z;

    geometry_msgs::Point pt8;
    pt8.x = max_point.x;
    pt8.y = max_point.y;
    pt8.z = max_point.z;

    lines.points.push_back(pt1);
    lines.points.push_back(pt2);
    lines.points.push_back(pt1);
    lines.points.push_back(pt3);
    lines.points.push_back(pt3);
    lines.points.push_back(pt4);
    lines.points.push_back(pt2);
    lines.points.push_back(pt4);

    lines.points.push_back(pt5);
    lines.points.push_back(pt6);
    lines.points.push_back(pt5);
    lines.points.push_back(pt7);
    lines.points.push_back(pt7);
    lines.points.push_back(pt8);
    lines.points.push_back(pt8);
    lines.points.push_back(pt6);


    lines.points.push_back(pt2);
    lines.points.push_back(pt6);
    lines.points.push_back(pt1);
    lines.points.push_back(pt5);
    lines.points.push_back(pt4);
    lines.points.push_back(pt8);
    lines.points.push_back(pt3);
    lines.points.push_back(pt7);



    if (number == 0) {
        lines.color.r = 1.0f;
    }
    else if (number == 1) {
        lines.color.g = 1.0f;
    }   else if (number == 2) {
        lines.color.b = 1.0f;
    }else if (number == 3) {
        lines.color.b = 1.0f;
        lines.color.g = 1.0f;
    }else if (number == 4) {
        lines.color.r = 1.0f;
        lines.color.g = 1.0f;
    }else if (number == 5) {
        lines.color.r = 1.0f;
        lines.color.b = 1.0f;
    }else if (number > 5) {
        lines.color.r = 1.0f;
        lines.color.g = 1.0f;
        lines.color.b = 1.0f;
    }

    pub_marker.publish(lines);

}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-04-18 03:58:49 -0500

Seen: 1,523 times

Last updated: Apr 18 '17