CARLA
 
载入中...
搜索中...
未找到
GeoReferenceParser.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
7#include "carla/opendrive/parser/GeoReferenceParser.h" // 引入 GeoReferenceParser 头文件
8
9#include "carla/Logging.h" // 引入日志功能
10#include "carla/StringUtil.h" // 引入字符串工具
11#include "carla/geom/GeoLocation.h" // 引入地理位置类
12#include "carla/road/MapBuilder.h" // 引入地图构建器
13
14#include <pugixml/pugixml.hpp> // 引入 XML 解析库
15
16#include <limits> // 引入数值限制
17#include <string> // 引入字符串处理
18#include <vector> // 引入向量容器
19
20namespace carla { // 定义 carla 命名空间
21namespace opendrive { // 定义 opendrive 命名空间
22namespace parser { // 定义 parser 命名空间
23
24 static double ParseDouble(const std::string &string_value) { // 静态函数,将字符串转换为双精度浮点数
25 return std::stod(string_value); // 使用 std::stod 转换
26 }
27
28 static geom::GeoLocation ParseGeoReference(const std::string &geo_reference_string) { // 静态函数,解析地理参考字符串
29 geom::GeoLocation result{ // 创建 GeoLocation 对象,初始化为 NaN
30 std::numeric_limits<double>::quiet_NaN(), // 纬度初始为 NaN
31 std::numeric_limits<double>::quiet_NaN(), // 经度初始为 NaN
32 0.0}; // 高度初始为 0.0
33
34 std::vector<std::string> geo_ref_splitted; // 创建字符串向量以存储拆分结果
35 StringUtil::Split(geo_ref_splitted, geo_reference_string, " "); // 按空格拆分 geo_reference_string
36
37 for (auto element: geo_ref_splitted) { // 遍历拆分后的每个元素
38 std::vector<std::string> geo_ref_key_value; // 创建键值对向量
39 StringUtil::Split(geo_ref_key_value, element, "="); // 按等号拆分元素
40 if (geo_ref_key_value.size() != 2u) { // 如果不是两个部分,则跳过
41 continue; // 继续下一个循环
42 }
43
44 if (geo_ref_key_value[0] == "+lat_0") { // 如果键是 +lat_0
45 result.latitude = ParseDouble(geo_ref_key_value[1]); // 解析并设置纬度
46 } else if (geo_ref_key_value[0] == "+lon_0") { // 如果键是 +lon_0
47 result.longitude = ParseDouble(geo_ref_key_value[1]); // 解析并设置经度
48 }
49 }
50
51 if (std::isnan(result.latitude) || std::isnan(result.longitude)) { // 如果纬度或经度仍为 NaN
52 log_warning("cannot parse georeference: '" + geo_reference_string + "'. Using default values."); // 记录警告日志
53 result.latitude = 42.0; // 使用默认纬度
54 result.longitude = 2.0; // 使用默认经度
55 }
56
57 log_debug("map geo reference: latitude ", result.latitude, ", longitude ", result.longitude); // 记录调试信息
58
59 return result; // 返回解析的 GeoLocation 对象
60 }
61
62 void GeoReferenceParser::Parse( // GeoReferenceParser 的 Parse 函数
63 const pugi::xml_document &xml, // 输入的 XML 文档
64 carla::road::MapBuilder &map_builder) { // 地图构建器的引用
65 map_builder.SetGeoReference(ParseGeoReference( // 设置地图的地理参考
66 xml.child("OpenDRIVE").child("header").child_value("geoReference"))); // 从 XML 中提取 geoReference 字段
67 }
68
69} // parser
70} // opendrive
71} // carla
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
Definition StringUtil.h:75
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
解析XML文档中的地理参考信息并构建道路地图 该函数读取XML文档中的地理参考数据,如坐标系统、投影信息 并使用这些信息来构建或更新道路地图
void SetGeoReference(const geom::GeoLocation &geo_reference)
Definition MapBuilder.h:359
xml_node child(const char_t *name) const
Definition pugixml.cpp:5685
const char_t * child_value() const
Definition pugixml.cpp:5787
static geom::GeoLocation ParseGeoReference(const std::string &geo_reference_string)
static double ParseDouble(const std::string &string_value)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
static void log_warning(Args &&... args)
Definition Logging.h:101
static void log_debug(Args &&... args)
Definition Logging.h:71
PUGI__FN xpath_string string_value(const xpath_node &na, xpath_allocator *alloc)
Definition pugixml.cpp:8044