19 #include <Eigen/Geometry>
22 #include <geometry_msgs/Point.h>
44 urdf::LinkConstSharedPtr link =
model_.getLink(link_name);
47 ROS_ERROR(
"Cannot find %s in URDF", link_name.c_str());
51 if (!link->collision->geometry)
53 ROS_ERROR(
"%s does not have collision geometry description.", link_name.c_str());
57 if (link->collision->geometry->type != urdf::Geometry::MESH)
59 ROS_ERROR(
"%s does not have mesh geometry", link_name.c_str());
64 std::string mesh_path = (
dynamic_cast<urdf::Mesh*
>(link->collision->geometry.get()))->filename;
67 Eigen::Vector3d scale((
dynamic_cast<urdf::Mesh*
>(link->collision->geometry.get()))->scale.x,
68 (
dynamic_cast<urdf::Mesh*
>(link->collision->geometry.get()))->scale.y,
69 (
dynamic_cast<urdf::Mesh*
>(link->collision->geometry.get()))->scale.z);
75 ROS_INFO(
"Loaded %s with %u vertices", mesh_path.c_str(), mesh->vertex_count);
78 Eigen::Matrix3d rotation = Eigen::Quaterniond(link->collision->origin.rotation.w,
79 link->collision->origin.rotation.x,
80 link->collision->origin.rotation.y,
81 link->collision->origin.rotation.z).toRotationMatrix();
82 Eigen::Vector3d translation(link->collision->origin.position.x,
83 link->collision->origin.position.y,
84 link->collision->origin.position.z);
87 for (
size_t v = 0; v < mesh->vertex_count; ++v)
89 Eigen::Vector3d p(mesh->vertices[(3 * v) + 0],
90 mesh->vertices[(3 * v) + 1],
91 mesh->vertices[(3 * v) + 2]);
93 p = (rotation * p) + translation;
95 mesh->vertices[(3 * v) + 0] = p(0);
96 mesh->vertices[(3 * v) + 1] = p(1);
97 mesh->vertices[(3 * v) + 2] = p(2);