Agrarsense
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ADeletionVolume Class Reference

#include <DeletionVolume.h>

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

Public Member Functions

 ADeletionVolume ()
 
void ChangeOverlapBounds (FVector Bounds)
 
void DestroyOverlappingActors (bool OnlyTrees)
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 

Protected Attributes

UBoxComponent * CollisionBox = nullptr
 
UBoundsVisualizerComponent * VisualizerComponent = nullptr
 

Detailed Description

Definition at line 16 of file DeletionVolume.h.

Constructor & Destructor Documentation

◆ ADeletionVolume()

ADeletionVolume::ADeletionVolume ( )

Definition at line 13 of file DeletionVolume.cpp.

14{
15 PrimaryActorTick.bCanEverTick = false;
16
17 CollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionBox"));
18 CollisionBox->InitBoxExtent(FVector(200.0f, 200.0f, 200.0f));
19 RootComponent = CollisionBox;
20
21 VisualizerComponent = CreateDefaultSubobject<UBoundsVisualizerComponent>(TEXT("BoundsVisualizerComponent"));
22 VisualizerComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
23 VisualizerComponent->SetGenerateOverlapEvents(false);
24 VisualizerComponent->SetupAttachment(RootComponent);
25 VisualizerComponent->SetVisibility(true);
26}
UBoxComponent * CollisionBox
UBoundsVisualizerComponent * VisualizerComponent

References CollisionBox, and VisualizerComponent.

Member Function Documentation

◆ BeginPlay()

void ADeletionVolume::BeginPlay ( )
overrideprotectedvirtual

Definition at line 28 of file DeletionVolume.cpp.

29{
30 Super::BeginPlay();
31
33 {
34 VisualizerComponent->SetCubeMesh();
35 VisualizerComponent->SetVisibility(true);
36 }
37}

References VisualizerComponent.

◆ ChangeOverlapBounds()

void ADeletionVolume::ChangeOverlapBounds ( FVector  Bounds)

Definition at line 56 of file DeletionVolume.cpp.

57{
58 if (IsValid(this))
59 {
60 if (CollisionBox)
61 {
62 CollisionBox->SetBoxExtent(Bounds);
63 }
64
66 {
67 VisualizerComponent->SetRelativeScale3D(Bounds);
68 }
69 }
70}

References CollisionBox, and VisualizerComponent.

Referenced by UROSCommands::HandleDestroyActors(), and USimulatorJsonParser::ParseVolumeDeletion().

◆ DestroyOverlappingActors()

void ADeletionVolume::DestroyOverlappingActors ( bool  OnlyTrees)

Destroys all actors overlapping with this actor's UBoxComponent. If OnlyTrees is true, only tree actors are destroyed; otherwise, all overlapping actors (InstancedActors) are destroyed.

Parameters
OnlyTreesIf true, only tree actors will be destroyed. If false, all overlapping actors will be destroyed.

Definition at line 72 of file DeletionVolume.cpp.

73{
74 if (!IsValid(this) || !CollisionBox)
75 {
76 return;
77 }
78
79 TArray<FString> Logs;
80
81 TArray<AActor*> OverlappingActors;
82 CollisionBox->GetOverlappingActors(OverlappingActors);
83
84 for (AActor* Actor : OverlappingActors)
85 {
86 // Only delete InstancedActor types
87 AInstancedActor* InstancedActor = Cast<AInstancedActor>(Actor);
88
89 if (InstancedActor && (!OnlyTrees || InstancedActor->IsTreeActor()))
90 {
91 InstancedActor->Destroy();
92
93 FVector ActorLocation = InstancedActor->GetActorLocation();
94 FString Msg = FString::Printf(TEXT("Removed actor from position: X=%f, Y=%f, Z=%f"), ActorLocation.X, ActorLocation.Y, ActorLocation.Z);
95 Logs.Add(Msg);
96 }
97 }
98
99 for (const FString& Msg : Logs)
100 {
102 }
103
104 // Destroy this actor after deleting overlapping actors inside the bounds.
105 this->Destroy();
106}
bool IsTreeActor() const
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)

References CollisionBox, Destroy, AInstancedActor::IsTreeActor(), and SimulatorLog::Log().

Referenced by UROSCommands::HandleDestroyActors(), and USimulatorJsonParser::ParseVolumeDeletion().

◆ EndPlay()

void ADeletionVolume::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual

Definition at line 39 of file DeletionVolume.cpp.

40{
41 Super::EndPlay(EndPlayReason);
42
43 if (CollisionBox)
44 {
45 CollisionBox->DestroyComponent();
46 CollisionBox = nullptr;
47 }
48
50 {
51 VisualizerComponent->DestroyComponent();
52 VisualizerComponent = nullptr;
53 }
54}

References CollisionBox, and VisualizerComponent.

Member Data Documentation

◆ CollisionBox

UBoxComponent* ADeletionVolume::CollisionBox = nullptr
protected

◆ VisualizerComponent

UBoundsVisualizerComponent* ADeletionVolume::VisualizerComponent = nullptr
protected

Definition at line 48 of file DeletionVolume.h.

Referenced by ADeletionVolume(), BeginPlay(), ChangeOverlapBounds(), and EndPlay().


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