Agrarsense
Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
USensorFactory Class Reference

#include <SensorFactory.h>

Inheritance diagram for USensorFactory:
Inheritance graph
[legend]
Collaboration diagram for USensorFactory:
Collaboration graph
[legend]

Static Public Member Functions

static USensorMapDataAssetGetSensorMapDataAsset ()
 
static ALidarSpawnLidarSensor (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FLidarParameters lidarParameters, bool SimulateSensor=true)
 
static ACameraSpawnCamera (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters cameraParameters, bool SimulateSensor=true)
 
static AThermalCameraSpawnThermalCamera (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FThermalCameraParameters thermalCameraParameters, bool SimulateSensor=true)
 
static ADepthCameraSpawnDepthCamera (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FDepthCameraParameters depthCameraParameters, bool SimulateSensor=true)
 
static ASemanticSegmentationCameraSpawnSegmentationCamera (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters cameraParameters, bool SimulateSensor=true)
 
static ADVSCameraSpawnDVSCamera (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FDVSCameraParameters DVSCameraParameters, bool SimulateSensor)
 
static ARadarSpawnRadar (const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FRadarParameters radarParameters, bool SimulateSensor=true)
 
static ACollisionSensorSpawnCollisionSensor (const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
 
static ATransformSensorSpawnTransformSensor (const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
 
static AOverlapSensorSpawnOverlapSensor (const FTransform &transform, FOverlapSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName)
 

Static Private Member Functions

template<typename T >
static T * SpawnSensor (const FTransform &transform, const FString &sensorIdentifier, const FString &sensorName, bool SpawnSensorModel=true)
 
static void SetSensorIdentifierAndNameWithFallbacks (ASensor *sensor, const FString &sensorIdentifier, const FString &sensorName)
 
static ASensorModelSpawnModelClassForSensor (ASensor *attachTo)
 
static ASensorModelSpawnModelClass (TSubclassOf< ASensorModel > modelClass, ASensor *attachTo)
 
static void Initialize ()
 

Static Private Attributes

static TWeakObjectPtr< USensorMapDataAssetSensorMapDataAsset
 

Detailed Description

SensorFactory is a UBlueprintFunctionLibrary based class in charge of spawning sensors. Sensors should not be spawned in any other way. Note. This Factory only works during runtime, don't call these functions in Editor without play mode on.

Definition at line 42 of file SensorFactory.h.

Member Function Documentation

◆ GetSensorMapDataAsset()

USensorMapDataAsset * USensorFactory::GetSensorMapDataAsset ( )
static

Definition at line 49 of file SensorFactory.cpp.

50{
51 Initialize();
52
53 if (SensorMapDataAsset.IsValid())
54 {
55 return SensorMapDataAsset.Get();
56 }
57 else
58 {
59 return nullptr;
60 }
61}
static void Initialize()
static TWeakObjectPtr< USensorMapDataAsset > SensorMapDataAsset

References Initialize(), and SensorMapDataAsset.

Referenced by SpawnModelClassForSensor().

◆ Initialize()

void USensorFactory::Initialize ( )
staticprivate

Initialize the factory. Should be called before using data or calling functions

Definition at line 26 of file SensorFactory.cpp.

27{
28 if (SensorMapDataAsset.IsValid())
29 {
30 return;
31 }
32
33 SensorMapDataAsset.Reset();
34 FSoftObjectPath SensorMapDataAssetPath(TEXT("/Game/Agrarsense/Data/Sensors/SensorMap"));
35 SensorMapDataAsset = Cast<USensorMapDataAsset>(SensorMapDataAssetPath.TryLoad());
36
37#if WITH_EDITOR
38 if (SensorMapDataAsset.IsValid())
39 {
40 UE_LOG(LogTemp, Warning, TEXT("USensorFactory.cpp: Loaded SensorMapDataAsset successfully."));
41 }
42 else
43 {
44 UE_LOG(LogTemp, Warning, TEXT("USensorFactory.cpp: Loading SensorMapDataAsset failed."));
45 }
46#endif
47}

References SensorMapDataAsset.

Referenced by GetSensorMapDataAsset().

◆ SetSensorIdentifierAndNameWithFallbacks()

void USensorFactory::SetSensorIdentifierAndNameWithFallbacks ( ASensor sensor,
const FString &  sensorIdentifier,
const FString &  sensorName 
)
staticprivate

Set sensor name and identifier but fallback to default values if sensor name and/or sensor identifier are empty.

Parameters
sensorSensor which name and identifier to change
sensorIdentifierSensor new identifier (empty identifier not accepted)
sensorNameSensor new name (empty name not accepted)

Definition at line 63 of file SensorFactory.cpp.

64{
65 bool generateIdentifier = sensorIdentifier.IsEmpty();
66 bool generateName = sensorName.IsEmpty();
67
68 FString generatedSensorIdentifier;
69
70 // If ID not given, use ESensorTypes as the ID
71 // and let the ActorInformation-interface handle the numbering after that
72 if (generateIdentifier)
73 {
74 generatedSensorIdentifier = UEnumUtilities::ConvertSensorTypeToString(sensor->GetSensorType());
75 }
76
77 // If not using generated name -> set the given sensor name
78 if (!generateName)
79 {
80 sensor->SetSensorName(sensorName);
81 }
82
83 sensor->SetSensorIdentifier(generateIdentifier ? generatedSensorIdentifier : sensorIdentifier);
84
85 // If using generated name -> use the identifier as the name too
86 if (generateName)
87 {
88 sensor->SetSensorName(sensor->GetSensorIdentifier());
89 }
90}
void SetSensorName(const FString newName)
Definition: Sensor.h:114
FString GetSensorIdentifier() const
Definition: Sensor.h:74
virtual ESensorTypes GetSensorType() const
Definition: Sensor.h:64
void SetSensorIdentifier(const FString newIdentifier)
Definition: Sensor.h:84
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)

References UEnumUtilities::ConvertSensorTypeToString(), ASensor::GetSensorIdentifier(), ASensor::GetSensorType(), ASensor::SetSensorIdentifier(), and ASensor::SetSensorName().

Referenced by SpawnSensor().

◆ SpawnCamera()

ACamera * USensorFactory::SpawnCamera ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FCameraBaseParameters  cameraParameters,
bool  SimulateSensor = true 
)
static

