utils.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 - 2016 CNRS
3 //
4 
5 #ifndef __pinocchio_parsers_utils_hpp__
6 #define __pinocchio_parsers_utils_hpp__
7 
8 #include <limits>
9 #include <sstream>
10 // #include <stdexcept>
11 
12 #include <boost/filesystem/fstream.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/format.hpp>
15 
17 #include <boost/filesystem.hpp>
18 
19 #include <exception>
20 
21 namespace pinocchio
22 {
27  {
28  UNKNOWN = 0,
30  };
31 
39  inline ModelFileExtensionType checkModelFileExtension(const std::string & filename)
40  {
41  const std::string extension = filename.substr(filename.find_last_of(".") + 1);
42 
43  if (extension == "urdf")
44  return URDF;
45 
46  return UNKNOWN;
47  }
48 
59  inline std::string
60  retrieveResourcePath(const std::string & string, const std::vector<std::string> & package_dirs)
61  {
62 
63  namespace bf = boost::filesystem;
64  std::string result_path;
65 
66  const std::string separator("://");
67  const std::size_t pos_separator = string.find(separator);
68  bf::path string_path(string);
69 
70  if (pos_separator != std::string::npos)
71  {
72  std::string scheme = string.substr(0, pos_separator);
73  std::string path = string.substr(pos_separator + 3, std::string::npos);
74 
75  if (scheme == "package" || scheme == "model")
76  {
77  // if exists p1/string, path = p1/string,
78  // else if exists p2/string, path = p2/string
79  // else return an empty string that may provoke an error in loadPolyhedronFromResource()
80 
81  // concatenate package_path with filename
82  for (std::size_t i = 0; i < package_dirs.size(); ++i)
83  {
84  if (bf::exists(bf::path(package_dirs[i] + "/" + path)))
85  {
86  result_path = std::string(package_dirs[i] + "/" + path);
87  break;
88  }
89  }
90  }
91  else if (scheme == "file")
92  {
93  result_path = path;
94  }
95  else
96  {
97  const std::string exception_message("Schemes of form" + scheme + "are not handled");
98  throw std::invalid_argument(exception_message);
99  }
100  }
101  else if (string_path.is_relative())
102  {
103  // handle the case where a relative mesh path is specified without using //package
104  for (std::size_t i = 0; i < package_dirs.size(); ++i)
105  {
106  if (bf::exists(bf::path(package_dirs[i] + "/" + string)))
107  {
108  result_path = std::string(package_dirs[i] + "/" + string);
109  break;
110  }
111  }
112  }
113  else // return the entry string
114  {
115  result_path = string;
116  }
117 
118  return result_path;
119  }
120 
121 } // namespace pinocchio
122 
123 #endif // __pinocchio_parsers_utils_hpp__
pinocchio::checkModelFileExtension
ModelFileExtensionType checkModelFileExtension(const std::string &filename)
Extract the type of the given model file according to its extension.
Definition: utils.hpp:39
quadrotor-ocp.path
string path
Definition: quadrotor-ocp.py:11
pinocchio::ModelFileExtensionType
ModelFileExtensionType
Supported model file extensions.
Definition: utils.hpp:26
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
pinocchio::UNKNOWN
@ UNKNOWN
Definition: utils.hpp:28
append-urdf-model-with-another-model.package_dirs
package_dirs
Definition: append-urdf-model-with-another-model.py:20
pinocchio::URDF
@ URDF
Definition: utils.hpp:29
filename
filename
pinocchio::retrieveResourcePath
std::string retrieveResourcePath(const std::string &string, const std::vector< std::string > &package_dirs)
Retrieve the path of the file whose path is given in URL-format. Currently convert from the following...
Definition: utils.hpp:60
file-explorer.hpp
boost::fusion
Definition: fusion.hpp:27
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:33