CARLA
Loading...
Searching...
No Matches
CarlaRecorderAnimVehicleWheels.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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"
10
11#include <algorithm>
12#include <limits>
13
14void WheelInfo::Write(std::ostream &OutFile) const
15{
16 WriteValue<EVehicleWheelLocation>(OutFile, Location);
17 WriteValue<float>(OutFile, SteeringAngle);
18 WriteValue<float>(OutFile, TireRotation);
19}
20
21void WheelInfo::Read(std::istream &InFile)
22{
23 ReadValue<EVehicleWheelLocation>(InFile, Location);
24 ReadValue<float>(InFile, SteeringAngle);
25 ReadValue<float>(InFile, TireRotation);
26}
27
28void CarlaRecorderAnimWheels::Write(std::ostream &OutFile)
29{
30 WriteValue<uint32_t>(OutFile, DatabaseId);
31 WriteValue<uint32_t>(OutFile, WheelValues.size());
32 for (const WheelInfo& Wheel : WheelValues)
33 {
34 Wheel.Write(OutFile);
35 }
36}
37
38void CarlaRecorderAnimWheels::Read(std::istream &InFile)
39{
40 ReadValue<uint32_t>(InFile, DatabaseId);
41 uint32_t NumWheels = 0;
42 ReadValue<uint32_t>(InFile, NumWheels);
43 // The same object is read again for every vehicle of a packet.
44 WheelValues.clear();
45 for (size_t i = 0; (i < NumWheels) && InFile; ++i)
46 {
47 WheelInfo Wheel;
48 Wheel.Read(InFile);
49 WheelValues.push_back(Wheel);
50 }
51}
52
53// ---------------------------------------------
54
59
64
65void CarlaRecorderAnimVehicleWheels::Write(std::ostream &OutFile)
66{
67 // write the packet id
68 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicleWheels));
69
70 std::streampos PosStart = OutFile.tellp();
71
72 // write a dummy packet size
73 uint32_t Total = 0;
74 WriteValue<uint32_t>(OutFile, Total);
75
76 // write total records
77 Total = std::min<size_t>(VehicleWheels.size(), std::numeric_limits<uint16_t>::max());
78 WriteValue<uint16_t>(OutFile, Total);
79
80 for (uint16_t i=0; i<Total; ++i)
81 VehicleWheels[i].Write(OutFile);
82
83 // write the real packet size
84 std::streampos PosEnd = OutFile.tellp();
85 Total = PosEnd - PosStart - sizeof(uint32_t);
86 OutFile.seekp(PosStart, std::ios::beg);
87 WriteValue<uint32_t>(OutFile, Total);
88 OutFile.seekp(PosEnd, std::ios::beg);
89}
90
91void CarlaRecorderAnimVehicleWheels::Read(std::istream &InFile)
92{
93 uint16_t i, Total = 0;
95
96 // read Total Vehicles
97 ReadValue<uint16_t>(InFile, Total);
98 for (i = 0; (i < Total) && InFile; ++i)
99 {
100 Wheels.Read(InFile);
101 Add(Wheels);
102 }
103}
104
105const std::vector<CarlaRecorderAnimWheels>& CarlaRecorderAnimVehicleWheels::GetVehicleWheels()
106{
107 return VehicleWheels;
108}
std::vector< CarlaRecorderAnimWheels > VehicleWheels
void Add(const CarlaRecorderAnimWheels &InObj)
const std::vector< CarlaRecorderAnimWheels > & GetVehicleWheels()
EVehicleWheelLocation Location
void Read(std::istream &InFile)
void Write(std::ostream &OutFile) const