Spawn new Camera sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FCameraBaseParametersFCameraBaseParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ACamera pointer or nullptr

Definition at line 104 of file SensorFactory.cpp.

105{
106 ACamera* camera = nullptr;
107 camera = SpawnSensor<ACamera>(transform, sensorIdentifier, sensorName, true);
108 if (camera)
109 {
110 camera->Init(cameraParameters, SimulateSensor);
111 }
112
113 return camera;
114}
Definition: Camera.h:52
virtual void Init(FCameraBaseParameters parameters, bool SimulateSensor=true)
Definition: Camera.cpp:80

References ACamera::Init().

◆ SpawnCollisionSensor()

ACollisionSensor * USensorFactory::SpawnCollisionSensor ( const FTransform &  transform,
AActor *  Owner,
const FString  sensorIdentifier,
const FString  sensorName,
bool  SimulateSensor = true 
)
static

Spawn new Collision sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
AActor*Owning actor
boolShould the sensor start simulating after spawn
Returns
ACollisionSensor pointer or nullptr

Definition at line 176 of file SensorFactory.cpp.

177{
178 ACollisionSensor* collisionSensor = nullptr;
179 collisionSensor = SpawnSensor<ACollisionSensor>(transform, sensorIdentifier, sensorName, false);
180 if (collisionSensor)
181 {
182 collisionSensor->Init(Owner, SimulateSensor);
183 }
184
185 return collisionSensor;
186}
void Init(AActor *NewOwner, bool SimulateSensor=true)

References ACollisionSensor::Init().

Referenced by AVehicle::BeginPlay().

◆ SpawnDepthCamera()

ADepthCamera * USensorFactory::SpawnDepthCamera ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FDepthCameraParameters  depthCameraParameters,
bool  SimulateSensor = true 
)
static

Spawn new Camera sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FCameraBaseParametersFCameraBaseParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ADepthCamera pointer or nullptr

Definition at line 128 of file SensorFactory.cpp.

