CARLA
 
载入中...
搜索中...
未找到
CarlaReplayer.h
浏览该文件的文档.
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#pragma once
8
9#include <fstream>
10#include <sstream>
11#include <unordered_map>
12
13#include <functional>
14#include "CarlaRecorderInfo.h"
21#include "CarlaRecorderState.h"
23#include "CarlaReplayerHelper.h"
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 double TimeFactor;
48 };
49
51
54
55 std::string ReplayFile(std::string Filename, double TimeStart = 0.0f, double Duration = 0.0f,
56 uint32_t FollowId = 0, bool ReplaySensors = false);
57
58 // void Start(void);
59 void Stop(bool KeepActors = false);
60
61 void Enable(void);
62
63 void Disable(void);
64
65 bool IsEnabled(void)
66 {
67 return Enabled;
68 }
69
70 // set episode
71 void SetEpisode(UCarlaEpisode *ThisEpisode)
72 {
73 Episode = ThisEpisode;
74 Helper.SetEpisode(ThisEpisode);
75 }
76
77 // playback speed (time factor)
78 void SetTimeFactor(double NewTimeFactor)
79 {
80 TimeFactor = NewTimeFactor;
81 }
82
83 // set ignore hero
84 void SetIgnoreHero(bool InIgnoreHero)
85 {
86 IgnoreHero = InIgnoreHero;
87 }
88
89 // set ignore spectator
90 void SetIgnoreSpectator(bool InIgnoreSpectator)
91 {
92 IgnoreSpectator = InIgnoreSpectator;
93 }
94
95 // check if after a map is loaded, we need to replay
96 void CheckPlayAfterMapLoaded(void);
97
98 // tick for the replayer
99 void Tick(float Time);
100
101private:
102
104 bool bReplaySensors = false;
106 // binary file reader
107 std::ifstream File;
111 // positions (to be able to interpolate)
112 std::vector<CarlaRecorderPosition> CurrPos;
113 std::vector<CarlaRecorderPosition> PrevPos;
114 // mapping id
115 std::unordered_map<uint32_t, uint32_t> MappedId;
116 // times
119 double TotalTime;
120 // helper
122 // follow camera
123 uint32_t FollowId;
124 // speed (time factor)
125 double TimeFactor { 1.0 };
126 // ignore hero vehicles
127 bool IgnoreHero { false };
128 bool IgnoreSpectator { true };
129 std::unordered_map<uint32_t, bool> IsHeroMap;
130
131 // utils
132 bool ReadHeader();
133
134 void SkipPacket();
135
136 double GetTotalTime(void);
137
138 void Rewind(void);
139
140 // processing packets
141 void ProcessToTime(double Time, bool IsFirstTime = false);
142
143 void ProcessVisualTime(void);
144
145 void ProcessEventsAdd(void);
146 void ProcessEventsDel(void);
147 void ProcessEventsParent(void);
148
149 void ProcessPositions(bool IsFirstTime = false);
150
151 void ProcessStates(void);
152
153 void ProcessAnimVehicle(void);
154 void ProcessAnimVehicleWheels(void);
155 void ProcessAnimWalker(void);
156 void ProcessAnimBiker(void);
157
158 void ProcessLightVehicle(void);
159 void ProcessLightScene(void);
160
161 void ProcessDoorVehicle(void);
162
163 void ProcessWalkerBones(void);
164
165 // positions
166 void UpdatePositions(double Per, double DeltaTime);
167
168 void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime);
169};
void SetEpisode(UCarlaEpisode *ThisEpisode)
void ProcessEventsDel(void)
void ProcessDoorVehicle(void)
void SetEpisode(UCarlaEpisode *ThisEpisode)
std::vector< CarlaRecorderPosition > PrevPos
void Rewind(void)
void ProcessVisualTime(void)
void ProcessLightVehicle(void)
double GetTotalTime(void)
std::vector< CarlaRecorderPosition > CurrPos
void ProcessAnimVehicleWheels(void)
void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime)
void ProcessAnimVehicle(void)
void SetIgnoreHero(bool InIgnoreHero)
std::string ReplayFile(std::string Filename, double TimeStart=0.0f, double Duration=0.0f, uint32_t FollowId=0, bool ReplaySensors=false)
void ProcessWalkerBones(void)
void Tick(float Time)
void ProcessPositions(bool IsFirstTime=false)
void SetIgnoreSpectator(bool InIgnoreSpectator)
void ProcessEventsParent(void)
void SetTimeFactor(double NewTimeFactor)
void UpdatePositions(double Per, double DeltaTime)
uint32_t FollowId
void ProcessEventsAdd(void)
void Enable(void)
static PlayAfterLoadMap Autoplay
std::ifstream File
UCarlaEpisode * Episode
CarlaRecorderFrame Frame
void ProcessAnimWalker(void)
void ProcessStates(void)
void ProcessAnimBiker(void)
bool IsEnabled(void)
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)
A simulation episode.