CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderPosition.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 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}
19void 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
39
40void 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
61void 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
75const std::vector<CarlaRecorderPosition>& CarlaRecorderPositions::GetPositions()
76{
77 return Positions;
78}
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
void ReadFVector(std::istream &InFile, FVector &OutObj)
std::vector< CarlaRecorderPosition > Positions
const std::vector< CarlaRecorderPosition > & GetPositions()
void Add(const CarlaRecorderPosition &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)