CARLA
CarlaRecorderAnimVehicle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
11 void CarlaRecorderAnimVehicle::Write(std::ostream &OutFile)
12 {
13  // database id
14  WriteValue<uint32_t>(OutFile, this->DatabaseId);
15  WriteValue<float>(OutFile, this->Steering);
16  WriteValue<float>(OutFile, this->Throttle);
17  WriteValue<float>(OutFile, this->Brake);
18  WriteValue<bool>(OutFile, this->bHandbrake);
19  WriteValue<int32_t>(OutFile, this->Gear);
20 }
21 void CarlaRecorderAnimVehicle::Read(std::istream &InFile)
22 {
23  // database id
24  ReadValue<uint32_t>(InFile, this->DatabaseId);
25  ReadValue<float>(InFile, this->Steering);
26  ReadValue<float>(InFile, this->Throttle);
27  ReadValue<float>(InFile, this->Brake);
28  ReadValue<bool>(InFile, this->bHandbrake);
29  ReadValue<int32_t>(InFile, this->Gear);
30 }
31 
32 // ---------------------------------------------
33 
35 {
36  Vehicles.clear();
37 }
38 
40 {
41  Vehicles.push_back(Vehicle);
42 }
43 
44 void CarlaRecorderAnimVehicles::Write(std::ostream &OutFile)
45 {
46  // write the packet id
47  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicle));
48 
49  std::streampos PosStart = OutFile.tellp();
50 
51  // write a dummy packet size
52  uint32_t Total = 0;
53  WriteValue<uint32_t>(OutFile, Total);
54 
55  // write total records
56  Total = Vehicles.size();
57  WriteValue<uint16_t>(OutFile, Total);
58 
59  for (uint16_t i=0; i<Total; ++i)
60  Vehicles[i].Write(OutFile);
61 
62  // write the real packet size
63  std::streampos PosEnd = OutFile.tellp();
64  Total = PosEnd - PosStart - sizeof(uint32_t);
65  OutFile.seekp(PosStart, std::ios::beg);
66  WriteValue<uint32_t>(OutFile, Total);
67  OutFile.seekp(PosEnd, std::ios::beg);
68 }
69 
70 void CarlaRecorderAnimVehicles::Read(std::istream &InFile)
71 {
72  uint16_t i, Total;
74 
75  // read Total Vehicles
76  ReadValue<uint16_t>(InFile, Total);
77  for (i = 0; i < Total; ++i)
78  {
79  Vehicle.Read(InFile);
80  Add(Vehicle);
81  }
82 }
83 
84 const std::vector<CarlaRecorderAnimVehicle>& CarlaRecorderAnimVehicles::GetVehicles()
85 {
86  return Vehicles;
87 }
void Add(const CarlaRecorderAnimVehicle &InObj)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderAnimVehicle > & GetVehicles()
void Read(std::istream &InFile)