129{
130 ADepthCamera* depthCamera = nullptr;
131 depthCamera = SpawnSensor<ADepthCamera>(transform, sensorIdentifier, sensorName, true);
132 if (depthCamera)
133 {
134 depthCamera->DepthInit(depthCameraParameters, SimulateSensor);
135 }
136
137 return depthCamera;
138}
void DepthInit(FDepthCameraParameters Parameters, bool SimulateSensor=true)
Definition: DepthCamera.cpp:15

References ADepthCamera::DepthInit().

◆ SpawnDVSCamera()

ADVSCamera * USensorFactory::SpawnDVSCamera ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FDVSCameraParameters  DVSCameraParameters,
bool  SimulateSensor 
)
static

Spawn new Camera sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FCameraBaseParametersFCameraBaseParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ADVSCamera pointer or nullptr

Definition at line 152 of file SensorFactory.cpp.

153{
154 ADVSCamera* dvscamera = nullptr;
155 dvscamera = SpawnSensor<ADVSCamera>(transform, sensorIdentifier, sensorName, true);
156 if (dvscamera)
157 {
158 dvscamera->DVSInit(DVSCameraParameters, SimulateSensor);
159 }
160
161 return dvscamera;
162}
void DVSInit(FDVSCameraParameters Parameters, bool SimulateSensor=true)
Definition: DVSCamera.cpp:39

References ADVSCamera::DVSInit().

◆ SpawnLidarSensor()

ALidar * USensorFactory::SpawnLidarSensor ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FLidarParameters  lidarParameters,
bool  SimulateSensor = true 
)
static

Spawn new Lidar sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FLidarParametersFLidarParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ALidar pointer or nullptr

Definition at line 92 of file SensorFactory.cpp.

93{
94 ALidar* lidar = nullptr;
95 lidar = SpawnSensor<ALidar>(transform, sensorIdentifier, sensorName, true);
96 if (lidar)
97 {
98 lidar->Init(lidarParameters, SimulateSensor);
99 }
100
101 return lidar;
102}
Definition: Lidar.h:34
void Init(FLidarParameters parameters, bool SimulateSensor=true)
Definition: Lidar.cpp:37

References ALidar::Init().

◆ SpawnModelClass()

ASensorModel * USensorFactory::SpawnModelClass ( TSubclassOf< ASensorModel modelClass,
ASensor attachTo 
)
staticprivate

Spawn sensor model (3D model) class attaching it to the given actor

Parameters
ModelClassASensorModel class for the sensor's model's class
attachToAttach to this sensor
Returns
Spawned model actor or nullptr

Definition at line 247 of file SensorFactory.cpp.

248{
249 ASensorModel* createdModelActor = nullptr;
250
251 if (!attachTo)
252 {
253 return createdModelActor;
254 }
255
256 UWorld* World = nullptr;
257 if (GEngine && GEngine->GameViewport)
258 {
259 World = GEngine->GameViewport->GetWorld();
260 }
261
262 if (World)
263 {
264 FVector sensorLocation = attachTo->GetActorLocation();
265 createdModelActor = World->SpawnActor<ASensorModel>(modelClass);
266
267 if (createdModelActor)
268 {
269 createdModelActor->AttachToActor(attachTo, FAttachmentTransformRules::SnapToTargetIncludingScale);
270
271 attachTo->SetSensorModel(createdModelActor);
272 createdModelActor->SetAttachedToSensor(attachTo);
273 createdModelActor->InitAfterSpawn();
274 }
275 }
276
277 return createdModelActor;
278}
void InitAfterSpawn()
void SetAttachedToSensor(ASensor *NewAttachedToSensor)
Definition: SensorModel.h:38
void SetSensorModel(ASensorModel *NewSensorModel)
Definition: Sensor.h:182

References ASensorModel::InitAfterSpawn(), ASensorModel::SetAttachedToSensor(), and ASensor::SetSensorModel().

Referenced by SpawnModelClassForSensor().

◆ SpawnModelClassForSensor()

ASensorModel * USensorFactory::SpawnModelClassForSensor ( ASensor attachTo)
staticprivate

