CARLA
WorldSnapshot.h
Go to the documentation of this file.
1 // Copyright (c) 2019 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 
12 
13 #include <boost/optional.hpp>
14 
15 namespace carla {
16 namespace client {
17 
18  class WorldSnapshot {
19  public:
20 
21  WorldSnapshot(std::shared_ptr<const detail::EpisodeState> state)
22  : _state(std::move(state)) {}
23 
24  /// Get the id of the episode associated with this world.
25  uint64_t GetId() const {
26  return _state->GetEpisodeId();
27  }
28 
29  size_t GetFrame() const {
30  return GetTimestamp().frame;
31  }
32 
33  /// Get timestamp of this snapshot.
34  const Timestamp &GetTimestamp() const {
35  return _state->GetTimestamp();
36  }
37 
38  /// Check if an actor is present in this snapshot.
39  bool Contains(ActorId actor_id) const {
40  return _state->ContainsActorSnapshot(actor_id);
41  }
42 
43  /// Find an ActorSnapshot by id.
44  boost::optional<ActorSnapshot> Find(ActorId actor_id) const {
45  return _state->GetActorSnapshotIfPresent(actor_id);
46  }
47 
48  /// Return number of ActorSnapshots present in this WorldSnapshot.
49  size_t size() const {
50  return _state->size();
51  }
52 
53  /// Return a begin iterator to the list of ActorSnapshots.
54  auto begin() const {
55  return _state->begin();
56  }
57 
58  /// Return a past-the-end iterator to the list of ActorSnapshots.
59  auto end() const {
60  return _state->end();
61  }
62 
63  bool operator==(const WorldSnapshot &rhs) const {
64  return GetTimestamp() == rhs.GetTimestamp();
65  }
66 
67  bool operator!=(const WorldSnapshot &rhs) const {
68  return !(*this == rhs);
69  }
70 
71  private:
72 
73  std::shared_ptr<const detail::EpisodeState> _state;
74  };
75 
76 } // namespace client
77 } // namespace carla
std::shared_ptr< const detail::EpisodeState > _state
Definition: WorldSnapshot.h:73
boost::optional< ActorSnapshot > Find(ActorId actor_id) const
Find an ActorSnapshot by id.
Definition: WorldSnapshot.h:44
uint64_t GetId() const
Get the id of the episode associated with this world.
Definition: WorldSnapshot.h:25
size_t size() const
Return number of ActorSnapshots present in this WorldSnapshot.
Definition: WorldSnapshot.h:49
bool operator==(const WorldSnapshot &rhs) const
Definition: WorldSnapshot.h:63
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
bool operator!=(const WorldSnapshot &rhs) const
Definition: WorldSnapshot.h:67
const Timestamp & GetTimestamp() const
Get timestamp of this snapshot.
Definition: WorldSnapshot.h:34
carla::ActorId ActorId
WorldSnapshot(std::shared_ptr< const detail::EpisodeState > state)
Definition: WorldSnapshot.h:21
auto end() const
Return a past-the-end iterator to the list of ActorSnapshots.
Definition: WorldSnapshot.h:59
bool Contains(ActorId actor_id) const
Check if an actor is present in this snapshot.
Definition: WorldSnapshot.h:39
auto begin() const
Return a begin iterator to the list of ActorSnapshots.
Definition: WorldSnapshot.h:54