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
57UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
58class AGRARSENSE_API USensorsManagerComponent : public UActorComponent
59{
60
61 GENERATED_BODY()
62
63public:
64 USensorsManagerComponent();
65
66 ~USensorsManagerComponent();
67
68public:
72 UFUNCTION(BlueprintCallable)
73 TArray<ASensor*> GetSensors() const { return Sensors; }
74
78 UFUNCTION(BlueprintCallable)
79 TArray<ALidar*> GetLidars() const { return Lidars; }
80
84 UFUNCTION(BlueprintCallable)
85 TArray<ACamera*> GetCameras() const { return Cameras; }
86
90 UFUNCTION(BlueprintCallable)
91 TArray<AThermalCamera*> GetThermalCameras() const { return ThermalCameras; }
92
96 UFUNCTION(BlueprintCallable)
97 TArray<ADVSCamera*> GetDVSCameras() const { return DVSCameras; }
98
102 UFUNCTION(BlueprintCallable)
103 TArray<ASemanticSegmentationCamera*> GetSegmentationCameras() const { return SegmentationCameras; }
104
108 UFUNCTION(BlueprintCallable)
109 TArray<ADepthCamera*> GetDepthCameras() const { return DepthCameras; }
110
114 UFUNCTION(BlueprintCallable)
115 TArray<ARadar*> GetRadars() const { return Radars; }
116
130 UFUNCTION(BlueprintCallable)
131 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);
132
146 UFUNCTION(BlueprintCallable)
147 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);
148
162 UFUNCTION(BlueprintCallable)
163 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);
164
178 UFUNCTION(BlueprintCallable)
179 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);
180
194 UFUNCTION(BlueprintCallable)
195 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);
196
210 UFUNCTION(BlueprintCallable)
211 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);
212
226 UFUNCTION(BlueprintCallable)
227 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);
228
242 UFUNCTION(BlueprintCallable)
243 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);
244
245 UFUNCTION(BlueprintCallable)
259 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);
260
265 UFUNCTION(BlueprintCallable)
266 void DestroyLidar(ALidar* lidarToDestroy);
267
272 UFUNCTION(BlueprintCallable)
273 void DestroyCamera(ACamera* cameraToDestroy);
274
279 UFUNCTION(BlueprintCallable)
280 void DestroyThermalCamera(AThermalCamera* thermalCameraToDestroy);
281
286 UFUNCTION(BlueprintCallable)
287 void DestroyDVSCamera(ADVSCamera* thermalCameraToDestroy);
288
293 UFUNCTION(BlueprintCallable)
294 void DestroySegmentationCamera(ASemanticSegmentationCamera* cameraToDestroy);
295
300 UFUNCTION(BlueprintCallable)
301 void DestroyDepthCamera(ADepthCamera* depthCameraToDestroy);
302
307 UFUNCTION(BlueprintCallable)
308 void DestroyRadar(ARadar* radarToDestroy);
309
314 UFUNCTION(BlueprintCallable)
315 void DestroySensor(ASensor* sensorToDestroy);
316
320 UFUNCTION(BlueprintCallable)
321 void DestroyAllSensors();
322
328 UFUNCTION(BlueprintCallable)
329 void LoadPreset(FVehicleSensorsPreset preset, bool simulateSensors);
330
331 UFUNCTION(BlueprintCallable)
332 FVehicleSensorsPreset GetSensorsAsPreset();
333
339 UFUNCTION(BlueprintCallable)
340 void AttachSensorToActor(ASensor* sensor, AActor* attachToActor);
341
348 UFUNCTION(BlueprintCallable)
349 void AttachSensorToBone(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
350
357 UFUNCTION(BlueprintCallable)
358 void AttachSensor(ASensor* sensor, USceneComponent* attachToComponent, const FName& boneName);
359
365 USceneComponent* GetComponentByHierarchyName(FString hierarchyName);
366
368
370 UPROPERTY(BlueprintAssignable)
371 FLidarSpawned OnLidarSpawned;
372
374 UPROPERTY(BlueprintAssignable)
375 FCameraSpawned OnCameraSpawned;
376
378 UPROPERTY(BlueprintAssignable)
379 FThermalCameraSpawned OnThermalCameraSpawned;
380
382 UPROPERTY(BlueprintAssignable)
383 FDVSCameraSpawned OnDVSCameraSpawned;
384
386 UPROPERTY(BlueprintAssignable)
387 FSegmentationCameraSpawned OnSegmentationCameraSpawned;
388
390 UPROPERTY(BlueprintAssignable)
391 FInstanceSegmentationCameraSpawned OnInstanceSegmentationCameraSpawned;
392
394 UPROPERTY(BlueprintAssignable)
395 FDepthCameraSpawned OnDepthCameraSpawned;
396
398 UPROPERTY(BlueprintAssignable)
399 FRadarSpawned OnRadarSpawned;
400
402 UPROPERTY(BlueprintAssignable)
403 FSensorSpawned OnSensorSpawned;
404
406 UPROPERTY(BlueprintAssignable)
407 FLidarDestroyed OnLidarDestroyed;
408
410 UPROPERTY(BlueprintAssignable)
411 FCameraDestroyed OnCameraDestroyed;
412
414 UPROPERTY(BlueprintAssignable)
415 FThermalCameraDestroyed OnThermalCameraDestroyed;
416
418 UPROPERTY(BlueprintAssignable)
419 FDVSCameraDestroyed OnDVSCameraDestroyed;
420
422 UPROPERTY(BlueprintAssignable)
423 FSegmentationCameraDestroyed OnSegmentationCameraDestroyed;
424
426 UPROPERTY(BlueprintAssignable)
427 FInstanceSegmentationCameraDestroyed OnInstanceSegmentationCameraDestroyed;
428
430 UPROPERTY(BlueprintAssignable)
431 FDepthCameraDestroyed OnDepthCameraDestroyed;
432
434 UPROPERTY(BlueprintAssignable)
435 FRadarDestroyed OnRadarDestroyed;
436
438 UPROPERTY(BlueprintAssignable)
439 FSensorDestroyed OnSensorDestroyed;
440
442
443 static const FString ComponentHierarchySeparator;
444
445private:
451 FTransform SensorRelativeTransformToWorld(const FTransform& relativeTransform);
452
459 FTransform SensorRelativeTransformToComponentWorld(const FTransform& relativeTransform, const FTransform& componentTransformWorld);
460
461 FTransform GetSensorAttachmentTransform(const FTransform& sensorRelativeTransform, USceneComponent* attachToComponent, const FName& attachToBone, bool revertScaleToVectorOne = true);
462
467 void AttachSensorToOwner(ASensor* sensor);
468
473 void DestroySensorActor(AActor* sensorActor);
474
479 UFUNCTION()
480 void OnCameraWindowClosed(ACamera* camera);
481
486 void AddSensorDestroyListener(ASensor* sensor);
487
492 void RemoveSensorDestroyListener(ASensor* sensor);
493
498 UFUNCTION()
499 void OnSensorDestroy(ASensor* sensor);
500
506 UFUNCTION()
507 FSensorPreset GetSensorPreset(ASensor* sensor);
508
510 UPROPERTY()
511 TArray<ASensor*> Sensors;
512
514 UPROPERTY()
515 TArray<ALidar*> Lidars;
516
518 UPROPERTY()
519 TArray<ACamera*> Cameras;
520
522 UPROPERTY()
523 TArray<AThermalCamera*> ThermalCameras;
524
526 UPROPERTY()
527 TArray<ADVSCamera*> DVSCameras;
528
530 UPROPERTY()
531 TArray<ASemanticSegmentationCamera*> SegmentationCameras;
532
534 UPROPERTY()
535 TArray<AInstanceSegmentationCamera*> InstanceSegmentationCameras;
536
538 UPROPERTY()
539 TArray<ADepthCamera*> DepthCameras;
540
542 UPROPERTY()
543 TArray<ARadar*> Radars;
544
545};
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