CARLA
 
载入中...
搜索中...
未找到
RoadMap.h
浏览该文件的文档.
1// Copyright (c) 2017 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#pragma once
8
9#include "UObject/NoExportTypes.h"
11#include "RoadMap.generated.h"
12
13/// 路线图交叉路口结果。请参阅 URoadMap。
14USTRUCT(BlueprintType)
16{
17 GENERATED_BODY()
18
19 /// 箱子在越野时的百分比。
20 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
21 float OffRoad;
22
23 ///框侵入对面车道的百分比(方向错误)。
24 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
25 float OppositeLane;
26};
27
28/// 数据存储在路线图像素中。请参阅 URoadMap。
30{
31 friend class URoadMap;
32
33 constexpr static int IsRoadRow = 15;
34
35 constexpr static int HasDirectionRow = 14;
36
37 constexpr static uint16 MaximumEncodedAngle = (1 << 14) - 1;
38
39 constexpr static uint16 AngleMask = (0xFFFF >> 2);
40
41public:
42
43 explicit FRoadMapPixelData(uint16 inValue) : Value(inValue) {}
44
45 ///此像素是否位于道路上。
46 bool IsRoad() const
47 {
48 return (Value & (1 << IsRoadRow)) != 0;
49 }
50
51 ///此像素是否定义了方向(例如,道路交叉口为
52 ///不是越野,但都没有明确的方向)。
53 bool HasDirection() const
54 {
55 return (Value & (1 << HasDirectionRow)) != 0;
56 }
57
58 /// 获取道路方向的方位角 [-PI, PI](球面
59 ///坐标)的 S Package。
60 ///
61 /// 未定义 if !HasDirection().
63 {
64 const float Angle = AngleMask & Value;
65 // 在内部,角度由 PI 旋转。
66 return (Angle * 2.0f * PI / MaximumEncodedAngle) - PI;
67 }
68
69 ///获取此像素处的道路方向。
70 ///
71 /// 为定义 if !HasDirection().
72 FVector GetDirection() const
73 {
74 const FVector2D SphericalCoords(HALF_PI, GetDirectionAzimuthalAngle());
75 return SphericalCoords.SphericalToUnitCartesian();
76 }
77
78 FColor EncodeAsColor() const;
79
80private:
81
82 static uint16 Encode(bool IsRoad, bool HasDirection, const FVector &Direction);
83
84 uint16 Value;
85};
86
87/// 关卡路线图。包含哪些区域是道路的 2D 信息
88///和车道方向。
89UCLASS()
90class CARLA_API URoadMap : public UObject
91{
92 GENERATED_BODY()
93
94public:
95
96 /// 创建有效的空地图(每个点都是越野的)。
97 URoadMap(const FObjectInitializer& ObjectInitializer);
98
99 /// 重置当前映射 - 初始化给定大小的空映射。
100 void Reset(
101 uint32 Width,
102 uint32 Height,
104 const FTransform &WorldToMap,
105 const FVector &MapOffset);
106
107 void SetPixelAt(
108 uint32 PixelX,
109 uint32 PixelY,
110 ECityMapMeshTag Tag,
111 const FTransform &Transform,
112 bool bInvertDirection = false);
113
114 uint32 GetWidth() const
115 {
116 return Width;
117 }
118
119 uint32 GetHeight() const
120 {
121 return Height;
122 }
123
124 /// 返回给定像素的世界位置。
125 FVector GetWorldLocation(uint32 PixelX, uint32 PixelY) const;
126
127 /// 检索存储在给定像素处的数据。
128 FRoadMapPixelData GetDataAt(uint32 PixelX, uint32 PixelY) const
129 {
130 check(IsValid());
131 return FRoadMapPixelData(RoadMapData[GetIndex(PixelX, PixelY)]);
132 }
133
134 /// 如果位于映射限制之外,则钳制值。
135 FRoadMapPixelData GetDataAt(const FVector &WorldLocation) const;
136
137 /// 将角色边界与地图相交。
138 ///
139 ///边界框将投影到地图上,并尽可能地对照它进行检查
140 ///与越野区域和对面车道的交叉路口.
142 const FTransform &BoxTransform,
143 const FVector &BoxExtent,
144 float ChecksPerCentimeter) const;
145
146 ///将当前地图另存为 PNG,并将像素数据编码为颜色。
147 bool SaveAsPNG(const FString &Folder, const FString &MapName) const;
148
149#if WITH_EDITOR
150
151 /// 将映射的状态记录到控制台。
152 void Log() const;
153
154 /// 将图像的每个像素绘制为调试点。
155 void DrawDebugPixelsToLevel(UWorld *World, bool bJustFlushDoNotDraw = false) const;
156
157#endif // WITH_EDITOR
158
159private:
160
161 int32 GetIndex(uint32 PixelX, uint32 PixelY) const
162 {
163 return PixelX + Width * PixelY;
164 }
165
166 bool IsValid() const
167 {
168 return ((RoadMapData.Num() > 0) && (RoadMapData.Num() == Height * Width));
169 }
170
171 /// 世界到地图的转换。
172 UPROPERTY(VisibleAnywhere)
173 FTransform WorldToMap;
174
175 /// 地图坐标中的偏移量。
176 UPROPERTY(VisibleAnywhere)
177 FVector MapOffset;
178
179 /// 每厘米像素数。
180 UPROPERTY(VisibleAnywhere)
182
183 /// 地图的宽度(以像素为单位)。
184 UPROPERTY(VisibleAnywhere)
185 uint32 Width;
186
187 /// 地图的高度(以像素为单位)。
188 UPROPERTY(VisibleAnywhere)
189 uint32 Height;
190
191 UPROPERTY()
192 TArray<uint16> RoadMapData;
193};
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld * World
ECityMapMeshTag
用于标识ProceduralMapGenerator所使用的网格的标签
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
关卡路线图。包含哪些区域是道路的 2D 信息 和车道方向。
Definition RoadMap.h:91
uint32 Height
地图的高度(以像素为单位)。
Definition RoadMap.h:189
FVector GetWorldLocation(uint32 PixelX, uint32 PixelY) const
返回给定像素的世界位置。
Definition RoadMap.cpp:270
int32 GetIndex(uint32 PixelX, uint32 PixelY) const
Definition RoadMap.h:161
void Reset(uint32 Width, uint32 Height, float PixelsPerCentimeter, const FTransform &WorldToMap, const FVector &MapOffset)
重置当前映射 - 初始化给定大小的空映射。
Definition RoadMap.cpp:128
bool IsValid() const
Definition RoadMap.h:166
void SetPixelAt(uint32 PixelX, uint32 PixelY, ECityMapMeshTag Tag, const FTransform &Transform, bool bInvertDirection=false)
Definition RoadMap.cpp:150
URoadMap(const FObjectInitializer &ObjectInitializer)
创建有效的空地图(每个点都是越野的)。
Definition RoadMap.cpp:104
float PixelsPerCentimeter
每厘米像素数。
Definition RoadMap.h:181
TArray< uint16 > RoadMapData
Definition RoadMap.h:192
FVector MapOffset
地图坐标中的偏移量。
Definition RoadMap.h:177
uint32 Width
地图的宽度(以像素为单位)。
Definition RoadMap.h:185
FTransform WorldToMap
世界到地图的转换。
Definition RoadMap.h:173
uint32 GetHeight() const
Definition RoadMap.h:119
bool SaveAsPNG(const FString &Folder, const FString &MapName) const
将当前地图另存为 PNG,并将像素数据编码为颜色。
Definition RoadMap.cpp:332
uint32 GetWidth() const
Definition RoadMap.h:114
FRoadMapIntersectionResult Intersect(const FTransform &BoxTransform, const FVector &BoxExtent, float ChecksPerCentimeter) const
将角色边界与地图相交。
Definition RoadMap.cpp:296
FRoadMapPixelData GetDataAt(uint32 PixelX, uint32 PixelY) const
检索存储在给定像素处的数据。
Definition RoadMap.h:128
路线图交叉路口结果。请参阅 URoadMap。
Definition RoadMap.h:16
数据存储在路线图像素中。请参阅 URoadMap。
Definition RoadMap.h:30
float GetDirectionAzimuthalAngle() const
获取道路方向的方位角 [-PI, PI](球面 坐标)的 S Package。
Definition RoadMap.h:62
bool HasDirection() const
此像素是否定义了方向(例如,道路交叉口为 不是越野,但都没有明确的方向)。
Definition RoadMap.h:53
FVector GetDirection() const
获取此像素处的道路方向。
Definition RoadMap.h:72
bool IsRoad() const
此像素是否位于道路上。
Definition RoadMap.h:46
FRoadMapPixelData(uint16 inValue)
Definition RoadMap.h:43