CARLA
FrameData.h
Go to the documentation of this file.
1 // Copyright (c) 2022 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 
33 
34 
35 #include <sstream>
36 #include <unordered_map>
37 
38 class UCarlaEpisode;
39 class FCarlaActor;
40 
42 {
43  // structures
65 
66  #pragma pack(push, 1)
67  struct Header
68  {
69  char Id;
70  uint32_t Size;
71  };
72  #pragma pack(pop)
73 
74 public:
75 
76  void SetEpisode(UCarlaEpisode* ThisEpisode) {Episode = ThisEpisode;}
77 
78  void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData = false, bool bIncludeActorsAgain = false);
79 
80  void PlayFrameData(UCarlaEpisode *ThisEpisode, std::unordered_map<uint32_t, uint32_t>& MappedId);
81 
82  void Clear();
83 
84  void Write(std::ostream& OutStream);
85  void Read(std::istream& InStream);
86 
87  // record functions
89  uint32_t DatabaseId,
90  uint8_t Type,
91  const FTransform &Transform,
92  FActorDescription ActorDescription,
93  bool bAddOtherRelatedInfo = true);
94  void AddEvent(const CarlaRecorderEventAdd &Event);
95  void AddEvent(const CarlaRecorderEventDel &Event);
96  void AddEvent(const CarlaRecorderEventParent &Event);
97 
98 private:
99  void AddCollision(AActor *Actor1, AActor *Actor2);
103  void AddAnimVehicleWheels(const CarlaRecorderAnimWheels &VehicleWheels);
104  void AddAnimWalker(const CarlaRecorderAnimWalker &Walker);
105  void AddAnimBiker(const CarlaRecorderAnimBiker &Biker);
106  void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle);
107  void AddEventLightSceneChanged(const UCarlaLight* Light);
108  void AddKinematics(const CarlaRecorderKinematics &ActorKinematics);
109  void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox);
110  void AddTriggerVolume(const ATrafficSignBase &TrafficSign);
111  void AddPhysicsControl(const ACarlaWheeledVehicle& Vehicle);
113 
114  void AddActorPosition(FCarlaActor *CarlaActor);
115  void AddWalkerAnimation(FCarlaActor *CarlaActor);
116  void AddBikerAnimation(FCarlaActor *CarlaActor);
117  void AddVehicleAnimation(FCarlaActor *CarlaActor);
118  void AddVehicleWheelsAnimation(FCarlaActor *CarlaActor);
119  void AddTrafficLightState(FCarlaActor *CarlaActor);
120  void AddVehicleLight(FCarlaActor *CarlaActor);
121  void AddActorKinematics(FCarlaActor *CarlaActor);
122  void AddActorBoundingBox(FCarlaActor *CarlaActor);
123 
124  void GetFrameCounter();
125 
126  std::pair<int, FCarlaActor*> CreateOrReuseActor(
127  FVector &Location,
128  FVector &Rotation,
129  FActorDescription &ActorDesc,
130  uint32_t DesiredId,
131  bool SpawnSensors,
132  std::unordered_map<uint32_t, uint32_t>& MappedId);
133 
134  // replay event for creating actor
135  std::pair<int, uint32_t> ProcessReplayerEventAdd(
136  FVector Location,
137  FVector Rotation,
138  CarlaRecorderActorDescription Description,
139  uint32_t DesiredId,
140  bool bIgnoreHero,
141  bool ReplaySensors,
142  std::unordered_map<uint32_t, uint32_t>& MappedId);
143 
144  // replay event for removing actor
145  bool ProcessReplayerEventDel(uint32_t DatabaseId);
146  // replay event for parenting actors
147  bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId);
148  // reposition actors
150  CarlaRecorderPosition Pos2, double Per, double DeltaTime);
151  // replay event for traffic light state
153  // set the animation for Vehicles
155  // set the animation for walkers
157  // set the animation for Vehicles Wheels
159  // set the animation for bikers
161  // set the vehicle light
163  // set scene lights
165  // replay finish
166  bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero,
167  std::unordered_map<uint32_t, bool> &IsHero);
168  // set the camera position to follow an actor
169  bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation);
170  // set the velocity of the actor
171  void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity);
172  // set the animation speed for walkers
173  void SetWalkerSpeed(uint32_t ActorId, float Speed);
174  // enable / disable physics for an actor
175  bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled);
176 
177  void SetFrameCounter();
178 
179  FCarlaActor* FindTrafficLightAt(FVector Location);
180 
181  void AddExistingActors(void);
182 
184 };
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
Definition: FrameData.cpp:874
void AddExistingActors(void)
Definition: FrameData.cpp:1203
void AddVehicleAnimation(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:393
CarlaRecorderPhysicsControls PhysicsControls
Definition: FrameData.h:62
CarlaRecorderInfo Info
Definition: FrameData.h:44
void ProcessReplayerAnimVehicleWheels(CarlaRecorderAnimWheels Vehicle)
Definition: FrameData.cpp:1007
void AddTriggerVolume(const ATrafficSignBase &TrafficSign)
Definition: FrameData.cpp:549
void AddAnimWalker(const CarlaRecorderAnimWalker &Walker)
Definition: FrameData.cpp:669
void AddEventLightSceneChanged(const UCarlaLight *Light)
Definition: FrameData.cpp:679
CarlaRecorderTrafficLightTimes TrafficLightTimes
Definition: FrameData.h:63
void AddWalkerAnimation(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:468
CarlaRecorderAnimBikers Bikers
Definition: FrameData.h:55
void AddAnimVehicle(const CarlaRecorderAnimVehicle &Vehicle)
Definition: FrameData.cpp:654
CarlaRecorderActorBoundingBoxes BoundingBoxes
Definition: FrameData.h:59
void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox)
Definition: FrameData.cpp:698
CarlaRecorderActorsKinematics Kinematics
Definition: FrameData.h:58
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
Definition: FrameData.cpp:1065
CarlaRecorderFrames Frames
Definition: FrameData.h:45
void AddVehicleLight(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:506
CarlaRecorderAnimVehicleWheels Wheels
Definition: FrameData.h:53
void AddAnimVehicleWheels(const CarlaRecorderAnimWheels &VehicleWheels)
Definition: FrameData.cpp:659
void Write(std::ostream &OutStream)
Definition: FrameData.cpp:207
void AddActorPosition(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:379
void AddVehicleWheelsAnimation(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:416
geom::Location Location
Definition: rpc/Location.h:14
void SetFrameCounter()
Definition: FrameData.cpp:1165
CarlaRecorderActorTriggerVolumes TriggerVolumes
Definition: FrameData.h:60
UCarlaEpisode * Episode
Definition: FrameData.h:183
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
Definition: FrameData.cpp:1031
A simulation episode.
Definition: CarlaEpisode.h:38
void SetWalkerSpeed(uint32_t ActorId, float Speed)
Definition: FrameData.cpp:1136
void AddPosition(const CarlaRecorderPosition &Position)
Definition: FrameData.cpp:587
CarlaRecorderEventsDel EventsDel
Definition: FrameData.h:47
CarlaRecorderPlatformTime PlatformTime
Definition: FrameData.h:61
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle)
Definition: FrameData.cpp:674
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
Definition: FrameData.cpp:1150
CarlaRecorderLightScenes LightScenes
Definition: FrameData.h:57
FCarlaActor * FindTrafficLightAt(FVector Location)
Definition: FrameData.cpp:1170
void AddActorBoundingBox(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:535
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
Definition: FrameData.cpp:23
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
Definition: FrameData.cpp:1070
CarlaRecorderEventsAdd EventsAdd
Definition: FrameData.h:46
bool ProcessReplayerEventDel(uint32_t DatabaseId)
Definition: FrameData.cpp:860
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool ReplaySensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
Definition: FrameData.cpp:799
A description of a Carla Actor with all its variation.
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
Definition: FrameData.cpp:989
CarlaRecorderLightVehicles LightVehicles
Definition: FrameData.h:56
uint32_t ActorId
Definition: ActorId.h:14
void AddKinematics(const CarlaRecorderKinematics &ActorKinematics)
Definition: FrameData.cpp:693
void SetEpisode(UCarlaEpisode *ThisEpisode)
Definition: FrameData.h:76
CarlaRecorderPositions Positions
Definition: FrameData.h:50
void AddTrafficLightTime(const ATrafficLightBase &TrafficLight)
Definition: FrameData.cpp:575
void Clear()
Definition: FrameData.cpp:185
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
Definition: FrameData.cpp:910
void AddState(const CarlaRecorderStateTrafficLight &State)
Definition: FrameData.cpp:649
void AddCollision(AActor *Actor1, AActor *Actor2)
Definition: FrameData.cpp:607
CarlaRecorderEventsParent EventsParent
Definition: FrameData.h:48
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
Definition: FrameData.cpp:966
CarlaRecorderAnimWalkers Walkers
Definition: FrameData.h:54
geom::Rotation Rotation
Definition: rpc/Transform.h:14
CarlaRecorderCollisions Collisions
Definition: FrameData.h:49
void AddActorKinematics(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:518
void AddAnimBiker(const CarlaRecorderAnimBiker &Biker)
Definition: FrameData.cpp:664
void AddTrafficLightState(FCarlaActor *CarlaActor)
Definition: FrameData.cpp:484
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
Definition: FrameData.cpp:1084
void AddPhysicsControl(const ACarlaWheeledVehicle &Vehicle)
Definition: FrameData.cpp:567
void Read(std::istream &InStream)
Definition: FrameData.cpp:224
CarlaRecorderStates States
Definition: FrameData.h:51
void PlayFrameData(UCarlaEpisode *ThisEpisode, std::unordered_map< uint32_t, uint32_t > &MappedId)
Definition: FrameData.cpp:78
void AddBikerAnimation(FCarlaActor *CarlaActor)
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
Definition: FrameData.cpp:1126
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
Definition: FrameData.cpp:1042
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
Definition: FrameData.cpp:303
Base class for CARLA wheeled vehicles.
CarlaRecorderAnimVehicles Vehicles
Definition: FrameData.h:52
std::pair< int, FCarlaActor * > CreateOrReuseActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
Definition: FrameData.cpp:709
void GetFrameCounter()
Definition: FrameData.cpp:703
void AddEvent(const CarlaRecorderEventAdd &Event)
Definition: FrameData.cpp:592
geom::Transform Transform
Definition: rpc/Transform.h:16
CarlaRecorderFrameCounter FrameCounter
Definition: FrameData.h:64
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
Definition: FrameData.cpp:940
A view over an actor and its properties.
Definition: CarlaActor.h:23