Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <urdf_traverser/UrdfTraverser.h>
00003 #include <urdf_traverser/Functions.h>
00004 #include <urdf2inventor/Helpers.h>
00005 #include <urdf2inventor/MeshConvertRecursionParams.h>
00006
00007 #include <urdf2graspit/Types.h>
00008 #include <urdf2graspit/ConvertGraspitMesh.h>
00009 #include <urdf2graspit/XMLFuncs.h>
00010
00011 using urdf_traverser::UrdfTraverser;
00012 using urdf_traverser::RecursionParams;
00013 using urdf2inventor::MeshConvertRecursionParams;
00014
00015 using urdf_traverser::LinkPtr;
00016 using urdf_traverser::JointPtr;
00017 using urdf_traverser::VisualPtr;
00018 using urdf_traverser::GeometryPtr;
00019 using urdf_traverser::MeshPtr;
00020 using urdf_traverser::SpherePtr;
00021 using urdf_traverser::CylinderPtr;
00022 using urdf_traverser::BoxPtr;
00023
00024
00028 int convertGraspItMesh(urdf_traverser::RecursionParamsPtr& p)
00029 {
00030
00031 typedef urdf2inventor::MeshConvertRecursionParams<std::string> MeshConvertRecursionParamsT;
00032 typename MeshConvertRecursionParamsT::Ptr param = baselib_binding_ns::dynamic_pointer_cast<MeshConvertRecursionParamsT>(p);
00033
00034 if (!param.get())
00035 {
00036 ROS_ERROR("Wrong recursion parameter type");
00037 return -1;
00038 }
00039
00040 LinkPtr link = param->getLink();
00041
00042 std::string linkMeshFile = urdf_traverser::helpers::getFilename(link->name.c_str()) + param->extension;
00043 std::string linkXML = urdf2graspit::xmlfuncs::getLinkDescXML(link, linkMeshFile, param->material);
00044
00045
00046 if (!param->resultMeshes.insert(std::make_pair(link->name, linkXML)).second)
00047 {
00048 ROS_ERROR("Could not insert the resulting mesh description file for link %s to the map", link->name.c_str());
00049 return -1;
00050 }
00051
00052 return 1;
00053 }
00054
00055 bool urdf2graspit::convertGraspItMeshes(
00056 UrdfTraverser& traverser,
00057 const std::string& fromLinkName,
00058 double scale_factor,
00059 const std::string& material,
00060 const std::string& file_extension,
00061 const EigenTransform& addVisualTransform,
00062 std::map<std::string, std::string>& meshDescXML)
00063 {
00064 std::string startLinkName=fromLinkName;
00065 if (startLinkName.empty()){
00066 startLinkName = traverser.getRootLinkName();
00067 }
00068
00069 urdf_traverser::LinkPtr startLink = traverser.getLink(startLinkName);
00070 if (!startLink.get())
00071 {
00072 ROS_ERROR("Link %s does not exist", startLinkName.c_str());
00073 return false;
00074 }
00075
00076 typedef urdf2inventor::MeshConvertRecursionParams<std::string> MeshConvertRecursionParamsT;
00077 typename MeshConvertRecursionParamsT::Ptr meshParams(new MeshConvertRecursionParamsT(
00078
00079 scale_factor,
00080 material,
00081 file_extension,
00082 addVisualTransform));
00083
00084 urdf_traverser::RecursionParamsPtr p(meshParams);
00085
00086 if (traverser.traverseTreeTopDown(startLinkName, boost::bind(&convertGraspItMesh, _1), p, true) <= 0)
00087 {
00088 ROS_ERROR_STREAM("Could not convert meshes.");
00089 return false;
00090 }
00091
00092 meshDescXML = meshParams->resultMeshes;
00093 return true;
00094 }
00095
00096