Agrarsense
Static Public Member Functions | List of all members
USensorUtilities Class Reference

#include <SensorUtilities.h>

Inheritance diagram for USensorUtilities:
Inheritance graph
[legend]
Collaboration diagram for USensorUtilities:
Collaboration graph
[legend]

Static Public Member Functions

static void EnableAllSensors (const UObject *WorldContextObject)
 
static void DisableAllSensors (const UObject *WorldContextObject)
 
static void SetSimulateAllSensors (const UObject *WorldContextObject, bool SimulateSensors)
 
static void DestroyAllSensors (const UObject *WorldContextObject, bool DestroyDefaultVehicleSensors=false)
 
static void EnableSensorsAttachedToVehicle (AVehicle *Vehicle)
 
static void DisableSensorsAttachedToVehicle (AVehicle *Vehicle)
 
static void SetSimulateSensorsAttachedToVehicle (AVehicle *Vehicle, bool SimulateSensors)
 
static void HideComponentForAllCameraSensors (UPrimitiveComponent *PrimitiveComponent)
 

Detailed Description

Class fo sensor related utilities.

Definition at line 20 of file SensorUtilities.h.

Member Function Documentation

◆ DestroyAllSensors()

void USensorUtilities::DestroyAllSensors ( const UObject *  WorldContextObject,
bool  DestroyDefaultVehicleSensors = false 
)
static

Destroy all sensors currently existing in the level. Default behavior does not destroy vehicle-related sensors like Transform, Collision or Overlap sensors.

Definition at line 42 of file SensorUtilities.cpp.

43{
44 // Most sensors should be attached to Vehicle(s)
45 // Get all Vehicles from the level and destroy the sensors through USensorsManagerComponent
46 TArray<AActor*> Vehicles;
47 UGameplayStatics::GetAllActorsOfClass(WorldContextObject, AVehicle::StaticClass(), Vehicles);
48 for (AActor* Actor : Vehicles)
49 {
50 AVehicle* Vehicle = Cast<AVehicle>(Actor);
51 if (Vehicle)
52 {
53 auto* SensorManager = Vehicle->GetSensorsManager();
54 if (SensorManager)
55 {
56 SensorManager->DestroyAllSensors();
57 }
58 }
59 }
60
61 Vehicles.Empty();
62
63 // Destroy remaining sensors if they exist
64 TArray<AActor*> Sensors;
65 UGameplayStatics::GetAllActorsOfClass(WorldContextObject, ASensor::StaticClass(), Sensors);
66 for (AActor* SensorActor : Sensors)
67 {
68 ASensor* Sensor = Cast<ASensor>(SensorActor);
69 if (Sensor)
70 {
71 bool AllowedToDestroy = true;
72 if (!DestroyDefaultVehicleSensors)
73 {
74 // We might not want to destroy these sensors,
75 // as these sensors cannot be spawned back any in way at the moment.
76 // These sensors are spawned automatically by Vehicle.cpp to each vehicle.
77 ESensorTypes SensorType = Sensor->GetSensorType();
78 if (SensorType == ESensorTypes::Overlap
79 || SensorType == ESensorTypes::Transform
80 || SensorType == ESensorTypes::Collision)
81 {
82 AllowedToDestroy = false;
83 }
84 }
85
86 if (AllowedToDestroy)
87 {
88 Sensor->Destroy();
89 }
90 }
91 }
92
93 Sensors.Empty();
94}
ESensorTypes
Definition: SensorTypes.h:15
Definition: Sensor.h:44
virtual ESensorTypes GetSensorType() const
Definition: Sensor.h:64

References Collision, ASensor::GetSensorType(), Overlap, Sensors, Transform, and Vehicle.

Referenced by UROSCommands::HandleDestroyAllSensors().

◆ DisableAllSensors()

void USensorUtilities::DisableAllSensors ( const UObject *  WorldContextObject)
static

Disable all sensors in the level.

Definition at line 21 of file SensorUtilities.cpp.

22{
23 SetSimulateAllSensors(WorldContextObject, false);
24}
static void SetSimulateAllSensors(const UObject *WorldContextObject, bool SimulateSensors)

References SetSimulateAllSensors().

