CARLA
Loading...
Searching...
No Matches
CarlaReplayer.h
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#pragma once
8
9#include "CarlaRecorderInfo.h"
10#include "CarlaRecorderFrames.h"
16#include "CarlaRecorderState.h"
18#include "CarlaReplayerHelper.h"
19
20#include <fstream>
21#include <sstream>
22#include <unordered_map>
23#include <functional>
24
25class UCarlaEpisode;
26
28{
29 #pragma pack(push, 1)
30 struct Header
31 {
32 char Id;
33 uint32_t Size;
34 };
35 #pragma pack(pop)
36
37public:
39 {
40 bool Enabled;
41 std::string Filename;
42 FString Mapfile;
43 double TimeStart;
44 double Duration;
45 uint32_t FollowId;
46 FTransform FollowOffset;
47 double TimeFactor;
50 };
51
53
56
57 std::string ReplayFile(std::string Filename, double TimeStart = 0.0f, double Duration = 0.0f,
58 uint32_t FollowId = 0, const FTransform& Offset = FTransform(), bool ReplaySensors = false,
59 bool ReplayWeather = false, std::string MapOverride = "");
60
61 // void Start(void);
62 void Stop(bool KeepActors = false);
63
64 void Enable(void);
65
66 void Disable(void);
67
68 bool IsEnabled(void)
69 {
70 return Enabled;
71 }
72
73 // set episode
74 void SetEpisode(UCarlaEpisode *ThisEpisode)
75 {
76 Episode = ThisEpisode;
77 Helper.SetEpisode(ThisEpisode);
78 }
79
80 // playback speed (time factor)
81 void SetTimeFactor(double NewTimeFactor)
82 {
83 TimeFactor = NewTimeFactor;
84 }
85
86 // set ignore hero
87 void SetIgnoreHero(bool InIgnoreHero)
88 {
89 IgnoreHero = InIgnoreHero;
90 }
91
92 // set ignore spectator
93 void SetIgnoreSpectator(bool InIgnoreSpectator)
94 {
95 IgnoreSpectator = InIgnoreSpectator;
96 }
97
98 // check if after a map is loaded, we need to replay
99 void CheckPlayAfterMapLoaded(void);
100
101 // tick for the replayer
102 void Tick(float Time);
103
104private:
105
107 bool bReplaySensors = false;
108 bool bReplayWeather = false;
110 // binary file reader
111 std::ifstream File;
115 // positions (to be able to interpolate)
116 std::vector<CarlaRecorderPosition> CurrPos;
117 std::vector<CarlaRecorderPosition> PrevPos;
118 // wheels (interpolated like the positions)
119 std::vector<CarlaRecorderAnimWheels> CurrWheels;
120 std::vector<CarlaRecorderAnimWheels> PrevWheels;
121 // mapping id
122 std::unordered_map<uint32_t, uint32_t> MappedId;
123 // times
126 double TotalTime;
127 // helper
129 // follow camera
130 uint32_t FollowId;
131 // follow camera offset
132 FTransform FollowOffset;
133 // speed (time factor)
134 double TimeFactor { 1.0 };
135 // ignore hero vehicles
136 bool IgnoreHero { false };
137 bool IgnoreSpectator { true };
138 std::unordered_map<uint32_t, bool> IsHeroMap;
139
140 // utils
141 bool ReadHeader();
142
143 void SkipPacket();
144
145 double GetTotalTime(void);
146
147 void Rewind(void);
148
149 // processing packets
150 void ProcessToTime(double Time, bool IsFirstTime = false);
151
152 void ProcessVisualTime(void);
153
154 void ProcessEventsAdd(void);
155 void ProcessEventsDel(void);
156 void ProcessEventsParent(void);
157
158 void ProcessPositions(bool IsFirstTime = false);
159
160 void ProcessStates(void);
161
162 void ProcessAnimVehicle(void);
163 void ProcessAnimVehicleWheels(bool IsFirstTime = false);
164 void ProcessAnimWalker(void);
165 void ProcessAnimBiker(void);
166
167 void ProcessLightVehicle(void);
168 void ProcessLightScene(void);
169
170 void ProcessDoorVehicle(void);
171
172 void ProcessWalkerBones(void);
173
174 void ProcessWeather(void);
175
176 // positions
177 void UpdatePositions(double Per, double DeltaTime);
178
179 // wheels, at the same point between frames as the positions
180 void UpdateWheels(double Per);
181
182 void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime);
183};
void SetEpisode(UCarlaEpisode *ThisEpisode)
void ProcessEventsDel(void)
void ProcessDoorVehicle(void)
void SetEpisode(UCarlaEpisode *ThisEpisode)
std::vector< CarlaRecorderPosition > PrevPos
FTransform FollowOffset
void Rewind(void)
void ProcessVisualTime(void)
void ProcessLightVehicle(void)
double GetTotalTime(void)
std::vector< CarlaRecorderPosition > CurrPos
std::vector< CarlaRecorderAnimWheels > PrevWheels
void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime)
void ProcessAnimVehicle(void)
void SetIgnoreHero(bool InIgnoreHero)
void ProcessWalkerBones(void)
void Tick(float Time)
void ProcessPositions(bool IsFirstTime=false)
void SetIgnoreSpectator(bool InIgnoreSpectator)
void ProcessEventsParent(void)
void SetTimeFactor(double NewTimeFactor)
std::string ReplayFile(std::string Filename, double TimeStart=0.0f, double Duration=0.0f, uint32_t FollowId=0, const FTransform &Offset=FTransform(), bool ReplaySensors=false, bool ReplayWeather=false, std::string MapOverride="")
void ProcessWeather(void)
void UpdatePositions(double Per, double DeltaTime)
uint32_t FollowId
void ProcessEventsAdd(void)
void Enable(void)
static PlayAfterLoadMap Autoplay
std::ifstream File
UCarlaEpisode * Episode
void UpdateWheels(double Per)
CarlaRecorderFrame Frame
void ProcessAnimWalker(void)
void ProcessStates(void)
void ProcessAnimBiker(void)
bool IsEnabled(void)
std::vector< CarlaRecorderAnimWheels > CurrWheels
CarlaRecorderInfo RecInfo
CarlaReplayerHelper Helper
void ProcessLightScene(void)
void CheckPlayAfterMapLoaded(void)
std::unordered_map< uint32_t, bool > IsHeroMap
void ProcessToTime(double Time, bool IsFirstTime=false)
void Disable(void)
std::unordered_map< uint32_t, uint32_t > MappedId
void Stop(bool KeepActors=false)
void ProcessAnimVehicleWheels(bool IsFirstTime=false)
A simulation episode.