Loading...
Searching...
No Matches
Model.hh
Go to the documentation of this file.
1/*
2 * Copyright 2018 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17#ifndef SDF_MODEL_HH_
18#define SDF_MODEL_HH_
19
20#include <memory>
21#include <string>
22#include <utility>
23#include <vector>
24#include <gz/math/Pose3.hh>
25#include <gz/utils/ImplPtr.hh>
26#include "sdf/Element.hh"
27#include "sdf/OutputConfig.hh"
28#include "sdf/ParserConfig.hh"
29#include "sdf/Plugin.hh"
30#include "sdf/SemanticPose.hh"
31#include "sdf/Types.hh"
32#include "sdf/sdf_config.h"
33#include "sdf/system_util.hh"
34
35namespace sdf
36{
37 // Inline bracket to help doxygen filtering.
38 inline namespace SDF_VERSION_NAMESPACE {
39 //
40
41 // Forward declarations.
42 class Frame;
43 class InterfaceModel;
44 class Joint;
45 class Link;
46 class ParserConfig;
47 class NestedInclude;
48 struct PoseRelativeToGraph;
49 struct FrameAttachedToGraph;
50 template <typename T> class ScopedGraph;
51 using InterfaceModelConstPtr = std::shared_ptr<const InterfaceModel>;
52
53
55 {
57 public: Model();
58
65 public: Errors Load(ElementPtr _sdf);
66
74 public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
75
80 public: Errors ValidateGraphs() const;
81
85 public: std::string Name() const;
86
90 public: void SetName(const std::string &_name);
91
96 public: bool Static() const;
97
102 public: void SetStatic(bool _static);
103
109 public: bool SelfCollide() const;
110
115 public: void SetSelfCollide(bool _selfCollide);
116
121 public: bool AllowAutoDisable() const;
122
127 public: void SetAllowAutoDisable(bool _allowAutoDisable);
128
133 public: bool EnableWind() const;
134
138 public: void SetEnableWind(bool _enableWind);
139
145 public: uint64_t LinkCount() const;
146
152 public: const Link *LinkByIndex(const uint64_t _index) const;
153
160 public: Link *LinkByIndex(uint64_t _index);
161
167 public: const Link *LinkByName(const std::string &_name) const;
168
174 public: Link *LinkByName(const std::string &_name);
175
181 public: bool LinkNameExists(const std::string &_name) const;
182
188 public: uint64_t JointCount() const;
189
195 public: const Joint *JointByIndex(const uint64_t _index) const;
196
203 public: Joint *JointByIndex(uint64_t _index);
204
210 public: bool JointNameExists(const std::string &_name) const;
211
219 public: const Joint *JointByName(const std::string &_name) const;
220
228 public: Joint *JointByName(const std::string &_name);
229
235 public: uint64_t FrameCount() const;
236
244 public: const Frame *FrameByIndex(const uint64_t _index) const;
245
253 public: Frame *FrameByIndex(uint64_t _index);
254
261 public: const Frame *FrameByName(const std::string &_name) const;
262
269 public: Frame *FrameByName(const std::string &_name);
270
276 public: bool FrameNameExists(const std::string &_name) const;
277
283 public: uint64_t ModelCount() const;
284
291 public: const Model *ModelByIndex(const uint64_t _index) const;
292
294 // based on an index.
299 public: Model *ModelByIndex(uint64_t _index);
300
306 public: bool ModelNameExists(const std::string &_name) const;
307
315 public: const Model *ModelByName(const std::string &_name) const;
316
324 public: Model *ModelByName(const std::string &_name);
325
331 public: const gz::math::Pose3d &RawPose() const;
332
336 public: void SetRawPose(const gz::math::Pose3d &_pose);
337
340 public: const Link *CanonicalLink() const;
341
346 public: const std::string &CanonicalLinkName() const;
347
352 public: void SetCanonicalLinkName(const std::string &_canonicalLink);
353
358 public: const std::string &PoseRelativeTo() const;
359
364 public: void SetPoseRelativeTo(const std::string &_frame);
365
370 public: sdf::ElementPtr Element() const;
371
376
379 public: const std::string &PlacementFrameName() const;
380
384 public: void SetPlacementFrameName(const std::string &_name);
385
390 // TODO(addisu): If the canonical link is inside an interface model, this
391 // function returns {nullptr, name}. This can be problematic for downstream
392 // applications.
393 public: std::pair<const Link *, std::string> CanonicalLinkAndRelativeName()
394 const;
395
400 public: uint64_t InterfaceModelCount() const;
401
408 public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
409 const uint64_t _index) const;
410
419 const uint64_t _index) const;
420
436 const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
437
448 const std::string &_name) const;
449
454 public: bool AddLink(const Link &_link);
455
460 public: bool AddJoint(const Joint &_joint);
461
466 public: bool AddModel(const Model &_model);
467
472 public: bool AddFrame(const Frame &_frame);
473
475 public: void ClearLinks();
476
478 public: void ClearJoints();
479
481 public: void ClearModels();
482
484 public: void ClearFrames();
485
488 public: std::string Uri() const;
489
492 public: void SetUri(const std::string &_uri);
493
497 public: const sdf::Plugins &Plugins() const;
498
503
505 public: void ClearPlugins();
506
509 public: void AddPlugin(const Plugin &_plugin);
510
516 public: void ResolveAutoInertials(sdf::Errors &_errors,
517 const ParserConfig &_config);
518
524 private: void SetPoseRelativeToGraph(
526
532 private: void SetFrameAttachedToGraph(
534
537 private: const std::vector<std::pair<std::optional<sdf::NestedInclude>,
538 sdf::InterfaceModelConstPtr>> &MergedInterfaceModels() const;
539
543 private: bool IsMerged() const;
544
555 private: sdf::Frame PrepareForMerge(sdf::Errors &_errors,
556 const std::string &_parentOfProxyFrame);
557
561 friend class Root;
562 friend class World;
563
564 // Allow ModelWrapper from FrameSemantics.cc to call MergedInterfaceModels
565 friend struct ModelWrapper;
566
568 GZ_UTILS_IMPL_PTR(dataPtr)
569 };
570 }
571}
572#endif
A Frame element descibes the properties associated with an explicit frame defined in a Model or World...
Definition Frame.hh:43
Definition Joint.hh:86
Definition Model.hh:55
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
bool AddModel(const Model &_model)
Add a model to the model.
bool AddJoint(const Joint &_joint)
Add a joint to the model.
void SetStatic(bool _static)
Set this model to be static or not static.
sdf::Plugins & Plugins()
Get a mutable vector of plugins attached to this object.
void ClearLinks()
Remove all links.
Joint * JointByName(const std::string &_name)
Get a mubtable joint based on a name.
const Link * LinkByIndex(const uint64_t _index) const
Get an immediate (not nested) child link based on an index.
uint64_t ModelCount() const
Get the number of nested models that are immediate (not recursively nested) children of this Model ob...
const std::string & CanonicalLinkName() const
Get the name of the model's canonical link.
uint64_t LinkCount() const
Get the number of links that are immediate (not nested) children of this Model object.
void SetUri(const std::string &_uri)
Set the URI associated with this model.
const gz::math::Pose3d & RawPose() const
Get the pose of the model.
bool JointNameExists(const std::string &_name) const
Get whether a joint name exists.
bool AddLink(const Link &_link)
Add a link to the model.
void SetCanonicalLinkName(const std::string &_canonicalLink)
Set the name of the model's canonical link.
std::string Name() const
Get the name of the model.
void SetAllowAutoDisable(bool _allowAutoDisable)
Set this model to allow auto-disabling.
bool FrameNameExists(const std::string &_name) const
Get whether an explicit frame name exists.
Joint * JointByIndex(uint64_t _index)
Get an immediate (not nested) mutable child joint based on an index.
void AddPlugin(const Plugin &_plugin)
Add a plugin to this object.
std::string Uri() const
Get the URI associated with this model.
const Link * LinkByName(const std::string &_name) const
Get a link based on a name.
void ClearPlugins()
Remove all plugins.
const Frame * FrameByIndex(const uint64_t _index) const
Get an immediate (not nested) child explicit frame based on an index.
bool LinkNameExists(const std::string &_name) const
Get whether a link name exists.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the model based on a element pointer.
void ResolveAutoInertials(sdf::Errors &_errors, const ParserConfig &_config)
Calculate and set the inertials for all the links belonging to the model object.
void ClearJoints()
Remove all joints.
Link * LinkByName(const std::string &_name)
Get a mutable link based on a name.
std::shared_ptr< const InterfaceModel > InterfaceModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child interface model based on an index.
bool Static() const
Check if this model should be static.
void SetPoseRelativeTo(const std::string &_frame)
Set the name of the coordinate frame relative to which this object's pose is expressed.
uint64_t InterfaceModelCount() const
Get the number of nested interface models that are immediate (not recursively nested) children of thi...
void SetSelfCollide(bool _selfCollide)
Set this model to self-collide or not self-collide.
const std::string & PlacementFrameName() const
Get the name of the placement frame of the model.
sdf::SemanticPose SemanticPose() const
Get SemanticPose object of this object to aid in resolving poses.
const sdf::Plugins & Plugins() const
Get the plugins attached to this object.
uint64_t FrameCount() const
Get the number of explicit frames that are immediate (not nested) children of this Model object.
Errors Load(ElementPtr _sdf)
Load the model based on a element pointer.
void ClearModels()
Remove all models.
bool SelfCollide() const
Check if this model should self-collide.
void ClearFrames()
Remove all frames.
void SetEnableWind(bool _enableWind)
Set whether this model should be subject to wind.
const Link * CanonicalLink() const
Get the model's canonical link.
bool EnableWind() const
Check if this model should be subject to wind.
uint64_t JointCount() const
Get the number of joints that are immediate (not nested) children of this Model object.
Model * ModelByName(const std::string &_name)
Get a mutable nested model based on a name.
const Frame * FrameByName(const std::string &_name) const
Get an explicit frame based on a name.
const Joint * JointByName(const std::string &_name) const
Get a joint based on a name.
bool NameExistsInFrameAttachedToGraph(const std::string &_name) const
Check if a given name exists in the FrameAttachedTo graph at the scope of the model.
bool AllowAutoDisable() const
Check if this model should be allowed to auto-disable.
const Model * ModelByName(const std::string &_name) const
Get a nested model based on a name.
bool ModelNameExists(const std::string &_name) const
Get whether a nested model name exists.
Frame * FrameByIndex(uint64_t _index)
Get a mutable immediate (not nested) child explicit frame based on an index.
void SetRawPose(const gz::math::Pose3d &_pose)
Set the pose of the model.
Model()
Default constructor.
void SetPlacementFrameName(const std::string &_name)
Set the name of the placement frame of the model.
Frame * FrameByName(const std::string &_name)
Get a mutable explicit frame based on a name.
Link * LinkByIndex(uint64_t _index)
Get an immediate (not nested) mutable child link based on an index.
const Joint * JointByIndex(const uint64_t _index) const
Get an immediate (not nested) child joint based on an index.
const Model * ModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child model based on an index.
std::pair< const Link *, std::string > CanonicalLinkAndRelativeName() const
Get the model's canonical link and the nested name of the link relative to the current model,...
sdf::ElementPtr ToElement(const OutputConfig &_config=OutputConfig::GlobalConfig()) const
Create and return an SDF element filled with data from this model.
void SetName(const std::string &_name)
Set the name of the model.
Model * ModelByIndex(uint64_t _index)
Get an immediate (not recursively nested) mutable child model.
const NestedInclude * InterfaceModelNestedIncludeByIndex(const uint64_t _index) const
Get the nested include information of an immediate (not recursively nested) child interface model bas...
bool AddFrame(const Frame &_frame)
Add a frame to the model.
Errors ValidateGraphs() const
Check that the FrameAttachedToGraph and PoseRelativeToGraph are valid.
const std::string & PoseRelativeTo() const
Get the name of the coordinate frame relative to which this object's pose is expressed.
Contains the necessary information about an included model file for custom model parsers to be able t...
Definition InterfaceElements.hh:46
This class contains configuration options for SDF output.
Definition OutputConfig.hh:59
This class contains configuration options for the libsdformat parser.
Definition ParserConfig.hh:106
Definition Plugin.hh:46
Root class that acts as an entry point to the SDF document model.
Definition Root.hh:58
Definition Collision.hh:44
SemanticPose is a data structure that can be used by different DOM objects to resolve poses on a Pose...
Definition SemanticPose.hh:55
Definition World.hh:59
std::shared_ptr< const InterfaceModel > InterfaceModelConstPtr
Definition InterfaceModel.hh:50
std::vector< Plugin > Plugins
A vector of Plugin.
Definition Plugin.hh:245
std::vector< Error > Errors
A vector of Error.
Definition Types.hh:81
std::shared_ptr< Element > ElementPtr
Definition Element.hh:55
namespace for Simulation Description Format parser
Definition Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:25