0
$\begingroup$

Rosanswers logo

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++;
 }
}

Originally posted by liquidmonkey on ROS Answers with karma: 37 on 2012-04-18

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by atp with karma: 529 on 2014-12-07

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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