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;
27class ADepthCamera;
28class ARadar;
30class ASensor;
31class ASensorModel;
32
35DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FThermalCameraSpawned, AThermalCamera*, thermalCamera);
37DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSegmentationCameraSpawned, ASemanticSegmentationCamera*, segmentationCamera);
42
43DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLidarDestroyed, FString, sensorIdentifier);
44DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCameraDestroyed, FString, sensorIdentifier);
45DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FThermalCameraDestroyed, FString, sensorIdentifier);
46DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDVSCameraDestroyed, FString, sensorIdentifier);
47DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSegmentationCameraDestroyed, FString, sensorIdentifier);
48DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInstanceSegmentationCameraDestroyed, FString, sensorIdentifier);
49DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDepthCameraDestroyed, FString, sensorIdentifier);
50DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRadarDestroyed, FString, sensorIdentifier);
51DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSensorDestroyed, ESensorTypes, sensorType, FString, sensorIdentifier);
52
56UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
57class AGRARSENSE_API USensorsManagerComponent : public UActorComponent
58{
59
60 GENERATED_BODY()
61
62public:
63 USensorsManagerComponent();
64
65 ~USensorsManagerComponent();
66
67public:
71 UFUNCTION(BlueprintCallable)
72 TArray<ASensor*> GetSensors() const { return Sensors; }
73
77 UFUNCTION(BlueprintCallable)
78 TArray<ALidar*> GetLidars() const { return Lidars; }
79
83 UFUNCTION(BlueprintCallable)
84 TArray<ACamera*> GetCameras() const { return Cameras; }
85
89 UFUNCTION(BlueprintCallable)
90 TArray<AThermalCamera*> GetThermalCameras() const { return ThermalCameras; }
91
95 UFUNCTION(BlueprintCallable)
96 TArray<ADVSCamera*> GetDVSCameras() const { return DVSCameras; }
97
101 UFUNCTION(BlueprintCallable)
102 TArray<ASemanticSegmentationCamera*> GetSegmentationCameras() const { return SegmentationCameras; }
103
107 UFUNCTION(BlueprintCallable)
108 TArray<ADepthCamera*> GetDepthCameras() const { return DepthCameras; }
109
113 UFUNCTION(BlueprintCallable)
114 TArray<ARadar*> GetRadars() const { return Radars; }
115
119 // UFUNCTION(BlueprintCallable)
120 // ACollisionSensor* GetCollisionSensor() const { return CollisionSensor; }
121
135 UFUNCTION(BlueprintCallable)
136 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);
137
151 UFUNCTION(BlueprintCallable)
152 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);
153
167 UFUNCTION(BlueprintCallable)
168 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);
169
183 UFUNCTION(BlueprintCallable)
184 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);
185
199 UFUNCTION(BlueprintCallable)
200 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);
201
215 UFUNCTION(BlueprintCallable)
216 AInstanceSegmentationCamera* SpawnInstanceSegmentationCamera(const FTransform& transform, bool isTransformRelativeToComponent, const FString sensorIdentifier, const FString sensorName, FCameraBaseParameters CameraParameters, bool simulateSensor, ASensorModel*& createdModel, USceneComponent* attachToComponent = nullptr, FName attachToBone = NAME_None);
217
231 UFUNCTION(BlueprintCallable)
232 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);
233
247 UFUNCTION(BlueprintCallable)
248 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);
249
250 UFUNCTION(BlueprintCallable)
264 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);
265
270 UFUNCTION(BlueprintCallable)
271 void DestroyLidar(ALidar* lidarToDestroy);
272
277 UFUNCTION(BlueprintCallable)
278 void DestroyCamera(ACamera* cameraToDestroy);
279
284 UFUNCTION(BlueprintCallable)
285 void DestroyThermalCamera(AThermalCamera* thermalCameraToDestroy);
286
291 UFUNCTION(BlueprintCallable)
292 void DestroyDVSCamera(ADVSCamera* thermalCameraToDestroy);
293
298 UFUNCTION(BlueprintCallable)
299 void DestroySegmentationCamera(ASemanticSegmentationCamera* cameraToDestroy);
300
305 UFUNCTION(BlueprintCallable)
306 void DestroyDepthCamera(ADepthCamera* depthCameraToDestroy);
307
312 UFUNCTION(BlueprintCallable)
313 void DestroyRadar(ARadar* radarToDestroy);
314
319 UFUNCTION(BlueprintCallable)
320 void DestroySensor(ASensor* sensorToDestroy);
321
325 UFUNCTION(BlueprintCallable)
326 void DestroyAllSensors();
327
333 UFUNCTION(BlueprintCallable)
334 void LoadPreset(FVehicleSensorsPreset preset, bool simulateSensors);
335
336 UFUNCTION(BlueprintCallable)
337 FVehicleSensorsPreset GetSensorsAsPreset();
338
344 UFUNCTION(BlueprintCallable)
345 void AttachSensorToActor(ASensor* sensor, AActor* attachToActor);
346
353 UFUNCTION(BlueprintCallable)
354 void AttachSensorToBone(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
355
362 UFUNCTION(BlueprintCallable)
363 void AttachSensor(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
364
370 USceneComponent* GetComponentByHierarchyName(FString hierarchyName);
371
373
375 UPROPERTY(BlueprintAssignable)
376 FLidarSpawned OnLidarSpawned;
377
379 UPROPERTY(BlueprintAssignable)
380 FCameraSpawned OnCameraSpawned;
381
383 UPROPERTY(BlueprintAssignable)
384 FThermalCameraSpawned OnThermalCameraSpawned;
385
387 UPROPERTY(BlueprintAssignable)
388 FDVSCameraSpawned OnDVSCameraSpawned;
389
391 UPROPERTY(BlueprintAssignable)
392 FSegmentationCameraSpawned OnSegmentationCameraSpawned;
393
395 UPROPERTY(BlueprintAssignable)
396 FInstanceSegmentationCameraSpawned OnInstanceSegmentationCameraSpawned;
397
399 UPROPERTY(BlueprintAssignable)
400 FDepthCameraSpawned OnDepthCameraSpawned;
401
403 UPROPERTY(BlueprintAssignable)
404 FRadarSpawned OnRadarSpawned;
405
407 UPROPERTY(BlueprintAssignable)
408 FSensorSpawned OnSensorSpawned;
409
411 UPROPERTY(BlueprintAssignable)
412 FLidarDestroyed OnLidarDestroyed;
413
415 UPROPERTY(BlueprintAssignable)
416 FCameraDestroyed OnCameraDestroyed;
417
419 UPROPERTY(BlueprintAssignable)
420 FThermalCameraDestroyed OnThermalCameraDestroyed;
421
423 UPROPERTY(BlueprintAssignable)
424 FDVSCameraDestroyed OnDVSCameraDestroyed;
425
427 UPROPERTY(BlueprintAssignable)
428 FSegmentationCameraDestroyed OnSegmentationCameraDestroyed;
429
431 UPROPERTY(BlueprintAssignable)
432 FInstanceSegmentationCameraDestroyed OnInstanceSegmentationCameraDestroyed;
433
435 UPROPERTY(BlueprintAssignable)
436 FDepthCameraDestroyed OnDepthCameraDestroyed;
437
439 UPROPERTY(BlueprintAssignable)
440 FRadarDestroyed OnRadarDestroyed;
441
443 UPROPERTY(BlueprintAssignable)
444 FSensorDestroyed OnSensorDestroyed;
445
447
448 static const FString ComponentHierarchySeparator;
449
450private:
456 FTransform SensorRelativeTransformToWorld(const FTransform& relativeTransform);
457
464 FTransform SensorRelativeTransformToComponentWorld(const FTransform& relativeTransform, const FTransform& componentTransformWorld);
465
466 FTransform GetSensorAttachmentTransform(const FTransform& sensorRelativeTransform, USceneComponent* attachToComponent, const FName& attachToBone, bool revertScaleToVectorOne = true);
467
472 void AttachSensorToOwner(ASensor* sensor);
473
478 void DestroySensorActor(AActor* sensorActor);
479
484 UFUNCTION()
485 void OnCameraWindowClosed(ACamera* camera);
486
491 void AddSensorDestroyListener(ASensor* sensor);
492
497 void RemoveSensorDestroyListener(ASensor* sensor);
498
503 UFUNCTION()
504 void OnSensorDestroy(ASensor* sensor);
505
511 UFUNCTION()
512 FSensorPreset GetSensorPreset(ASensor* sensor);
513
515 UPROPERTY()
516 TArray<ASensor*> Sensors;
517
519 UPROPERTY()
520 TArray<ALidar*> Lidars;
521
523 UPROPERTY()
524 TArray<ACamera*> Cameras;
525
527 UPROPERTY()
528 TArray<AThermalCamera*> ThermalCameras;
529
531 UPROPERTY()
532 TArray<ADVSCamera*> DVSCameras;
533
535 UPROPERTY()
536 TArray<ASemanticSegmentationCamera*> SegmentationCameras;
537
539 UPROPERTY()
540 TArray<AInstanceSegmentationCamera*> InstanceSegmentationCameras;
541
543 UPROPERTY()
544 TArray<ADepthCamera*> DepthCameras;
545
547 UPROPERTY()
548 TArray<ARadar*> Radars;
549
551 // If we want to add reference to collision sensor in this
552 // ACollisionSensor* CollisionSensor;
553};
ESensorTypes
Definition: SensorTypes.h:15
@ InstanceSegmentationCamera
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSensorDestroyed, ESensorTypes, sensorType, FString, sensorIdentifier)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLidarSpawned, ALidar *, lidar)
Definition: Camera.h:53
Definition: Lidar.h:35
Definition: Radar.h:26
Definition: Sensor.h:45