CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Recorder
CarlaRecorderHelpers.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 "
CarlaRecorderHelpers.h
"
8
9
#include <util/ue-header-guard-begin.h>
10
#include <Containers/UnrealString.h>
11
#include <util/ue-header-guard-end.h>
12
13
#include <fstream>
14
#include <vector>
15
16
// create a temporal buffer to convert from and to FString and bytes; one per
17
// thread, since Multi-GPU frames are parsed off the game thread
18
static
thread_local
std::vector<uint8_t>
CarlaRecorderHelperBuffer
;
19
20
// get the final path + filename
21
std::string
GetRecorderFilename
(std::string Filename)
22
{
23
std::string Filename2;
24
25
// check if a relative path was specified
26
if
(Filename.find(
"\\"
) != std::string::npos || Filename.find(
"/"
) != std::string::npos || Filename.find(
":"
) != std::string::npos)
27
Filename2 = Filename;
28
else
29
{
30
FString Path = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir());
31
Filename2 = TCHAR_TO_UTF8(*Path) + Filename;
32
}
33
34
return
Filename2;
35
}
36
37
// ------
38
// write
39
// ------
40
41
// write binary data from FVector
42
void
WriteFVector
(std::ostream &OutFile,
const
FVector &InObj)
43
{
44
WriteValue<double>
(OutFile, InObj.X);
45
WriteValue<double>
(OutFile, InObj.Y);
46
WriteValue<double>
(OutFile, InObj.Z);
47
}
48
49
// write binary data from FTransform
50
void
WriteFTransform
(std::ofstream &OutFile,
const
FTransform &InObj)
51
{
52
WriteFVector
(OutFile, InObj.GetTranslation());
53
WriteFVector
(OutFile, InObj.GetRotation().Euler());
54
}
55
56
// write binary data from FString (length + text)
57
void
WriteFString
(std::ostream &OutFile,
const
FString &InObj)
58
{
59
// encode the string to UTF8 to know the final length
60
FTCHARToUTF8 EncodedString(*InObj);
61
int16_t Length = EncodedString.Length();
62
// write
63
WriteValue<uint16_t>
(OutFile, Length);
64
OutFile.write(
reinterpret_cast<
char
*
>
(TCHAR_TO_UTF8(*InObj)), Length);
65
}
66
67
// -----
68
// read
69
// -----
70
71
// read binary data to FVector
72
void
ReadFVector
(std::istream &InFile, FVector &OutObj)
73
{
74
ReadValue<double>
(InFile, OutObj.X);
75
ReadValue<double>
(InFile, OutObj.Y);
76
ReadValue<double>
(InFile, OutObj.Z);
77
}
78
79
// read binary data to FTransform
80
void
ReadFTransform
(std::ifstream &InFile, FTransform &OutObj)
81
{
82
FVector Vec;
83
ReadFVector
(InFile, Vec);
84
OutObj.SetTranslation(Vec);
85
ReadFVector
(InFile, Vec);
86
OutObj.GetRotation().MakeFromEuler(Vec);
87
}
88
89
// read binary data to FString (length + text)
90
void
ReadFString
(std::istream &InFile, FString &OutObj)
91
{
92
uint16_t Length = 0;
93
ReadValue<uint16_t>
(InFile, Length);
94
// make room in vector buffer
95
if
(
CarlaRecorderHelperBuffer
.capacity() < Length + 1)
96
{
97
CarlaRecorderHelperBuffer
.reserve(Length + 1);
98
}
99
CarlaRecorderHelperBuffer
.clear();
100
// initialize the vector space with 0
101
CarlaRecorderHelperBuffer
.resize(Length + 1);
102
// read
103
InFile.read(
reinterpret_cast<
char
*
>
(
CarlaRecorderHelperBuffer
.data()), Length);
104
// convert from UTF8 to FString
105
OutObj = FString(UTF8_TO_TCHAR(
CarlaRecorderHelperBuffer
.data()));
106
}
CarlaRecorderHelperBuffer
static std::vector< uint8_t > CarlaRecorderHelperBuffer
Definition
CarlaRecorderHelpers.cpp:18
WriteFTransform
void WriteFTransform(std::ofstream &OutFile, const FTransform &InObj)
Definition
CarlaRecorderHelpers.cpp:50
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
ReadFTransform
void ReadFTransform(std::ifstream &InFile, FTransform &OutObj)
Definition
CarlaRecorderHelpers.cpp:80
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
GetRecorderFilename
std::string GetRecorderFilename(std::string Filename)
Definition
CarlaRecorderHelpers.cpp:21
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
Generated by
1.18.0