MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / Load

Method Load

LibCarla/source/carla/sumonetwork/SumoNetwork.cpp:73–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73SumoNetwork SumoNetwork::Load(const std::string& file) {
74 std::ifstream ifs;
75 ifs.open(file, std::ios::in);
76 std::ostringstream ss;
77 ss << ifs.rdbuf();
78 ifs.close();
79
80 pugi::xml_document xml;
81 xml.load_string(ss.str().c_str());
82
83 SumoNetwork sumo_network;
84
85 pugi::xml_node net_node = xml.child("net");
86
87 pugi::xml_node location_node = net_node.child("location");
88 sumo_network._offset = parse_coordinates(location_node.attribute("netOffset").value());
89
90 std::pair<geom::Vector2D, geom::Vector2D> bounds = parse_bounds(location_node.attribute("convBoundary").value());
91 sumo_network._bounds_min = bounds.first;
92 sumo_network._bounds_max = bounds.second;
93
94 // origBoundary: LonLat -> (parse_bounds swaps) -> LatLon
95 std::pair<geom::Vector2D, geom::Vector2D> originalBounds = parse_bounds(location_node.attribute("origBoundary").value());
96 sumo_network._original_bounds_min = originalBounds.first;
97 sumo_network._original_bounds_max = originalBounds.second;
98
99 for (pugi::xml_node edge_node : net_node.children("edge")) {
100 Edge edge;
101 edge.id = edge_node.attribute("id").value();
102 edge.from = edge_node.attribute("from").value();
103 edge.to = edge_node.attribute("to").value();
104 edge.priority = edge_node.attribute("priority").as_int();
105 std::string function = edge_node.attribute("function").value();
106 if (function == "internal") edge.function = Function::Internal;
107 else if (function == "connector") edge.function = Function::Connector;
108 else if (function == "crossing") edge.function = Function::Crossing;
109 else if (function == "walkingarea") edge.function = Function::WalkingArea;
110 else edge.function = Function::Normal;
111
112 // Temp vector required because order of lanes read do not necessarily match
113 // order of their indexes.
114 std::vector<Lane> lanes_temp;
115 for (pugi::xml_node lane_node : edge_node.children("lane")) {
116 Lane lane;
117 lane.id = lane_node.attribute("id").value();
118 lane.index = lane_node.attribute("index").as_uint();
119 lane.speed = lane_node.attribute("speed").as_float();
120 lane.length = lane_node.attribute("length").as_float();
121 lane.shape = parse_shape_list(lane_node.attribute("shape").value());
122 lanes_temp.emplace_back(std::move(lane));
123 }
124 edge.lanes.resize(lanes_temp.size());
125 // TODO: Check if sorting passes or there are invalid instances, e.g. indexes
126 // that exceed the bounds of the number of lanes.
127 for (size_t i = 0; i < lanes_temp.size(); i++) {
128 edge.lanes[lanes_temp[i].index] = std::move(lanes_temp[i]);
129 }
130

Callers

nothing calls this directly

Calls 15

parse_coordinatesFunction · 0.85
parse_boundsFunction · 0.85
parse_shape_listFunction · 0.85
parse_string_listFunction · 0.85
load_stringMethod · 0.80
childMethod · 0.80
valueMethod · 0.80
attributeMethod · 0.80
childrenMethod · 0.80
as_intMethod · 0.80
as_uintMethod · 0.80
as_floatMethod · 0.80

Tested by

no test coverage detected