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