CARLA
 
载入中...
搜索中...
未找到
ProfilesParser.cpp
浏览该文件的文档.
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
8
10
11#include <pugixml/pugixml.hpp>
12
13namespace carla {
14namespace opendrive {
15namespace parser {
16
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
27 std::string side { "both" };
28 };
29
30 struct LateralShape {
31 double t { 0.0 };
32 };
33
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" };
44 };
45
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")) {
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){
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: RoadInfo classes must be created to fit this information
132 // for (auto const pro : lateral_profile) {
133 // if (pro.type == "superelevation")
134 // map_builder.AddRoadLateralSuperElevation(pro.road, pro.s, pro.a,
135 // pro.b, pro.c, pro.d);
136 // else if (pro.type == "crossfall")
137 // map_builder.AddRoadLateralCrossfall(pro.road, pro.s, pro.a, pro.b,
138 // pro.c, pro.d, pro.cross.side);
139 // else if (pro.type == "shape")
140 // map_builder.AddRoadLateralShape(pro.road, pro.s, pro.a, pro.b, pro.c,
141 // pro.d, pro.shape.t);
142 // }
143 }
144
145} // namespace parser
146} // namespace opendrive
147} // namespace carla
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
void AddRoadElevationProfile(Road *road, const double s, const double a, const double b, const double c, const double d)
Road * GetRoad(const RoadId road_id)
xml_node child(const char_t *name) const
Definition pugixml.cpp:5490
xml_object_range< xml_node_iterator > children() const
Definition pugixml.cpp:5425
uint32_t RoadId
Definition RoadTypes.h:15
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133