CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Recorder
CarlaRecorderEventAdd.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
7
#include "
CarlaRecorderEventAdd.h
"
8
#include "
CarlaRecorder.h
"
9
#include "
CarlaRecorderHelpers.h
"
10
11
#include <algorithm>
12
#include <limits>
13
14
void
CarlaRecorderEventAdd::Write
(std::ostream &OutFile)
const
15
{
16
// database id
17
WriteValue<uint32_t>
(OutFile, this->
DatabaseId
);
18
WriteValue<uint8_t>
(OutFile, this->
Type
);
19
20
// transform
21
WriteFVector
(OutFile, this->
Location
);
22
WriteFVector
(OutFile, this->
Rotation
);
23
24
// description type
25
WriteValue<uint32_t>
(OutFile, this->
Description
.
UId
);
26
WriteFString
(OutFile, this->
Description
.
Id
);
27
28
// attributes
29
uint16_t Total = this->
Description
.
Attributes
.size();
30
WriteValue<uint16_t>
(OutFile, Total);
31
for
(uint16_t i=0; i<Total; ++i)
32
{
33
// type
34
WriteValue<uint8_t>
(OutFile, this->
Description
.
Attributes
[i].Type);
35
WriteFString
(OutFile, this->
Description
.
Attributes
[i].Id);
36
WriteFString
(OutFile, this->
Description
.
Attributes
[i].Value);
37
}
38
}
39
40
void
CarlaRecorderEventAdd::Read
(std::istream &InFile)
41
{
42
// database id
43
ReadValue<uint32_t>
(InFile, this->
DatabaseId
);
44
45
// database type
46
ReadValue<uint8_t>
(InFile, this->
Type
);
47
48
// transform
49
ReadFVector
(InFile, this->
Location
);
50
ReadFVector
(InFile, this->
Rotation
);
51
52
// description type
53
ReadValue<uint32_t>
(InFile, this->
Description
.
UId
);
54
ReadFString
(InFile, this->
Description
.
Id
);
55
56
// attributes
57
uint16_t Total = 0;
58
ReadValue<uint16_t>
(InFile, Total);
59
this->
Description
.
Attributes
.clear();
60
for
(uint16_t i=0; (i<Total) && InFile; ++i)
61
{
62
CarlaRecorderActorAttribute
Att;
63
ReadValue<uint8_t>
(InFile, Att.
Type
);
64
ReadFString
(InFile, Att.
Id
);
65
ReadFString
(InFile, Att.
Value
);
66
this->
Description
.
Attributes
.push_back(std::move(Att));
67
}
68
}
69
70
//---------------------------------------------
71
72
void
CarlaRecorderEventsAdd::Clear
(
void
)
73
{
74
Events
.clear();
75
}
76
77
void
CarlaRecorderEventsAdd::Add
(
const
CarlaRecorderEventAdd
&Event)
78
{
79
Events
.push_back(std::move(Event));
80
}
81
82
void
CarlaRecorderEventsAdd::Write
(std::ostream &OutFile)
83
{
84
// write the packet id
85
WriteValue<char>
(OutFile,
static_cast<
char
>
(
CarlaRecorderPacketId::EventAdd
));
86
87
std::streampos PosStart = OutFile.tellp();
88
89
// write a dummy packet size
90
uint32_t Total = 0;
91
WriteValue<uint32_t>
(OutFile, Total);
92
93
// write total records
94
Total = std::min<size_t>(
Events
.size(), std::numeric_limits<uint16_t>::max());
95
WriteValue<uint16_t>
(OutFile, Total);
96
97
for
(uint16_t i=0; i<Total; ++i)
98
Events
[i].
Write
(OutFile);
99
100
// write the real packet size
101
std::streampos PosEnd = OutFile.tellp();
102
Total = PosEnd - PosStart -
sizeof
(uint32_t);
103
OutFile.seekp(PosStart, std::ios::beg);
104
WriteValue<uint32_t>
(OutFile, Total);
105
OutFile.seekp(PosEnd, std::ios::beg);
106
}
107
108
void
CarlaRecorderEventsAdd::Read
(std::istream &InFile)
109
{
110
CarlaRecorderEventAdd
EventAdd
;
111
uint16_t i, Total = 0;
112
ReadValue<uint16_t>
(InFile, Total);
113
for
(i = 0; (i < Total) && InFile; ++i)
114
{
115
EventAdd
.Read(InFile);
116
Add
(
EventAdd
);
117
}
118
}
119
120
const
std::vector<CarlaRecorderEventAdd>&
CarlaRecorderEventsAdd::GetEvents
()
121
{
122
return
Events
;
123
}
CarlaRecorderEventAdd.h
WriteFString
void WriteFString(std::ostream &OutFile, const FString &InObj)
Definition
CarlaRecorderHelpers.cpp:57
ReadFString
void ReadFString(std::istream &InFile, FString &OutObj)
Definition
CarlaRecorderHelpers.cpp:90
WriteFVector
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
Definition
CarlaRecorderHelpers.cpp:42
ReadFVector
void ReadFVector(std::istream &InFile, FVector &OutObj)
Definition
CarlaRecorderHelpers.cpp:72
CarlaRecorderHelpers.h
WriteValue
void WriteValue(std::ostream &OutFile, const T &InObj)
Definition
CarlaRecorderHelpers.h:21
ReadValue
void ReadValue(std::istream &InFile, T &OutObj)
Definition
CarlaRecorderHelpers.h:60
CarlaRecorder.h
CarlaRecorderPacketId::EventAdd
@ EventAdd
Definition
CarlaRecorder.h:53
CarlaRecorderEventsAdd::Events
std::vector< CarlaRecorderEventAdd > Events
Definition
CarlaRecorderEventAdd.h:49
CarlaRecorderEventsAdd::Add
void Add(const CarlaRecorderEventAdd &Event)
Definition
CarlaRecorderEventAdd.cpp:77
CarlaRecorderEventsAdd::Clear
void Clear(void)
Definition
CarlaRecorderEventAdd.cpp:72
CarlaRecorderEventsAdd::Read
void Read(std::istream &InFile)
Definition
CarlaRecorderEventAdd.cpp:108
CarlaRecorderEventsAdd::Write
void Write(std::ostream &OutFile)
Definition
CarlaRecorderEventAdd.cpp:82
CarlaRecorderEventsAdd::GetEvents
const std::vector< CarlaRecorderEventAdd > & GetEvents()
Definition
CarlaRecorderEventAdd.cpp:120
CarlaRecorderActorAttribute
Definition
CarlaRecorderEventAdd.h:13
CarlaRecorderActorAttribute::Type
uint8_t Type
Definition
CarlaRecorderEventAdd.h:14
CarlaRecorderActorAttribute::Id
FString Id
Definition
CarlaRecorderEventAdd.h:15
CarlaRecorderActorAttribute::Value
FString Value
Definition
CarlaRecorderEventAdd.h:16
CarlaRecorderActorDescription::UId
uint32_t UId
Definition
CarlaRecorderEventAdd.h:21
CarlaRecorderActorDescription::Attributes
std::vector< CarlaRecorderActorAttribute > Attributes
Definition
CarlaRecorderEventAdd.h:23
CarlaRecorderActorDescription::Id
FString Id
Definition
CarlaRecorderEventAdd.h:22
CarlaRecorderEventAdd
Definition
CarlaRecorderEventAdd.h:27
CarlaRecorderEventAdd::Location
FVector Location
Definition
CarlaRecorderEventAdd.h:30
CarlaRecorderEventAdd::Write
void Write(std::ostream &OutFile) const
Definition
CarlaRecorderEventAdd.cpp:14
CarlaRecorderEventAdd::Rotation
FVector Rotation
Definition
CarlaRecorderEventAdd.h:31
CarlaRecorderEventAdd::Read
void Read(std::istream &InFile)
Definition
CarlaRecorderEventAdd.cpp:40
CarlaRecorderEventAdd::DatabaseId
uint32_t DatabaseId
Definition
CarlaRecorderEventAdd.h:28
CarlaRecorderEventAdd::Description
CarlaRecorderActorDescription Description
Definition
CarlaRecorderEventAdd.h:32
CarlaRecorderEventAdd::Type
uint8_t Type
Definition
CarlaRecorderEventAdd.h:29
Generated by
1.18.0