DART  6.7.3
DartLoader.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_UTILS_URDF_DARTLOADER_HPP_
34 #define DART_UTILS_URDF_DARTLOADER_HPP_
35 
36 #include <Eigen/Core>
37 #include <Eigen/Geometry>
38 #include <map>
39 #include <string>
40 
43 #include "dart/common/Uri.hpp"
45 #include "dart/dynamics/Joint.hpp"
50 
51 namespace urdf
52 {
53  class ModelInterface;
54  class Link;
55  class Joint;
56  class Pose;
57  class Vector3;
58 }
59 
60 namespace dart {
61 
62 namespace dynamics
63 {
64  class Skeleton;
65  class BodyNode;
66  class Joint;
67  class Shape;
68 }
69 namespace simulation
70 {
71  class World;
72 }
73 
74 namespace utils {
75 
79 class DartLoader {
80  public:
82  DartLoader();
83 
103  void addPackageDirectory(const std::string& _packageName,
104  const std::string& _packageDirectory);
105 
108  const common::Uri& _uri,
109  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr);
110 
113  const std::string& _urdfString, const common::Uri& _baseUri,
114  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr);
115 
118  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr);
119 
122  const std::string& _urdfString, const common::Uri& _baseUri,
123  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr);
124 
125 private:
126  typedef std::shared_ptr<dynamics::BodyNode::Properties> BodyPropPtr;
127  typedef std::shared_ptr<dynamics::Joint::Properties> JointPropPtr;
128 
130  const urdf::ModelInterface* _model,
131  const common::Uri& _baseUri,
132  const common::ResourceRetrieverPtr& _resourceRetriever);
133 
134  static bool createSkeletonRecursive(
135  const urdf::ModelInterface* model,
136  dynamics::SkeletonPtr _skel,
137  const urdf::Link* _lk,
138  dynamics::BodyNode* _parent,
139  const common::Uri& _baseUri,
140  const common::ResourceRetrieverPtr& _resourceRetriever);
141 
142  static bool addMimicJointsRecursive(
143  const urdf::ModelInterface* model,
144  dynamics::SkeletonPtr _skel,
145  const urdf::Link* _lk);
146 
147  template <class VisualOrCollision>
148  static dynamics::ShapePtr createShape(const VisualOrCollision* _vizOrCol,
149  const common::Uri& _baseUri,
150  const common::ResourceRetrieverPtr& _resourceRetriever);
151 
153  const urdf::Joint* _jt,
154  const dynamics::BodyNode::Properties& _body,
155  dynamics::BodyNode* _parent,
156  dynamics::SkeletonPtr _skeleton,
157  const common::Uri& _baseUri,
158  const common::ResourceRetrieverPtr& _resourceRetriever);
159 
160  static bool createDartNodeProperties(
161  const urdf::Link* _lk,
163  const common::Uri& _baseUri,
164  const common::ResourceRetrieverPtr& _resourceRetriever);
165 
166  static bool createShapeNodes(
167  const urdf::ModelInterface* model,
168  const urdf::Link* lk,
169  dynamics::BodyNode* bodyNode,
170  const common::Uri& baseUri,
171  const common::ResourceRetrieverPtr& resourceRetriever);
172 
174  const common::ResourceRetrieverPtr& _resourceRetriever);
175 
176  static Eigen::Isometry3d toEigen(const urdf::Pose& _pose);
177  static Eigen::Vector3d toEigen(const urdf::Vector3& _vector);
178 
179  static bool readFileToString(
180  const common::ResourceRetrieverPtr& _resourceRetriever,
181  const common::Uri& _uri,
182  std::string &_output);
183 
187 };
188 
189 }
190 }
191 
192 #endif // DART_UTILS_URDF_DARTLOADER_HPP_
BodyPropPtr properties
Definition: SdfParser.cpp:80
Definition: CompositeData.hpp:180
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:78
Definition: DartLoader.hpp:79
utils::CompositeResourceRetrieverPtr mRetriever
Definition: DartLoader.hpp:186
static dynamics::ShapePtr createShape(const VisualOrCollision *_vizOrCol, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function createShape
Definition: DartLoader.cpp:606
static Eigen::Isometry3d toEigen(const urdf::Pose &_pose)
@function pose2Affine3d
Definition: DartLoader.cpp:687
dart::simulation::WorldPtr parseWorld(const common::Uri &_uri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr)
Parse a file to produce a World.
Definition: DartLoader.cpp:126
static dart::dynamics::SkeletonPtr modelInterfaceToSkeleton(const urdf::ModelInterface *_model, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function modelInterfaceToSkeleton
Definition: DartLoader.cpp:197
void addPackageDirectory(const std::string &_packageName, const std::string &_packageDirectory)
Specify the directory of a ROS package.
Definition: DartLoader.cpp:75
static bool createSkeletonRecursive(const urdf::ModelInterface *model, dynamics::SkeletonPtr _skel, const urdf::Link *_lk, dynamics::BodyNode *_parent, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
Definition: DartLoader.cpp:272
dart::simulation::WorldPtr parseWorldString(const std::string &_urdfString, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr)
Parse a text string to produce a World.
Definition: DartLoader.cpp:140
common::ResourceRetrieverPtr getResourceRetriever(const common::ResourceRetrieverPtr &_resourceRetriever)
Definition: DartLoader.cpp:666
static dynamics::BodyNode * createDartJointAndNode(const urdf::Joint *_jt, const dynamics::BodyNode::Properties &_body, dynamics::BodyNode *_parent, dynamics::SkeletonPtr _skeleton, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function createDartJoint
Definition: DartLoader.cpp:375
static bool addMimicJointsRecursive(const urdf::ModelInterface *model, dynamics::SkeletonPtr _skel, const urdf::Link *_lk)
Definition: DartLoader.cpp:306
common::LocalResourceRetrieverPtr mLocalRetriever
Definition: DartLoader.hpp:184
std::shared_ptr< dynamics::Joint::Properties > JointPropPtr
Definition: DartLoader.hpp:127
static bool readFileToString(const common::ResourceRetrieverPtr &_resourceRetriever, const common::Uri &_uri, std::string &_output)
@function readXml
Definition: DartLoader.cpp:358
std::shared_ptr< dynamics::BodyNode::Properties > BodyPropPtr
Definition: DartLoader.hpp:126
static bool createShapeNodes(const urdf::ModelInterface *model, const urdf::Link *lk, dynamics::BodyNode *bodyNode, const common::Uri &baseUri, const common::ResourceRetrieverPtr &resourceRetriever)
Definition: DartLoader.cpp:558
dynamics::SkeletonPtr parseSkeletonString(const std::string &_urdfString, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr)
Parse a text string to produce a Skeleton.
Definition: DartLoader.cpp:104
DartLoader()
Constructor with the default ResourceRetriever.
Definition: DartLoader.cpp:65
static bool createDartNodeProperties(const urdf::Link *_lk, dynamics::BodyNode::Properties &properties, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function createDartNode
Definition: DartLoader.cpp:508
utils::PackageResourceRetrieverPtr mPackageRetriever
Definition: DartLoader.hpp:185
dynamics::SkeletonPtr parseSkeleton(const common::Uri &_uri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr)
Parse a file to produce a Skeleton.
Definition: DartLoader.cpp:81
::fcl::Vec3f Vector3
Definition: BackwardCompatibility.hpp:140
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
std::shared_ptr< LocalResourceRetriever > LocalResourceRetrieverPtr
Definition: LocalResourceRetriever.hpp:58
std::shared_ptr< Shape > ShapePtr
Definition: SmartPointer.hpp:81
std::shared_ptr< Skeleton > SkeletonPtr
Definition: SmartPointer.hpp:60
std::shared_ptr< World > WorldPtr
Definition: SmartPointer.hpp:41
std::shared_ptr< CompositeResourceRetriever > CompositeResourceRetrieverPtr
Definition: CompositeResourceRetriever.hpp:88
std::shared_ptr< PackageResourceRetriever > PackageResourceRetrieverPtr
Definition: PackageResourceRetriever.hpp:107
Definition: BulletCollisionDetector.cpp:63
Definition: DartLoader.hpp:52
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87