Spawn sensor model (3D model) class attaching it to the given actor

Parameters
attachToSensor to attach to
Returns
Spawned model actor or nullptr

Definition at line 212 of file SensorFactory.cpp.

213{
214 ASensorModel* spawnedModel = nullptr;
215
216 if (!attachTo)
217 {
218 return spawnedModel;
219 }
220
222
223 if (SensorMap)
224 {
225 ESensorTypes sensorType = attachTo->GetSensorType();
226
227 TSubclassOf<ASensorModel> modelClass = nullptr;
228
229 bool matchFound;
230
231 USensorDataAsset* sensorData = SensorMap->GetAssetDataBySensorType(sensorType, matchFound);
232
233 if (matchFound && sensorData)
234 {
235 modelClass = sensorData->ModelClass;
236 }
237
238 if (modelClass)
239 {
240 spawnedModel = SpawnModelClass(modelClass, attachTo);
241 }
242 }
243
244 return spawnedModel;
245}
ESensorTypes
Definition: SensorTypes.h:15
TSubclassOf< ASensorModel > ModelClass
static USensorMapDataAsset * GetSensorMapDataAsset()
static ASensorModel * SpawnModelClass(TSubclassOf< ASensorModel > modelClass, ASensor *attachTo)
USensorDataAsset * GetAssetDataBySensorType(ESensorTypes SensorType, bool &MatchFound)

References USensorMapDataAsset::GetAssetDataBySensorType(), GetSensorMapDataAsset(), ASensor::GetSensorType(), USensorDataAsset::ModelClass, and SpawnModelClass().

Referenced by SpawnSensor().

◆ SpawnOverlapSensor()

AOverlapSensor * USensorFactory::SpawnOverlapSensor ( const FTransform &  transform,
FOverlapSensorParameters  Parameters,
const FString  sensorIdentifier,
const FString  sensorName 
)
static

Spawn new Overlap sensor. BlueprintCallable. This is spawned by default on every vehicle

Parameters
FTransformlocation to spawn sensor
FOverlapSensorParameters*Overlap sensor parameters
Returns
AOverlapSensor pointer or nullptr

Definition at line 200 of file SensorFactory.cpp.

201{
202 AOverlapSensor* OverlapSensor = nullptr;
203 OverlapSensor = SpawnSensor<AOverlapSensor>(transform, sensorIdentifier, sensorName, false);
204 if (OverlapSensor)
205 {
206 OverlapSensor->Init(Parameters);
207 }
208
209 return OverlapSensor;
210}
void Init(FOverlapSensorParameters InParameters)

References AOverlapSensor::Init().

Referenced by AVehicle::BeginPlay().

◆ SpawnRadar()

ARadar * USensorFactory::SpawnRadar ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FRadarParameters  radarParameters,
bool  SimulateSensor = true 
)
static

Spawn new Radar sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FRadarParametersFRadarParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ARadar pointer or nullptr

Definition at line 164 of file SensorFactory.cpp.

165{
166 ARadar* radar = nullptr;
167 radar = SpawnSensor<ARadar>(transform, sensorIdentifier, sensorName, true);
168 if (radar)
169 {
170 radar->Init(radarParameters, SimulateSensor);
171 }
172
173 return radar;
174}
Definition: Radar.h:26
void Init(FRadarParameters parameters, bool SimulateSensor=true)
Definition: Radar.cpp:22

References ARadar::Init().

◆ SpawnSegmentationCamera()

ASemanticSegmentationCamera * USensorFactory::SpawnSegmentationCamera ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FCameraBaseParameters  cameraParameters,
bool  SimulateSensor = true 
)
static

Spawn new Camera sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FCameraBaseParametersFCameraBaseParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
ASemanticSegmentationCamera pointer

Definition at line 140 of file SensorFactory.cpp.

141{
142 ASemanticSegmentationCamera* segmentationCamera = nullptr;
143 segmentationCamera = SpawnSensor<ASemanticSegmentationCamera>(transform, sensorIdentifier, sensorName, true);
144 if (segmentationCamera)
145 {
146 segmentationCamera->Init(cameraParameters, SimulateSensor);
147 }
148
149 return segmentationCamera;
150}
void Init(FCameraBaseParameters parameters, bool SimulateSensor=true) override

