CARLA
Loading...
Searching...
No Matches
CarlaRecorderWalkerBones.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 CarlaRecorderWalkerBones::Write(std::ofstream &OutFile)
15{
16 // database id
17 WriteValue<uint32_t>(OutFile, this->DatabaseId);
18
19 // write all bones
20 WriteValue<uint16_t>(OutFile, this->Bones.size());
21 for (const auto& Obj : this->Bones)
22 {
23 // name & transform
24 WriteFString(OutFile, Obj.Name);
25 WriteFVector(OutFile, Obj.Location);
26 WriteFVector(OutFile, Obj.Rotation);
27 }
28}
29
30void CarlaRecorderWalkerBones::Read(std::ifstream &InFile)
31{
32 // database id
33 ReadValue<uint32_t>(InFile, this->DatabaseId);
34
35 // read all bones
36 uint16_t Total;
37 ReadValue<uint16_t>(InFile, Total);
38 this->Bones.reserve(Total);
39 FString Name;
40 FVector Location, Rotation;
41 for (int i=0; i<Total; ++i)
42 {
43 // name & transform
44 ReadFString(InFile, Name);
45 ReadFVector(InFile, Location);
46 ReadFVector(InFile, Rotation);
47 // add to the vector of bones
48 this->Bones.emplace_back(Name, Location, Rotation);
49 }
50}
51
53{
54 Bones.clear();
55}
56
57// ---------------------------------------------
58
60{
61 Walkers.clear();
62}
63
65{
66 Walkers.push_back(Walker);
67}
68
69void CarlaRecorderWalkersBones::Write(std::ofstream &OutFile)
70{
71 // write the packet id
72 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::WalkerBones));
73
74 std::streampos PosStart = OutFile.tellp();
75
76 // write a dummy packet size
77 uint32_t Total = 0;
78 WriteValue<uint32_t>(OutFile, Total);
79
80 // write total records
81 Total = std::min<size_t>(Walkers.size(), std::numeric_limits<uint16_t>::max());
82 WriteValue<uint16_t>(OutFile, Total);
83
84 // write records
85 for (uint16_t i=0; i<Total; ++i)
86 Walkers[i].Write(OutFile);
87
88 // write the real packet size
89 std::streampos PosEnd = OutFile.tellp();
90 Total = PosEnd - PosStart - sizeof(uint32_t);
91 OutFile.seekp(PosStart, std::ios::beg);
92 WriteValue<uint32_t>(OutFile, Total);
93 OutFile.seekp(PosEnd, std::ios::beg);
94}
void WriteFString(std::ostream &OutFile, const FString &InObj)
void ReadFString(std::istream &InFile, FString &OutObj)
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
void ReadFVector(std::istream &InFile, FVector &OutObj)
void Write(std::ofstream &OutFile)
std::vector< CarlaRecorderWalkerBones > Walkers
void Add(const CarlaRecorderWalkerBones &InObj)
void Read(std::ifstream &InFile)
std::vector< CarlaRecorderWalkerBone > Bones
void Write(std::ofstream &OutFile)