CARLA
SignComponent.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 
8 #include "SignComponent.h"
9 
13 #include "carla/rpc/String.h"
15 
16 USignComponent::USignComponent()
17 {
18  PrimaryComponentTick.bCanEverTick = false;
19 }
20 
21 // Called when the game starts
22 void USignComponent::BeginPlay()
23 {
24  Super::BeginPlay();
25 
26 }
27 
28 // Called every frame
29 void USignComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
30 {
31  Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
32 
33 }
34 
35 const FString& USignComponent::GetSignId() const
36 {
37  return SignId;
38 }
39 
40 void USignComponent::SetSignId(const FString &Id) {
41  SignId = Id;
42 }
43 
44 void USignComponent::InitializeSign(const cr::Map &Map)
45 {
46 
47 }
48 
49 TArray<std::pair<cr::RoadId, const cre::RoadInfoSignal*>>
50  USignComponent::GetAllReferencesToThisSignal(const cr::Map &Map)
51 {
52  TArray<std::pair<cr::RoadId, const cre::RoadInfoSignal*>> Result;
53  auto waypoints = Map.GenerateWaypointsOnRoadEntries();
54  std::unordered_set<cr::RoadId> ExploredRoads;
55  for (auto & waypoint : waypoints)
56  {
57  // Check if we already explored this road
58  if (ExploredRoads.count(waypoint.road_id) > 0)
59  {
60  continue;
61  }
62  ExploredRoads.insert(waypoint.road_id);
63 
64  // Multiple times for same road (performance impact, not in behavior)
65  auto SignalReferences = Map.GetLane(waypoint).
66  GetRoad()->GetInfos<cre::RoadInfoSignal>();
67  for (auto *SignalReference : SignalReferences)
68  {
69  FString SignalId(SignalReference->GetSignalId().c_str());
70  if(SignalId == GetSignId())
71  {
72  Result.Add({waypoint.road_id, SignalReference});
73  }
74  }
75  }
76  return Result;
77 }
78 
79 const cr::Signal* USignComponent::GetSignal(const cr::Map &Map) const
80 {
81  std::string std_signal_id = carla::rpc::FromFString(GetSignId());
82  if (Map.GetSignals().count(std_signal_id))
83  {
84  return Map.GetSignals().at(std_signal_id).get();
85  }
86  return nullptr;
87 }
88 
89 UBoxComponent* USignComponent::GenerateTriggerBox(const FTransform &BoxTransform,
90  float BoxSize)
91 {
92  AActor *ParentActor = GetOwner();
93  UBoxComponent *BoxComponent = NewObject<UBoxComponent>(ParentActor);
94  BoxComponent->RegisterComponent();
95  BoxComponent->AttachToComponent(
96  ParentActor->GetRootComponent(),
97  FAttachmentTransformRules::KeepRelativeTransform);
98  BoxComponent->SetWorldTransform(BoxTransform);
99  BoxComponent->SetBoxExtent(FVector(BoxSize, BoxSize, BoxSize), true);
100  return BoxComponent;
101 }
102 
103 UBoxComponent* USignComponent::GenerateTriggerBox(const FTransform &BoxTransform,
104  const FVector &BoxSize)
105 {
106  AActor *ParentActor = GetOwner();
107  UBoxComponent *BoxComponent = NewObject<UBoxComponent>(ParentActor);
108  BoxComponent->RegisterComponent();
109  BoxComponent->AttachToComponent(
110  ParentActor->GetRootComponent(),
111  FAttachmentTransformRules::KeepRelativeTransform);
112  BoxComponent->SetWorldTransform(BoxTransform);
113  BoxComponent->SetBoxExtent(BoxSize, true);
114  return BoxComponent;
115 }
116 
117 void USignComponent::AddEffectTriggerVolume(UBoxComponent* TriggerVolume)
118 {
119  EffectTriggerVolumes.Add(TriggerVolume);
120 }
121 
122 const TArray<UBoxComponent*> USignComponent::GetEffectTriggerVolume() const
123 {
124  return EffectTriggerVolumes;
125 }
std::string SignId
Definition: RoadTypes.h:25
const Lane & GetLane(Waypoint waypoint) const
======================================================================== – Road information --------...
Definition: road/Map.cpp:834
std::vector< Waypoint > GenerateWaypointsOnRoadEntries(Lane::LaneType lane_type=Lane::LaneType::Driving) const
Generate waypoints on each lane at the start of each road.
Definition: road/Map.cpp:662
const std::unordered_map< SignId, std::unique_ptr< Signal > > & GetSignals() const
Definition: road/Map.h:188
std::vector< const T * > GetInfos() const
Definition: Lane.h:85