References ASemanticSegmentationCamera::Init().

◆ SpawnSensor()

template<typename T >
T * USensorFactory::SpawnSensor ( const FTransform &  transform,
const FString &  sensorIdentifier,
const FString &  sensorName,
bool  SpawnSensorModel = true 
)
staticprivate

Definition at line 281 of file SensorFactory.cpp.

282{
283 UWorld* World = nullptr;
284
285 if (GEngine && GEngine->GameViewport)
286 {
287 // This might only fail if called in Editor without play mode.
288 World = GEngine->GameViewport->GetWorld();
289 }
290
291 T* Sensor = nullptr;
292
293 if (World)
294 {
295 Sensor = World->SpawnActorDeferred<T>(T::StaticClass(), transform);
296 if (Sensor)
297 {
298 SetSensorIdentifierAndNameWithFallbacks(Sensor, sensorIdentifier, sensorName);
299 Sensor->FinishSpawning(transform);
300
301 if (SpawnSensorModel)
302 {
303 SpawnModelClassForSensor(Cast<ASensor>(Sensor));
304 }
305 }
306 }
307
308 return Sensor;
309}
static void SetSensorIdentifierAndNameWithFallbacks(ASensor *sensor, const FString &sensorIdentifier, const FString &sensorName)
static ASensorModel * SpawnModelClassForSensor(ASensor *attachTo)

References SetSensorIdentifierAndNameWithFallbacks(), and SpawnModelClassForSensor().

◆ SpawnThermalCamera()

AThermalCamera * USensorFactory::SpawnThermalCamera ( const FTransform &  transform,
const FString  sensorIdentifier,
const FString  sensorName,
FThermalCameraParameters  thermalCameraParameters,
bool  SimulateSensor = true 
)
static

Spawn new Camera sensor. BlueprintCallable.

Parameters
FTransformlocation to spawn sensor
FStringSensor's unique identifier
FStringSensor's name
FCameraBaseParametersFCameraBaseParameters parameters struct
boolShould the sensor start simulating after spawn
Returns
AThermalCamera pointer or nullptr

Definition at line 116 of file SensorFactory.cpp.

117{
118 AThermalCamera* thermalCamera = nullptr;
119 thermalCamera = SpawnSensor<AThermalCamera>(transform, sensorIdentifier, sensorName, true);
120 if (thermalCamera)
121 {
122 thermalCamera->ThermalInit(thermalCameraParameters, SimulateSensor);
123 }
124
125 return thermalCamera;
126}
void ThermalInit(FThermalCameraParameters Parameters, bool SimulateSensor=true)

References AThermalCamera::ThermalInit().

◆ SpawnTransformSensor()

ATransformSensor * USensorFactory::SpawnTransformSensor ( const FTransform &  transform,
AActor *  Owner,
const FString  sensorIdentifier,
const FString  sensorName,
bool  SimulateSensor = true 
)
static

Spawn new Tranform sensor. BlueprintCallable. This is spawned by default on every vehicle

Parameters
FTransformlocation to spawn sensor
AActor*Owning actor
boolShould the sensor start simulating after spawn
Returns
ATransformSensor pointer or nullptr

Definition at line 188 of file SensorFactory.cpp.

189{
190 ATransformSensor* transformSensor = nullptr;
191 transformSensor = SpawnSensor<ATransformSensor>(transform, sensorIdentifier, sensorName, false);
192 if (transformSensor)
193 {
194 transformSensor->Init(Owner, SimulateSensor);
195 }
196
197 return transformSensor;
198}
void Init(AActor *TransformActor, bool SimulateSensor=true)

References ATransformSensor::Init().

Referenced by AVehicle::BeginPlay().

Member Data Documentation

◆ SensorMapDataAsset

TWeakObjectPtr< USensorMapDataAsset > USensorFactory::SensorMapDataAsset
staticprivate

Sensor map data asset to hold sensor specific base data

Definition at line 213 of file SensorFactory.h.

Referenced by GetSensorMapDataAsset(), and Initialize().


The documentation for this class was generated from the following files: