CARLA
CarlaRecorderAnimVehicleWheels.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"
8 #include "CarlaRecorderHelpers.h"
10 
11 void WheelInfo::Write(std::ostream &OutFile) const
12 {
13  WriteValue<EVehicleWheelLocation>(OutFile, Location);
14  WriteValue<float>(OutFile, SteeringAngle);
15  WriteValue<float>(OutFile, TireRotation);
16 }
17 
18 void WheelInfo::Read(std::istream &InFile)
19 {
20  ReadValue<EVehicleWheelLocation>(InFile, Location);
21  ReadValue<float>(InFile, SteeringAngle);
22  ReadValue<float>(InFile, TireRotation);
23 }
24 
25 void CarlaRecorderAnimWheels::Write(std::ostream &OutFile)
26 {
27  WriteValue<uint32_t>(OutFile, DatabaseId);
28  WriteValue<uint32_t>(OutFile, WheelValues.size());
29  for (const WheelInfo& Wheel : WheelValues)
30  {
31  Wheel.Write(OutFile);
32  }
33 }
34 
35 void CarlaRecorderAnimWheels::Read(std::istream &InFile)
36 {
37  ReadValue<uint32_t>(InFile, DatabaseId);
38  uint32_t NumWheels = 0;
39  ReadValue<uint32_t>(InFile, NumWheels);
40  WheelValues.reserve(NumWheels);
41  for (size_t i = 0; i < NumWheels; ++i)
42  {
43  WheelInfo Wheel;
44  Wheel.Read(InFile);
45  WheelValues.push_back(Wheel);
46  }
47 }
48 
49 // ---------------------------------------------
50 
52 {
53  VehicleWheels.clear();
54 }
55 
57 {
58  VehicleWheels.push_back(Vehicle);
59 }
60 
61 void CarlaRecorderAnimVehicleWheels::Write(std::ostream &OutFile)
62 {
63  // write the packet id
64  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicleWheels));
65 
66  std::streampos PosStart = OutFile.tellp();
67 
68  // write a dummy packet size
69  uint32_t Total = 0;
70  WriteValue<uint32_t>(OutFile, Total);
71 
72  // write total records
73  Total = VehicleWheels.size();
74  WriteValue<uint16_t>(OutFile, Total);
75 
76  for (uint16_t i=0; i<Total; ++i)
77  VehicleWheels[i].Write(OutFile);
78 
79  // write the real packet size
80  std::streampos PosEnd = OutFile.tellp();
81  Total = PosEnd - PosStart - sizeof(uint32_t);
82  OutFile.seekp(PosStart, std::ios::beg);
83  WriteValue<uint32_t>(OutFile, Total);
84  OutFile.seekp(PosEnd, std::ios::beg);
85 }
86 
87 void CarlaRecorderAnimVehicleWheels::Read(std::istream &InFile)
88 {
89  uint16_t i, Total;
91 
92  // read Total Vehicles
93  ReadValue<uint16_t>(InFile, Total);
94  for (i = 0; i < Total; ++i)
95  {
96  Wheels.Read(InFile);
97  Add(Wheels);
98  }
99 }
100 
101 const std::vector<CarlaRecorderAnimWheels>& CarlaRecorderAnimVehicleWheels::GetVehicleWheels()
102 {
103  return VehicleWheels;
104 }
void Add(const CarlaRecorderAnimWheels &InObj)
void Write(std::ostream &OutFile) const
EVehicleWheelLocation Location
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
const std::vector< CarlaRecorderAnimWheels > & GetVehicleWheels()