CARLA
CarlaRecorderPosition.cpp
Go to the documentation of this file.
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"
9 #include "CarlaRecorderHelpers.h"
10 
11 void CarlaRecorderPosition::Write(std::ostream &OutFile)
12 {
13  // database id
14  WriteValue<uint32_t>(OutFile, this->DatabaseId);
15  // transform
16  WriteFVector(OutFile, this->Location);
17  WriteFVector(OutFile, this->Rotation);
18 }
19 void CarlaRecorderPosition::Read(std::istream &InFile)
20 {
21  // database id
22  ReadValue<uint32_t>(InFile, this->DatabaseId);
23  // transform
24  ReadFVector(InFile, this->Location);
25  ReadFVector(InFile, this->Rotation);
26 }
27 
28 // ---------------------------------------------
29 
31 {
32  Positions.clear();
33 }
34 
36 {
37  Positions.push_back(Position);
38 }
39 
40 void CarlaRecorderPositions::Write(std::ostream &OutFile)
41 {
42  // write the packet id
43  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::Position));
44 
45  // write the packet size
46  uint32_t Total = 2 + Positions.size() * sizeof(CarlaRecorderPosition);
47  WriteValue<uint32_t>(OutFile, Total);
48 
49  // write total records
50  Total = Positions.size();
51  WriteValue<uint16_t>(OutFile, Total);
52 
53  // write records
54  if (Total > 0)
55  {
56  OutFile.write(reinterpret_cast<const char *>(Positions.data()),
57  Positions.size() * sizeof(CarlaRecorderPosition));
58  }
59 }
60 
61 void CarlaRecorderPositions::Read(std::istream &InFile)
62 {
63  uint16_t i, Total;
64 
65  // read all positions
66  ReadValue<uint16_t>(InFile, Total);
67  for (i = 0; i < Total; ++i)
68  {
70  Pos.Read(InFile);
71  Add(Pos);
72  }
73 }
74 
75 const std::vector<CarlaRecorderPosition>& CarlaRecorderPositions::GetPositions()
76 {
77  return Positions;
78 }
void Read(std::istream &InFile)
void Add(const CarlaRecorderPosition &InObj)
void ReadFVector(std::istream &InFile, FVector &OutObj)
const std::vector< CarlaRecorderPosition > & GetPositions()
void Read(std::istream &InFile)
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
void Write(std::ostream &OutFile)
void Write(std::ostream &OutFile)