common.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <RBDyn/Joint.h>
8 #include <RBDyn/MultiBody.h>
10 #include <RBDyn/MultiBodyGraph.h>
11 #include <RBDyn/parsers/api.h>
12 
13 #include <SpaceVecAlg/SpaceVecAlg>
14 
15 #include <boost/variant.hpp>
16 
17 #include <Eigen/Core>
18 #include <string>
19 
20 namespace rbd
21 {
22 
23 namespace parsers
24 {
25 
26 enum class ParserInput
27 {
28  File,
30 };
31 
33 {
34 public:
35  std::map<std::string, std::vector<double>> lower;
36  std::map<std::string, std::vector<double>> upper;
37  std::map<std::string, std::vector<double>> velocity;
38  std::map<std::string, std::vector<double>> torque;
39 };
40 
42 {
43 public:
44  struct Mesh
45  {
46  Mesh() : scaleV(Eigen::Vector3d::Ones()) {}
47  std::string filename;
48  Eigen::Vector3d scaleV;
49  };
50  struct Box
51  {
52  Box() : size(Eigen::Vector3d::Zero()) {}
53  Eigen::Vector3d size;
54  };
55  struct Cylinder
56  {
57  Cylinder() : radius(0.), length(0.) {}
58  double radius;
59  double length;
60  };
61  struct Sphere
62  {
63  Sphere() : radius(0.) {}
64  double radius;
65  };
66 
76  {
77  Superellipsoid() : size(Eigen::Vector3d::Zero()), epsilon1(1), epsilon2(1) {}
78  Eigen::Vector3d size;
79  double epsilon1, epsilon2;
80  };
81 
82  enum Type
83  {
84  BOX,
89  UNKNOWN
90  };
92  using Data = boost::variant<Box, Cylinder, Mesh, Sphere, Superellipsoid>;
94 
95  Geometry() : type(UNKNOWN) {}
96 };
97 
106 {
107  struct Color
108  {
109  double r;
110  double g;
111  double b;
112  double a;
113  };
114  struct Texture
115  {
116  std::string filename;
117  };
118 
119  enum class Type
120  {
121  NONE,
122  COLOR,
123  TEXTURE
124  };
126  using Data = boost::variant<Color, Texture>;
128 
129  Material() : type(Type::NONE) {}
130 };
131 
133 {
134  std::string name;
135  sva::PTransformd origin;
138 };
139 
142 {
144  bool fixed_ = true;
145 
152  std::vector<std::string> filtered_links_ = {};
153 
161  bool remove_filtered_links_ = true;
162 
164  bool transform_inertia_ = true;
165 
167  std::string base_link_ = "";
168 
173  bool remove_virtual_links_ = false;
174 
176  std::string spherical_suffix_ = "_spherical";
177 
179  inline ParserParameters & fixed(bool fixed) noexcept
180  {
181  fixed_ = fixed;
182  return *this;
183  }
184 
186  inline ParserParameters & filtered_links(const std::vector<std::string> & links) noexcept
187  {
188  filtered_links_ = links;
189  return *this;
190  }
191 
193  inline ParserParameters & remove_filtered_links(bool value) noexcept
194  {
195  remove_filtered_links_ = value;
196  return *this;
197  }
198 
200  inline ParserParameters & transform_inertia(bool value) noexcept
201  {
202  transform_inertia_ = value;
203  return *this;
204  }
205 
207  inline ParserParameters & base_link(const std::string & link) noexcept
208  {
209  base_link_ = link;
210  return *this;
211  }
212 
214  inline ParserParameters & remove_virtual_links(bool value) noexcept
215  {
216  remove_virtual_links_ = value;
217  return *this;
218  }
219 
221  inline ParserParameters & spherical_suffix(const std::string & suffix) noexcept
222  {
223  spherical_suffix_ = suffix;
224  return *this;
225  }
226 };
227 
229 {
234  std::map<std::string, std::vector<Visual>> visual;
235  std::map<std::string, std::vector<Visual>> collision;
236  std::string name;
237 };
238 
243 RBDYN_PARSERS_DLLAPI ParserResult from_file(const std::string & file_path,
244  bool fixed = true,
245  const std::vector<std::string> & filtered_links = {},
246  bool transform_inertia = true,
247  const std::string & base_link = "",
248  bool with_virtual_links = true,
249  const std::string spherical_suffix = "_spherical");
250 
256 RBDYN_PARSERS_DLLAPI ParserResult from_file(const std::string & file_path, const ParserParameters & params);
257 
265 RBDYN_PARSERS_DLLAPI std::string prefix_path(const std::string & path);
266 
267 } // namespace parsers
268 
269 } // namespace rbd
rbd::parsers::Geometry::Cylinder::Cylinder
Cylinder()
Definition: common.h:57
rbd::parsers::Material::Color::g
double g
Definition: common.h:110
rbd::parsers::Geometry::Superellipsoid::Superellipsoid
Superellipsoid()
Definition: common.h:77
rbd::parsers::Visual::name
std::string name
Definition: common.h:134
rbd::parsers::Geometry
Definition: common.h:41
rbd::parsers::Geometry::Box
Definition: common.h:50
rbd::parsers::Geometry::BOX
@ BOX
Definition: common.h:84
rbd::parsers::Geometry::Cylinder::length
double length
Definition: common.h:59
rbd::parsers::Geometry::Superellipsoid::epsilon2
double epsilon2
Definition: common.h:79
rbd::parsers::Limits::velocity
std::map< std::string, std::vector< double > > velocity
Definition: common.h:37
rbd::parsers::Material::Color
Definition: common.h:107
rbd::parsers::ParserResult::mbg
rbd::MultiBodyGraph mbg
Definition: common.h:232
rbd::parsers::Visual::material
Material material
Definition: common.h:137
rbd::parsers::ParserResult::name
std::string name
Definition: common.h:236
rbd::parsers::Limits
Definition: common.h:32
rbd::parsers::Geometry::Superellipsoid::size
Eigen::Vector3d size
Definition: common.h:78
rbd::parsers::Geometry::Box::size
Eigen::Vector3d size
Definition: common.h:53
rbd::parsers::ParserParameters::remove_virtual_links
ParserParameters & remove_virtual_links(bool value) noexcept
Definition: common.h:214
rbd::parsers::ParserParameters::remove_filtered_links
ParserParameters & remove_filtered_links(bool value) noexcept
Definition: common.h:193
rbd::parsers::Geometry::MESH
@ MESH
Definition: common.h:87
rbd::parsers::Geometry::Mesh::scaleV
Eigen::Vector3d scaleV
Definition: common.h:48
rbd::parsers::Geometry::Sphere::radius
double radius
Definition: common.h:64
rbd::parsers::Visual::origin
sva::PTransformd origin
Definition: common.h:135
rbd::parsers::ParserParameters::spherical_suffix
ParserParameters & spherical_suffix(const std::string &suffix) noexcept
Definition: common.h:221
rbd::MultiBody
Definition: MultiBody.h:29
rbd::parsers::ParserInput::File
@ File
rbd::parsers::Material::Color::b
double b
Definition: common.h:111
rbd::parsers::ParserResult::limits
Limits limits
Definition: common.h:233
Joint.h
rbd::parsers::Geometry::Mesh::filename
std::string filename
Definition: common.h:47
rbd::parsers::Material::Data
boost::variant< Color, Texture > Data
Definition: common.h:126
rbd::parsers::from_file
RBDYN_PARSERS_DLLAPI ParserResult from_file(const std::string &file_path, bool fixed=true, const std::vector< std::string > &filtered_links={}, bool transform_inertia=true, const std::string &base_link="", bool with_virtual_links=true, const std::string spherical_suffix="_spherical")
Checks the file extension and parses it as URDF or YAML accordingly.
rbd::parsers::prefix_path
RBDYN_PARSERS_DLLAPI std::string prefix_path(const std::string &path)
Ensures that a path is prefixed by either package:// or file://.
rbd::parsers::Material::Material
Material()
Definition: common.h:129
rbd::parsers::Limits::torque
std::map< std::string, std::vector< double > > torque
Definition: common.h:38
rbd::parsers::ParserResult
Definition: common.h:228
RBDYN_PARSERS_DLLAPI
#define RBDYN_PARSERS_DLLAPI
Definition: api.h:43
rbd::parsers::Geometry::Box::Box
Box()
Definition: common.h:52
rbd::parsers::Geometry::Superellipsoid
A Superellipsoid can approximate primitive shapes as boxes, cylinders and pyrimids while remaining st...
Definition: common.h:75
rbd::parsers::Geometry::Sphere
Definition: common.h:61
rbd::parsers::Material::Color::a
double a
Definition: common.h:112
MultiBodyConfig.h
rbd::parsers::ParserResult::mb
rbd::MultiBody mb
Definition: common.h:230
rbd::parsers::Material
Definition: common.h:105
rbd::MultiBodyGraph
Definition: MultiBodyGraph.h:32
rbd::parsers::Geometry::Data
boost::variant< Box, Cylinder, Mesh, Sphere, Superellipsoid > Data
Definition: common.h:92
rbd::parsers::Geometry::Sphere::Sphere
Sphere()
Definition: common.h:63
rbd::parsers::Material::Texture
Definition: common.h:114
rbd::parsers::Limits::lower
std::map< std::string, std::vector< double > > lower
Definition: common.h:35
rbd::parsers::ParserParameters::transform_inertia
ParserParameters & transform_inertia(bool value) noexcept
Definition: common.h:200
rbd::parsers::Geometry::type
Type type
Definition: common.h:91
rbd
Definition: common.h:20
rbd::parsers::Geometry::Mesh
Definition: common.h:44
rbd::parsers::Geometry::Cylinder
Definition: common.h:55
MultiBodyGraph.h
rbd::parsers::ParserParameters::fixed
ParserParameters & fixed(bool fixed) noexcept
Definition: common.h:179
rbd::MultiBodyConfig
Definition: MultiBodyConfig.h:23
MultiBody.h
rbd::parsers::Geometry::SUPERELLIPSOID
@ SUPERELLIPSOID
Definition: common.h:88
rbd::parsers::ParserParameters::base_link
ParserParameters & base_link(const std::string &link) noexcept
Definition: common.h:207
rbd::parsers::Material::data
Data data
Definition: common.h:127
rbd::parsers::Geometry::data
Data data
Definition: common.h:93
rbd::parsers::ParserResult::mbc
rbd::MultiBodyConfig mbc
Definition: common.h:231
rbd::parsers::ParserParameters
Definition: common.h:141
rbd::parsers::Visual::geometry
Geometry geometry
Definition: common.h:136
rbd::parsers::Material::Texture::filename
std::string filename
Definition: common.h:116
rbd::parsers::ParserInput
ParserInput
Definition: common.h:26
rbd::parsers::Geometry::Mesh::Mesh
Mesh()
Definition: common.h:46
rbd::parsers::ParserParameters::filtered_links
ParserParameters & filtered_links(const std::vector< std::string > &links) noexcept
Definition: common.h:186
rbd::parsers::Geometry::Geometry
Geometry()
Definition: common.h:95
rbd::parsers::ParserInput::Description
@ Description
rbd::parsers::Visual
Definition: common.h:132
rbd::parsers::Material::Color::r
double r
Definition: common.h:109
rbd::parsers::Geometry::SPHERE
@ SPHERE
Definition: common.h:86
rbd::parsers::Geometry::Type
Type
Definition: common.h:82
rbd::parsers::Material::type
Type type
Definition: common.h:125
rbd::parsers::ParserResult::collision
std::map< std::string, std::vector< Visual > > collision
Definition: common.h:235
rbd::parsers::Geometry::Cylinder::radius
double radius
Definition: common.h:58
rbd::parsers::Material::Type
Type
Definition: common.h:119
rbd::parsers::Geometry::CYLINDER
@ CYLINDER
Definition: common.h:85
rbd::parsers::ParserResult::visual
std::map< std::string, std::vector< Visual > > visual
Definition: common.h:234
rbd::parsers::Limits::upper
std::map< std::string, std::vector< double > > upper
Definition: common.h:36
api.h