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
11
12// 功能: 将 WheelInfo 对象的数据写入到指定的输出流中
13void WheelInfo::Write(std::ostream &OutFile) const
14{
15 // 写入车辆车轮的位置信息
16 // WriteValue 是一个模板函数,用于将指定类型的值写入输出流
17 // EVehicleWheelLocation 是车轮位置的枚举类型
18 WriteValue<EVehicleWheelLocation>(OutFile, Location);
19
20 // 写入车轮的转向角度
21 // SteeringAngle 是一个浮点数,表示车轮的转向角度
22 WriteValue<float>(OutFile, SteeringAngle);
23
24 // 写入轮胎的旋转角度
25 // TireRotation 是一个浮点数,表示轮胎的旋转角度
26 WriteValue<float>(OutFile, TireRotation);
27}
28
29void WheelInfo::Read(std::istream &InFile)
30{
31 ReadValue<EVehicleWheelLocation>(InFile, Location);
32 ReadValue<float>(InFile, SteeringAngle);
33 ReadValue<float>(InFile, TireRotation);
34}
35
36void CarlaRecorderAnimWheels::Write(std::ostream &OutFile)
37{
38 WriteValue<uint32_t>(OutFile, DatabaseId);
39 WriteValue<uint32_t>(OutFile, WheelValues.size());
40 for (const WheelInfo& Wheel : WheelValues)
41 {
42 Wheel.Write(OutFile);
43 }
44}
45
46void CarlaRecorderAnimWheels::Read(std::istream &InFile)
47{
48 ReadValue<uint32_t>(InFile, DatabaseId);
49 uint32_t NumWheels = 0;
50 ReadValue<uint32_t>(InFile, NumWheels);
51 WheelValues.resize(NumWheels);
52 for (size_t i = 0; i < NumWheels; ++i)
53 {
54 WheelInfo Wheel;
55 Wheel.Read(InFile);
56 WheelValues[i] = Wheel;
57 }
58}
59
60// ---------------------------------------------
61
66
71
72void CarlaRecorderAnimVehicleWheels::Write(std::ostream &OutFile)
73{
74 // 写入数据包 ID
75 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicleWheels));
76
77 std::streampos PosStart = OutFile.tellp();
78
79 // 写入虚拟数据包大小
80 uint32_t Total = 0;
81 WriteValue<uint32_t>(OutFile, Total);
82
83 // 写入总记录数
84 Total = VehicleWheels.size();
85 WriteValue<uint16_t>(OutFile, Total);
86
87 for (uint16_t i=0; i<Total; ++i)
88 VehicleWheels[i].Write(OutFile);
89
90 // 写入实际数据包大小
91 std::streampos PosEnd = OutFile.tellp();
92 Total = PosEnd - PosStart - sizeof(uint32_t);
93 OutFile.seekp(PosStart, std::ios::beg);
94 WriteValue<uint32_t>(OutFile, Total);
95 OutFile.seekp(PosEnd, std::ios::beg);
96}
97
98void CarlaRecorderAnimVehicleWheels::Read(std::istream &InFile)
99{
100 uint16_t i, Total;
102
103 // 记录车辆总数
104 ReadValue<uint16_t>(InFile, Total);
105 for (i = 0; i < Total; ++i)
106 {
107 Wheels.Read(InFile);
108 Add(Wheels);
109 }
110}
111
112const std::vector<CarlaRecorderAnimWheels>& CarlaRecorderAnimVehicleWheels::GetVehicleWheels()
113{
114 return VehicleWheels;
115}
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