CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Util
RayTracer.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 "
Carla/Util/RayTracer.h
"
8
#include "
Carla.h
"
9
#include "
Carla/Game/CarlaStatics.h
"
10
#include "
Carla/Game/Tagger.h
"
11
12
13
namespace
crp
=
carla::rpc
;
14
15
std::vector<crp::LabelledPoint>
URayTracer::CastRay
(
16
FVector StartLocation, FVector EndLocation, UWorld * World)
17
{
18
TArray<FHitResult> OutHits;
19
World->LineTraceMultiByChannel(
20
OutHits,
21
StartLocation,
22
EndLocation,
23
ECC_GameTraceChannel3,
// overlap channel
24
FCollisionQueryParams(),
25
FCollisionResponseParams()
26
);
27
std::vector<crp::LabelledPoint> result;
28
for
(
auto
& Hit : OutHits)
29
{
30
UPrimitiveComponent* Component = Hit.GetComponent();
31
crp::CityObjectLabel
ComponentTag =
32
ATagger::GetTagOfTaggedComponent
(*Component);
33
34
FVector UELocation = Hit.Location;
35
ACarlaGameModeBase
* GameMode =
UCarlaStatics::GetGameMode
(World);
36
ALargeMapManager
* LargeMap = GameMode->
GetLMManager
();
37
if
(LargeMap)
38
{
39
UELocation = LargeMap->
LocalToGlobalLocation
(UELocation);
40
}
41
result.emplace_back(
crp::LabelledPoint
(UELocation, ComponentTag));
42
}
43
return
result;
44
}
45
46
std::pair<bool, crp::LabelledPoint>
URayTracer::ProjectPoint
(
47
FVector StartLocation, FVector Direction,
float
MaxDistance, UWorld * World)
48
{
49
FHitResult Hit;
50
bool
bDidHit = World->LineTraceSingleByChannel(
51
Hit,
52
StartLocation,
53
StartLocation + Direction.GetSafeNormal() * MaxDistance,
54
ECC_GameTraceChannel2,
// camera
55
FCollisionQueryParams(),
56
FCollisionResponseParams()
57
);
58
if
(bDidHit)
59
{
60
UPrimitiveComponent* Component = Hit.GetComponent();
61
crp::CityObjectLabel
ComponentTag =
62
ATagger::GetTagOfTaggedComponent
(*Component);
63
64
FVector UELocation = Hit.Location;
65
ACarlaGameModeBase
* GameMode =
UCarlaStatics::GetGameMode
(World);
66
ALargeMapManager
* LargeMap = GameMode->
GetLMManager
();
67
if
(LargeMap)
68
{
69
UELocation = LargeMap->
LocalToGlobalLocation
(UELocation);
70
}
71
return
std::make_pair(bDidHit,
crp::LabelledPoint
(UELocation, ComponentTag));
72
}
73
return
std::make_pair(bDidHit,
crp::LabelledPoint
(FVector(0.0f,0.0f,0.0f),
crp::CityObjectLabel::None
));
74
}
CarlaStatics.h
Carla.h
RayTracer.h
Tagger.h
ACarlaGameModeBase
Base class for the CARLA Game Mode.
Definition
CarlaGameModeBase.h:41
ACarlaGameModeBase::GetLMManager
ALargeMapManager * GetLMManager() const
Definition
CarlaGameModeBase.h:129
ALargeMapManager
Definition
LargeMapManager.h:62
ALargeMapManager::LocalToGlobalLocation
FVector LocalToGlobalLocation(const FVector &InLocation) const
Definition
LargeMapManager.cpp:369
ATagger::GetTagOfTaggedComponent
static crp::CityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
Retrieve the tag of an already tagged component.
Definition
Tagger.cpp:213
UCarlaStatics::GetGameMode
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
Definition
CarlaStatics.h:69
URayTracer::ProjectPoint
static std::pair< bool, carla::rpc::LabelledPoint > ProjectPoint(FVector StartLocation, FVector Direction, float MaxDistance, UWorld *World)
Definition
RayTracer.cpp:46
URayTracer::CastRay
static std::vector< carla::rpc::LabelledPoint > CastRay(FVector StartLocation, FVector EndLocation, UWorld *World)
Definition
RayTracer.cpp:15
carla::rpc
Definition
DebugShapeDrawer.h:11
carla::rpc::CityObjectLabel
CityObjectLabel
Definition
ObjectLabel.h:16
carla::rpc::CityObjectLabel::None
@ None
Definition
ObjectLabel.h:17
carla::rpc::LabelledPoint
Definition
LabelledPoint.h:16
Generated by
1.18.0