CARLA
EpisodeState.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/Iterator.h"
10 #include "carla/ListView.h"
11 #include "carla/NonCopyable.h"
13 #include "carla/client/Timestamp.h"
14 #include "carla/geom/Vector3DInt.h"
16 
17 #include <boost/optional.hpp>
18 
19 #include <memory>
20 #include <unordered_map>
21 
22 namespace carla {
23 namespace client {
24 namespace detail {
25 
26  /// Represents the state of all the actors of an episode at a given frame.
28  : public std::enable_shared_from_this<EpisodeState>,
29  private NonCopyable {
30 
32 
33  public:
34 
35  explicit EpisodeState(uint64_t episode_id) : _episode_id(episode_id) {}
36 
37  explicit EpisodeState(const sensor::data::RawEpisodeState &state);
38 
39  auto GetEpisodeId() const {
40  return _episode_id;
41  }
42 
43  auto GetFrame() const {
44  return _timestamp.frame;
45  }
46 
47  const auto &GetTimestamp() const {
48  return _timestamp;
49  }
50 
52  return _simulation_state;
53  }
54 
55  bool HasMapChanged() const {
56  return (_simulation_state & SimulationState::MapChange) != SimulationState::None;
57  }
58 
59  bool IsLightUpdatePending() const {
60  return (_simulation_state & SimulationState::PendingLightUpdate) != 0;
61  }
62 
63  bool ContainsActorSnapshot(ActorId actor_id) const {
64  return _actors.find(actor_id) != _actors.end();
65  }
66 
68  ActorSnapshot state;
69  CopyActorSnapshotIfPresent(id, state);
70  return state;
71  }
72 
73  boost::optional<ActorSnapshot> GetActorSnapshotIfPresent(ActorId id) const {
74  boost::optional<ActorSnapshot> state;
75  CopyActorSnapshotIfPresent(id, state);
76  return state;
77  }
78 
79  auto GetActorIds() const {
80  return MakeListView(
83  }
84 
85  size_t size() const {
86  return _actors.size();
87  }
88 
89  auto begin() const {
91  }
92 
93  auto end() const {
95  }
96 
97  private:
98 
99  template <typename T>
100  void CopyActorSnapshotIfPresent(ActorId id, T &value) const {
101  auto it = _actors.find(id);
102  if (it != _actors.end()) {
103  value = it->second;
104  }
105  }
106 
107  const uint64_t _episode_id;
108 
110 
112 
114 
115  std::unordered_map<ActorId, ActorSnapshot> _actors;
116  };
117 
118 } // namespace detail
119 } // namespace client
120 } // namespace carla
ActorSnapshot GetActorSnapshot(ActorId id) const
Definition: EpisodeState.h:67
void CopyActorSnapshotIfPresent(ActorId id, T &value) const
Definition: EpisodeState.h:100
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::size_t frame
Number of frames elapsed since the simulator was launched.
Definition: Timestamp.h:30
Represents the state of all the actors of an episode at a given frame.
Definition: EpisodeState.h:27
EpisodeState(uint64_t episode_id)
Definition: EpisodeState.h:35
bool ContainsActorSnapshot(ActorId actor_id) const
Definition: EpisodeState.h:63
carla::ActorId ActorId
static auto make_map_values_const_iterator(It it)
Creates an iterator over const references to the values of a map.
Definition: Iterator.h:43
boost::optional< ActorSnapshot > GetActorSnapshotIfPresent(ActorId id) const
Definition: EpisodeState.h:73
const auto & GetTimestamp() const
Definition: EpisodeState.h:47
State of the episode at a given frame.
SimulationState GetsimulationState() const
Definition: EpisodeState.h:51
static auto make_map_keys_const_iterator(It it)
Creates an iterator over const references to the keys of a map.
Definition: Iterator.h:25
Inherit (privately) to suppress copy/move construction and assignment.
static auto MakeListView(Iterator begin, Iterator end)
std::unordered_map< ActorId, ActorSnapshot > _actors
Definition: EpisodeState.h:115