CARLA
Loading...
Searching...
No Matches
GeoTrafficSign.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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#include "GeoTrafficSign.h"
8#include "Carla.h"
9
10AGeoTrafficSign::AGeoTrafficSign(const FObjectInitializer &ObjectInitializer)
11 : Super(ObjectInitializer)
12{
13 Pole = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Pole"));
14 Pole->SetupAttachment(RootComponent);
15 Pole->SetMobility(EComponentMobility::Static);
16 Pole->SetCollisionProfileName(TEXT("BlockAll"));
17
18 Plate = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Plate"));
19 Plate->SetupAttachment(RootComponent);
20 Plate->SetMobility(EComponentMobility::Static);
21 Plate->SetCollisionProfileName(TEXT("NoCollision"));
22}
23
24void AGeoTrafficSign::Setup(UStaticMesh* PoleMesh, UStaticMesh* PlateMesh, UMaterialInterface* PlateMaterial,
25 FVector PlateOffset, float PlateYaw, float PlateScale)
26{
27 Pole->SetStaticMesh(PoleMesh);
28 Plate->SetStaticMesh(PlateMesh);
29 if (PlateMaterial != nullptr)
30 {
31 Plate->SetMaterial(0, PlateMaterial);
32 }
33 Plate->SetRelativeLocation(PlateOffset);
34 Plate->SetRelativeRotation(FRotator(0.0f, PlateYaw, 0.0f));
35 Plate->SetRelativeScale3D(FVector(PlateScale));
36}
37
38ETrafficSignState AGeoTrafficSign::StateForSignal(const FString& Type, const FString& Subtype)
39{
40 if (Type == TEXT("206"))
41 {
42 return ETrafficSignState::StopSign;
43 }
44 if (Type == TEXT("205"))
45 {
46 return ETrafficSignState::YieldSign;
47 }
48 if (Type == TEXT("274"))
49 {
50 return SpeedLimitStateForKmh(FCString::Atoi(*Subtype));
51 }
53}
54
56{
57 Super::PostInitializeComponents();
59 {
61 }
62}
63
64void AGeoTrafficSign::ConfigureForSignal(const FString& Type, const FString& Subtype)
65{
66 XodrType = Type;
67 XodrSubtype = Subtype;
68 if (Type == TEXT("274"))
69 {
70 SetSpeedLimitKmh(FCString::Atoi(*Subtype));
71 }
72 else
73 {
74 SetTrafficSignState(StateForSignal(Type, Subtype));
75 }
76}
ETrafficSignState SpeedLimitStateForKmh(int32 Kmh)
The dedicated state for a km/h value, ETrafficSignState::SpeedLimit when there is none (then store th...
ETrafficSignState
static ETrafficSignState StateForSignal(const FString &Type, const FString &Subtype)
The ETrafficSignState the traffic-light manager matches against for an OpenDRIVE signal type/subtype:...
UStaticMeshComponent * Plate
void ConfigureForSignal(const FString &Type, const FString &Subtype)
Set XodrType / XodrSubtype and the matching runtime state (speed limit in km/h from the subtype) so A...
void Setup(UStaticMesh *PoleMesh, UStaticMesh *PlateMesh, UMaterialInterface *PlateMaterial, FVector PlateOffset, float PlateYaw, float PlateScale)
Assign meshes / material and place the plate.
AGeoTrafficSign(const FObjectInitializer &ObjectInitializer)
virtual void PostInitializeComponents() override
Levels baked before every km/h value had a state carry UNKNOWN for e.g.
UStaticMeshComponent * Pole
ETrafficSignState GetTrafficSignState() const
void SetTrafficSignState(ETrafficSignState State)
void SetSpeedLimitKmh(int32 Kmh)
Make this a speed-limit sign for Kmh: picks the dedicated state when one exists, the custom state (va...