CARLA
Loading...
Searching...
No Matches
CityMapGenerator.h
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#pragma once
8
11#include "MapGen/GraphParser.h"
12
13#include <util/ue-header-guard-begin.h>
14#include "UObject/ObjectSaveContext.h"
15#include <util/ue-header-guard-end.h>
16
17#include "CityMapGenerator.generated.h"
18
19class URoadMap;
20
21/// Generates a random city using the meshes provided.
22///
23/// @note At this point it only generates roads and sidewalks.
24UCLASS(HideCategories=(Input,Rendering,Actor))
25class CARLA_API ACityMapGenerator : public ACityMapMeshHolder
26{
27 GENERATED_BODY()
28
29 // ===========================================================================
30 /// @name Constructor and destructor
31 // ===========================================================================
32 /// @{
33public:
34
35 ACityMapGenerator(const FObjectInitializer& ObjectInitializer);
36
38
39 /// @}
40 // ===========================================================================
41 /// @name Overriden from UObject
42 // ===========================================================================
43 /// @{
44public:
45
46 virtual void PreSave(FObjectPreSaveContext ObjectSaveContext) override;
47
48 /// @}
49 // ===========================================================================
50 /// @name Overriden from ACityMapMeshHolder
51 // ===========================================================================
52 /// @{
53private:
54
55 virtual void UpdateMap() override;
56
57 /// @}
58 // ===========================================================================
59 /// @name Road map
60 // ===========================================================================
61 /// @{
62public:
63
64 UFUNCTION(BlueprintCallable)
66 {
67 return RoadMap;
68 }
69
70 /// @}
71 // ===========================================================================
72 /// @name Map construction and update related methods
73 // ===========================================================================
74 /// @{
75private:
76
77 /// Update the random seeds. Generate random if no fixed seed is used.
78 void UpdateSeeds();
79
80 /// Regenerate the DCEL.
81 void GenerateGraph();
82
83 /// Add the road meshes to the scene based on the current DCEL.
84 void GenerateRoads();
85
86 /// Generate the road map image and save to disk if requested.
87 void GenerateRoadMap();
88
89 /// @}
90 // ===========================================================================
91 /// @name Map generation properties
92 // ===========================================================================
93 /// @{
94private:
95
96 /** Size X of the map in map units. The map unit is calculated based in the
97 * tile mesh of the road (see Map Scale).
98 */
99 UPROPERTY(Category = "Map Generation", EditAnywhere, meta = (ClampMin = "10", ClampMax = "200"))
100 uint32 MapSizeX = 20u;
101
102 /** Size Y of the map in map units. The map unit is calculated based in the
103 * tile mesh of the road (see Map Scale).
104 */
105 UPROPERTY(Category = "Map Generation", EditAnywhere, meta = (ClampMin = "10", ClampMax = "200"))
106 uint32 MapSizeY = 20u;
107
108 /** If false, no mesh is added, only the internal representation of road is
109 * generated.
110 */
111 UPROPERTY(Category = "Map Generation", EditAnywhere)
112 bool bGenerateRoads = true;
113
114 /** If false, a random seed is generated each time. */
115 UPROPERTY(Category = "Map Generation", EditAnywhere)
116 bool bUseFixedSeed = true;
117
118 /** Seed of the random map generated. */
119 UPROPERTY(Category = "Map Generation", EditAnywhere, meta = (EditCondition = bUseFixedSeed))
120 int32 Seed = 123456789;
121
122 /// @}
123 // ===========================================================================
124 /// @name Road Map
125 // ===========================================================================
126 /// @{
127private:
128
129 /** Trigger the generation a the road map image of the current layout (used
130 * for off-road and opposite lane invasion detection).
131 */
132 UPROPERTY(Category = "Road Map", EditAnywhere)
134
135 /** The resolution in pixels per map unit of the road map. The map unit is
136 * calculated based in the tile mesh of the road (see Map Scale).
137 */
138 UPROPERTY(Category = "Road Map", EditAnywhere, meta = (ClampMin = "1", ClampMax = "500"))
139 uint32 PixelsPerMapUnit = 50u;
140
141 /** Whether the road map should be generated based on left-hand traffic. */
142 UPROPERTY(Category = "Road Map", EditAnywhere)
143 bool bLeftHandTraffic = false;
144
145 /** If true, the road map encoded as an image is saved to disk. The image is
146 * saved to the "Saved" folder of the project.
147 */
148 UPROPERTY(Category = "Road Map", EditAnywhere)
150
151 /** If true, a debug point is drawn in the level for each pixel of the road
152 * map.
153 */
154 UPROPERTY(Category = "Road Map", EditAnywhere)
156
157 /** The road map is re-computed on save so we always store an up-to-date
158 * version. Uncheck this only for testing purposes as the road map might get
159 * out-of-sync with the current road layout.
160 */
161 UPROPERTY(Category = "Road Map", EditAnywhere, AdvancedDisplay)
163
164 /** If true, activate the custom depth pass of each tagged actor in the level.
165 * This pass is necessary for rendering the semantic segmentation. However,
166 * it may add a performance penalty since occlusion doesn't seem to be
167 * applied to objects having this value active.
168 */
169 UPROPERTY(Category = "Road Map", EditAnywhere, AdvancedDisplay)
171
172 UPROPERTY()
174
175 /// @}
176 // ===========================================================================
177 /// @name Other private members
178 // ===========================================================================
179 /// @{
180private:
181
182 TUniquePtr<MapGen::DoublyConnectedEdgeList> Dcel;
183
184 TUniquePtr<MapGen::GraphParser> DcelParser;
185 /// @}
186};
bool bGenerateRoadMapOnSave
The road map is re-computed on save so we always store an up-to-date version.
bool bGenerateRoads
If false, no mesh is added, only the internal representation of road is generated.
uint32 MapSizeY
Size Y of the map in map units.
int32 Seed
Seed of the random map generated.
uint32 PixelsPerMapUnit
The resolution in pixels per map unit of the road map.
virtual void UpdateMap() override
Here does nothing, implement in derived classes.
TUniquePtr< MapGen::DoublyConnectedEdgeList > Dcel
bool bDrawDebugPixelsToLevel
If true, a debug point is drawn in the level for each pixel of the road map.
bool bLeftHandTraffic
Whether the road map should be generated based on left-hand traffic.
bool bUseFixedSeed
If false, a random seed is generated each time.
bool bTriggerRoadMapGeneration
Trigger the generation a the road map image of the current layout (used for off-road and opposite lan...
ACityMapGenerator(const FObjectInitializer &ObjectInitializer)
URoadMap * GetRoadMap()
TUniquePtr< MapGen::GraphParser > DcelParser
virtual void PreSave(FObjectPreSaveContext ObjectSaveContext) override
uint32 MapSizeX
Size X of the map in map units.
bool bSaveRoadMapToDisk
If true, the road map encoded as an image is saved to disk.
bool bTagForSemanticSegmentation
If true, activate the custom depth pass of each tagged actor in the level.
ACityMapMeshHolder(const FObjectInitializer &ObjectInitializer)
Initializes the mesh holders.
Road map of the level.
Definition RoadMap.h:95