helper_functions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <string>
19 #include <map>
20 
21 #include <ros/ros.h>
22 #include <ros/package.h>
23 #include <boost/filesystem.hpp>
25 
26 
28 const std::string resolveURI(const std::string& path)
29 {
30  static std::map<std::string, std::string> package_cache;
31  std::string uri = path;
32 
33  if (uri.find("file://") == 0)
34  {
35  // Strip off the file://
36  uri.erase(0, strlen("file://"));
37 
38  // Resolve the mesh path as a file URI
39  boost::filesystem::path file_path(uri);
40  return file_path.string();
41  }
42  else if (uri.find("package://") == 0)
43  {
44  // Strip off the package://
45  uri.erase(0, strlen("package://"));
46 
47  // Resolve the mesh path as a ROS package URI
48  size_t package_end = uri.find("/");
49  std::string package = uri.substr(0, package_end);
50  std::string package_path;
51 
52  // Use the package cache if we have resolved this package before
53  std::map<std::string, std::string>::iterator it = package_cache.find(package);
54  if (it != package_cache.end())
55  {
56  package_path = it->second;
57  }
58  else
59  {
60  package_path = ros::package::getPath(package);
61  package_cache[package] = package_path;
62  }
63 
64  // Show a warning if the package was not resolved
65  if (package_path.empty())
66  {
67  ROS_ERROR("Unable to find package [%s].", package.c_str());
68  return "";
69  }
70 
71  // Append the remaining relative path
72  boost::filesystem::path file_path(package_path);
73  uri.erase(0, package_end);
74  file_path /= uri;
75 
76  // Return the canonical path
77  return file_path.string();
78  }
79  else
80  {
81  ROS_ERROR("Cannot handle mesh URI type [%s].", uri.c_str());
82  return "";
83  }
84 }
string package
const std::string resolveURI(const std::string &path)
ROSLIB_DECL std::string getPath(const std::string &package_name)
#define ROS_ERROR(...)


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47