CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderAnimVehicleWheels.cpp
浏览该文件的文档.
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"
10
11void WheelInfo::Write(std::ostream &OutFile) const
12{
13 WriteValue<EVehicleWheelLocation>(OutFile, Location);
14 WriteValue<float>(OutFile, SteeringAngle);
15 WriteValue<float>(OutFile, TireRotation);
16}
17
18void WheelInfo::Read(std::istream &InFile)
19{
20 ReadValue<EVehicleWheelLocation>(InFile, Location);
21 ReadValue<float>(InFile, SteeringAngle);
22 ReadValue<float>(InFile, TireRotation);
23}
24
25void 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
35void 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.resize(NumWheels);
41 for (size_t i = 0; i < NumWheels; ++i)
42 {
43 WheelInfo Wheel;
44 Wheel.Read(InFile);
45 WheelValues[i] = Wheel;
46 }
47}
48
49// ---------------------------------------------
50
55
60
61void 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
87void 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
101const std::vector<CarlaRecorderAnimWheels>& CarlaRecorderAnimVehicleWheels::GetVehicleWheels()
102{
103 return VehicleWheels;
104}
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