CARLA
LightManager.h
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <mutex>
10 #include <vector>
11 #include <unordered_map>
12 #include <unordered_set>
13 
14 #include "carla/Memory.h"
15 #include "carla/NonCopyable.h"
16 
18 #include "carla/client/Light.h"
20 #include "carla/rpc/LightState.h"
21 
22 namespace carla {
23 namespace client {
24 
26  : public EnableSharedFromThis<LightManager> {
27 
29 
30 public:
31 
33 
34  ~LightManager();
35 
39  _lights = other._lights;
40  _episode = other._episode;
43  _dirty = other._dirty;
44  }
45 
46  void SetEpisode(detail::EpisodeProxy episode);
47 
48  std::vector<Light> GetAllLights(LightGroup type = LightGroup::None) const;
49  // TODO: std::vector<Light> GetAllLightsInRoad(RoadId id, LightGroup type = LightGroup::None);
50  // TODO: std::vector<Light> GetAllLightsInDistance(Vec3 origin, float distance, LightGroup type = Light::LightType::None);
51 
52  void TurnOn(std::vector<Light>& lights);
53  void TurnOff(std::vector<Light>& lights);
54  void SetActive(std::vector<Light>& lights, std::vector<bool>& active);
55  std::vector<bool> IsActive(std::vector<Light>& lights) const;
56  std::vector<Light> GetTurnedOnLights(LightGroup type = LightGroup::None) const;
57  std::vector<Light> GetTurnedOffLights(LightGroup type = LightGroup::None) const;
58 
59  void SetColor(std::vector<Light>& lights, Color color);
60  void SetColor(std::vector<Light>& lights, std::vector<Color>& colors);
61  std::vector<Color> GetColor(std::vector<Light>& lights) const;
62 
63  void SetIntensity(std::vector<Light>& lights, float intensity);
64  void SetIntensity(std::vector<Light>& lights, std::vector<float>& intensities);
65  std::vector<float> GetIntensity(std::vector<Light>& lights) const;
66 
67  void SetLightGroup(std::vector<Light>& lights, LightGroup group);
68  void SetLightGroup(std::vector<Light>& lights, std::vector<LightGroup>& groups);
69  std::vector<LightGroup> GetLightGroup(std::vector<Light>& lights) const;
70 
71  void SetLightState(std::vector<Light>& lights, LightState state);
72  void SetLightState(std::vector<Light>& lights, std::vector<LightState>& states);
73  std::vector<LightState> GetLightState(std::vector<Light>& lights) const;
74 
75  Color GetColor(LightId id) const;
76  float GetIntensity(LightId id) const;
79  bool IsActive(LightId id) const;
80 
81  void SetActive(LightId id, bool active);
82  void SetColor(LightId id, Color color);
83  void SetIntensity(LightId id, float intensity);
84  void SetLightState(LightId id, const LightState& new_state);
85  void SetLightStateNoLock(LightId id, const LightState& new_state);
86  void SetLightGroup(LightId id, LightGroup group);
87 
88  void SetDayNightCycle(const bool active);
89 
90 private:
91 
92  const LightState& RetrieveLightState(LightId id) const;
93 
95  void UpdateServerLightsState(bool discard_client = false);
96  void ApplyChanges();
97 
98  std::unordered_map<LightId, LightState> _lights_state;
99  std::unordered_map<LightId, LightState> _lights_changes;
100  std::unordered_map<LightId, Light> _lights;
101 
103 
104  std::mutex _mutex;
105 
109  bool _dirty = false;
110 };
111 
112 } // namespace client
113 } // namespace carla
std::unordered_map< LightId, LightState > _lights_changes
Definition: LightManager.h:99
detail::EpisodeProxy _episode
Definition: LightManager.h:102
const LightState & RetrieveLightState(LightId id) const
void TurnOn(std::vector< Light > &lights)
A 32-bit BGRA color.
std::vector< Light > GetTurnedOnLights(LightGroup type=LightGroup::None) const
void SetColor(std::vector< Light > &lights, Color color)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void SetLightStateNoLock(LightId id, const LightState &new_state)
void UpdateServerLightsState(bool discard_client=false)
void SetEpisode(detail::EpisodeProxy episode)
void SetActive(std::vector< Light > &lights, std::vector< bool > &active)
std::vector< float > GetIntensity(std::vector< Light > &lights) const
LightManager(const LightManager &other)
Definition: LightManager.h:36
std::vector< LightState > GetLightState(std::vector< Light > &lights) const
std::unordered_map< LightId, Light > _lights
Definition: LightManager.h:100
void SetIntensity(std::vector< Light > &lights, float intensity)
std::unordered_map< LightId, LightState > _lights_state
Definition: LightManager.h:98
std::vector< Color > GetColor(std::vector< Light > &lights) const
std::vector< Light > GetTurnedOffLights(LightGroup type=LightGroup::None) const
std::vector< bool > IsActive(std::vector< Light > &lights) const
void SetLightState(std::vector< Light > &lights, LightState state)
void TurnOff(std::vector< Light > &lights)
std::vector< LightGroup > GetLightGroup(std::vector< Light > &lights) const
void SetLightGroup(std::vector< Light > &lights, LightGroup group)
void SetDayNightCycle(const bool active)
std::vector< Light > GetAllLights(LightGroup type=LightGroup::None) const