41 visualization_msgs::Marker& mk)
43 switch (shape_msg.type)
46 if (shape_msg.dimensions.size() <
48 throw std::runtime_error(
"Insufficient dimensions in sphere definition");
52 mk.scale.x = mk.scale.y = mk.scale.z = shape_msg.dimensions[shape_msgs::SolidPrimitive::SPHERE_RADIUS] * 2.0;
56 if (shape_msg.dimensions.size() <
58 throw std::runtime_error(
"Insufficient dimensions in box definition");
61 mk.type = visualization_msgs::Marker::CUBE;
62 mk.scale.x = shape_msg.dimensions[shape_msgs::SolidPrimitive::BOX_X];
63 mk.scale.y = shape_msg.dimensions[shape_msgs::SolidPrimitive::BOX_Y];
64 mk.scale.z = shape_msg.dimensions[shape_msgs::SolidPrimitive::BOX_Z];
68 if (shape_msg.dimensions.size() <
70 throw std::runtime_error(
"Insufficient dimensions in cone definition");
75 mk.scale.x = shape_msg.dimensions[shape_msgs::SolidPrimitive::CONE_RADIUS] * 2.0;
76 mk.scale.y = mk.scale.x;
77 mk.scale.z = shape_msg.dimensions[shape_msgs::SolidPrimitive::CONE_HEIGHT];
81 if (shape_msg.dimensions.size() <
83 throw std::runtime_error(
"Insufficient dimensions in cylinder definition");
87 mk.scale.x = shape_msg.dimensions[shape_msgs::SolidPrimitive::CYLINDER_RADIUS] * 2.0;
88 mk.scale.y = mk.scale.x;
89 mk.scale.z = shape_msg.dimensions[shape_msgs::SolidPrimitive::CYLINDER_HEIGHT];
96 throw std::runtime_error(
"Unknown shape type: " + ss.str());
102 bool use_mesh_triangle_list)
104 if (shape_msg.triangles.empty() || shape_msg.vertices.empty())
105 throw std::runtime_error(
"Mesh definition is empty");
106 if (use_mesh_triangle_list)
108 mk.type = visualization_msgs::Marker::TRIANGLE_LIST;
109 mk.scale.x = mk.scale.y = mk.scale.z = 1.0;
110 for (std::size_t i = 0; i < shape_msg.triangles.size(); ++i)
112 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[0]]);
113 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[1]]);
114 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[2]]);
119 mk.type = visualization_msgs::Marker::LINE_LIST;
120 mk.scale.x = mk.scale.y = mk.scale.z = 0.01;
121 for (std::size_t i = 0; i < shape_msg.triangles.size(); ++i)
123 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[0]]);
124 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[1]]);
125 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[0]]);
126 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[2]]);
127 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[1]]);
128 mk.points.push_back(shape_msg.vertices[shape_msg.triangles[i].vertex_indices[2]]);
void constructMarkerFromShape(const shape_msgs::Mesh &shape_msg, visualization_msgs::Marker &marker, bool use_mesh_triangle_list=true)
Convert a shape_msgs::Mesh shape_msg to a visualization_msgs::Marker marker.
The number of dimensions of a particular shape.