CARLA
 
载入中...
搜索中...
未找到
GeometryParser.cpp
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// 参考:https://www.cnblogs.com/aixing/p/16225067.html
5//
6// This work is licensed under the terms of the MIT license.
7// For a copy, see <https://opensource.org/licenses/MIT>.
8
10
12
13#include <pugixml/pugixml.hpp>
14
15namespace carla {
16namespace opendrive {
17namespace parser {
18
20
21 // 弧线描述了有着恒定曲率(curvature)的道路参考线。
22 // 在OpenDRIVE中,弧线用<geometry> 元素里的<arc>元素来表示。
23 // 正曲率:左曲线(逆时针运动)
24 // 负曲率:右曲线(顺时针运动)
25 struct GeometryArc {
26 double curvature { 0.0 }; // 贯穿元素的恒定曲率(单位:1/m)
27 };
28
29 // 螺旋线是以起始位置的曲率(@curvStart)和结束位置的曲率(@curvEnd)为特征。
30 // 沿着螺旋线的弧形长度(见 <geometry> 元素@length),曲率从头至尾呈线性。
32 double curvStart { 0.0 }; // 起始位置的曲率
33 double curvEnd { 0.0 }; // 结束位置的曲率
34 };
35
36 // 局部三次多项式表达式:v(u) = a + b*u + c*u^2 + d*u^3
37 // 在OpenDRIVE中,三次多项式用 <geometry> 元素里的 <poly3> 元素来表示。
39 double a { 0.0 };
40 double b { 0.0 };
41 double c { 0.0 };
42 double d { 0.0 };
43 };
44
45 // 参数三次曲线表达式:
46 // u(p) = aU + bU*p + cU*p^2 + dU*p^3
47 // v(p) = aV + bV * p + cV * p^2 + dV * p^3
48 // 在OpenDRIVE中,参数三次曲线用 <geometry> 元素里的 <paramPoly3> 元素来表示。
50 double aU { 0.0 };
51 double bU { 0.0 };
52 double cU { 0.0 };
53 double dU { 0.0 };
54 double aV { 0.0 };
55 double bV { 0.0 };
56 double cV { 0.0 };
57 double dV { 0.0 };
58 std::string p_range { "arcLength" };
59 };
60
61 struct Geometry {
63 double s { 0.0 };
64 double x { 0.0 };
65 double y { 0.0 };
66 double hdg { 0.0 };
67 double length { 0.0 };
68 std::string type { "line" };
73 };
74
75 // 几何构造解析器
77 const pugi::xml_document &xml,
78 carla::road::MapBuilder &map_builder) {
79
80 std::vector<Geometry> geometry;
81
82 for (pugi::xml_node node_road : xml.child("OpenDRIVE").children("road")) {
83
84 // 解析规划视图
85 pugi::xml_node node_plan_view = node_road.child("planView");
86 if (node_plan_view) {
87 // 所有的几何构造
88 for (pugi::xml_node node_geo : node_plan_view.children("geometry")) {
89 Geometry geo;
90
91 // 获取路的 id
92 geo.road_id = node_road.attribute("id").as_uint();
93
94 // 获取常用属性:geometry 标签中共有 5 个属性:https://cniter.github.io/posts/b7d79231.html
95 geo.s = node_geo.attribute("s").as_double(); // 该段 geometry 沿参考线起始(start)位置
96 geo.x = node_geo.attribute("x").as_double(); // 该段 geometry 在惯性坐标系下起始横坐标
97 geo.y = node_geo.attribute("y").as_double(); // 该段 geometry 在惯性坐标系下起始纵坐标
98 geo.hdg = node_geo.attribute("hdg").as_double(); // 该段 geometry 在惯性坐标系下起始弧度
99 geo.length = node_geo.attribute("length").as_double(); // 该段 geometry 长度
100
101 // 检查几何构造的类型:直线、螺旋线、圆弧线、三次曲线、参数化三次曲线
102 pugi::xml_node node = node_geo.first_child();
103 geo.type = node.name();
104 if (geo.type == "arc") { // 圆弧线 arcs
105 geo.arc.curvature = node.attribute("curvature").as_double();
106 } else if (geo.type == "spiral") { // 螺旋线 spirals
107 geo.spiral.curvStart = node.attribute("curvStart").as_double();
108 geo.spiral.curvEnd = node.attribute("curvEnd").as_double();
109 } else if (geo.type == "poly3") { // 三次曲线 cubic polynomials
110 geo.poly3.a = node.attribute("a").as_double();
111 geo.poly3.b = node.attribute("b").as_double();
112 geo.poly3.c = node.attribute("c").as_double();
113 geo.poly3.d = node.attribute("d").as_double();
114 } else if (geo.type == "paramPoly3") { // 参数化三次曲线 parametric cubic polynomials
115 geo.param_poly3.aU = node.attribute("aU").as_double();
116 geo.param_poly3.bU = node.attribute("bU").as_double();
117 geo.param_poly3.cU = node.attribute("cU").as_double();
118 geo.param_poly3.dU = node.attribute("dU").as_double();
119 geo.param_poly3.aV = node.attribute("aV").as_double();
120 geo.param_poly3.bV = node.attribute("bV").as_double();
121 geo.param_poly3.cV = node.attribute("cV").as_double();
122 geo.param_poly3.dV = node.attribute("dV").as_double();
123 geo.param_poly3.p_range = node.attribute("pRange").value();
124 }
125
126 // add it
127 geometry.emplace_back(geo);
128 }
129 }
130 }
131
132 // map_builder calls
133 for (auto const geo : geometry) {
134 carla::road::Road *road = map_builder.GetRoad(geo.road_id);
135 if (geo.type == "line") {
136 map_builder.AddRoadGeometryLine(road, geo.s, geo.x, geo.y, geo.hdg, geo.length);
137 } else if (geo.type == "arc") {
138 map_builder.AddRoadGeometryArc(road, geo.s, geo.x, geo.y, geo.hdg, geo.length, geo.arc.curvature);
139 } else if (geo.type == "spiral") {
140 map_builder.AddRoadGeometrySpiral(road,
141 geo.s,
142 geo.x,
143 geo.y,
144 geo.hdg,
145 geo.length,
146 geo.spiral.curvStart,
147 geo.spiral.curvEnd);
148 } else if (geo.type == "poly3") {
149 map_builder.AddRoadGeometryPoly3(road,
150 geo.s,
151 geo.x,
152 geo.y,
153 geo.hdg,
154 geo.length,
155 geo.poly3.a,
156 geo.poly3.b,
157 geo.poly3.c,
158 geo.poly3.d);
159 } else if (geo.type == "paramPoly3") {
160 map_builder.AddRoadGeometryParamPoly3(road,
161 geo.s,
162 geo.x,
163 geo.y,
164 geo.hdg,
165 geo.length,
166 geo.param_poly3.aU,
167 geo.param_poly3.bU,
168 geo.param_poly3.cU,
169 geo.param_poly3.dU,
170 geo.param_poly3.aV,
171 geo.param_poly3.bV,
172 geo.param_poly3.cV,
173 geo.param_poly3.dV,
174 geo.param_poly3.p_range);
175 }
176 }
177 }
178
179} // namespace parser
180} // namespace opendrive
181} // namespace carla
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
解析XML文档中的几何信息并构建道路地图
void AddRoadGeometryArc(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvature)
void AddRoadGeometryParamPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double aU, const double bU, const double cU, const double dU, const double aV, const double bV, const double cV, const double dV, const std::string p_range)
void AddRoadGeometryPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double a, const double b, const double c, const double d)
Road * GetRoad(const RoadId road_id)
void AddRoadGeometrySpiral(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvStart, const double curvEnd)
void AddRoadGeometryLine(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length)
double as_double(double def=0) const
Definition pugixml.cpp:5373
const char_t * value() const
Definition pugixml.cpp:5410
xml_node child(const char_t *name) const
Definition pugixml.cpp:5685
xml_node first_child() const
Definition pugixml.cpp:5817
xml_object_range< xml_node_iterator > children() const
Definition pugixml.cpp:5620
xml_attribute attribute(const char_t *name) const
Definition pugixml.cpp:5695
const char_t * name() const
Definition pugixml.cpp:5670
uint32_t RoadId
Definition RoadTypes.h:20
CARLA模拟器的主命名空间。
Definition Carla.cpp:139