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"
15 
16 #include <boost/optional.hpp>
17 
18 #include <memory>
19 #include <unordered_map>
20 
21 namespace carla {
22 namespace client {
23 namespace detail {
24 
25  /// Represents the state of all the actors of an episode at a given frame.
27  : public std::enable_shared_from_this<EpisodeState>,
28  private NonCopyable {
29 
31 
32  public:
33 
34  explicit EpisodeState(uint64_t episode_id) : _episode_id(episode_id) {}
35 
36  explicit EpisodeState(const sensor::data::RawEpisodeState &state);
37 
38  auto GetEpisodeId() const {
39  return _episode_id;
40  }
41 
42  auto GetFrame() const {
43  return _timestamp.frame;
44  }
45 
46  const auto &GetTimestamp() const {
47  return _timestamp;
48  }
49 
51  return _simulation_state;
52  }
53 
54  bool HasMapChanged() const {
55  return (_simulation_state & SimulationState::MapChange) != SimulationState::None;
56  }
57 
58  bool IsLightUpdatePending() const {
59  return (_simulation_state & SimulationState::PendingLightUpdate) != 0;
60  }
61 
62  bool ContainsActorSnapshot(ActorId actor_id) const {
63  return _actors.find(actor_id) != _actors.end();
64  }
65 
67  ActorSnapshot state;
68  CopyActorSnapshotIfPresent(id, state);
69  return state;
70  }
71 
72  boost::optional<ActorSnapshot> GetActorSnapshotIfPresent(ActorId id) const {
73  boost::optional<ActorSnapshot> state;
74  CopyActorSnapshotIfPresent(id, state);
75  return state;
76  }
77 
78  auto GetActorIds() const {
79  return MakeListView(
82  }
83 
84  size_t size() const {
85  return _actors.size();
86  }
87 
88  auto begin() const {
90  }
91 
92  auto end() const {
94  }
95 
96  private:
97 
98  template <typename T>
99  void CopyActorSnapshotIfPresent(ActorId id, T &value) const {
100  auto it = _actors.find(id);
101  if (it != _actors.end()) {
102  value = it->second;
103  }
104  }
105 
106  const uint64_t _episode_id;
107 
109 
111 
112  std::unordered_map<ActorId, ActorSnapshot> _actors;
113  };
114 
115 } // namespace detail
116 } // namespace client
117 } // namespace carla
ActorSnapshot GetActorSnapshot(ActorId id) const
Definition: EpisodeState.h:66
void CopyActorSnapshotIfPresent(ActorId id, T &value) const
Definition: EpisodeState.h:99
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
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:26
EpisodeState(uint64_t episode_id)
Definition: EpisodeState.h:34
bool ContainsActorSnapshot(ActorId actor_id) const
Definition: EpisodeState.h:62
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:72
const auto & GetTimestamp() const
Definition: EpisodeState.h:46
State of the episode at a given frame.
SimulationState GetsimulationState() const
Definition: EpisodeState.h:50
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:112