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 SetLightGroup(LightId id, LightGroup group);
86 
87 private:
88 
89  const LightState& RetrieveLightState(LightId id) const;
90 
92  void UpdateServerLightsState(bool discard_client = false);
93  void ApplyChanges();
94 
95  std::unordered_map<LightId, LightState> _lights_state;
96  std::unordered_map<LightId, LightState> _lights_changes;
97  std::unordered_map<LightId, Light> _lights;
98 
100 
101  std::mutex _mutex;
102 
106  bool _dirty = false;
107 };
108 
109 } // namespace client
110 } // namespace carla
std::unordered_map< LightId, LightState > _lights_changes
Definition: LightManager.h:96
detail::EpisodeProxy _episode
Definition: LightManager.h:99
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:99
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:97
void SetIntensity(std::vector< Light > &lights, float intensity)
std::unordered_map< LightId, LightState > _lights_state
Definition: LightManager.h:95
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)
std::vector< Light > GetAllLights(LightGroup type=LightGroup::None) const