##

WorldState.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/* Desc: A world state
* Author: Nate Koenig
*/
#ifndef GAZEBO_PHYSICS_WORLDSTATE_HH_
#define GAZEBO_PHYSICS_WORLDSTATE_HH_
#include <string>
#include <vector>
#include <sdf/sdf.hh>
#include "gazebo/physics/State.hh"
#include "gazebo/physics/ModelState.hh"
#include "gazebo/physics/LightState.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
class GZ_PHYSICS_VISIBLE WorldState : public State
{
public: WorldState();
public: explicit WorldState(const WorldPtr _world);
public: explicit WorldState(const sdf::ElementPtr _sdf);
public: virtual ~WorldState();
public: void Load(const WorldPtr _world);
public: void LoadWithFilter(const WorldPtr _world,
const std::string &_filter);
public: virtual void Load(const sdf::ElementPtr _elem);
public: void SetWorld(const WorldPtr _world);
public: ModelState_M GetModelStates(const boost::regex &_regex) const;
public: const ModelState_M &GetModelStates() const;
public: const LightState_M &LightStates() const;
public: unsigned int GetModelStateCount() const;
public: unsigned int LightStateCount() const;
public: ModelState GetModelState(const std::string &_modelName) const;
public: LightState GetLightState(const std::string &_lightName) const;
public: bool HasModelState(const std::string &_modelName) const;
public: bool HasLightState(const std::string &_lightName) const;
public: const std::vector<std::string> &Insertions() const;
public: void SetInsertions(const std::vector<std::string> &_insertions);
public: const std::vector<std::string> &Deletions() const;
public: void SetDeletions(const std::vector<std::string> &_deletions);
public: bool IsZero() const;
public: void FillSDF(sdf::ElementPtr _sdf);
public: virtual void SetWallTime(const common::Time &_time);
public: virtual void SetRealTime(const common::Time &_time);
public: virtual void SetSimTime(const common::Time &_time);
public: virtual void SetIterations(const uint64_t _iterations);
public: WorldState &operator=(const WorldState &_state);
public: WorldState operator-(const WorldState &_state) const;
public: WorldState operator+(const WorldState &_state) const;
public: inline friend std::ostream &operator<<(std::ostream &_out,
const gazebo::physics::WorldState &_state)
{
_out << "<state world_name='" << _state.name << "'>"
<< "<sim_time>" << _state.simTime << "</sim_time>"
<< "<wall_time>" << _state.wallTime << "</wall_time>"
<< "<real_time>" << _state.realTime << "</real_time>"
<< "<iterations>" << _state.iterations << "</iterations>";
// List all of the inserted models
if (_state.insertions.size() > 0)
{
_out << "<insertions>";
for (std::vector<std::string>::const_iterator iter =
_state.insertions.begin();
iter != _state.insertions.end(); ++iter)
{
_out << *iter;
}
_out << "</insertions>";
}
// List all of the deleted models
if (_state.deletions.size() > 0)
{
_out << "<deletions>";
for (std::vector<std::string>::const_iterator iter =
_state.deletions.begin();
iter != _state.deletions.end(); ++iter)
{
_out << "<name>" << (*iter) << "</name>";
}
_out << "</deletions>";
}
// List the model states
for (const auto &model : _state.modelStates)
{
_out << model.second;
}
// List the light states
for (const auto &light : _state.lightStates)
{
_out << light.second;
}
_out << "</state>";
return _out;
}
private: ModelState_M modelStates;
private: LightState_M lightStates;
private: std::vector<std::string> insertions;
private: std::vector<std::string> deletions;
private: WorldPtr world;
};
}
}
#endif
gazebo::physics::WorldState::LightStateCount
unsigned int LightStateCount() const
Get the number of light states.
gazebo::physics::State::wallTime
common::Time wallTime
Times for the state data.
Definition: State.hh:127
gazebo::physics::State::iterations
uint64_t iterations
The number of simulation iterations when this state was generated.
Definition: State.hh:131
gazebo::physics::WorldState::LightStates
const LightState_M & LightStates() const
Get the light states.
gazebo::physics::WorldState::SetSimTime
virtual void SetSimTime(const common::Time &_time)
Set the sim time when this state was generated.
gazebo::physics::ModelState_M
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:233
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
gazebo::physics::WorldState::SetWallTime
virtual void SetWallTime(const common::Time &_time)
Set the wall time when this state was generated.
gazebo::physics::WorldState::SetDeletions
void SetDeletions(const std::vector< std::string > &_deletions)
Set a new vector of SDF deletions.
gazebo::physics::WorldState::SetIterations
virtual void SetIterations(const uint64_t _iterations)
Set the simulation interations when this state was generated.
ModelState.hh
gazebo::physics::WorldState::Insertions
const std::vector< std::string > & Insertions() const
Get the vector of SDF insertions.
gazebo::physics::WorldState::operator<<
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::WorldState &_state)
Stream insertion operator.
Definition: WorldState.hh:211
system.hh
gazebo::physics::WorldState::Deletions
const std::vector< std::string > & Deletions() const
Get the vector of SDF deletions.
gazebo::physics::WorldState::HasModelState
bool HasModelState(const std::string &_modelName) const
Return true if WorldState has a ModelState with the given name.
State.hh
gazebo::physics::State::realTime
common::Time realTime
Definition: State.hh:127
gazebo::physics::WorldState::operator-
WorldState operator-(const WorldState &_state) const
Subtraction operator.
gazebo::physics::WorldState::SetWorld
void SetWorld(const WorldPtr _world)
Set the world.
gazebo::physics::LightState
Store state information of a Light object.
Definition: LightState.hh:38
gazebo::physics::WorldState::GetLightState
LightState GetLightState(const std::string &_lightName) const
Get a light state by light name.
gazebo::physics::WorldState::GetModelStateCount
unsigned int GetModelStateCount() const
Get the number of model states.
gazebo::physics::WorldState::Load
void Load(const WorldPtr _world)
Load from a World pointer.
gazebo::physics::ModelState
Store state information of a physics::Model object.
Definition: ModelState.hh:48
gazebo::physics::State::simTime
common::Time simTime
Definition: State.hh:127
gazebo::physics::WorldState::GetModelState
ModelState GetModelState(const std::string &_modelName) const
Get a model state by model name.
gazebo::physics::State
State of an entity.
Definition: State.hh:43
gazebo::physics::LightState_M
std::map< std::string, LightState > LightState_M
Definition: PhysicsTypes.hh:237
gazebo::physics::WorldState::SetRealTime
virtual void SetRealTime(const common::Time &_time)
Set the real time when this state was generated.
gazebo::physics::WorldState::operator=
WorldState & operator=(const WorldState &_state)
Assignment operator.
gazebo::physics::WorldState::IsZero
bool IsZero() const
Return true if the values in the state are zero.
gazebo::physics::WorldState
Store state information of a physics::World object.
Definition: WorldState.hh:47
gazebo::physics::State::name
std::string name
Name associated with this State.
Definition: State.hh:124
gazebo::physics::WorldPtr
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
gazebo::physics::WorldState::FillSDF
void FillSDF(sdf::ElementPtr _sdf)
Populate a state SDF element with data from the object.
gazebo::physics::WorldState::operator+
WorldState operator+(const WorldState &_state) const
Addition operator.
gazebo::physics::WorldState::SetInsertions
void SetInsertions(const std::vector< std::string > &_insertions)
Set a new vector of SDF insertions.
gazebo::physics::WorldState::GetModelStates
const ModelState_M & GetModelStates() const
Get the model states.
gazebo::physics::WorldState::HasLightState
bool HasLightState(const std::string &_lightName) const
Return true if WorldState has a LightState with the given name.
gazebo::physics::WorldState::LoadWithFilter
void LoadWithFilter(const WorldPtr _world, const std::string &_filter)
Load from a World pointer.
LightState.hh
gazebo::physics::WorldState::WorldState
WorldState()
Default constructor.
gazebo::physics::WorldState::~WorldState
virtual ~WorldState()
Destructor.