CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
opendrive
parser
ProfilesParser.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/opendrive/parser/ProfilesParser.h
"
8
9
#include "
carla/road/MapBuilder.h
"
10
11
#include <
third-party/pugixml/pugixml.hpp
>
12
13
namespace
carla
{
14
namespace
opendrive
{
15
namespace
parser
{
16
17
struct
ElevationProfile
{
18
carla::road::Road
*
road
{
nullptr
};
19
double
s
{ 0.0 };
20
double
a
{ 0.0 };
21
double
b
{ 0.0 };
22
double
c
{ 0.0 };
23
double
d
{ 0.0 };
24
};
25
26
struct
LateralCrossfall
{
27
std::string
side
{
"both"
};
28
};
29
30
struct
LateralShape
{
31
double
t
{ 0.0 };
32
};
33
34
struct
LateralProfile
{
35
carla::road::Road
*
road
{
nullptr
};
36
double
s
{ 0.0 };
37
double
a
{ 0.0 };
38
double
b
{ 0.0 };
39
double
c
{ 0.0 };
40
double
d
{ 0.0 };
41
std::string
type
{
"superelevation"
};
42
LateralCrossfall
cross
;
43
LateralShape
shape
;
44
};
45
46
void
ProfilesParser::Parse
(
47
const
pugi::xml_document
&xml,
48
carla::road::MapBuilder
&map_builder) {
49
50
std::vector<ElevationProfile> elevation_profile;
51
std::vector<LateralProfile> lateral_profile;
52
53
for
(
pugi::xml_node
node_road : xml.
child
(
"OpenDRIVE"
).
children
(
"road"
)) {
54
55
// parse elevation profile
56
pugi::xml_node
node_profile = node_road.
child
(
"elevationProfile"
);
57
uint64_t number_profiles = 0;
58
if
(node_profile) {
59
// all geometry
60
for
(
pugi::xml_node
node_elevation : node_profile.
children
(
"elevation"
)) {
61
ElevationProfile
elev;
62
63
// get road id
64
road::RoadId
road_id = node_road.attribute(
"id"
).as_uint();
65
elev.
road
= map_builder.
GetRoad
(road_id);
66
67
// get common properties
68
elev.
s
= node_elevation.attribute(
"s"
).as_double();
69
elev.
a
= node_elevation.attribute(
"a"
).as_double();
70
elev.
b
= node_elevation.attribute(
"b"
).as_double();
71
elev.
c
= node_elevation.attribute(
"c"
).as_double();
72
elev.
d
= node_elevation.attribute(
"d"
).as_double();
73
74
// add it
75
elevation_profile.emplace_back(elev);
76
number_profiles++;
77
}
78
}
79
// add a default profile if none is found
80
if
(number_profiles == 0){
81
ElevationProfile
elev;
82
road::RoadId
road_id = node_road.attribute(
"id"
).as_uint();
83
elev.
road
= map_builder.
GetRoad
(road_id);
84
85
// get common properties
86
elev.
s
= 0;
87
elev.
a
= 0;
88
elev.
b
= 0;
89
elev.
c
= 0;
90
elev.
d
= 0;
91
92
// add it
93
elevation_profile.emplace_back(elev);
94
}
95
96
// parse lateral profile
97
node_profile = node_road.
child
(
"lateralProfile"
);
98
if
(node_profile) {
99
for
(
pugi::xml_node
node : node_profile.
children
()) {
100
LateralProfile
lateral;
101
102
// get road id
103
road::RoadId
road_id = node_road.attribute(
"id"
).as_uint();
104
lateral.
road
= map_builder.
GetRoad
(road_id);
105
106
// get common properties
107
lateral.
s
= node.attribute(
"s"
).as_double();
108
lateral.
a
= node.attribute(
"a"
).as_double();
109
lateral.
b
= node.attribute(
"b"
).as_double();
110
lateral.
c
= node.attribute(
"c"
).as_double();
111
lateral.
d
= node.attribute(
"d"
).as_double();
112
113
// handle different types
114
lateral.
type
= node.name();
115
if
(lateral.
type
==
"crossfall"
) {
116
lateral.
cross
.
side
= node.attribute(
"side"
).value();
117
}
else
if
(lateral.
type
==
"shape"
) {
118
lateral.
shape
.
t
= node.attribute(
"t"
).as_double();
119
}
120
121
// add it
122
lateral_profile.emplace_back(lateral);
123
}
124
}
125
}
126
127
// map_builder calls
128
for
(
auto
const
pro : elevation_profile) {
129
map_builder.
AddRoadElevationProfile
(pro.road, pro.s, pro.a, pro.b, pro.c, pro.d);
130
}
131
/// @todo superelevation and crossfall still need RoadInfo classes.
132
for
(
auto
const
pro : lateral_profile) {
133
if
(pro.type ==
"shape"
) {
134
map_builder.
AddRoadLateralShape
(pro.road, pro.s, pro.a, pro.b, pro.c,
135
pro.d, pro.shape.t);
136
}
137
}
138
}
139
140
}
// namespace parser
141
}
// namespace opendrive
142
}
// namespace carla
MapBuilder.h
ProfilesParser.h
carla::opendrive::parser::ProfilesParser::Parse
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
Definition
ProfilesParser.cpp:46
carla::road::MapBuilder
Definition
MapBuilder.h:22
carla::road::MapBuilder::AddRoadLateralShape
void AddRoadLateralShape(Road *road, const double s, const double a, const double b, const double c, const double d, const double t)
Definition
MapBuilder.cpp:89
carla::road::MapBuilder::AddRoadElevationProfile
void AddRoadElevationProfile(Road *road, const double s, const double a, const double b, const double c, const double d)
Definition
MapBuilder.cpp:77
carla::road::MapBuilder::GetRoad
Road * GetRoad(const RoadId road_id)
Definition
MapBuilder.cpp:665
carla::road::Road
Definition
road/Road.h:32
pugi::xml_document
Definition
pugixml.hpp:997
pugi::xml_node
Definition
pugixml.hpp:451
pugi::xml_node::child
xml_node child(const char_t *name) const
Definition
pugixml.cpp:5490
pugi::xml_node::children
xml_object_range< xml_node_iterator > children() const
Definition
pugixml.cpp:5425
carla::opendrive::parser
Definition
ControllerParser.cpp:15
carla::opendrive
Definition
OpenDriveParser.cpp:25
carla::road::RoadId
uint32_t RoadId
Definition
RoadTypes.h:15
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
pugixml.hpp
carla::opendrive::parser::ElevationProfile
Definition
ProfilesParser.cpp:17
carla::opendrive::parser::ElevationProfile::s
double s
Definition
ProfilesParser.cpp:19
carla::opendrive::parser::ElevationProfile::b
double b
Definition
ProfilesParser.cpp:21
carla::opendrive::parser::ElevationProfile::c
double c
Definition
ProfilesParser.cpp:22
carla::opendrive::parser::ElevationProfile::d
double d
Definition
ProfilesParser.cpp:23
carla::opendrive::parser::ElevationProfile::road
carla::road::Road * road
Definition
ProfilesParser.cpp:18
carla::opendrive::parser::ElevationProfile::a
double a
Definition
ProfilesParser.cpp:20
carla::opendrive::parser::LateralCrossfall
Definition
ProfilesParser.cpp:26
carla::opendrive::parser::LateralCrossfall::side
std::string side
Definition
ProfilesParser.cpp:27
carla::opendrive::parser::LateralProfile
Definition
ProfilesParser.cpp:34
carla::opendrive::parser::LateralProfile::type
std::string type
Definition
ProfilesParser.cpp:41
carla::opendrive::parser::LateralProfile::s
double s
Definition
ProfilesParser.cpp:36
carla::opendrive::parser::LateralProfile::b
double b
Definition
ProfilesParser.cpp:38
carla::opendrive::parser::LateralProfile::cross
LateralCrossfall cross
Definition
ProfilesParser.cpp:42
carla::opendrive::parser::LateralProfile::a
double a
Definition
ProfilesParser.cpp:37
carla::opendrive::parser::LateralProfile::road
carla::road::Road * road
Definition
ProfilesParser.cpp:35
carla::opendrive::parser::LateralProfile::c
double c
Definition
ProfilesParser.cpp:39
carla::opendrive::parser::LateralProfile::shape
LateralShape shape
Definition
ProfilesParser.cpp:43
carla::opendrive::parser::LateralProfile::d
double d
Definition
ProfilesParser.cpp:40
carla::opendrive::parser::LateralShape
Definition
ProfilesParser.cpp:30
carla::opendrive::parser::LateralShape::t
double t
Definition
ProfilesParser.cpp:31
Generated by
1.18.0