CARLA
 
载入中...
搜索中...
未找到
LightManager.h
浏览该文件的文档.
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
17#include "carla/client/detail/Episode.h" // 引入细节中的Episode模块
18#include "carla/client/Light.h" // 引入Light模块
19#include "carla/client/LightState.h" // 引入LightState模块
20#include "carla/rpc/LightState.h" // 引入RPC中的LightState模块
21
22namespace carla {
23namespace client {
24
25class LightManager // 光照管理器类
26 : public EnableSharedFromThis<LightManager> { // 允许从自身获取共享指针
27
28 using LightGroup = rpc::LightState::LightGroup; // 定义LightGroup类型
29
30public:
31
32 LightManager() {} // 构造函数
33
34 ~LightManager(); // 析构函数
35
36 LightManager(const LightManager& other) : EnableSharedFromThis<LightManager>() { // 拷贝构造函数
37 _lights_state = other._lights_state; // 拷贝灯光状态
38 _lights_changes = other._lights_changes; // 拷贝灯光变更状态
39 _lights = other._lights; // 拷贝灯光
40 _episode = other._episode; // 拷贝Episode
41 _on_tick_register_id = other._on_tick_register_id; // 拷贝tick注册ID
42 _on_light_update_register_id = other._on_light_update_register_id; // 拷贝灯光更新注册ID
43 _dirty = other._dirty; // 拷贝脏标志
44 }
45
46 void SetEpisode(detail::WeakEpisodeProxy episode); // 设置当前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; // 获取单个灯光强度
77 LightState GetLightState(LightId id) const; // 获取单个灯光状态
78 LightGroup GetLightGroup(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
90private:
91
92 const LightState& RetrieveLightState(LightId id) const; // 检索灯光状态
93
94 void QueryLightsStateToServer(); // 查询灯光状态到服务器
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
102 detail::WeakEpisodeProxy _episode; // 弱引用的Episode
103
104 std::mutex _mutex; // 互斥锁
105
106 LightState _state; // 当前状态
107 size_t _on_tick_register_id = 0; // tick注册ID
108 size_t _on_light_update_register_id = 0; // 灯光更新注册ID
109 bool _dirty = false; // 脏标志
110};
111
112} // namespace client
113} // namespace carla
std::vector< Light > GetTurnedOffLights(LightGroup type=LightGroup::None) const
LightManager(const LightManager &other)
std::vector< Light > GetTurnedOnLights(LightGroup type=LightGroup::None) const
std::vector< LightGroup > GetLightGroup(std::vector< Light > &lights) const
void SetIntensity(std::vector< Light > &lights, float intensity)
std::vector< bool > IsActive(std::vector< Light > &lights) const
std::vector< Color > GetColor(std::vector< Light > &lights) const
const LightState & RetrieveLightState(LightId id) const
void SetLightState(std::vector< Light > &lights, LightState state)
std::unordered_map< LightId, LightState > _lights_changes
void TurnOff(std::vector< Light > &lights)
void SetLightStateNoLock(LightId id, const LightState &new_state)
detail::WeakEpisodeProxy _episode
void SetColor(std::vector< Light > &lights, Color color)
void TurnOn(std::vector< Light > &lights)
std::vector< float > GetIntensity(std::vector< Light > &lights) const
void SetDayNightCycle(const bool active)
std::unordered_map< LightId, LightState > _lights_state
void SetLightGroup(std::vector< Light > &lights, LightGroup group)
void SetEpisode(detail::WeakEpisodeProxy episode)
void SetActive(std::vector< Light > &lights, std::vector< bool > &active)
std::unordered_map< LightId, Light > _lights
void UpdateServerLightsState(bool discard_client=false)
std::vector< LightState > GetLightState(std::vector< Light > &lights) const
std::vector< Light > GetAllLights(LightGroup type=LightGroup::None) const
EpisodeProxyImpl< EpisodeProxyPointerType::Weak > WeakEpisodeProxy
uint32_t LightId
定义灯光ID的类型,使用uint32_t表示。
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
包含CARLA客户端相关类和函数的命名空间。
表示车辆灯光状态的结构体。