Klamp't  0.9.0
urdf_link.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Wim Meeussen */
36 
37 #ifndef URDF_INTERFACE_LINK_H
38 #define URDF_INTERFACE_LINK_H
39 
40 #include <string>
41 #include <vector>
42 #include <map>
43 #include <memory>
44 
45 #include "urdf_joint.h"
46 #include "urdf_color.h"
47 
48 namespace urdf{
49 
50  // ******************************
51  // GEOMETRY STUFF
52  // ******************************
53 
57  class Geometry {
58  public:
59  enum {SPHERE, BOX, CYLINDER, MESH} type;
60 
61  virtual ~Geometry(void)
62  {
63  }
64  };
65 
69  class Sphere : public Geometry {
70  public:
71  Sphere() { this->clear(); };
72  double radius;
73 
74  void clear()
75  {
76  radius = 0;
77  };
78  };
79 
83  class Box : public Geometry {
84  public:
85  Box() { this->clear(); };
86  Vector3 dim;
87 
88  void clear()
89  {
90  this->dim.clear();
91  };
92  };
93 
97  class Cylinder : public Geometry {
98 
99  public:
100  Cylinder() { this->clear(); };
101  double length;
102  double radius;
103 
104  void clear()
105  {
106  length = 0;
107  radius = 0;
108  };
109 };
110 
114  class Mesh : public Geometry {
115  public:
116  Mesh() { this->clear(); };
117  std::string filename;
118  Vector3 scale;
119 
120  void clear()
121  {
122  filename.clear();
123  // default scale
124  scale.x = 1;
125  scale.y = 1;
126  scale.z = 1;
127  };
128  };
129 
130  // ******************************
131  // MATERIAL STUFF
132  // ******************************
133 
137  class Material {
138  public:
139  Material() { this->clear(); };
140  std::string name;
141  std::string texture_filename;
142  Color color;
143 
144  void clear()
145  {
146  color.clear();
147  texture_filename.clear();
148  name.clear();
149  };
150  };
151 
152  // ******************************
153  // INERTIAL STUFF
154  // ******************************
155 
159  class Inertial {
160  public:
161  Inertial() { this->clear(); };
162  Pose origin;
163  double mass;
164  double ixx,ixy,ixz,iyy,iyz,izz;
165 
166  void clear()
167  {
168  origin.clear();
169  mass = 0;
170  ixx = ixy = ixz = iyy = iyz = izz = 0;
171  };
172  };
173 
174  // ******************************
175  // VISUAL STUFF
176  // ******************************
177 
181  class Visual {
182  public:
183  Visual() { this->clear(); };
184  Pose origin;
185  std::shared_ptr<Geometry> geometry;
186 
187  std::string material_name;
188  std::shared_ptr<Material> material;
189 
190  void clear()
191  {
192  origin.clear();
193  material_name.clear();
194  material.reset();
195  geometry.reset();
196  this->group_name.clear();
197  };
198  std::string group_name;
199  };
200 
201  // ******************************
202  // COLLISION STUFF
203  // ******************************
204 
208  class Collision {
209  public:
210  Collision() { this->clear(); };
211  Pose origin;
212  std::shared_ptr<Geometry> geometry;
213 
214  void clear()
215  {
216  origin.clear();
217  geometry.reset();
218  this->group_name.clear();
219  };
220  std::string group_name;
221  };
222 
223 
224  // ******************************
225  // LINK STUFF
226  // ******************************
227 
231  class Link {
232  public:
233  Link() { this->clear(); };
234 
235  std::string name;
236 
238  std::shared_ptr<Inertial> inertial;
239 
241  std::shared_ptr<Visual> visual;
242 
244  std::shared_ptr<Collision> collision;
245 
247  std::map<std::string, std::shared_ptr<std::vector<std::shared_ptr<Visual> > > > visual_groups;
248 
250  std::map<std::string, std::shared_ptr<std::vector<std::shared_ptr<Collision> > > > collision_groups;
251 
255  std::shared_ptr<Joint> parent_joint;
256 
257  std::vector<std::shared_ptr<Joint> > child_joints;
258  std::vector<std::shared_ptr<Link> > child_links;
259 
260  std::shared_ptr<Link> getParent() const
261  {return parent_link_.lock();};
262 
263  void setParent(const std::shared_ptr<Link> &parent)
264  { parent_link_ = parent; }
265 
266  void clear()
267  {
268  this->name.clear();
269  this->inertial.reset();
270  this->visual.reset();
271  this->collision.reset();
272  this->parent_joint.reset();
273  this->child_joints.clear();
274  this->child_links.clear();
275  this->collision_groups.clear();
276  };
277 
278  std::vector<std::shared_ptr<Geometry > > getVisualGeoms(const std::string& group_name) const
279  {
280  std::vector<std::shared_ptr<Geometry > > geoms;
281  if (this->visual_groups.find(group_name) != this->visual_groups.end()) {
282  const auto& vs = this->visual_groups.at(group_name);
283  for(const auto& vis : *vs)
284  geoms.push_back(vis->geometry);
285  }
286  return geoms;
287  }
288 
289  std::vector<Pose> getVisualPoses(const std::string& group_name) const
290  {
291  std::vector<Pose> poses;
292  if (this->visual_groups.find(group_name) != this->visual_groups.end()) {
293  const auto& vs = this->visual_groups.at(group_name);
294  for(const auto& vis : *vs)
295  poses.push_back(vis->origin);
296  }
297  return poses;
298  }
299 
300  std::vector<std::shared_ptr<Geometry > > getCollisionGeoms(const std::string& group_name) const
301  {
302  std::vector<std::shared_ptr<Geometry > > geoms;
303  if (this->collision_groups.find(group_name) != this->collision_groups.end()) {
304  const auto& vs = this->collision_groups.at(group_name);
305  for(const auto& vis : *vs)
306  geoms.push_back(vis->geometry);
307  }
308  return geoms;
309  }
310 
311  std::vector<Pose> getCollisionPoses(const std::string& group_name) const
312  {
313  std::vector<Pose> poses;
314  if (this->collision_groups.find(group_name) != this->collision_groups.end()) {
315  const auto& vs = this->collision_groups.at(group_name);
316  for(const auto& vis : *vs)
317  poses.push_back(vis->origin);
318  }
319  return poses;
320  }
321 
322  private:
323  std::weak_ptr<Link> parent_link_;
324 
325  };
326 
327 
328 } // namespace urdf
329 
330 #endif
Definition: urdf_color.h:52
Definition: urdf_link.h:69
Definition: urdf_link.h:114
Definition: urdf_link.h:83
Definition: urdf_link.h:97
Definition: urdf_link.h:181
Definition: urdf_color.h:46
Definition: urdf_pose.h:239
Definition: urdf_pose.h:54
Definition: urdf_link.h:208
Definition: urdf_link.h:159
Definition: urdf_link.h:137