Agrarsense
SensorsManagerComponent.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "Components/ActorComponent.h"
9#include "CoreMinimal.h"
10#include "GameFramework/Actor.h"
11
18
19#include "SensorsManagerComponent.generated.h"
20
21class ALidar;
22class ACamera;
23class AThermalCamera;
24class ADVSCamera;
26class ADepthCamera;
27class ARadar;
29class ASensor;
30class ASensorModel;
31
34DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FThermalCameraSpawned, AThermalCamera*, thermalCamera);
36DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSegmentationCameraSpawned, ASemanticSegmentationCamera*, segmentationCamera);
40
41DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLidarDestroyed, FString, sensorIdentifier);
42DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCameraDestroyed, FString, sensorIdentifier);
43DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FThermalCameraDestroyed, FString, sensorIdentifier);
44DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDVSCameraDestroyed, FString, sensorIdentifier);
45DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSegmentationCameraDestroyed, FString, sensorIdentifier);
46DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDepthCameraDestroyed, FString, sensorIdentifier);
47DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRadarDestroyed, FString, sensorIdentifier);
48DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSensorDestroyed, ESensorTypes, sensorType, FString, sensorIdentifier);
49
53UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
54class AGRARSENSE_API USensorsManagerComponent : public UActorComponent
55{
56
57 GENERATED_BODY()
58
59public:
60 USensorsManagerComponent();
61
62 ~USensorsManagerComponent();
63
64public:
68 UFUNCTION(BlueprintCallable)
69 TArray<ASensor*> GetSensors() const { return Sensors; }
70
74 UFUNCTION(BlueprintCallable)
75 TArray<ALidar*> GetLidars() const { return Lidars; }
76
80 UFUNCTION(BlueprintCallable)
81 TArray<ACamera*> GetCameras() const { return Cameras; }
82
86 UFUNCTION(BlueprintCallable)
87 TArray<AThermalCamera*> GetThermalCameras() const { return ThermalCameras; }
88
92 UFUNCTION(BlueprintCallable)
93 TArray<ADVSCamera*> GetDVSCameras() const { return DVSCameras; }
94
98 UFUNCTION(BlueprintCallable)
99 TArray<ASemanticSegmentationCamera*> GetSegmentationCameras() const { return SegmentationCameras; }
100
104 UFUNCTION(BlueprintCallable)
105 TArray<ADepthCamera*> GetDepthCameras() const { return DepthCameras; }
106
110 UFUNCTION(BlueprintCallable)
111 TArray<ARadar*> GetRadars() const { return Radars; }
112
116 // UFUNCTION(BlueprintCallable)
117 // ACollisionSensor* GetCollisionSensor() const { return CollisionSensor; }
118
132 UFUNCTION(BlueprintCallable)
133 ALidar* SpawnLidar(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FLidarParameters lidarParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
134
148 UFUNCTION(BlueprintCallable)
149 ACamera* SpawnCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters cameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
150
164 UFUNCTION(BlueprintCallable)
165 AThermalCamera* SpawnThermalCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FThermalCameraParameters thermalCameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
166
180 UFUNCTION(BlueprintCallable)
181 ADVSCamera* SpawnDVSCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FDVSCameraParameters DVSCameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
182
196 UFUNCTION(BlueprintCallable)
197 ASemanticSegmentationCamera* SpawnSegmentationCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters CameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
198
212 UFUNCTION(BlueprintCallable)
213 ADepthCamera* SpawnDepthCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FDepthCameraParameters DepthCameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
214
228 UFUNCTION(BlueprintCallable)
229 ARadar* SpawnRadar(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FRadarParameters radarParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
230
231 UFUNCTION(BlueprintCallable)
245 ASensor* SpawnSensor(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, ESensorTypes sensorType, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
246
251 UFUNCTION(BlueprintCallable)
252 void DestroyLidar(ALidar* lidarToDestroy);
253
258 UFUNCTION(BlueprintCallable)
259 void DestroyCamera(ACamera* cameraToDestroy);
260
265 UFUNCTION(BlueprintCallable)
266 void DestroyThermalCamera(AThermalCamera* thermalCameraToDestroy);
267
272 UFUNCTION(BlueprintCallable)
273 void DestroyDVSCamera(ADVSCamera* thermalCameraToDestroy);
274
279 UFUNCTION(BlueprintCallable)
280 void DestroySegmentationCamera(ASemanticSegmentationCamera* cameraToDestroy);
281
286 UFUNCTION(BlueprintCallable)
287 void DestroyDepthCamera(ADepthCamera* depthCameraToDestroy);
288
293 UFUNCTION(BlueprintCallable)
294 void DestroyRadar(ARadar* radarToDestroy);
295
300 UFUNCTION(BlueprintCallable)
301 void DestroySensor(ASensor* sensorToDestroy);
302
306 UFUNCTION(BlueprintCallable)
307 void DestroyAllSensors();
308
314 UFUNCTION(BlueprintCallable)
315 void LoadPreset(FVehicleSensorsPreset preset, bool simulateSensors);
316
317 UFUNCTION(BlueprintCallable)
318 FVehicleSensorsPreset GetSensorsAsPreset();
319
325 UFUNCTION(BlueprintCallable)
326 void AttachSensorToActor(ASensor* sensor, AActor* attachToActor);
327
334 UFUNCTION(BlueprintCallable)
335 void AttachSensorToBone(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
336
343 UFUNCTION(BlueprintCallable)
344 void AttachSensor(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
345
351 USceneComponent* GetComponentByHierarchyName(FString hierarchyName);
352
354
356 UPROPERTY(BlueprintAssignable)
357 FLidarSpawned OnLidarSpawned;
358
360 UPROPERTY(BlueprintAssignable)
361 FCameraSpawned OnCameraSpawned;
362
364 UPROPERTY(BlueprintAssignable)
365 FThermalCameraSpawned OnThermalCameraSpawned;
366
368 UPROPERTY(BlueprintAssignable)
369 FDVSCameraSpawned OnDVSCameraSpawned;
370
372 UPROPERTY(BlueprintAssignable)
373 FSegmentationCameraSpawned OnSegmentationCameraSpawned;
374
376 UPROPERTY(BlueprintAssignable)
377 FDepthCameraSpawned OnDepthCameraSpawned;
378
380 UPROPERTY(BlueprintAssignable)
381 FRadarSpawned OnRadarSpawned;
382
384 UPROPERTY(BlueprintAssignable)
385 FSensorSpawned OnSensorSpawned;
386
388 UPROPERTY(BlueprintAssignable)
389 FLidarDestroyed OnLidarDestroyed;
390
392 UPROPERTY(BlueprintAssignable)
393 FCameraDestroyed OnCameraDestroyed;
394
396 UPROPERTY(BlueprintAssignable)
397 FThermalCameraDestroyed OnThermalCameraDestroyed;
398
400 UPROPERTY(BlueprintAssignable)
401 FDVSCameraDestroyed OnDVSCameraDestroyed;
402
404 UPROPERTY(BlueprintAssignable)
405 FSegmentationCameraDestroyed OnSegmentationCameraDestroyed;
406
408 UPROPERTY(BlueprintAssignable)
409 FDepthCameraDestroyed OnDepthCameraDestroyed;
410
412 UPROPERTY(BlueprintAssignable)
413 FRadarDestroyed OnRadarDestroyed;
414
416 UPROPERTY(BlueprintAssignable)
417 FSensorDestroyed OnSensorDestroyed;
418
420
421 static const FString ComponentHierarchySeparator;
422
423private:
429 FTransform SensorRelativeTransformToWorld(const FTransform& relativeTransform);
430
437 FTransform SensorRelativeTransformToComponentWorld(const FTransform& relativeTransform, const FTransform& componentTransformWorld);
438
439 FTransform GetSensorAttachmentTransform(const FTransform& sensorRelativeTransform, USceneComponent* attachToComponent, const FName& attachToBone, bool revertScaleToVectorOne = true);
440
445 void AttachSensorToOwner(ASensor* sensor);
446
451 void DestroySensorActor(AActor* sensorActor);
452
457 UFUNCTION()
458 void OnCameraWindowClosed(ACamera* camera);
459
464 void AddSensorDestroyListener(ASensor* sensor);
465
470 void RemoveSensorDestroyListener(ASensor* sensor);
471
476 UFUNCTION()
477 void OnSensorDestroy(ASensor* sensor);
478
484 UFUNCTION()
485 FSensorPreset GetSensorPreset(ASensor* sensor);
486
488 UPROPERTY()
489 TArray<ASensor*> Sensors;
490
492 UPROPERTY()
493 TArray<ALidar*> Lidars;
494
496 UPROPERTY()
497 TArray<ACamera*> Cameras;
498
500 UPROPERTY()
501 TArray<AThermalCamera*> ThermalCameras;
502
504 UPROPERTY()
505 TArray<ADVSCamera*> DVSCameras;
506
508 UPROPERTY()
509 TArray<ASemanticSegmentationCamera*> SegmentationCameras;
510
512 UPROPERTY()
513 TArray<ADepthCamera*> DepthCameras;
514
516 UPROPERTY()
517 TArray<ARadar*> Radars;
518
520 // If we want to add reference to collision sensor in this
521 // ACollisionSensor* CollisionSensor;
522};
ESensorTypes
Definition: SensorTypes.h:15
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSensorDestroyed, ESensorTypes, sensorType, FString, sensorIdentifier)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLidarSpawned, ALidar *, lidar)
Definition: Camera.h:52
Definition: Lidar.h:34
Definition: Radar.h:26
Definition: Sensor.h:44