/usr/include/kido/utils/sdf/SdfParser.hpp is in libkido-utils-dev 0.1.0+dfsg-2build9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | #ifndef KIDO_UTILS_SDFPARSER_H
#define KIDO_UTILS_SDFPARSER_H
#include <map>
#include <string>
#include <functional>
#include <Eigen/Dense>
#include <Eigen/StdVector>
// TinyXML-2 Library
// http://www.grinninglizard.com/tinyxml2/index.html
#include <tinyxml2.h>
#include "kido/common/Deprecated.hpp"
#include "kido/utils/XmlHelpers.hpp"
#include "kido/common/ResourceRetriever.hpp"
#include "kido/dynamics/BodyNode.hpp"
#include "kido/dynamics/WeldJoint.hpp"
#include "kido/dynamics/RevoluteJoint.hpp"
#include "kido/dynamics/PrismaticJoint.hpp"
#include "kido/dynamics/ScrewJoint.hpp"
#include "kido/dynamics/UniversalJoint.hpp"
#include "kido/dynamics/BallJoint.hpp"
#include "kido/dynamics/TranslationalJoint.hpp"
#include "kido/dynamics/FreeJoint.hpp"
#include "kido/simulation/World.hpp"
namespace kido {
namespace dynamics {
class Skeleton;
class BodyNode;
class Shape;
class Joint;
class WeldJoint;
class PrismaticJoint;
class RevoluteJoint;
class ScrewJoint;
class UniversalJoint;
class BallJoint;
class EulerXYZJoint;
class EulerJoint;
class TranslationalJoint;
class FreeJoint;
}
namespace simulation {
class World;
}
namespace utils {
class SdfParser
{
public:
// TODO: Make common::ResourceRetriever optional.
static kido::simulation::WorldPtr readSdfFile(
const common::Uri& _fileUri,
const common::ResourceRetrieverPtr& _retriever = nullptr);
static simulation::WorldPtr readSdfFile(
const common::Uri& _fileUri,
const common::ResourceRetrieverPtr& _retriever,
std::function<simulation::WorldPtr (
tinyxml2::XMLElement*, const std::string&,
const common::ResourceRetrieverPtr&)> xmlReader);
// TODO: Make common::ResourceRetriever optional.
static dynamics::SkeletonPtr readSkeleton(
const common::Uri& _fileUri,
const common::ResourceRetrieverPtr& _retriever = nullptr);
static dynamics::SkeletonPtr readSkeleton(
const common::Uri& _fileUri,
const common::ResourceRetrieverPtr& _retriever,
std::function<dynamics::SkeletonPtr(
tinyxml2::XMLElement*, const std::string&,
const common::ResourceRetrieverPtr&)> xmlReader);
typedef std::shared_ptr<dynamics::BodyNode::Properties> BodyPropPtr;
struct SDFBodyNode
{
BodyPropPtr properties;
Eigen::Isometry3d initTransform;
std::string type;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
typedef std::shared_ptr<dynamics::Joint::Properties> JointPropPtr;
struct SDFJoint
{
JointPropPtr properties;
std::string parentName;
std::string childName;
std::string type;
};
// Maps the name of a BodyNode to its properties
typedef Eigen::aligned_map<std::string, SDFBodyNode> BodyMap;
// Maps a child BodyNode to the properties of its parent Joint
typedef std::map<std::string, SDFJoint> JointMap;
static simulation::WorldPtr readWorld(
tinyxml2::XMLElement* _worldElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever);
/// \brief
static simulation::WorldPtr readWorld(
tinyxml2::XMLElement* _worldElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever,
std::function<dynamics::SkeletonPtr(
tinyxml2::XMLElement*, const std::string&,
const common::ResourceRetrieverPtr&)> skeletonReader);
/// \brief
static void readPhysics(tinyxml2::XMLElement* _physicsElement,
simulation::WorldPtr _world);
/// \brief
static dynamics::SkeletonPtr readSkeleton(
tinyxml2::XMLElement* _skeletonElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever);
static dynamics::SkeletonPtr readSkeleton(
tinyxml2::XMLElement* _skeletonElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever,
std::function<SDFBodyNode (tinyxml2::XMLElement*,
const Eigen::Isometry3d&,
const std::string&,
const common::ResourceRetrieverPtr&)> bodyReader,
std::function<bool(dynamics::SkeletonPtr,
dynamics::BodyNode*,
const SDFJoint&,
const SDFBodyNode&)> pairCreator);
static bool createPair(dynamics::SkeletonPtr skeleton,
dynamics::BodyNode* parent,
const SDFJoint& newJoint,
const SDFBodyNode& newBody);
enum NextResult
{
VALID,
CONTINUE,
BREAK,
CREATE_FREEJOINT_ROOT
};
static NextResult getNextJointAndNodePair(BodyMap::iterator& body,
JointMap::const_iterator& parentJoint,
dynamics::BodyNode*& parentBody,
const dynamics::SkeletonPtr skeleton,
BodyMap& sdfBodyNodes,
const JointMap& sdfJoints);
/// \brief
static dynamics::SkeletonPtr makeSkeleton(
tinyxml2::XMLElement* _skeletonElement,
Eigen::Isometry3d& skeletonFrame);
/// \brief
template <class NodeType>
static std::pair<dynamics::Joint*,dynamics::BodyNode*> createJointAndNodePair(
dynamics::SkeletonPtr skeleton,
dynamics::BodyNode* parent,
const SDFJoint& joint,
const SDFBodyNode& node)
{
const std::string& type = joint.type;
if (std::string("prismatic") == type)
return skeleton->createJointAndBodyNodePair<dynamics::PrismaticJoint>(parent,
static_cast<const dynamics::PrismaticJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("revolute") == type)
return skeleton->createJointAndBodyNodePair<dynamics::RevoluteJoint>(parent,
static_cast<const dynamics::RevoluteJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("screw") == type)
return skeleton->createJointAndBodyNodePair<dynamics::ScrewJoint>(parent,
static_cast<const dynamics::ScrewJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("revolute2") == type)
return skeleton->createJointAndBodyNodePair<dynamics::UniversalJoint>(parent,
static_cast<const dynamics::UniversalJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("ball") == type)
return skeleton->createJointAndBodyNodePair<dynamics::BallJoint>(parent,
static_cast<const dynamics::BallJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("free") == type)
return skeleton->createJointAndBodyNodePair<dynamics::FreeJoint>(parent,
static_cast<const dynamics::FreeJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
dterr << "[SdfParser::createJointAndNodePair] Unsupported Joint type encountered: "
<< type << ". Please report this as a bug! We will now quit parsing.\n";
return std::pair<dynamics::Joint*, dynamics::BodyNode*>(nullptr, nullptr);
}
/// \brief
static BodyMap readAllBodyNodes(
tinyxml2::XMLElement* _skeletonElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever,
const Eigen::Isometry3d& skeletonFrame);
static BodyMap readAllBodyNodes(
tinyxml2::XMLElement* _skeletonElement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever,
const Eigen::Isometry3d& skeletonFrame,
std::function<SDFBodyNode(tinyxml2::XMLElement*,
const Eigen::Isometry3d&,
const std::string&,
const common::ResourceRetrieverPtr&)> bodyReader);
/// \brief
static SDFBodyNode readBodyNode(
tinyxml2::XMLElement* _bodyNodeElement,
const Eigen::Isometry3d& _skeletonFrame,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever);
/// \brief
static dynamics::ShapePtr readShape(
tinyxml2::XMLElement* _shapelement,
const std::string& _skelPath,
const common::ResourceRetrieverPtr& _retriever);
/// \brief
static JointMap readAllJoints(
tinyxml2::XMLElement* _skeletonElement,
const Eigen::Isometry3d& skeletonFrame,
const BodyMap& sdfBodyNodes);
/// \brief
static SDFJoint readJoint(tinyxml2::XMLElement* _jointElement,
const BodyMap& _bodies,
const Eigen::Isometry3d& _skeletonFrame);
static kido::dynamics::WeldJoint::Properties readWeldJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::RevoluteJoint::Properties readRevoluteJoint(
tinyxml2::XMLElement* _revoluteJointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::PrismaticJoint::Properties readPrismaticJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::ScrewJoint::Properties readScrewJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::UniversalJoint::Properties readUniversalJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::BallJoint::Properties readBallJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static kido::dynamics::EulerJoint* readEulerJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static kido::dynamics::TranslationalJoint::Properties readTranslationalJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static dynamics::FreeJoint::Properties readFreeJoint(
tinyxml2::XMLElement* _jointElement,
const Eigen::Isometry3d& _parentModelFrame,
const std::string& _name);
static common::ResourceRetrieverPtr getResourceRetriever(
const common::ResourceRetrieverPtr& _retriever);
};
} // namespace utils
} // namespace kido
#endif // #ifndef KIDO_UTILS_SDFPARSER_H
|