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

retrieve the bounding box of a mesh

asked 2011-02-21 11:39:17 -0600

ben gravatar image

Before I venture into figuring out how to make a bounding box of a mesh from a .mesh file or .stl file, I thought I would ask on this forum if the following has already been done somewhere in ros-pkgs:

  • retrieve a mesh file when the file path is in the resource_retriever format: "package://pr2_description/meshes/forearm_v0/forearm.stl"

  • compute a bounding box for the mesh

Maybe I'm just being lazy but I feel like it must have been done somewhere.

thanks, ben

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-02-22 14:14:41 -0600

ben gravatar image

Thanks fergs. It was actually pretty easy once I looked at the geometric_shapes package (motion_planning_common stack - version 3.0 or newer). I copied code from 2 different locations to accomplish the 2 things I listed above.

bool SBPLCollisionSpace::getBoundingCylinderOfMesh(std::string mesh_file, shapes::Shape &mesh, bodies::BoundingCylinder &cyl)
{
  bool retval = false;

  if (!mesh_file.empty())
  {
    resource_retriever::Retriever retriever;
    resource_retriever::MemoryResource res;
    bool ok = true;

    try
    {
      res = retriever.get(mesh_file);
    }
    catch (resource_retriever::Exception& e)
    {
      ROS_ERROR("%s", e.what());
      ok = false;
    }

    if (ok)
    {
      if (res.size == 0)
        ROS_WARN("Retrieved empty mesh for resource '%s'", mesh_file.c_str());
      else
      {
        mesh = shapes::createMeshFromBinaryStlData(reinterpret_cast<char*>(res.data.get()), res.size);
        if (mesh == NULL)
          ROS_ERROR("Failed to load mesh '%s'", mesh_file.c_str());
        else
          retval = true;
      }
    }
  }
  else
    ROS_WARN("Empty mesh filename");

  if(retval)
  {
    const bodies::Body *body=new bodies::ConvexMesh(mesh);
    body->computeBoundingCylinder(cyl);
    ROS_INFO("Bounding cylinder has radius: %0.3f  length: %0.3f", cyl.radius, cyl.length);
  }

  return retval;
}
edit flag offensive delete link more
1

answered 2011-02-21 12:46:19 -0600

fergs gravatar image

You might take a look at the geometry_shapes package: http://www.ros.org/wiki/geometric_shapes

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2011-02-21 11:39:17 -0600

Seen: 1,871 times

Last updated: Feb 22 '11