Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <string>
00019 #include <map>
00020
00021 #include <ros/ros.h>
00022 #include <ros/package.h>
00023 #include <boost/filesystem.hpp>
00024 #include "cob_obstacle_distance/helpers/helper_functions.hpp"
00025
00026
00028 const std::string resolveURI(const std::string& path)
00029 {
00030 static std::map<std::string, std::string> package_cache;
00031 std::string uri = path;
00032
00033 if (uri.find("file://") == 0)
00034 {
00035
00036 uri.erase(0, strlen("file://"));
00037
00038
00039 boost::filesystem::path file_path(uri);
00040 return file_path.string();
00041 }
00042 else if (uri.find("package://") == 0)
00043 {
00044
00045 uri.erase(0, strlen("package://"));
00046
00047
00048 size_t package_end = uri.find("/");
00049 std::string package = uri.substr(0, package_end);
00050 std::string package_path;
00051
00052
00053 std::map<std::string, std::string>::iterator it = package_cache.find(package);
00054 if (it != package_cache.end())
00055 {
00056 package_path = it->second;
00057 }
00058 else
00059 {
00060 package_path = ros::package::getPath(package);
00061 package_cache[package] = package_path;
00062 }
00063
00064
00065 if (package_path.empty())
00066 {
00067 ROS_ERROR("Unable to find package [%s].", package.c_str());
00068 return "";
00069 }
00070
00071
00072 boost::filesystem::path file_path(package_path);
00073 uri.erase(0, package_end);
00074 file_path /= uri;
00075
00076
00077 return file_path.string();
00078 }
00079 else
00080 {
00081 ROS_ERROR("Cannot handle mesh URI type [%s].", uri.c_str());
00082 return "";
00083 }
00084 }