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* RGBCamera = nullptr;
107 RGBCamera = SpawnSensor<ACamera>(transform, sensorIdentifier, sensorName, true);
108 if (RGBCamera)
109 {
110 RGBCamera->Init(cameraParameters, SimulateSensor);
111 }
112
113 return RGBCamera;
114}
Definition: Camera.h:52

References RGBCamera.

◆ 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 if (Owner)
180 {
181 CollisionSensor = SpawnSensor<ACollisionSensor>(transform, sensorIdentifier, sensorName, false);
182 if (CollisionSensor)
183 {
184 CollisionSensor->Init(Owner, SimulateSensor);
185 CollisionSensor->AttachToActor(Owner, FAttachmentTransformRules::KeepWorldTransform);
186 }
187 }
188
189 return CollisionSensor;
190}
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}

References DepthCamera.

◆ 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}

References DVSCamera.

◆ 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* LidarSensor = nullptr;
95 LidarSensor = SpawnSensor<ALidar>(transform, sensorIdentifier, sensorName, true);
96 if (LidarSensor)
97 {
98 LidarSensor->Init(lidarParameters, SimulateSensor);
99 }
100
101 return LidarSensor;
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 255 of file SensorFactory.cpp.

256{
257 ASensorModel* createdModelActor = nullptr;
258
259 if (!attachTo)
260 {
261 return createdModelActor;
262 }
263
264 UWorld* World = nullptr;
265 if (GEngine && GEngine->GameViewport)
266 {
267 World = GEngine->GameViewport->GetWorld();
268 }
269
270 if (World)
271 {
272 FVector sensorLocation = attachTo->GetActorLocation();
273 createdModelActor = World->SpawnActor<ASensorModel>(modelClass);
274
275 if (createdModelActor)
276 {
277 createdModelActor->AttachToActor(attachTo, FAttachmentTransformRules::SnapToTargetIncludingScale);
278
279 attachTo->SetSensorModel(createdModelActor);
280 createdModelActor->SetAttachedToSensor(attachTo);
281 createdModelActor->InitAfterSpawn();
282 }
283 }
284
285 return createdModelActor;
286}
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 220 of file SensorFactory.cpp.

221{
222 ASensorModel* spawnedModel = nullptr;
223
224 if (!attachTo)
225 {
226 return spawnedModel;
227 }
228
230
231 if (SensorMap)
232 {
233 ESensorTypes sensorType = attachTo->GetSensorType();
234
235 TSubclassOf<ASensorModel> modelClass = nullptr;
236
237 bool matchFound;
238
239 USensorDataAsset* sensorData = SensorMap->GetAssetDataBySensorType(sensorType, matchFound);
240
241 if (matchFound && sensorData)
242 {
243 modelClass = sensorData->ModelClass;
244 }
245
246 if (modelClass)
247 {
248 spawnedModel = SpawnModelClass(modelClass, attachTo);
249 }
250 }
251
252 return spawnedModel;
253}
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 208 of file SensorFactory.cpp.

209{
210 AOverlapSensor* OverlapSensor = nullptr;
211 OverlapSensor = SpawnSensor<AOverlapSensor>(transform, sensorIdentifier, sensorName, false);
212 if (OverlapSensor)
213 {
214 OverlapSensor->Init(Parameters);
215 }
216
217 return OverlapSensor;
218}
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* RadarSensor = nullptr;
167 RadarSensor = SpawnSensor<ARadar>(transform, sensorIdentifier, sensorName, true);
168 if (RadarSensor)
169 {
170 RadarSensor->Init(radarParameters, SimulateSensor);
171 }
172
173 return RadarSensor;
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{
143 SemanticSegmentationCamera = SpawnSensor<ASemanticSegmentationCamera>(transform, sensorIdentifier, sensorName, true);
145 {
146 SemanticSegmentationCamera->Init(cameraParameters, SimulateSensor);
147 }
148
150}
@ SemanticSegmentationCamera

References SemanticSegmentationCamera.

◆ SpawnSensor()

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

Definition at line 289 of file SensorFactory.cpp.

290{
291 UWorld* World = nullptr;
292
293 if (GEngine && GEngine->GameViewport)
294 {
295 // This might only fail if called in Editor without play mode.
296 World = GEngine->GameViewport->GetWorld();
297 }
298
299 T* Sensor = nullptr;
300
301 if (World)
302 {
303 Sensor = World->SpawnActorDeferred<T>(T::StaticClass(), transform);
304 if (Sensor)
305 {
306 SetSensorIdentifierAndNameWithFallbacks(Sensor, sensorIdentifier, sensorName);
307 Sensor->FinishSpawning(transform);
308
309 if (SpawnSensorModel)
310 {
311 SpawnModelClassForSensor(Cast<ASensor>(Sensor));
312 }
313 }
314 }
315
316 return Sensor;
317}
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}

References ThermalCamera.

◆ 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 192 of file SensorFactory.cpp.

193{
194 ATransformSensor* TransformSensor = nullptr;
195 if (Owner)
196 {
197 TransformSensor = SpawnSensor<ATransformSensor>(transform, sensorIdentifier, sensorName, false);
198 if (TransformSensor)
199 {
200 TransformSensor->Init(Owner, SimulateSensor);
201 TransformSensor->AttachToActor(Owner, FAttachmentTransformRules::KeepWorldTransform);
202 }
203 }
204
205 return TransformSensor;
206}
void Init(AActor *TransformActor, bool SimulateSensor=true)

References ATransformSensor::Init().

Referenced by ASensor::BeginPlay(), and 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: