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

Revision history [back]

ros::Publisher marker_pub;
marker_pub = nh.advertise<visualization_msgs::Marker> ("visualization_marker",1);
visualization_msgs::Marker marker;
marker.header.frame_id = "/camera_link";
marker.header.stamp = ros::Time();
marker.ns = "lines";
marker.action = visualization_msgs::Marker::ADD;
marker.pose.orientation.w = 1;
marker.id = 1;
marker.type = visualization_msgs::Marker::POINTS;
marker.scale.x = 0.001;
marker.scale.y = 0.001;
marker.scale.z = 0.001;
marker.color.a = 1.0;
marker.color.r = 0.0;
marker.color.g = 1.0;
marker.color.b = 0.0;

     geometry_msgs::Point p; std_msgs::ColorRGBA pc;
     for(int i=0;i<a.size() && ros::ok();i++) {
        p.x = a.at(i); p.y = b.at(i); p.z = c.at(i); 
        pc.r =(float) r1.at(i)/255; pc.g =(float) g1.at(i)/255; pc.b =(float) b1.at(i)/255; pc.a=1;
        marker.points.push_back(p);
        marker.colors.push_back(pc); 
     }
     marker_pub.publish(marker);

This is the code which i tried and it is working as thought. Here a,b,c are vectors containing position of point and r1,g1,b1 are vectors containg color of given point.