Convert pcl::PolygonMesh to visualization_msgs::Marker
Hi everyone,
I am now working on converting PolygonMesh in PCL to Marker messages in ROS. I had some problems with rendering. I simply add polygons to a Marker message piece by piece and set the color to white, here is my code,
visualization_msgs::Marker marker;
geometry_msgs::Point temp;
std_msgs::ColorRGBA color;
pcl::PointCloud<pcl::PointXYZ>::Ptr mesh_cloud(new pcl::PointCloud<pcl::PointXYZ>);
int polygon_size;
int vertices_size;
marker.header.frame_id = "base";
marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
marker.action = visualization_msgs::Marker::ADD;
marker.scale.x = 1.0;
marker.scale.y = 1.0;
marker.scale.z = 1.0;
marker.pose.position.x = 0.0;
marker.pose.position.y = 0.0;
marker.pose.position.z = 0.0;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
marker.pose.orientation.w = 1.0;
color.a = 1;
color.r = 255;
color.g = 255;
color.b = 255;
polygon_size = mesh.polygons.size();
fromPCLPointCloud2(mesh.cloud, *mesh_cloud);
for (int i = 0; i < polygon_size; i++)
{
vertices_size = mesh.polygons[i].vertices.size();
for (int j = 0; j < vertices_size; j++)
{
temp.x = mesh_cloud->points[mesh.polygons[i].vertices[j]].x;
temp.y = mesh_cloud->points[mesh.polygons[i].vertices[j]].y;
temp.z = mesh_cloud->points[mesh.polygons[i].vertices[j]].z;
marker.points.push_back(temp);
marker.color = color;
}
}
But the results are not good, I don't know how can I tell the Marker which side is up or down. Can anybody who is happen to know this help me please? Any clues or suggestions would be appreciated!
I am having the same exact problem. Could you please post the solution if you found it?
There is a solution but I haven't implemented it yet. You just need to make sure that for each triangle, the vertices are added counterclockwise (or clockwise), then the colors will be consistent.
Ok I will try your suggestion and will get back to you as soon as I have it working. If you also implement it please post it. Thanks :)