CARLA
CarlaRecorderLightScene.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 
8 #include "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
11 
12 void CarlaRecorderLightScene::Write(std::ostream &OutFile)
13 {
14  WriteValue<int>(OutFile, this->LightId);
15  WriteValue<float>(OutFile, this->Intensity);
16  WriteValue<FLinearColor>(OutFile, this->Color);
17  WriteValue<bool>(OutFile, this->bOn);
18  WriteValue<uint8>(OutFile, this->Type);
19 }
20 void CarlaRecorderLightScene::Read(std::istream &InFile)
21 {
22  ReadValue<int>(InFile, this->LightId);
23  ReadValue<float>(InFile, this->Intensity);
24  ReadValue<FLinearColor>(InFile, this->Color);
25  ReadValue<bool>(InFile, this->bOn);
26  ReadValue<uint8>(InFile, this->Type);
27 }
28 
29 // ---------------------------------------------
30 
32 {
33  Lights.clear();
34 }
35 
37 {
38  Lights.push_back(Vehicle);
39 }
40 
41 void CarlaRecorderLightScenes::Write(std::ostream &OutFile)
42 {
43  if (Lights.size() == 0)
44  {
45  return;
46  }
47  // write the packet id
48  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::SceneLight));
49 
50  std::streampos PosStart = OutFile.tellp();
51 
52  // write a dummy packet size
53  uint32_t Total = 2 + Lights.size() * sizeof(CarlaRecorderLightScene);
54  WriteValue<uint32_t>(OutFile, Total);
55 
56  // write total records
57  Total = Lights.size();
58  WriteValue<uint16_t>(OutFile, Total);
59 
60  for (auto& Light : Lights)
61  {
62  Light.Write(OutFile);
63  }
64 
65 }
66 
67 void CarlaRecorderLightScenes::Read(std::istream &InFile)
68 {
69  uint16_t Total;
70  CarlaRecorderLightScene LightScene;
71 
72  // read Total light events
73  ReadValue<uint16_t>(InFile, Total);
74  for (uint16_t i = 0; i < Total; ++i)
75  {
76  LightScene.Read(InFile);
77  Add(LightScene);
78  }
79 }
80 
81 const std::vector<CarlaRecorderLightScene>& CarlaRecorderLightScenes::GetLights()
82 {
83  return Lights;
84 }
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderLightScene > & GetLights()
void Add(const CarlaRecorderLightScene &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)