Referenced by UROSCommands::HandleDisableAllSensors(), and UROSCommands::HandleSetAllSensorsEnabled().

◆ DisableSensorsAttachedToVehicle()

void USensorUtilities::DisableSensorsAttachedToVehicle ( AVehicle Vehicle)
static

Disable all sensors attached to Vehicle actor

Definition at line 101 of file SensorUtilities.cpp.

102{
104}
static void SetSimulateSensorsAttachedToVehicle(AVehicle *Vehicle, bool SimulateSensors)

References SetSimulateSensorsAttachedToVehicle(), and Vehicle.

◆ EnableAllSensors()

void USensorUtilities::EnableAllSensors ( const UObject *  WorldContextObject)
static

Enable all sensors in the level.

Definition at line 16 of file SensorUtilities.cpp.

17{
18 SetSimulateAllSensors(WorldContextObject, true);
19}

References SetSimulateAllSensors().

Referenced by UROSCommands::HandleEnableAllSensors(), and UROSCommands::HandleSetAllSensorsEnabled().

◆ EnableSensorsAttachedToVehicle()

void USensorUtilities::EnableSensorsAttachedToVehicle ( AVehicle Vehicle)
static

Enable all sensors attached to Vehicle actor

Definition at line 96 of file SensorUtilities.cpp.

References SetSimulateSensorsAttachedToVehicle(), and Vehicle.

◆ HideComponentForAllCameraSensors()

void USensorUtilities::HideComponentForAllCameraSensors ( UPrimitiveComponent *  PrimitiveComponent)
static

Hides the specified primitive component for all camera sensors in the level. Most of the rendering related components are derived from UPrimitiveComponent.

Parameters
PrimitiveComponent- The primitive component to be hidden for all camera sensors.

Definition at line 130 of file SensorUtilities.cpp.

131{
132 if (PrimitiveComponent)
133 {
134 ASensor::HideComponentForAllCameras(PrimitiveComponent);
135 }
136}
static void HideComponentForAllCameras(UPrimitiveComponent *PrimitiveComponent)
Definition: Sensor.cpp:255

References ASensor::HideComponentForAllCameras().

◆ SetSimulateAllSensors()

void USensorUtilities::SetSimulateAllSensors ( const UObject *  WorldContextObject,
bool  SimulateSensors 
)
static

Set Simulate all sensors in the level.

Definition at line 26 of file SensorUtilities.cpp.

27{
28 // Get all ASensor actors from the level
29 TArray<AActor*> Sensors;
30 UGameplayStatics::GetAllActorsOfClass(WorldContextObject, ASensor::StaticClass(), Sensors);
31
32 for (AActor* SensorActor : Sensors)
33 {
34 ASensor* sensor = Cast<ASensor>(SensorActor);
35 if (sensor != nullptr)
36 {
37 sensor->SetSimulateSensor(SimulateSensors);
38 }
39 }
40}
void SetSimulateSensor(bool SimulateSensor)
Definition: Sensor.h:151

References Sensors, and ASensor::SetSimulateSensor().

Referenced by DisableAllSensors(), and EnableAllSensors().

◆ SetSimulateSensorsAttachedToVehicle()

void USensorUtilities::SetSimulateSensorsAttachedToVehicle ( AVehicle Vehicle,
bool  SimulateSensors 
)
static

Set Simulate all sensors attached to Vehicle actor

Definition at line 106 of file SensorUtilities.cpp.

107{
108 if (Vehicle == nullptr)
109 {
110#if WITH_EDITOR
111 UE_LOG(LogTemp, Warning, TEXT("vehicle is nullptr. Returning."));
112#endif
113 return;
114 }
115
116 // Get all Actors attached to Vehicle actor
117 TArray<AActor*> Actors;
118 Vehicle->GetAttachedActors(Actors);
119
120 for (AActor* actor : Actors)
121 {
122 ASensor* sensor = Cast<ASensor>(actor);
123 if (sensor)
124 {
125 sensor->SetSimulateSensor(SimulateSensors);
126 }
127 }
128}

References ASensor::SetSimulateSensor(), and Vehicle.

Referenced by DisableSensorsAttachedToVehicle(), and EnableSensorsAttachedToVehicle().


The documentation for this class was generated from the following files: