CARLA
CarlaLight.cpp
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 #include "CarlaLight.h"
8 #include "CarlaLightSubsystem.h"
10 
11 UCarlaLight::UCarlaLight()
12 {
13  PrimaryComponentTick.bCanEverTick = false;
14 }
15 
16 void UCarlaLight::BeginPlay()
17 {
18  Super::BeginPlay();
19 
20  RegisterLight();
21 }
22 
23 void UCarlaLight::RegisterLight()
24 {
25  if(bRegistered)
26  {
27  return;
28  }
29 
30  UWorld *World = GetWorld();
31  if(World)
32  {
33  UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
34  CarlaLightSubsystem->RegisterLight(this);
35  }
36  RegisterLightWithWeather();
37  bRegistered = true;
38 }
39 
40 void UCarlaLight::OnComponentDestroyed(bool bDestroyingHierarchy)
41 {
42  Super::OnComponentDestroyed(bDestroyingHierarchy);
43 }
44 
45 void UCarlaLight::EndPlay(const EEndPlayReason::Type EndPlayReason)
46 {
47  UWorld *World = GetWorld();
48  if(World)
49  {
50  UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
51  CarlaLightSubsystem->UnregisterLight(this);
52  }
53  Super::EndPlay(EndPlayReason);
54 }
55 
56 void UCarlaLight::SetLightIntensity(float Intensity)
57 {
58  LightIntensity = Intensity;
59  UpdateLights();
60 }
61 
62 float UCarlaLight::GetLightIntensity() const
63 {
64  return LightIntensity;
65 }
66 
67 void UCarlaLight::SetLightColor(FLinearColor Color)
68 {
69  LightColor = Color;
70  UpdateLights();
71  RecordLightChange();
72 }
73 
74 FLinearColor UCarlaLight::GetLightColor() const
75 {
76  return LightColor;
77 }
78 
79 void UCarlaLight::SetLightOn(bool bOn)
80 {
81  bLightOn = bOn;
82  UpdateLights();
83  RecordLightChange();
84 }
85 
86 bool UCarlaLight::GetLightOn() const
87 {
88  return bLightOn;
89 }
90 
91 void UCarlaLight::SetLightType(ELightType Type)
92 {
93  LightType = Type;
94 }
95 
96 ELightType UCarlaLight::GetLightType() const
97 {
98  return LightType;
99 }
100 
101 carla::rpc::LightState UCarlaLight::GetLightState()
102 {
104  GetLocation(),
105  LightIntensity,
106  static_cast<carla::rpc::LightState::LightGroup>(LightType),
107  LightColor,
108  bLightOn
109  );
110 
111  state._id = GetId();
112 
113  return state;
114 }
115 
116 void UCarlaLight::SetLightState(carla::rpc::LightState LightState)
117 {
118  LightIntensity = LightState._intensity;
119  LightColor = LightState._color;
120  LightType = static_cast<ELightType>(LightState._group);
121  bLightOn = LightState._active;
122  UpdateLights();
123  RecordLightChange();
124 }
125 
126 FVector UCarlaLight::GetLocation() const
127 {
128  auto Location = GetOwner()->GetActorLocation();
129  ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(GetWorld());
130  ALargeMapManager* LargeMap = GameMode->GetLMManager();
131  if (LargeMap)
132  {
134  }
135  return Location;
136 }
137 
138 int UCarlaLight::GetId() const
139 {
140  return Id;
141 }
142 
143 void UCarlaLight::SetId(int InId)
144 {
145  Id = InId;
146 }
147 
148 void UCarlaLight::RecordLightChange() const
149 {
150  auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
151  if (Episode)
152  {
153  auto* Recorder = Episode->GetRecorder();
154  if (Recorder && Recorder->IsEnabled())
155  {
156  Recorder->AddEventLightSceneChanged(this);
157  }
158  }
159 }
sensor::data::Color Color
void UnregisterLight(UCarlaLight *CarlaLight)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:58
geom::Location Location
Definition: rpc/Location.h:14
ELightType
Definition: CarlaLight.h:22
ALargeMapManager * GetLMManager() const
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:68
void RegisterLight(UCarlaLight *CarlaLight)
Base class for the CARLA Game Mode.
FVector LocalToGlobalLocation(const FVector &InLocation) const