World.hh
Go to the documentation of this file.
1/*
2 * Copyright 2017 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_WORLD_HH_
18#define SDF_WORLD_HH_
19
20#include <memory>
21#include <optional>
22#include <string>
23#include <gz/math/SphericalCoordinates.hh>
24#include <gz/math/Vector3.hh>
25#include <gz/utils/ImplPtr.hh>
26
27#include "sdf/Atmosphere.hh"
28#include "sdf/Element.hh"
29#include "sdf/Gui.hh"
30#include "sdf/OutputConfig.hh"
31#include "sdf/ParserConfig.hh"
32#include "sdf/Plugin.hh"
33#include "sdf/Scene.hh"
34#include "sdf/Types.hh"
35#include "sdf/sdf_config.h"
36#include "sdf/system_util.hh"
37
38namespace sdf
39{
40 // Inline bracket to help doxygen filtering.
41 inline namespace SDF_VERSION_NAMESPACE {
42 //
43
44 // Forward declare private data class.
45 class Actor;
46 class Frame;
47 class InterfaceModel;
48 class Joint;
49 class Light;
50 class Model;
51 class ParserConfig;
52 class Physics;
53 class NestedInclude;
54 struct PoseRelativeToGraph;
55 struct FrameAttachedToGraph;
56 template <typename T> class ScopedGraph;
57
59 {
61 public: World();
62
69 public: Errors Load(ElementPtr _sdf);
70
78 public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
79
84 public: Errors ValidateGraphs() const;
85
88 public: std::string Name() const;
89
92 public: void SetName(const std::string &_name);
93
98 public: std::string AudioDevice() const;
99
104 public: void SetAudioDevice(const std::string &_device);
105
110 public: gz::math::Vector3d WindLinearVelocity() const;
111
116 public: void SetWindLinearVelocity(const gz::math::Vector3d &_wind);
117
123 public: gz::math::Vector3d Gravity() const;
124
128 public: void SetGravity(const gz::math::Vector3d &_gravity);
129
136 public: gz::math::Vector3d MagneticField() const;
137
144 public: void SetMagneticField(const gz::math::Vector3d &_mag);
145
148 public: const gz::math::SphericalCoordinates *
150
154 const gz::math::SphericalCoordinates &_coord);
155
161 public: uint64_t ModelCount() const;
162
169 public: const Model *ModelByIndex(const uint64_t _index) const;
170
177 public: Model *ModelByIndex(uint64_t _index);
178
186 public: const Model *ModelByName(const std::string &_name) const;
187
195 public: Model *ModelByName(const std::string &_name);
196
202 public: bool ModelNameExists(const std::string &_name) const;
203
208 public: bool AddModel(const Model &_model);
209
214 public: bool AddActor(const Actor &_actor);
215
220 public: bool AddJoint(const Joint &_joint);
221
226 public: bool AddLight(const Light &_light);
227
232 public: bool AddPhysics(const Physics &_physics);
233
238 public: bool AddFrame(const Frame &_frame);
239
241 public: void ClearModels();
242
244 public: void ClearActors();
245
247 public: void ClearJoints();
248
250 public: void ClearLights();
251
253 public: void ClearPhysics();
254
256 public: void ClearFrames();
257
260 public: uint64_t ActorCount() const;
261
267 public: const Actor *ActorByIndex(const uint64_t _index) const;
268
274 public: Actor *ActorByIndex(uint64_t _index);
275
279 public: bool ActorNameExists(const std::string &_name) const;
280
286 public: uint64_t FrameCount() const;
287
295 public: const Frame *FrameByIndex(const uint64_t _index) const;
296
304 public: Frame *FrameByIndex(uint64_t _index);
305
312 public: const Frame *FrameByName(const std::string &_name) const;
313
320 public: Frame *FrameByName(const std::string &_name);
321
327 public: bool FrameNameExists(const std::string &_name) const;
328
331 public: uint64_t JointCount() const;
332
338 public: const Joint *JointByIndex(uint64_t _index) const;
339
345 public: Joint *JointByIndex(uint64_t _index);
346
353 public: const Joint *JointByName(const std::string &_name) const;
354
361 public: Joint *JointByName(const std::string &_name);
362
366 public: bool JointNameExists(const std::string &_name) const;
367
370 public: uint64_t LightCount() const;
371
377 public: const Light *LightByIndex(const uint64_t _index) const;
378
384 public: Light *LightByIndex(uint64_t _index);
385
389 public: bool LightNameExists(const std::string &_name) const;
390
395 public: const sdf::Atmosphere *Atmosphere() const;
396
399 public: void SetAtmosphere(const sdf::Atmosphere &_atmosphere);
400
405 public: const sdf::Gui *Gui() const;
406
409 public: void SetGui(const sdf::Gui &_gui);
410
415 public: const sdf::Scene *Scene() const;
416
419 public: void SetScene(const sdf::Scene &_scene);
420
425 public: sdf::ElementPtr Element() const;
426
429 public: uint64_t PhysicsCount() const;
430
437 public: const Physics *PhysicsByIndex(const uint64_t _index) const;
438
445 public: Physics *PhysicsByIndex(uint64_t _index);
446
449 public: const Physics *PhysicsDefault() const;
450
454 public: bool PhysicsNameExists(const std::string &_name) const;
455
460 public: uint64_t InterfaceModelCount() const;
461
468 public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
469 const uint64_t _index) const;
470
479 const uint64_t _index) const;
480
488 const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
489
500 const std::string &_name) const;
501
505 public: const sdf::Plugins &Plugins() const;
506
511
513 public: void ClearPlugins();
514
517 public: void AddPlugin(const Plugin &_plugin);
518
524 public: void ResolveAutoInertials(sdf::Errors &_errors,
525 const ParserConfig &_config);
526
531 private: void SetPoseRelativeToGraph(
533
538 private: void SetFrameAttachedToGraph(
540
543 friend class Root;
544
546 GZ_UTILS_IMPL_PTR(dataPtr)
547 };
548 }
549}
550#endif
Provides a description of an actor.
Definition: Actor.hh:192
The Atmosphere class contains information about an atmospheric model and related parameters such as t...
Definition: Atmosphere.hh:46
A Frame element descibes the properties associated with an explicit frame defined in a Model or World...
Definition: Frame.hh:43
Definition: Gui.hh:32
Definition: Joint.hh:86
Provides a description of a light source.
Definition: Light.hh:64
Definition: Model.hh:55
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
static OutputConfig & GlobalConfig()
Mutable access to a singleton OutputConfig that serves as the global OutputConfig object for all pars...
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:100
The physics element specifies the type and properties of a dynamics engine.
Definition: Physics.hh:37
Definition: Plugin.hh:46
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:58
Definition: Scene.hh:34
Definition: Collision.hh:43
Definition: World.hh:59
Physics * PhysicsByIndex(uint64_t _index)
Get a mutable physics profile based on an index.
void ClearPlugins()
Remove all plugins.
const Joint * JointByIndex(uint64_t _index) const
Get a joint based on an index.
const sdf::Atmosphere * Atmosphere() const
Get a pointer to the atmosphere model associated with this world.
const NestedInclude * InterfaceModelNestedIncludeByIndex(const uint64_t _index) const
Get the nested include information of an immediate (not recursively nested) child interface model bas...
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
void SetAudioDevice(const std::string &_device)
Set the audio device name.
sdf::Plugins & Plugins()
Get a mutable vector of plugins attached to this object.
bool LightNameExists(const std::string &_name) const
Get whether a light name exists.
const Physics * PhysicsByIndex(const uint64_t _index) const
Get a physics profile based on an index.
bool ModelNameExists(const std::string &_name) const
Get whether a model name exists.
const Frame * FrameByName(const std::string &_name) const
Get an explicit frame based on a name.
const Frame * FrameByIndex(const uint64_t _index) const
Get an immediate (not nested) child explicit frame based on an index.
bool AddModel(const Model &_model)
Add a model to the world.
void ClearPhysics()
Remove all physics.
bool JointNameExists(const std::string &_name) const
Get whether a joint name exists.
bool NameExistsInFrameAttachedToGraph(const std::string &_name) const
Check if a given name exists in the FrameAttachedTo graph at the scope of the world.
std::shared_ptr< const InterfaceModel > InterfaceModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child interface model based on an index.
void SetName(const std::string &_name)
Set the name of the world.
void ClearFrames()
Remove all frames.
Joint * JointByName(const std::string &_name)
Get a mutable joint based on a name.
uint64_t JointCount() const
Get the number of joints.
bool AddLight(const Light &_light)
Add a light to the world.
uint64_t LightCount() const
Get the number of lights.
void AddPlugin(const Plugin &_plugin)
Add a plugin to this object.
gz::math::Vector3d MagneticField() const
Get the magnetic vector in Tesla, expressed in a coordinate frame defined by the SphericalCoordinates...
void SetGravity(const gz::math::Vector3d &_gravity)
Set the acceleration due to gravity.
void SetWindLinearVelocity(const gz::math::Vector3d &_wind)
Set the wind linear velocity in the global/world coordinate frame.
Errors ValidateGraphs() const
Check that the FrameAttachedToGraph and PoseRelativeToGraph are valid.
const sdf::Gui * Gui() const
Get a pointer to the Gui associated with this world.
uint64_t PhysicsCount() const
Get the number of physics profiles.
Frame * FrameByName(const std::string &_name)
Get a mutable explicit frame based on a name.
bool AddPhysics(const Physics &_physics)
Add a physics object to the world.
const Actor * ActorByIndex(const uint64_t _index) const
Get an actor based on an index.
uint64_t ModelCount() const
Get the number of models that are immediate (not nested) children of this World object.
const sdf::Scene * Scene() const
Get a pointer to the Scene associated with this world.
bool PhysicsNameExists(const std::string &_name) const
Get whether a physics profile name exists.
void ClearActors()
Remove all actors.
World()
Default constructor.
const Model * ModelByName(const std::string &_name) const
Get a model based on a name.
Model * ModelByIndex(uint64_t _index)
Get an immediate (not recursively nested) mutable child model based on an index.
void SetGui(const sdf::Gui &_gui)
Set the Gui parameters associated with this world.
Frame * FrameByIndex(uint64_t _index)
Get a mutable immediate (not nested) child explicit frame based on an index.
bool AddJoint(const Joint &_joint)
Add a joint to the world.
Errors Load(ElementPtr _sdf)
Load the world based on a element pointer.
Light * LightByIndex(uint64_t _index)
Get a mutable light based on an index.
const Light * LightByIndex(const uint64_t _index) const
Get a light based on an index.
uint64_t FrameCount() const
Get the number of explicit frames that are immediate (not nested) children of this World object.
void ClearJoints()
Remove all joints.
void SetScene(const sdf::Scene &_scene)
Set the Scene parameters associated with this world.
void ResolveAutoInertials(sdf::Errors &_errors, const ParserConfig &_config)
Calculate and set the inertials for all the models in the world object.
void SetMagneticField(const gz::math::Vector3d &_mag)
Set the magnetic vector in Tesla, expressed in a coordinate frame defined by the SphericalCoordinate.
const Joint * JointByName(const std::string &_name) const
Get an joint based on a name.
bool AddActor(const Actor &_actor)
Add an actor to the world.
bool ActorNameExists(const std::string &_name) const
Get whether an actor name exists.
gz::math::Vector3d Gravity() const
Get the acceleration due to gravity.
void ClearLights()
Remove all lights.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the world based on a element pointer.
uint64_t InterfaceModelCount() const
Get the number of nested interface models that are immediate (not recursively nested) children of thi...
void SetAtmosphere(const sdf::Atmosphere &_atmosphere)
Set the atmosphere model associated with this world.
bool FrameNameExists(const std::string &_name) const
Get whether an explicit frame name exists.
const sdf::Plugins & Plugins() const
Get the plugins attached to this object.
sdf::ElementPtr ToElement(const OutputConfig &_config=OutputConfig::GlobalConfig()) const
Create and return an SDF element filled with data from this world.
gz::math::Vector3d WindLinearVelocity() const
Get the wind linear velocity in the global/world coordinate frame.
std::string Name() const
Get the name of the world.
Model * ModelByName(const std::string &_name)
Get a mutable model based on a name.
bool AddFrame(const Frame &_frame)
Add a frame object to the world.
const Physics * PhysicsDefault() const
Get the default physics profile.
void SetSphericalCoordinates(const gz::math::SphericalCoordinates &_coord)
Set the spherical coordinates for the world origin.
uint64_t ActorCount() const
Get the number of actors.
Joint * JointByIndex(uint64_t _index)
Get a mutable 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.
const gz::math::SphericalCoordinates * SphericalCoordinates() const
Get the spherical coordinates for the world origin.
std::string AudioDevice() const
Get the audio device name.
Actor * ActorByIndex(uint64_t _index)
Get a mutable actor based on an index.
void ClearModels()
Remove all models.
std::vector< Plugin > Plugins
A vector of Plugin.
Definition: Plugin.hh:245
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:95
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