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

Method Parse

LibCarla/source/carla/opendrive/parser/RoadParser.cpp:113–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111 }
112
113 void RoadParser::Parse(
114 const pugi::xml_document &xml,
115 carla::road::MapBuilder &map_builder) {
116
117 std::vector<Road> roads;
118
119 for (pugi::xml_node node_road : xml.child("OpenDRIVE").children("road")) {
120 Road road { 0, "", 0.0, -1, 0, 0, {}, {}, {} };
121
122 // attributes
123 road.id = node_road.attribute("id").as_uint();
124 road.name = node_road.attribute("name").value();
125 road.length = node_road.attribute("length").as_double();
126 road.junction_id = node_road.attribute("junction").as_int();
127
128 // link
129 pugi::xml_node link = node_road.child("link");
130 if (link) {
131 if (link.child("predecessor")) {
132 road.predecessor = link.child("predecessor").attribute("elementId").as_uint();
133 }
134 if (link.child("successor")) {
135 road.successor = link.child("successor").attribute("elementId").as_uint();
136 }
137 }
138
139 // types
140 for (pugi::xml_node node_type : node_road.children("type")) {
141 RoadTypeSpeed type { 0.0, "", 0.0, "" };
142
143 type.s = node_type.attribute("s").as_double();
144 type.type = node_type.attribute("type").value();
145
146 // speed type
147 pugi::xml_node speed = node_type.child("speed");
148 if (speed) {
149 type.max = speed.attribute("max").as_double();
150 type.unit = speed.attribute("unit").value();
151 }
152
153 // add it
154 road.speed.emplace_back(type);
155 }
156
157 // section offsets
158 for (pugi::xml_node node_offset : node_road.child("lanes").children("laneOffset")) {
159 LaneOffset offset { 0.0, 0.0, 0.0, 0.0, 0.0 };
160 offset.s = node_offset.attribute("s").as_double();
161 offset.a = node_offset.attribute("a").as_double();
162 offset.b = node_offset.attribute("b").as_double();
163 offset.c = node_offset.attribute("c").as_double();
164 offset.d = node_offset.attribute("d").as_double();
165 road.section_offsets.emplace_back(offset);
166 }
167 // Add default lane offset if none is found
168 if(road.section_offsets.size() == 0) {
169 LaneOffset offset { 0.0, 0.0, 0.0, 0.0, 0.0 };
170 road.section_offsets.emplace_back(offset);

Callers

nothing calls this directly

Calls 15

StringToLaneTypeFunction · 0.85
childrenMethod · 0.80
childMethod · 0.80
as_uintMethod · 0.80
attributeMethod · 0.80
valueMethod · 0.80
as_doubleMethod · 0.80
as_intMethod · 0.80
as_boolMethod · 0.80
AddRoadMethod · 0.80
CreateRoadSpeedMethod · 0.80
CreateSectionOffsetMethod · 0.80

Tested by

no test coverage detected