21#include "Engine/GameViewportClient.h"
34 FSoftObjectPath SensorMapDataAssetPath(TEXT(
"/Game/Agrarsense/Data/Sensors/SensorMap"));
40 UE_LOG(LogTemp, Warning, TEXT(
"USensorFactory.cpp: Loaded SensorMapDataAsset successfully."));
44 UE_LOG(LogTemp, Warning, TEXT(
"USensorFactory.cpp: Loading SensorMapDataAsset failed."));
65 bool generateIdentifier = sensorIdentifier.IsEmpty();
66 bool generateName = sensorName.IsEmpty();
68 FString generatedSensorIdentifier;
72 if (generateIdentifier)
83 sensor->
SetSensorIdentifier(generateIdentifier ? generatedSensorIdentifier : sensorIdentifier);
95 lidar = SpawnSensor<ALidar>(transform, sensorIdentifier, sensorName,
true);
98 lidar->
Init(lidarParameters, SimulateSensor);
107 camera = SpawnSensor<ACamera>(transform, sensorIdentifier, sensorName,
true);
110 camera->
Init(cameraParameters, SimulateSensor);
119 thermalCamera = SpawnSensor<AThermalCamera>(transform, sensorIdentifier, sensorName,
true);
122 thermalCamera->
ThermalInit(thermalCameraParameters, SimulateSensor);
125 return thermalCamera;
131 depthCamera = SpawnSensor<ADepthCamera>(transform, sensorIdentifier, sensorName,
true);
134 depthCamera->
DepthInit(depthCameraParameters, SimulateSensor);
143 segmentationCamera = SpawnSensor<ASemanticSegmentationCamera>(transform, sensorIdentifier, sensorName,
true);
144 if (segmentationCamera)
146 segmentationCamera->
Init(cameraParameters, SimulateSensor);
149 return segmentationCamera;
155 dvscamera = SpawnSensor<ADVSCamera>(transform, sensorIdentifier, sensorName,
true);
158 dvscamera->
DVSInit(DVSCameraParameters, SimulateSensor);
167 radar = SpawnSensor<ARadar>(transform, sensorIdentifier, sensorName,
true);
170 radar->
Init(radarParameters, SimulateSensor);
179 collisionSensor = SpawnSensor<ACollisionSensor>(transform, sensorIdentifier, sensorName,
false);
182 collisionSensor->
Init(Owner, SimulateSensor);
185 return collisionSensor;
191 transformSensor = SpawnSensor<ATransformSensor>(transform, sensorIdentifier, sensorName,
false);
194 transformSensor->
Init(Owner, SimulateSensor);
197 return transformSensor;
203 OverlapSensor = SpawnSensor<AOverlapSensor>(transform, sensorIdentifier, sensorName,
false);
206 OverlapSensor->
Init(Parameters);
209 return OverlapSensor;
227 TSubclassOf<ASensorModel> modelClass =
nullptr;
233 if (matchFound && sensorData)
253 return createdModelActor;
256 UWorld* World =
nullptr;
257 if (GEngine && GEngine->GameViewport)
259 World = GEngine->GameViewport->GetWorld();
264 FVector sensorLocation = attachTo->GetActorLocation();
265 createdModelActor = World->SpawnActor<
ASensorModel>(modelClass);
267 if (createdModelActor)
269 createdModelActor->AttachToActor(attachTo, FAttachmentTransformRules::SnapToTargetIncludingScale);
277 return createdModelActor;
283 UWorld* World =
nullptr;
285 if (GEngine && GEngine->GameViewport)
288 World = GEngine->GameViewport->GetWorld();
295 Sensor = World->SpawnActorDeferred<T>(T::StaticClass(), transform);
299 Sensor->FinishSpawning(transform);
301 if (SpawnSensorModel)
virtual void Init(FCameraBaseParameters parameters, bool SimulateSensor=true)
void Init(AActor *NewOwner, bool SimulateSensor=true)
void DVSInit(FDVSCameraParameters Parameters, bool SimulateSensor=true)
void DepthInit(FDepthCameraParameters Parameters, bool SimulateSensor=true)
void Init(FLidarParameters parameters, bool SimulateSensor=true)
void Init(FOverlapSensorParameters InParameters)
void Init(FRadarParameters parameters, bool SimulateSensor=true)
void Init(FCameraBaseParameters parameters, bool SimulateSensor=true) override
void SetAttachedToSensor(ASensor *NewAttachedToSensor)
void SetSensorModel(ASensorModel *NewSensorModel)
void SetSensorName(const FString newName)
FString GetSensorIdentifier() const
virtual ESensorTypes GetSensorType() const
void SetSensorIdentifier(const FString newIdentifier)
void ThermalInit(FThermalCameraParameters Parameters, bool SimulateSensor=true)
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)
TSubclassOf< ASensorModel > ModelClass
static T * SpawnSensor(const FTransform &transform, const FString &sensorIdentifier, const FString &sensorName, bool SpawnSensorModel=true)
static ATransformSensor * SpawnTransformSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static void SetSensorIdentifierAndNameWithFallbacks(ASensor *sensor, const FString &sensorIdentifier, const FString &sensorName)
static ASensorModel * SpawnModelClassForSensor(ASensor *attachTo)
static ARadar * SpawnRadar(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FRadarParameters radarParameters, bool SimulateSensor=true)
static TWeakObjectPtr< USensorMapDataAsset > SensorMapDataAsset
static ACollisionSensor * SpawnCollisionSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static AThermalCamera * SpawnThermalCamera(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FThermalCameraParameters thermalCameraParameters, bool SimulateSensor=true)
static ACamera * SpawnCamera(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters cameraParameters, bool SimulateSensor=true)
static ADVSCamera * SpawnDVSCamera(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FDVSCameraParameters DVSCameraParameters, bool SimulateSensor)
static USensorMapDataAsset * GetSensorMapDataAsset()
static ASensorModel * SpawnModelClass(TSubclassOf< ASensorModel > modelClass, ASensor *attachTo)
static ADepthCamera * SpawnDepthCamera(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FDepthCameraParameters depthCameraParameters, bool SimulateSensor=true)
static ALidar * SpawnLidarSensor(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FLidarParameters lidarParameters, bool SimulateSensor=true)
static AOverlapSensor * SpawnOverlapSensor(const FTransform &transform, FOverlapSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName)
static ASemanticSegmentationCamera * SpawnSegmentationCamera(const FTransform &transform, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters cameraParameters, bool SimulateSensor=true)
USensorDataAsset * GetAssetDataBySensorType(ESensorTypes SensorType, bool &MatchFound)