WorldState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 /* Desc: A world state
18  * Author: Nate Koenig
19  */
20 
21 #ifndef GAZEBO_PHYSICS_WORLDSTATE_HH_
22 #define GAZEBO_PHYSICS_WORLDSTATE_HH_
23 
24 #include <string>
25 #include <vector>
26 
27 #include <sdf/sdf.hh>
28 
29 #include "gazebo/physics/State.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
47  class GZ_PHYSICS_VISIBLE WorldState : public State
48  {
50  public: WorldState();
51 
56  public: explicit WorldState(const WorldPtr _world);
57 
62  public: explicit WorldState(const sdf::ElementPtr _sdf);
63 
65  public: virtual ~WorldState();
66 
71  public: void Load(const WorldPtr _world);
72 
78  public: void LoadWithFilter(const WorldPtr _world,
79  const std::string &_filter);
80 
85  public: virtual void Load(const sdf::ElementPtr _elem);
86 
89  public: void SetWorld(const WorldPtr _world);
90 
95  public: ModelState_M GetModelStates(const boost::regex &_regex) const;
96 
99  public: const ModelState_M &GetModelStates() const;
100 
103  public: const LightState_M &LightStates() const;
104 
109  public: unsigned int GetModelStateCount() const;
110 
115  public: unsigned int LightStateCount() const;
116 
121  public: ModelState GetModelState(const std::string &_modelName) const;
122 
127  public: LightState GetLightState(const std::string &_lightName) const;
128 
133  public: bool HasModelState(const std::string &_modelName) const;
134 
139  public: bool HasLightState(const std::string &_lightName) const;
140 
145  public: const std::vector<std::string> &Insertions() const;
146 
152  public: void SetInsertions(const std::vector<std::string> &_insertions);
153 
157  public: const std::vector<std::string> &Deletions() const;
158 
162  public: void SetDeletions(const std::vector<std::string> &_deletions);
163 
168  public: bool IsZero() const;
169 
172  public: void FillSDF(sdf::ElementPtr _sdf);
173 
177  public: virtual void SetWallTime(const common::Time &_time);
178 
181  public: virtual void SetRealTime(const common::Time &_time);
182 
185  public: virtual void SetSimTime(const common::Time &_time);
186 
190  public: virtual void SetIterations(const uint64_t _iterations);
191 
195  public: WorldState &operator=(const WorldState &_state);
196 
200  public: WorldState operator-(const WorldState &_state) const;
201 
205  public: WorldState operator+(const WorldState &_state) const;
206 
211  public: inline friend std::ostream &operator<<(std::ostream &_out,
212  const gazebo::physics::WorldState &_state)
213  {
214  _out << "<state world_name='" << _state.name << "'>"
215  << "<sim_time>" << _state.simTime << "</sim_time>"
216  << "<wall_time>" << _state.wallTime << "</wall_time>"
217  << "<real_time>" << _state.realTime << "</real_time>"
218  << "<iterations>" << _state.iterations << "</iterations>";
219 
220  // List all of the inserted models
221  if (_state.insertions.size() > 0)
222  {
223  _out << "<insertions>";
224  for (std::vector<std::string>::const_iterator iter =
225  _state.insertions.begin();
226  iter != _state.insertions.end(); ++iter)
227  {
228  _out << *iter;
229  }
230  _out << "</insertions>";
231  }
232 
233  // List all of the deleted models
234  if (_state.deletions.size() > 0)
235  {
236  _out << "<deletions>";
237  for (std::vector<std::string>::const_iterator iter =
238  _state.deletions.begin();
239  iter != _state.deletions.end(); ++iter)
240  {
241  _out << "<name>" << (*iter) << "</name>";
242  }
243  _out << "</deletions>";
244  }
245 
246  // List the model states
247  for (const auto &model : _state.modelStates)
248  {
249  _out << model.second;
250  }
251 
252  // List the light states
253  for (const auto &light : _state.lightStates)
254  {
255  _out << light.second;
256  }
257 
258  _out << "</state>";
259 
260  return _out;
261  }
262 
264  private: ModelState_M modelStates;
265 
267  private: LightState_M lightStates;
268 
271  private: std::vector<std::string> insertions;
272 
275  private: std::vector<std::string> deletions;
276 
278  private: WorldPtr world;
279  };
281  }
282 }
283 #endif
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:48
Store state information of a Light object.
Definition: LightState.hh:39
Store state information of a physics::Model object.
Definition: ModelState.hh:49
State of an entity.
Definition: State.hh:50
uint64_t iterations
The number of simulation iterations when this state was generated.
Definition: State.hh:137
common::Time wallTime
Times for the state data.
Definition: State.hh:133
std::string name
Name associated with this State.
Definition: State.hh:130
common::Time simTime
Definition: State.hh:133
common::Time realTime
Definition: State.hh:133
Store state information of a physics::World object.
Definition: WorldState.hh:48
void LoadWithFilter(const WorldPtr _world, const std::string &_filter)
Load from a World pointer.
void SetInsertions(const std::vector< std::string > &_insertions)
Set a new vector of SDF insertions.
virtual void SetRealTime(const common::Time &_time)
Set the real time when this state was generated.
virtual void SetSimTime(const common::Time &_time)
Set the sim time when this state was generated.
void SetWorld(const WorldPtr _world)
Set the world.
void Load(const WorldPtr _world)
Load from a World pointer.
virtual void SetWallTime(const common::Time &_time)
Set the wall time when this state was generated.
WorldState operator+(const WorldState &_state) const
Addition operator.
bool HasLightState(const std::string &_lightName) const
Return true if WorldState has a LightState with the given name.
WorldState(const WorldPtr _world)
Constructor.
WorldState operator-(const WorldState &_state) const
Subtraction operator.
LightState GetLightState(const std::string &_lightName) const
Get a light state by light name.
ModelState_M GetModelStates(const boost::regex &_regex) const
Get model states based on a regular expression.
virtual ~WorldState()
Destructor.
unsigned int GetModelStateCount() const
Get the number of model states.
const std::vector< std::string > & Insertions() const
Get the vector of SDF insertions.
bool IsZero() const
Return true if the values in the state are zero.
unsigned int LightStateCount() const
Get the number of light states.
void SetDeletions(const std::vector< std::string > &_deletions)
Set a new vector of SDF deletions.
WorldState()
Default constructor.
WorldState(const sdf::ElementPtr _sdf)
Constructor.
const ModelState_M & GetModelStates() const
Get the model states.
ModelState GetModelState(const std::string &_modelName) const
Get a model state by model name.
WorldState & operator=(const WorldState &_state)
Assignment operator.
bool HasModelState(const std::string &_modelName) const
Return true if WorldState has a ModelState with the given name.
void FillSDF(sdf::ElementPtr _sdf)
Populate a state SDF element with data from the object.
virtual void Load(const sdf::ElementPtr _elem)
Load state from SDF element.
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::WorldState &_state)
Stream insertion operator.
Definition: WorldState.hh:211
const std::vector< std::string > & Deletions() const
Get the vector of SDF deletions.
virtual void SetIterations(const uint64_t _iterations)
Set the simulation interations when this state was generated.
const LightState_M & LightStates() const
Get the light states.
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:233
std::map< std::string, LightState > LightState_M
Definition: PhysicsTypes.hh:237
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Forward declarations for the common classes.
Definition: Animation.hh:27