SUMO - Simulation of Urban MObility
NIImporter_OpenDrive.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Importer for networks stored in openDrive format
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 #include <string>
34 #include <cmath>
35 #include <iterator>
39 #include <utils/common/ToString.h>
42 #include <netbuild/NBEdge.h>
43 #include <netbuild/NBEdgeCont.h>
44 #include <netbuild/NBNode.h>
45 #include <netbuild/NBNodeCont.h>
46 #include <netbuild/NBNetBuilder.h>
47 #include <netbuild/NBOwnTLDef.h>
55 #include <utils/xml/XMLSubSys.h>
56 #include <utils/geom/Boundary.h>
57 #include "NILoader.h"
58 #include "NIImporter_OpenDrive.h"
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 
65 // ===========================================================================
66 // definitions
67 // ===========================================================================
68 #define C_LENGTH 10.
69 
70 // ===========================================================================
71 // static variables
72 // ===========================================================================
95 
97 };
98 
99 
131 
133 };
134 
135 
138 
139 // ===========================================================================
140 // method definitions
141 // ===========================================================================
142 // ---------------------------------------------------------------------------
143 // static methods (interface in this case)
144 // ---------------------------------------------------------------------------
145 void
147  // check whether the option is set (properly)
148  if (!oc.isUsableFileList("opendrive-files")) {
149  return;
150  }
151  // prepare types
152  myImportAllTypes = oc.getBool("opendrive.import-all-lanes");
153  myImportWidths = !oc.getBool("opendrive.ignore-widths");
154  NBTypeCont& tc = nb.getTypeCont();
155  // build the handler
156  std::map<std::string, OpenDriveEdge*> edges;
157  NIImporter_OpenDrive handler(nb.getTypeCont(), edges);
158  // parse file(s)
159  std::vector<std::string> files = oc.getStringVector("opendrive-files");
160  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
161  if (!FileHelpers::isReadable(*file)) {
162  WRITE_ERROR("Could not open opendrive file '" + *file + "'.");
163  return;
164  }
165  handler.setFileName(*file);
166  PROGRESS_BEGIN_MESSAGE("Parsing opendrive from '" + *file + "'");
167  XMLSubSys::runParser(handler, *file);
169  }
170  // split inner/outer edges
171  std::map<std::string, OpenDriveEdge*> innerEdges, outerEdges;
172  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
173  if ((*i).second->isInner) {
174  innerEdges[(*i).first] = (*i).second;
175  } else {
176  outerEdges[(*i).first] = (*i).second;
177  }
178  }
179 
180  // convert geometries into a discretised representation
181  computeShapes(edges);
182  // check whether lane sections are valid and whether further must be introduced
183  revisitLaneSections(tc, edges);
184 
185  // -------------------------
186  // node building
187  // -------------------------
188  // build nodes#1
189  // look at all links which belong to a node, collect their bounding boxes
190  // and place the node in the middle of this bounding box
191  std::map<std::string, Boundary> posMap;
192  std::map<std::string, std::string> edge2junction;
193  // compute node positions
194  for (std::map<std::string, OpenDriveEdge*>::iterator i = innerEdges.begin(); i != innerEdges.end(); ++i) {
195  OpenDriveEdge* e = (*i).second;
196  assert(e->junction != "-1" && e->junction != "");
197  edge2junction[e->id] = e->junction;
198  if (posMap.find(e->junction) == posMap.end()) {
199  posMap[e->junction] = Boundary();
200  }
201  posMap[e->junction].add(e->geom.getBoxBoundary());
202  }
203  // build nodes
204  for (std::map<std::string, Boundary>::iterator i = posMap.begin(); i != posMap.end(); ++i) {
205  if (!nb.getNodeCont().insert((*i).first, (*i).second.getCenter())) {
206  throw ProcessError("Could not add node '" + (*i).first + "'.");
207  }
208  }
209  // assign built nodes
210  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
211  OpenDriveEdge* e = (*i).second;
212  for (std::vector<OpenDriveLink>::iterator j = e->links.begin(); j != e->links.end(); ++j) {
213  OpenDriveLink& l = *j;
214  const std::string& nid = l.elementID;
215  if (l.elementType != OPENDRIVE_ET_ROAD) {
216  if (nb.getNodeCont().retrieve(nid) == 0) {
217  // not yet seen, build (possibly a junction without connections)
218  Position pos = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e->geom[-1] : e->geom[0];
219  if (!nb.getNodeCont().insert(nid, pos)) {
220  throw ProcessError("Could not build node '" + nid + "'.");
221  }
222  }
223  // set node information
225  continue;
226  }
227  if (edge2junction.find(l.elementID) != edge2junction.end()) {
228  // set node information of an internal road
229  setNodeSecure(nb.getNodeCont(), *e, edge2junction[l.elementID], l.linkType);
230  continue;
231  }
232  }
233  }
234  // we should now have all nodes set for links which are not outer edge-to-outer edge links
235 
236 
237  // build nodes#2
238  // build nodes for all outer edge-to-outer edge connections
239  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
240  OpenDriveEdge* e = (*i).second;
241  for (std::vector<OpenDriveLink>::iterator j = e->links.begin(); j != e->links.end(); ++j) {
242  OpenDriveLink& l = *j;
243  if (l.elementType != OPENDRIVE_ET_ROAD || edge2junction.find(l.elementID) != edge2junction.end()) {
244  // is a connection to an internal edge, or a node, skip
245  continue;
246  }
247  // we have a direct connection between to external edges
248  std::string id1 = e->id;
249  std::string id2 = l.elementID;
250  if (id1 < id2) {
251  std::swap(id1, id2);
252  }
253  std::string nid = id1 + "." + id2;
254  if (nb.getNodeCont().retrieve(nid) == 0) {
255  // not yet seen, build
256  Position pos = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e->geom[-1] : e->geom[0];
257  if (!nb.getNodeCont().insert(nid, pos)) {
258  throw ProcessError("Could not build node '" + nid + "'.");
259  }
260  }
261  /* debug-stuff
262  else {
263  Position pos = l.linkType==OPENDRIVE_LT_SUCCESSOR ? e.geom[e.geom.size()-1] : e.geom[0];
264  cout << nid << " " << pos << " " << nb.getNodeCont().retrieve(nid)->getPosition() << endl;
265  }
266  */
267  setNodeSecure(nb.getNodeCont(), *e, nid, l.linkType);
268  }
269  }
270  // we should now have start/end nodes for all outer edge-to-outer edge connections
271 
272 
273  // build nodes#3
274  // assign further nodes generated from inner-edges
275  // these nodes have not been assigned earlier, because the connections are referenced in inner-edges
276  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
277  OpenDriveEdge* e = (*i).second;
278  if (e->to != 0 && e->from != 0) {
279  continue;
280  }
281  for (std::map<std::string, OpenDriveEdge*>::iterator j = innerEdges.begin(); j != innerEdges.end(); ++j) {
282  OpenDriveEdge* ie = (*j).second;
283  for (std::vector<OpenDriveLink>::iterator k = ie->links.begin(); k != ie->links.end(); ++k) {
284  OpenDriveLink& il = *k;
285  if (il.elementType != OPENDRIVE_ET_ROAD || il.elementID != e->id) {
286  // not conneted to the currently investigated outer edge
287  continue;
288  }
289  std::string nid = edge2junction[ie->id];
290  if (il.contactPoint == OPENDRIVE_CP_START) {
292  } else {
294  }
295  }
296  }
297 
298  }
299 
300  // build start/end nodes which were not defined previously
301  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
302  OpenDriveEdge* e = (*i).second;
303  if (e->from == 0) {
304  const std::string nid = e->id + ".begin";
305  e->from = getOrBuildNode(nid, e->geom.front(), nb.getNodeCont());
306  }
307  if (e->to == 0) {
308  const std::string nid = e->id + ".end";
309  e->to = getOrBuildNode(nid, e->geom.back(), nb.getNodeCont());
310  }
311  }
312 
313 
314  // -------------------------
315  // edge building
316  // -------------------------
317  SUMOReal defaultSpeed = tc.getSpeed("");
318  // build edges
319  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
320  OpenDriveEdge* e = (*i).second;
321  bool lanesBuilt = false;
322 
323  // go along the lane sections, build a node in between of each pair
324 
327 
329  NBNode* sFrom = e->from;
330  NBNode* sTo = e->to;
331  int priorityR = e->getPriority(OPENDRIVE_TAG_RIGHT);
332  int priorityL = e->getPriority(OPENDRIVE_TAG_LEFT);
333  SUMOReal sB = 0;
334  SUMOReal sE = e->length;
335  // 0-length geometries are possible if only the inner points are represented
336  const SUMOReal length2D = e->geom.length2D();
337  SUMOReal cF = length2D == 0 ? 1 : e->length / length2D;
338  NBEdge* prevRight = 0;
339  NBEdge* prevLeft = 0;
340 
341  // starting at the same node as ending, and no lane sections?
342  if (sFrom == sTo && e->laneSections.size() == 1) {
343  // --> loop, split!
345  ls.s = e->length / 2.;
346  e->laneSections.push_back(ls);
347  WRITE_WARNING("Edge '" + e->id + "' has to be split as it connects same junctions.")
348  }
349 
350  // build along lane sections
351  for (std::vector<OpenDriveLaneSection>::iterator j = e->laneSections.begin(); j != e->laneSections.end(); ++j) {
352  // add internal node if needed
353  if (j == e->laneSections.end() - 1) {
354  sTo = e->to;
355  sE = e->length / cF;
356  } else {
357  SUMOReal nextS = (j + 1)->s;
358  sTo = new NBNode(e->id + "." + toString(nextS), e->geom.positionAtOffset(nextS));
359  if (!nb.getNodeCont().insert(sTo)) {
360  throw ProcessError("Could not add node '" + sTo->getID() + "'.");
361  }
362  sE = nextS / cF;
363  }
364  PositionVector geom = e->geom.getSubpart2D(sB, sE);
365  std::string id = e->id;
366  if (sFrom != e->from || sTo != e->to) {
367  id = id + "." + toString((*j).s);
368  } else if (e->laneSections.size() == 1) {
369  id = id + ".0.00";
370  }
371 
372  // build lanes to right
373  NBEdge* currRight = 0;
374  if ((*j).rightLaneNumber > 0) {
375  currRight = new NBEdge("-" + id, sFrom, sTo, "", defaultSpeed, (*j).rightLaneNumber, priorityR,
377  if (!nb.getEdgeCont().insert(currRight)) {
378  throw ProcessError("Could not add edge '" + currRight->getID() + "'.");
379  }
380  lanesBuilt = true;
381  const std::vector<OpenDriveLane>& lanes = (*j).lanesByDir[OPENDRIVE_TAG_RIGHT];
382  for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
383  std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
384  if (lp != (*j).laneMap.end()) {
385  int sumoLaneIndex = lp->second;
386  NBEdge::Lane& sumoLane = currRight->getLaneStruct(sumoLaneIndex);
387  const OpenDriveLane& odLane = *k;
388 
389  sumoLane.origID = e->id + " -" + toString((*k).id);
390  sumoLane.speed = odLane.speed != 0 ? odLane.speed : tc.getSpeed(odLane.type);
391  sumoLane.permissions = tc.getPermissions(odLane.type);
392  sumoLane.width = myImportWidths && odLane.width != 0 ? odLane.width : tc.getWidth(odLane.type);
393  }
394  }
395  // connect lane sections
396  if (prevRight != 0) {
397  std::map<int, int> connections = (*j).getInnerConnections(OPENDRIVE_TAG_RIGHT, *(j - 1));
398  for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
399  prevRight->addLane2LaneConnection((*k).first, currRight, (*k).second, NBEdge::L2L_VALIDATED);
400  }
401  }
402  prevRight = currRight;
403  }
404 
405  // build lanes to left
406  NBEdge* currLeft = 0;
407  if ((*j).leftLaneNumber > 0) {
408  currLeft = new NBEdge(id, sTo, sFrom, "", defaultSpeed, (*j).leftLaneNumber, priorityL,
410  if (!nb.getEdgeCont().insert(currLeft)) {
411  throw ProcessError("Could not add edge '" + currLeft->getID() + "'.");
412  }
413  lanesBuilt = true;
414  const std::vector<OpenDriveLane>& lanes = (*j).lanesByDir[OPENDRIVE_TAG_LEFT];
415  for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
416  std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
417  if (lp != (*j).laneMap.end()) {
418  int sumoLaneIndex = lp->second;
419  NBEdge::Lane& sumoLane = currLeft->getLaneStruct(sumoLaneIndex);
420  const OpenDriveLane& odLane = *k;
421 
422  sumoLane.origID = e->id + " " + toString((*k).id);
423  sumoLane.speed = odLane.speed != 0 ? odLane.speed : tc.getSpeed(odLane.type);
424  sumoLane.permissions = tc.getPermissions(odLane.type);
425  sumoLane.width = myImportWidths && odLane.width != 0 ? odLane.width : tc.getWidth(odLane.type);
426  }
427  }
428  // connect lane sections
429  if (prevLeft != 0) {
430  std::map<int, int> connections = (*j).getInnerConnections(OPENDRIVE_TAG_LEFT, *(j - 1));
431  for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
432  currLeft->addLane2LaneConnection((*k).first, prevLeft, (*k).second, NBEdge::L2L_VALIDATED);
433  }
434  }
435  prevLeft = currLeft;
436  }
437  (*j).sumoID = id;
438 
439 
440  sB = sE;
441  sFrom = sTo;
442  }
443  if (!lanesBuilt) {
444  WRITE_WARNING("Edge '" + e->id + "' has no lanes.");
445  }
446  }
447 
448  // -------------------------
449  // connections building
450  // -------------------------
451  // generate explicit lane-to-lane connections
452  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
453  setEdgeLinks2(*(*i).second, edges);
454  }
455  // compute connections across intersections, if any
456  std::vector<Connection> connections2;
457  for (std::map<std::string, OpenDriveEdge*>::iterator j = edges.begin(); j != edges.end(); ++j) {
458  const std::set<Connection>& conns = (*j).second->connections;
459 
460  for (std::set<Connection>::const_iterator i = conns.begin(); i != conns.end(); ++i) {
461  if (innerEdges.find((*i).fromEdge) != innerEdges.end()) {
462  // connections starting at inner edges are processed by starting from outer edges
463  continue;
464  }
465  if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
466  buildConnectionsToOuter(*i, innerEdges, connections2);
467  } else {
468  connections2.push_back(*i);
469  }
470  }
471  }
472  // set connections
473  for (std::vector<Connection>::const_iterator i = connections2.begin(); i != connections2.end(); ++i) {
474  std::string fromEdge = (*i).fromEdge;
475  if (edges.find(fromEdge) == edges.end()) {
476  WRITE_WARNING("While setting connections: from-edge '" + fromEdge + "' is not known.");
477  continue;
478  }
479  OpenDriveEdge* odFrom = edges[fromEdge];
480  int fromLane = (*i).fromLane;
481  bool fromLast = ((*i).fromCP == OPENDRIVE_CP_END) ^ ((*i).fromLane > 0 && !(*i).all);
482  fromEdge = fromLast ? odFrom->laneSections.back().sumoID : odFrom->laneSections[0].sumoID;
483 
484  std::string toEdge = (*i).toEdge;
485  if (edges.find(toEdge) == edges.end()) {
486  WRITE_WARNING("While setting connections: to-edge '" + toEdge + "' is not known.");
487  continue;
488  }
489 
490  OpenDriveEdge* odTo = edges[toEdge];
491  int toLane = (*i).toLane;
492  bool toLast = ((*i).toCP == OPENDRIVE_CP_END) || ((*i).toLane > 0);
493  toEdge = toLast ? odTo->laneSections.back().sumoID : odTo->laneSections[0].sumoID;
494 
495  if (fromLane == UNSET_CONNECTION) {
496  fromLane = toLast ? odTo->laneSections.back().laneMap.begin()->first : odTo->laneSections[0].laneMap.begin()->first;
497  }
498  if (fromLane < 0) {
499  fromEdge = revertID(fromEdge);
500  }
501  if (toLane == UNSET_CONNECTION) {
502  toLane = toLast ? odTo->laneSections.back().laneMap.begin()->first : odTo->laneSections[0].laneMap.begin()->first;
503  }
504  if (toLane < 0) {
505  toEdge = revertID(toEdge);
506  }
507  fromLane = fromLast ? odFrom->laneSections.back().laneMap[fromLane] : odFrom->laneSections[0].laneMap[fromLane];
508  toLane = toLast ? odTo->laneSections.back().laneMap[toLane] : odTo->laneSections[0].laneMap[toLane];
509  NBEdge* from = nb.getEdgeCont().retrieve(fromEdge);
510  NBEdge* to = nb.getEdgeCont().retrieve(toEdge);
511  if (from == 0) {
512  WRITE_WARNING("Could not find fromEdge representation of '" + fromEdge + "' in connection '" + (*i).origID + "'.");
513  }
514  if (to == 0) {
515  WRITE_WARNING("Could not find fromEdge representation of '" + toEdge + "' in connection '" + (*i).origID + "'.");
516  }
517  if (from == 0 || to == 0) {
518  continue;
519  }
520 
521  from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER);
522 
523  if ((*i).origID != "") {
524  // @todo: this is the most silly way to determine the connection
525  std::vector<NBEdge::Connection>& cons = from->getConnections();
526  for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); ++k) {
527  if ((*k).fromLane == fromLane && (*k).toEdge == to && (*k).toLane == toLane) {
528  (*k).origID = (*i).origID + " " + toString((*i).origLane);
529  break;
530  }
531  }
532  }
533  }
534 
535 
536  // -------------------------
537  // traffic lights
538  // -------------------------
539  std::map<std::string, std::string> tlsControlled;
540  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
541  OpenDriveEdge* e = (*i).second;
542  for (std::vector<OpenDriveSignal>::const_iterator j = e->signals.begin(); j != e->signals.end(); ++j) {
543  if ((*j).type != "1000001") { // traffic_light (Section 6.11)
544  continue;
545  }
546  std::vector<OpenDriveLaneSection>::iterator k = e->laneSections.begin();
547  bool found = false;
548  for (; k != e->laneSections.end() - 1 && !found;) {
549  if ((*j).s > (*k).s && (*j).s <= (*(k + 1)).s) {
550  found = true;
551  } else {
552  ++k;
553  }
554  }
555 
556  // @todo: major problem, currently, still not completely solved:
557  // inner edges may have traffic lights, too. Nice on one hand, as directions can be recognized
558  // but hard to follow backwards
559  std::string id = (*k).sumoID;
560  if (id == "") {
561  if (e->junction != "") {
562  //WRITE_WARNING("Found a traffic light signal on an internal edge; will not build it (original edge id='" + e->id + "').");
563  std::string fromID, toID;
564  for (std::vector<OpenDriveLink>::const_iterator l = e->links.begin(); l != e->links.end(); ++l) {
565  if ((*l).linkType == OPENDRIVE_LT_PREDECESSOR && (*l).elementType == OPENDRIVE_ET_ROAD) {
566  if (fromID != "") {
567  WRITE_WARNING("Ambigous start of connection.");
568  }
569  fromID = (*l).elementID;
570  OpenDriveEdge* e = edges[fromID];
571  fromID = (*l).contactPoint == OPENDRIVE_CP_START ? e->laneSections[0].sumoID : e->laneSections.back().sumoID;
572  }
573  if ((*l).linkType == OPENDRIVE_LT_SUCCESSOR && (*l).elementType == OPENDRIVE_ET_ROAD) {
574  if (toID != "") {
575  WRITE_WARNING("Ambigous end of connection.");
576  }
577  toID = (*l).elementID;
578  OpenDriveEdge* e = edges[toID];
579  toID = (*l).contactPoint == OPENDRIVE_CP_START ? e->laneSections[0].sumoID : e->laneSections.back().sumoID;
580  }
581  }
582  id = fromID + "->" + toID;
583  } else {
584  WRITE_WARNING("Found a traffic light signal on an unknown edge (original edge id='" + e->id + "').");
585  continue;
586  }
587  }
588 
589  if ((*j).orientation > 0) {
590  id = "-" + id;
591  }
592  tlsControlled[id] = (*j).name;
593  }
594  }
595 
596  for (std::map<std::string, std::string>::iterator i = tlsControlled.begin(); i != tlsControlled.end(); ++i) {
597  std::string id = (*i).first;
598  if (id.find("->") != std::string::npos) {
599  id = id.substr(0, id.find("->"));
600  }
601  NBEdge* e = nb.getEdgeCont().retrieve(id);
602  if (e == 0) {
603  WRITE_WARNING("Could not find edge '" + id + "' while building its traffic light.");
604  continue;
605  }
606  NBNode* toNode = e->getToNode();
607  NBTrafficLightDefinition* tlDef = 0;
608  if (!toNode->isTLControlled()) {
610  tlDef = new NBOwnTLDef(toNode->getID(), toNode, 0, type);
611  if (!nb.getTLLogicCont().insert(tlDef)) {
612  // actually, nothing should fail here
613  delete tlDef;
614  throw ProcessError();
615  }
616  toNode->addTrafficLight(tlDef);
617  static_cast<NBOwnTLDef*>(tlDef)->setSinglePhase();
618  }
619  tlDef = *toNode->getControllingTLS().begin();
620  tlDef->addParameter("connection:" + id, (*i).second);
621  }
622 
623  // -------------------------
624  // clean up
625  // -------------------------
626  if (oc.exists("geometry.min-dist") && oc.isSet("geometry.min-dist")) {
627  oc.unSet("geometry.min-dist");
628  }
629  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
630  delete(*i).second;
631  }
632 }
633 
634 
635 
636 void
637 NIImporter_OpenDrive::buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into) {
638 
639  OpenDriveEdge* dest = innerEdges.find(c.toEdge)->second;
640  if (dest == 0) {
642  return;
643  }
644  const std::set<Connection>& conts = dest->connections;
645  for (std::set<Connection>::const_iterator i = conts.begin(); i != conts.end(); ++i) {
646  if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
647  std::vector<Connection> t;
648  buildConnectionsToOuter(*i, innerEdges, t);
649  for (std::vector<Connection>::const_iterator j = t.begin(); j != t.end(); ++j) {
650  // @todo this section is unverified
651  Connection cn = (*j);
652  cn.fromEdge = c.fromEdge;
653  cn.fromLane = c.fromLane;
654  cn.fromCP = c.fromCP;
655  cn.all = c.all; // @todo "all" is a hack trying to avoid the "from is zero" problem;
656  into.push_back(cn);
657  }
658  } else {
659  if ((*i).fromLane == c.toLane) {
660  Connection cn = (*i);
661  cn.fromEdge = c.fromEdge;
662  cn.fromLane = c.fromLane;
663  cn.fromCP = c.fromCP;
664  cn.all = c.all;
665  cn.origID = c.toEdge;
666  cn.origLane = c.toLane;
667  into.push_back(cn);
668  }
669  }
670  }
671 }
672 
673 
674 void
675 NIImporter_OpenDrive::setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges) {
676  for (std::vector<OpenDriveLink>::iterator i = e.links.begin(); i != e.links.end(); ++i) {
677  OpenDriveLink& l = *i;
678  if (l.elementType != OPENDRIVE_ET_ROAD) {
679  // we assume that links to nodes are later given as connections to edges
680  continue;
681  }
682  // get the right direction of the connected edge
683  std::string connectedEdge = l.elementID;
684  std::string edgeID = e.id;
685 
686  OpenDriveLaneSection& laneSection = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e.laneSections.back() : e.laneSections[0];
687  const std::map<int, int>& laneMap = laneSection.laneMap;
688  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT) != laneSection.lanesByDir.end()) {
689  const std::vector<OpenDriveLane>& lanes = laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT)->second;
690  for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
691  if (!myImportAllTypes && laneMap.find((*j).id) == laneMap.end()) {
692  continue;
693  }
694  Connection c; // @todo: give Connection a new name and a constructor
695  c.fromEdge = e.id;
696  c.fromLane = (*j).id;
698  c.toLane = l.linkType == OPENDRIVE_LT_SUCCESSOR ? (*j).successor : (*j).predecessor;
699  c.toEdge = connectedEdge;
700  c.toCP = l.contactPoint;
701  c.all = false;
702  if (l.linkType != OPENDRIVE_LT_SUCCESSOR) {
703  std::swap(c.fromEdge, c.toEdge);
704  std::swap(c.fromLane, c.toLane);
705  std::swap(c.fromCP, c.toCP);
706  }
707  if (edges.find(c.fromEdge) == edges.end()) {
708  WRITE_ERROR("While setting connections: incoming road '" + c.fromEdge + "' is not known.");
709  } else {
710  OpenDriveEdge* src = edges.find(c.fromEdge)->second;
711  src->connections.insert(c);
712  }
713  }
714  }
715  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT) != laneSection.lanesByDir.end()) {
716  const std::vector<OpenDriveLane>& lanes = laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT)->second;
717  for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
718  if (!myImportAllTypes && laneMap.find((*j).id) == laneMap.end()) {
719  continue;
720  }
721  Connection c;
722  c.toEdge = e.id;
723  c.toLane = (*j).id;
725  c.fromLane = l.linkType == OPENDRIVE_LT_SUCCESSOR ? (*j).successor : (*j).predecessor;
726  c.fromEdge = connectedEdge;
727  c.fromCP = l.contactPoint;
728  c.all = false;
729  if (l.linkType != OPENDRIVE_LT_SUCCESSOR) {
730  std::swap(c.fromEdge, c.toEdge);
731  std::swap(c.fromLane, c.toLane);
732  std::swap(c.fromCP, c.toCP);
733  }
734  if (edges.find(c.fromEdge) == edges.end()) {
735  WRITE_ERROR("While setting connections: incoming road '" + c.fromEdge + "' is not known.");
736  } else {
737  OpenDriveEdge* src = edges.find(c.fromEdge)->second;
738  src->connections.insert(c);
739  }
740  }
741  }
742  }
743 }
744 
745 
746 std::string NIImporter_OpenDrive::revertID(const std::string& id) {
747  if (id[0] == '-') {
748  return id.substr(1);
749  }
750  return "-" + id;
751 }
752 
753 NBNode*
754 NIImporter_OpenDrive::getOrBuildNode(const std::string& id, const Position& pos,
755  NBNodeCont& nc) {
756  if (nc.retrieve(id) == 0) {
757  // not yet built; build now
758  if (!nc.insert(id, pos)) {
759  // !!! clean up
760  throw ProcessError("Could not add node '" + id + "'.");
761  }
762  }
763  return nc.retrieve(id);
764 }
765 
766 
767 void
769  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt) {
770  NBNode* n = nc.retrieve(nodeID);
771  if (n == 0) {
772  throw ProcessError("Could not find node '" + nodeID + "'.");
773  }
774  if (lt == OPENDRIVE_LT_SUCCESSOR) {
775  if (e.to != 0 && e.to != n) {
776  throw ProcessError("Edge '" + e.id + "' has two end nodes.");
777  }
778  e.to = n;
779  } else {
780  if (e.from != 0 && e.from != n) {
781  throw ProcessError("Edge '" + e.id + "' has two start nodes.");
782  }
783  e.from = n;
784  }
785 }
786 
787 
788 
789 
790 
791 
792 
793 void
794 NIImporter_OpenDrive::computeShapes(std::map<std::string, OpenDriveEdge*>& edges) {
796  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
797  OpenDriveEdge& e = *(*i).second;
799  for (std::vector<OpenDriveGeometry>::iterator j = e.geometries.begin(); j != e.geometries.end(); ++j) {
800  OpenDriveGeometry& g = *j;
801  PositionVector geom;
802  switch (g.type) {
804  break;
805  case OPENDRIVE_GT_LINE:
806  geom = geomFromLine(e, g);
807  break;
808  case OPENDRIVE_GT_SPIRAL:
809  geom = geomFromSpiral(e, g);
810  break;
811  case OPENDRIVE_GT_ARC:
812  geom = geomFromArc(e, g);
813  break;
814  case OPENDRIVE_GT_POLY3:
815  geom = geomFromPoly(e, g);
816  break;
817  default:
818  break;
819  }
820  if (e.geom.size() > 0 && prevType == OPENDRIVE_GT_LINE) {
821  // remove redundant end point of the previous geometry segment
822  // (the start point of the current segment should have the same value)
823  // this avoids geometry errors due to imprecision
824  if (!e.geom.back().almostSame(geom.front())) {
825  const int index = (int)(j - e.geometries.begin());
826  WRITE_WARNING("Mismatched geometry for edge '" + e.id + "' between geometry segments " + toString(index - 1) + " and " + toString(index) + ".");
827  }
828  e.geom.pop_back();
829  }
830  for (PositionVector::iterator k = geom.begin(); k != geom.end(); ++k) {
832  }
833  prevType = g.type;
834  }
835  if (oc.exists("geometry.min-dist") && oc.isSet("geometry.min-dist")) {
836  e.geom.removeDoublePoints(oc.getFloat("geometry.min-dist"), true);
837  }
838  for (unsigned int j = 0; j < e.geom.size(); ++j) {
840  WRITE_ERROR("Unable to project coordinates for.");
841  }
842  }
843  // add z-data
844  int k = 0;
845  SUMOReal pos = 0;
846  const SUMOReal length = e.geom.length2D();
847  for (std::vector<OpenDriveElevation>::iterator j = e.elevations.begin(); j != e.elevations.end(); ++j) {
848  const OpenDriveElevation& el = *j;
849  const SUMOReal sNext = (j + 1) == e.elevations.end() ? length : (*(j + 1)).s;
850  while (k < (int)e.geom.size() && pos <= sNext) {
851  if (k > 0) {
852  pos += e.geom[k - 1].distanceTo2D(e.geom[k]);
853  }
854  const SUMOReal ds = pos - el.s;
855  const SUMOReal z = el.a + el.b * ds + el.c * ds * ds + el.d * ds * ds * ds;
856  e.geom[k].add(0, 0, z);
857  k++;
858  }
859  }
860  }
861 }
862 
863 
864 void
865 NIImporter_OpenDrive::revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges) {
866  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
867  OpenDriveEdge& e = *(*i).second;
868  std::vector<OpenDriveLaneSection>& laneSections = e.laneSections;
869  // split by speed limits
870  std::vector<OpenDriveLaneSection> newSections;
871  for (std::vector<OpenDriveLaneSection>::iterator j = laneSections.begin(); j != laneSections.end(); ++j) {
872  std::vector<OpenDriveLaneSection> splitSections;
873  bool splitBySpeed = (*j).buildSpeedChanges(tc, splitSections);
874  if (!splitBySpeed) {
875  newSections.push_back(*j);
876  } else {
877  std::copy(splitSections.begin(), splitSections.end(), back_inserter(newSections));
878  }
879  }
880 
881  e.laneSections = newSections;
882  laneSections = e.laneSections;
883  SUMOReal lastS = -1;
884  // check whether the lane sections are in the right order
885  bool sorted = true;
886  for (std::vector<OpenDriveLaneSection>::const_iterator j = laneSections.begin(); j != laneSections.end() && sorted; ++j) {
887  if ((*j).s <= lastS) {
888  sorted = false;
889  }
890  lastS = (*j).s;
891  }
892  if (!sorted) {
893  WRITE_WARNING("The sections of edge '" + e.id + "' are not sorted properly.");
894  sort(e.laneSections.begin(), e.laneSections.end(), sections_by_s_sorter());
895  }
896  // check whether no duplicates of s-value occure
897  lastS = -1;
898  laneSections = e.laneSections;
899  for (std::vector<OpenDriveLaneSection>::iterator j = laneSections.begin(); j != laneSections.end();) {
900  bool simlarToLast = fabs((*j).s - lastS) < POSITION_EPS;
901  lastS = (*j).s;
902  if (simlarToLast) {
903  WRITE_WARNING("Almost duplicate s-value '" + toString(lastS) + "' for lane sections occured at edge '" + e.id + "'; second entry was removed.");
904  j = laneSections.erase(j);
905  } else {
906  ++j;
907  }
908  }
909  }
910 }
911 
912 
915  UNUSED_PARAMETER(e);
916  PositionVector ret;
917  ret.push_back(Position(g.x, g.y));
918  ret.push_back(calculateStraightEndPoint(g.hdg, g.length, Position(g.x, g.y)));
919  return ret;
920 }
921 
922 
925  UNUSED_PARAMETER(e);
926  PositionVector ret;
927  SUMOReal curveStart = g.params[0];
928  SUMOReal curveEnd = g.params[1];
929  Point2D<double> end;
930  try {
931  EulerSpiral s(Point2D<double>(g.x, g.y), g.hdg, curveStart, (curveEnd - curveStart) / g.length, g.length);
932  std::vector<Point2D<double> > into;
933  s.computeSpiral(into, 1.);
934  for (std::vector<Point2D<double> >::iterator i = into.begin(); i != into.end(); ++i) {
935  ret.push_back(Position((*i).getX(), (*i).getY()));
936  }
937  } catch (const std::runtime_error& error) {
938  WRITE_WARNING("Could not compute spiral geometry for edge '" + e.id + "' (" + error.what() + ").");
939  ret.push_back(Position(g.x, g.y));
940  }
941  return ret.getSubpart2D(0, g.length);
942 }
943 
944 
947  UNUSED_PARAMETER(e);
948  PositionVector ret;
949  SUMOReal dist = 0.0;
950  SUMOReal centerX = g.x;
951  SUMOReal centerY = g.y;
952  // left: positive value
953  SUMOReal curvature = g.params[0];
954  SUMOReal radius = 1. / curvature;
955  // center point
956  calculateCurveCenter(&centerX, &centerY, radius, g.hdg);
957  SUMOReal endX = g.x;
958  SUMOReal endY = g.y;
959  SUMOReal startX = g.x;
960  SUMOReal startY = g.y;
961  SUMOReal geo_posS = g.s;
962  SUMOReal geo_posE = g.s;
963  bool end = false;
964  do {
965  geo_posE += C_LENGTH;
966  if (geo_posE - g.s > g.length) {
967  geo_posE = g.s + g.length;
968  }
969  if (geo_posE - g.s > g.length) {
970  geo_posE = g.s + g.length;
971  }
972  calcPointOnCurve(&endX, &endY, centerX, centerY, radius, geo_posE - geo_posS);
973 
974  dist += (geo_posE - geo_posS);
975  //
976  ret.push_back(Position(startX, startY));
977  //
978  startX = endX;
979  startY = endY;
980  geo_posS = geo_posE;
981 
982  if (geo_posE - (g.s + g.length) < 0.001 && geo_posE - (g.s + g.length) > -0.001) {
983  end = true;
984  }
985  } while (!end);
986  return ret.getSubpart2D(0, g.length);
987 }
988 
989 
992  UNUSED_PARAMETER(e);
993  PositionVector ret;
994  for (SUMOReal off = 0; off < g.length + 2.; off += 2.) {
995  SUMOReal x = off;
996  SUMOReal y = g.params[0] + g.params[1] * off + g.params[2] * pow(off, 2.) + g.params[3] * pow(off, 3.);
997  SUMOReal s = sin(g.hdg);
998  SUMOReal c = cos(g.hdg);
999  SUMOReal xnew = x * c - y * s;
1000  SUMOReal ynew = x * s + y * c;
1001  ret.push_back(Position(g.x + xnew, g.y + ynew));
1002  }
1003  return ret.getSubpart2D(0, g.length);
1004 }
1005 
1006 
1007 Position
1008 NIImporter_OpenDrive::calculateStraightEndPoint(double hdg, double length, const Position& start) {
1009  double normx = 1.0f;
1010  double normy = 0.0f;
1011  double x2 = normx * cos(hdg) - normy * sin(hdg);
1012  double y2 = normx * sin(hdg) + normy * cos(hdg);
1013  normx = x2 * length;
1014  normy = y2 * length;
1015  return Position(start.x() + normx, start.y() + normy);
1016 }
1017 
1018 
1019 void
1021  SUMOReal normX = 1.0;
1022  SUMOReal normY = 0.0;
1023  SUMOReal tmpX;
1024  SUMOReal turn;
1025  if (ad_radius > 0) {
1026  turn = -1.0;
1027  } else {
1028  turn = 1.0;
1029  }
1030 
1031  tmpX = normX;
1032  normX = normX * cos(ad_hdg) + normY * sin(ad_hdg);
1033  normY = tmpX * sin(ad_hdg) + normY * cos(ad_hdg);
1034 
1035  tmpX = normX;
1036  normX = turn * normY;
1037  normY = -turn * tmpX;
1038 
1039  normX = fabs(ad_radius) * normX;
1040  normY = fabs(ad_radius) * normY;
1041 
1042  *ad_x += normX;
1043  *ad_y += normY;
1044 }
1045 
1046 
1047 void
1049  SUMOReal ad_r, SUMOReal ad_length) {
1050  double rotAngle = ad_length / fabs(ad_r);
1051  double vx = *ad_x - ad_centerX;
1052  double vy = *ad_y - ad_centerY;
1053  double tmpx;
1054 
1055  double turn;
1056  if (ad_r > 0) {
1057  turn = -1; //left
1058  } else {
1059  turn = 1; //right
1060  }
1061  tmpx = vx;
1062  vx = vx * cos(rotAngle) + turn * vy * sin(rotAngle);
1063  vy = -1 * turn * tmpx * sin(rotAngle) + vy * cos(rotAngle);
1064  *ad_x = vx + ad_centerX;
1065  *ad_y = vy + ad_centerY;
1066 }
1067 
1068 
1069 // ---------------------------------------------------------------------------
1070 // section
1071 // ---------------------------------------------------------------------------
1073  lanesByDir[OPENDRIVE_TAG_LEFT] = std::vector<OpenDriveLane>();
1074  lanesByDir[OPENDRIVE_TAG_RIGHT] = std::vector<OpenDriveLane>();
1075  lanesByDir[OPENDRIVE_TAG_CENTER] = std::vector<OpenDriveLane>();
1076 }
1077 
1078 
1079 void
1081  unsigned int sumoLane = 0;
1082  const std::vector<OpenDriveLane>& dirLanesR = lanesByDir.find(OPENDRIVE_TAG_RIGHT)->second;
1083  for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanesR.rbegin(); i != dirLanesR.rend(); ++i) {
1084  if (myImportAllTypes || (tc.knows((*i).type) && !tc.getShallBeDiscarded((*i).type))) {
1085  laneMap[(*i).id] = sumoLane++;
1086  }
1087  }
1088  rightLaneNumber = sumoLane;
1089  sumoLane = 0;
1090  const std::vector<OpenDriveLane>& dirLanesL = lanesByDir.find(OPENDRIVE_TAG_LEFT)->second;
1091  for (std::vector<OpenDriveLane>::const_iterator i = dirLanesL.begin(); i != dirLanesL.end(); ++i) {
1092  if (myImportAllTypes || (tc.knows((*i).type) && !tc.getShallBeDiscarded((*i).type))) {
1093  laneMap[(*i).id] = sumoLane++;
1094  }
1095  }
1096  leftLaneNumber = sumoLane;
1097 }
1098 
1099 
1100 std::map<int, int>
1102  std::map<int, int> ret;
1103  const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
1104  for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
1105  std::map<int, int>::const_iterator toP = laneMap.find((*i).id);
1106  if (toP == laneMap.end()) {
1107  // the current lane is not available in SUMO
1108  continue;
1109  }
1110  int to = (*toP).second;
1111  int from = UNSET_CONNECTION;
1112  if ((*i).predecessor != UNSET_CONNECTION) {
1113  from = (*i).predecessor;
1114  }
1115  if (from != UNSET_CONNECTION) {
1116  std::map<int, int>::const_iterator fromP = prev.laneMap.find(from);
1117  if (fromP != prev.laneMap.end()) {
1118  from = (*fromP).second;
1119  } else {
1120  from = UNSET_CONNECTION;
1121  }
1122  }
1123  if (from != UNSET_CONNECTION && to != UNSET_CONNECTION) {
1124  if (ret.find(from) != ret.end()) {
1125 // WRITE_WARNING("double connection");
1126  }
1127  if (dir == OPENDRIVE_TAG_LEFT) {
1128  std::swap(from, to);
1129  }
1130  ret[from] = to;
1131  } else {
1132 // WRITE_WARNING("missing connection");
1133  }
1134  }
1135  return ret;
1136 }
1137 
1138 
1141  OpenDriveLaneSection ret(*this);
1142  ret.s += startPos;
1143  for (unsigned int k = 0; k != ret.lanesByDir[OPENDRIVE_TAG_RIGHT].size(); ++k) {
1145  l.speed = 0;
1146  std::vector<std::pair<SUMOReal, SUMOReal> >::const_iterator i = std::find_if(l.speeds.begin(), l.speeds.end(), same_position_finder(startPos));
1147  if (i != l.speeds.end()) {
1148  l.speed = (*i).second;
1149  }
1150  }
1151  for (unsigned int k = 0; k != ret.lanesByDir[OPENDRIVE_TAG_LEFT].size(); ++k) {
1153  std::vector<std::pair<SUMOReal, SUMOReal> >::const_iterator i = std::find_if(l.speeds.begin(), l.speeds.end(), same_position_finder(startPos));
1154  l.speed = 0;
1155  if (i != l.speeds.end()) {
1156  l.speed = (*i).second;
1157  }
1158  }
1159  return ret;
1160 }
1161 
1162 
1163 bool
1164 NIImporter_OpenDrive::OpenDriveLaneSection::buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections) {
1165  std::set<SUMOReal> speedChangePositions;
1166  // collect speed change positions and apply initial speed to the begin
1167  for (std::vector<OpenDriveLane>::iterator k = lanesByDir[OPENDRIVE_TAG_RIGHT].begin(); k != lanesByDir[OPENDRIVE_TAG_RIGHT].end(); ++k) {
1168  for (std::vector<std::pair<SUMOReal, SUMOReal> >::const_iterator l = (*k).speeds.begin(); l != (*k).speeds.end(); ++l) {
1169  speedChangePositions.insert((*l).first);
1170  if ((*l).first == 0) {
1171  (*k).speed = (*l).second;
1172  }
1173  }
1174  }
1175  for (std::vector<OpenDriveLane>::iterator k = lanesByDir[OPENDRIVE_TAG_LEFT].begin(); k != lanesByDir[OPENDRIVE_TAG_LEFT].end(); ++k) {
1176  for (std::vector<std::pair<SUMOReal, SUMOReal> >::const_iterator l = (*k).speeds.begin(); l != (*k).speeds.end(); ++l) {
1177  speedChangePositions.insert((*l).first);
1178  if ((*l).first == 0) {
1179  (*k).speed = (*l).second;
1180  }
1181  }
1182  }
1183  // do nothing if there is none
1184  if (speedChangePositions.size() == 0) {
1185  return false;
1186  }
1187  if (*speedChangePositions.begin() > 0) {
1188  speedChangePositions.insert(0);
1189  }
1190  //
1191  for (std::set<SUMOReal>::iterator i = speedChangePositions.begin(); i != speedChangePositions.end(); ++i) {
1192  if (i == speedChangePositions.begin()) {
1193  newSections.push_back(*this);
1194  } else {
1195  newSections.push_back(buildLaneSection(*i));
1196  }
1197  }
1198  // propagate speeds
1199  for (int i = 0; i != (int)newSections.size(); ++i) {
1200  OpenDriveLaneSection& ls = newSections[i];
1201  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> >& lanesByDir = ls.lanesByDir;
1202  for (std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> >::iterator k = lanesByDir.begin(); k != lanesByDir.end(); ++k) {
1203  std::vector<OpenDriveLane>& lanes = (*k).second;
1204  for (int j = 0; j != (int)lanes.size(); ++j) {
1205  OpenDriveLane& l = lanes[j];
1206  if (l.speed != 0) {
1207  continue;
1208  }
1209  if (i > 0) {
1210  l.speed = newSections[i - 1].lanesByDir[(*k).first][j].speed;
1211  } else {
1212  tc.getSpeed(l.type);
1213  }
1214  }
1215  }
1216  }
1217  return true;
1218 }
1219 
1220 
1221 
1222 // ---------------------------------------------------------------------------
1223 // edge
1224 // ---------------------------------------------------------------------------
1225 int
1227  int prio = 1;
1228  for (std::vector<OpenDriveSignal>::const_iterator i = signals.begin(); i != signals.end(); ++i) {
1229  int tmp = 1;
1230  if ((*i).type == "301" || (*i).type == "306") {
1231  tmp = 2;
1232  }
1233  if ((*i).type == "205") {
1234  tmp = 0;
1235  }
1236  if (tmp != 1 && dir == OPENDRIVE_TAG_RIGHT && (*i).orientation > 0) {
1237  prio = tmp;
1238  }
1239  if (tmp != 1 && dir == OPENDRIVE_TAG_LEFT && (*i).orientation < 0) {
1240  prio = tmp;
1241  }
1242 
1243  }
1244  return prio;
1245 }
1246 
1247 
1248 
1249 // ---------------------------------------------------------------------------
1250 // loader methods
1251 // ---------------------------------------------------------------------------
1252 NIImporter_OpenDrive::NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges)
1254  myTypeContainer(tc), myCurrentEdge("", "", "", -1), myEdges(edges) {
1255 }
1256 
1257 
1259 }
1260 
1261 
1262 void
1264  const SUMOSAXAttributes& attrs) {
1265  bool ok = true;
1266  switch (element) {
1267  case OPENDRIVE_TAG_HEADER: {
1268  int majorVersion = attrs.get<int>(OPENDRIVE_ATTR_REVMAJOR, 0, ok);
1269  int minorVersion = attrs.get<int>(OPENDRIVE_ATTR_REVMINOR, 0, ok);
1270  if (majorVersion != 1 || minorVersion != 2) {
1271  WRITE_WARNING("Given openDrive file '" + getFileName() + "' uses version " + toString(majorVersion) + "." + toString(minorVersion) + ";\n Version 1.2 is supported.");
1272  }
1273  }
1274  break;
1275  case OPENDRIVE_TAG_ROAD: {
1276  std::string id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, 0, ok);
1277  std::string streetName = attrs.getOpt<std::string>(OPENDRIVE_ATTR_NAME, 0, ok, "", false);
1278  std::string junction = attrs.get<std::string>(OPENDRIVE_ATTR_JUNCTION, id.c_str(), ok);
1279  SUMOReal length = attrs.get<SUMOReal>(OPENDRIVE_ATTR_LENGTH, id.c_str(), ok);
1280  myCurrentEdge = OpenDriveEdge(id, streetName, junction, length);
1281  }
1282  break;
1284  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_ROAD) {
1285  std::string elementType = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTTYPE, myCurrentEdge.id.c_str(), ok);
1286  std::string elementID = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTID, myCurrentEdge.id.c_str(), ok);
1287  std::string contactPoint = attrs.hasAttribute(OPENDRIVE_ATTR_CONTACTPOINT)
1288  ? attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentEdge.id.c_str(), ok)
1289  : "end";
1290  addLink(OPENDRIVE_LT_PREDECESSOR, elementType, elementID, contactPoint);
1291  }
1292  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_LANE) {
1293  int no = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1294  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1295  l.predecessor = no;
1296  }
1297  }
1298  break;
1299  case OPENDRIVE_TAG_SUCCESSOR: {
1300  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_ROAD) {
1301  std::string elementType = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTTYPE, myCurrentEdge.id.c_str(), ok);
1302  std::string elementID = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTID, myCurrentEdge.id.c_str(), ok);
1303  std::string contactPoint = attrs.hasAttribute(OPENDRIVE_ATTR_CONTACTPOINT)
1304  ? attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentEdge.id.c_str(), ok)
1305  : "start";
1306  addLink(OPENDRIVE_LT_SUCCESSOR, elementType, elementID, contactPoint);
1307  }
1308  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_LANE) {
1309  int no = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1310  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1311  l.successor = no;
1312  }
1313  }
1314  break;
1315  case OPENDRIVE_TAG_GEOMETRY: {
1316  SUMOReal length = attrs.get<SUMOReal>(OPENDRIVE_ATTR_LENGTH, myCurrentEdge.id.c_str(), ok);
1317  SUMOReal s = attrs.get<SUMOReal>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1318  SUMOReal x = attrs.get<SUMOReal>(OPENDRIVE_ATTR_X, myCurrentEdge.id.c_str(), ok);
1319  SUMOReal y = attrs.get<SUMOReal>(OPENDRIVE_ATTR_Y, myCurrentEdge.id.c_str(), ok);
1320  SUMOReal hdg = attrs.get<SUMOReal>(OPENDRIVE_ATTR_HDG, myCurrentEdge.id.c_str(), ok);
1321  myCurrentEdge.geometries.push_back(OpenDriveGeometry(length, s, x, y, hdg));
1322  }
1323  break;
1324  case OPENDRIVE_TAG_ELEVATION: {
1325  SUMOReal s = attrs.get<SUMOReal>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1326  SUMOReal a = attrs.get<SUMOReal>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok);
1327  SUMOReal b = attrs.get<SUMOReal>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok);
1328  SUMOReal c = attrs.get<SUMOReal>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok);
1329  SUMOReal d = attrs.get<SUMOReal>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok);
1330  myCurrentEdge.elevations.push_back(OpenDriveElevation(s, a, b, c, d));
1331  }
1332  break;
1333  case OPENDRIVE_TAG_LINE: {
1334  std::vector<SUMOReal> vals;
1336  }
1337  break;
1338  case OPENDRIVE_TAG_SPIRAL: {
1339  std::vector<SUMOReal> vals;
1340  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_CURVSTART, myCurrentEdge.id.c_str(), ok));
1341  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_CURVEND, myCurrentEdge.id.c_str(), ok));
1343  }
1344  break;
1345  case OPENDRIVE_TAG_ARC: {
1346  std::vector<SUMOReal> vals;
1347  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_CURVATURE, myCurrentEdge.id.c_str(), ok));
1349  }
1350  break;
1351  case OPENDRIVE_TAG_POLY3: {
1352  std::vector<SUMOReal> vals;
1353  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok));
1354  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok));
1355  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok));
1356  vals.push_back(attrs.get<SUMOReal>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok));
1358  }
1359  break;
1361  SUMOReal s = attrs.get<SUMOReal>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1363  }
1364  break;
1365  case OPENDRIVE_TAG_LEFT:
1367  break;
1368  case OPENDRIVE_TAG_CENTER:
1370  break;
1371  case OPENDRIVE_TAG_RIGHT:
1373  break;
1374  case OPENDRIVE_TAG_LANE: {
1375  std::string type = attrs.get<std::string>(OPENDRIVE_ATTR_TYPE, myCurrentEdge.id.c_str(), ok);
1376  int id = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1377  std::string level = attrs.hasAttribute(OPENDRIVE_ATTR_LEVEL)
1378  ? attrs.get<std::string>(OPENDRIVE_ATTR_LEVEL, myCurrentEdge.id.c_str(), ok)
1379  : "";
1381  ls.lanesByDir[myCurrentLaneDirection].push_back(OpenDriveLane(id, level, type));
1382  }
1383  break;
1384  case OPENDRIVE_TAG_SIGNAL: {
1385  int id = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1386  std::string type = attrs.get<std::string>(OPENDRIVE_ATTR_TYPE, myCurrentEdge.id.c_str(), ok);
1387  std::string name = attrs.getOpt<std::string>(OPENDRIVE_ATTR_NAME, myCurrentEdge.id.c_str(), ok, "", false);
1388  int orientation = attrs.get<std::string>(OPENDRIVE_ATTR_ORIENTATION, myCurrentEdge.id.c_str(), ok) == "-" ? -1 : 1;
1389  SUMOReal s = attrs.get<SUMOReal>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1390  bool dynamic = attrs.get<std::string>(OPENDRIVE_ATTR_DYNAMIC, myCurrentEdge.id.c_str(), ok) == "no" ? false : true;
1391  myCurrentEdge.signals.push_back(OpenDriveSignal(id, type, name, orientation, dynamic, s));
1392  }
1393  break;
1395  myCurrentJunctionID = attrs.get<std::string>(OPENDRIVE_ATTR_ID, myCurrentJunctionID.c_str(), ok);
1396  break;
1397  case OPENDRIVE_TAG_CONNECTION: {
1398  std::string id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, myCurrentJunctionID.c_str(), ok);
1399  myCurrentIncomingRoad = attrs.get<std::string>(OPENDRIVE_ATTR_INCOMINGROAD, myCurrentJunctionID.c_str(), ok);
1401  std::string cp = attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentJunctionID.c_str(), ok);
1403  myConnectionWasEmpty = true;
1404  }
1405  break;
1406  case OPENDRIVE_TAG_LANELINK: {
1407  int from = attrs.get<int>(OPENDRIVE_ATTR_FROM, myCurrentJunctionID.c_str(), ok);
1408  int to = attrs.get<int>(OPENDRIVE_ATTR_TO, myCurrentJunctionID.c_str(), ok);
1409  Connection c;
1411  c.toEdge = myCurrentConnectingRoad;
1412  c.fromLane = from;
1413  c.toLane = to;
1414  c.fromCP = OPENDRIVE_CP_END;
1415  c.toCP = myCurrentContactPoint;
1416  c.all = false;
1417  if (myEdges.find(c.fromEdge) == myEdges.end()) {
1418  WRITE_ERROR("In laneLink-element: incoming road '" + c.fromEdge + "' is not known.");
1419  } else {
1420  OpenDriveEdge* e = myEdges.find(c.fromEdge)->second;
1421  e->connections.insert(c);
1422  myConnectionWasEmpty = false;
1423  }
1424  }
1425  break;
1426  case OPENDRIVE_TAG_WIDTH: {
1427  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 1] == OPENDRIVE_TAG_LANE) {
1428  SUMOReal width = attrs.get<SUMOReal>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok);
1429  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1430  l.width = MAX2(l.width, width);
1431  }
1432  }
1433  break;
1434  case OPENDRIVE_TAG_SPEED: {
1435  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 1] == OPENDRIVE_TAG_LANE) {
1436  SUMOReal speed = attrs.get<SUMOReal>(OPENDRIVE_ATTR_MAX, myCurrentEdge.id.c_str(), ok);
1437  SUMOReal pos = attrs.get<SUMOReal>(OPENDRIVE_ATTR_SOFFSET, myCurrentEdge.id.c_str(), ok);
1438  myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back().speeds.push_back(std::make_pair(pos, speed));
1439  }
1440  }
1441  break;
1442  default:
1443  break;
1444  }
1445  myElementStack.push_back(element);
1446 }
1447 
1448 
1449 void
1451  myElementStack.pop_back();
1452  switch (element) {
1453  case OPENDRIVE_TAG_ROAD:
1455  break;
1457  if (myConnectionWasEmpty) {
1458  Connection c;
1461  c.fromLane = 0;
1462  c.toLane = 0;
1465  c.all = true;
1466  if (myEdges.find(c.fromEdge) == myEdges.end()) {
1467  WRITE_ERROR("In laneLink-element: incoming road '" + c.fromEdge + "' is not known.");
1468  } else {
1469  OpenDriveEdge* e = myEdges.find(c.fromEdge)->second;
1470  e->connections.insert(c);
1471  }
1472  }
1473  break;
1475  myCurrentEdge.laneSections.back().buildLaneMapping(myTypeContainer);
1476  }
1477  break;
1478  default:
1479  break;
1480  }
1481 }
1482 
1483 
1484 
1485 void
1486 NIImporter_OpenDrive::addLink(LinkType lt, const std::string& elementType,
1487  const std::string& elementID,
1488  const std::string& contactPoint) {
1489  OpenDriveLink l(lt, elementID);
1490  // elementType
1491  if (elementType == "road") {
1493  } else if (elementType == "junction") {
1495  }
1496  // contact point
1497  if (contactPoint == "start") {
1499  } else if (contactPoint == "end") {
1501  }
1502  // add
1503  myCurrentEdge.links.push_back(l);
1504 }
1505 
1506 
1507 void
1508 NIImporter_OpenDrive::addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals) {
1509  // checks
1510  if (myCurrentEdge.geometries.size() == 0) {
1511  throw ProcessError("Mismatching paranthesis in geometry definition for road '" + myCurrentEdge.id + "'");
1512  }
1514  if (last.type != OPENDRIVE_GT_UNKNOWN) {
1515  throw ProcessError("Double geometry information for road '" + myCurrentEdge.id + "'");
1516  }
1517  // set
1518  last.type = type;
1519  last.params = vals;
1520 }
1521 
1522 
1523 bool
1525  if (c1.fromEdge != c2.fromEdge) {
1526  return c1.fromEdge < c2.fromEdge;
1527  }
1528  if (c1.toEdge != c2.toEdge) {
1529  return c1.toEdge < c2.toEdge;
1530  }
1531  if (c1.fromLane != c2.fromLane) {
1532  return c1.fromLane < c2.fromLane;
1533  }
1534  return c1.toLane < c2.toLane;
1535 }
1536 
1537 
1538 
1539 /****************************************************************************/
1540 
std::map< std::string, OpenDriveEdge * > & myEdges
static void calculateCurveCenter(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_radius, SUMOReal ad_hdg)
std::vector< int > myElementStack
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:203
static PositionVector geomFromLine(const OpenDriveEdge &e, const OpenDriveGeometry &g)
static StringBijection< int >::Entry openDriveAttrs[]
The names of openDrive-XML attributes (for passing to GenericSAXHandler)
NBTypeCont & getTypeCont()
Returns the type container.
Definition: NBNetBuilder.h:169
static bool transformCoordinates(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
void addLink(LinkType lt, const std::string &elementType, const std::string &elementID, const std::string &contactPoint)
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
std::string junction
The id of the junction the edge belongs to.
std::vector< OpenDriveElevation > elevations
GeometryType
OpenDrive geometry type enumeration.
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:304
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge * > &innerEdges, std::vector< Connection > &into)
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
Representation of a lane section.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Definition: NBEdge.h:70
Representation of an openDrive "link".
bool addLane2LaneConnection(unsigned int fromLane, NBEdge *dest, unsigned int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, SUMOReal contPos=UNSPECIFIED_CONTPOS)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:696
The base class for traffic light logic definitions.
ContactPoint myCurrentContactPoint
SUMOReal s
The starting offset of this lane section.
T MAX2(T a, T b)
Definition: StdDefs.h:75
static PositionVector geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g)
std::map< OpenDriveXMLTag, std::vector< OpenDriveLane > > lanesByDir
The lanes, sorted by their direction.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:205
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:114
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
friend bool operator<(const Connection &c1, const Connection &c2)
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:219
static NBNode * getOrBuildNode(const std::string &id, const Position &pos, NBNodeCont &nc)
Builds a node or returns the already built.
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The connection was computed and validated.
Definition: NBEdge.h:115
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static std::string revertID(const std::string &id)
PositionVector reverse() const
reverse position vector
#define C_LENGTH
SUMOReal speed
The speed allowed on this lane.
Definition: NBEdge.h:130
OpenDriveXMLTag myCurrentLaneDirection
static void calcPointOnCurve(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY, SUMOReal ad_r, SUMOReal ad_length)
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:122
const std::string & getID() const
Returns the id.
Definition: Named.h:66
SUMOReal length2D() const
Returns the length.
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:132
std::vector< OpenDriveLink > links
A handler which converts occuring elements and attributes into enums.
OpenDriveLaneSection buildLaneSection(SUMOReal startPos)
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:183
const std::string & getFileName() const
returns the current file name
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
Definition: NBNode.h:318
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:162
std::string type
The lane&#39;s type.
int getPriority(OpenDriveXMLTag dir) const
Returns the edge&#39;s priority, regarding the direction.
Encapsulated SAX-Attributes.
static StringBijection< TrafficLightType > TrafficLightTypes
static Position calculateStraightEndPoint(double hdg, double length, const Position &start)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:153
void computeSpiral(std::vector< Point2D< double > > &spiral, double ds=0, int NPts=0)
Definition: euler.cpp:262
std::string id
The id of the edge.
A list of positions.
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
NIImporter_OpenDrive(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file) ...
bool buildSpeedChanges(const NBTypeCont &tc, std::vector< OpenDriveLaneSection > &newSections)
const NBTypeCont & myTypeContainer
SUMOReal width
The lane&#39;s width;.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
std::vector< OpenDriveLaneSection > laneSections
std::map< int, int > laneMap
A mapping from OpenDrive to SUMO-index (the first is signed, the second unsigned) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
#define POSITION_EPS
Definition: config.h:188
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
OpenDriveXMLTag
Numbers representing openDrive-XML - element names.
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:77
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
The connection was given by the user.
Definition: NBEdge.h:113
static PositionVector geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g)
static PositionVector geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static StringBijection< int >::Entry openDriveTags[]
The names of openDrive-XML elements (for passing to GenericSAXHandler)
std::string origID
An original ID, if given.
Definition: NBEdge.h:140
void buildLaneMapping(const NBTypeCont &tc)
Build the mapping from OpenDrive to SUMO lanes.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
std::vector< OpenDriveSignal > signals
LinkType
OpenDrive link type enumeration.
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
static void computeShapes(std::map< std::string, OpenDriveEdge * > &edges)
Computes a polygon representation of each edge&#39;s geometry.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:371
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:312
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:247
std::map< int, int > getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection &prev)
Returns the links from the previous to this lane section.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:161
SUMOReal speed
The lane&#39;s speed (set in post-processing)
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
Representation of an OpenDrive geometry part.
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:201
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:81
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:177
unsigned int rightLaneNumber
The number of lanes on the right and on the left side, respectively.
static void setEdgeLinks2(OpenDriveEdge &e, const std::map< std::string, OpenDriveEdge * > &edges)
std::vector< OpenDriveGeometry > geometries
Represents a single node (junction) during network building.
Definition: NBNode.h:74
T get(const std::string &str) const
Lane & getLaneStruct(unsigned int lane)
Definition: NBEdge.h:1090
A class for sorting lane sections by their s-value.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
#define SUMOReal
Definition: config.h:214
static void setNodeSecure(NBNodeCont &nc, OpenDriveEdge &e, const std::string &nodeID, NIImporter_OpenDrive::LinkType lt)
void push_back_noDoublePos(const Position &p)
insert in back a non double position
A connection between two roads.
void addGeometryShape(GeometryType type, const std::vector< SUMOReal > &vals)
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:110
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:213
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOReal length
The length of the edge.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:786
Importer for networks stored in openDrive format.
std::vector< std::pair< SUMOReal, SUMOReal > > speeds
List of positions/speeds of speed changes.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
SUMOReal width
This lane&#39;s width.
Definition: NBEdge.h:138
#define UNSET_CONNECTION
TrafficLightType
A storage for available types of edges.
Definition: NBTypeCont.h:62
std::string streetName
The road name of the edge.
void myEndElement(int element)
Called when a closing tag occurs.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static void revisitLaneSections(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Rechecks lane sections of the given edges.
Coefficients of an elevation profile (3rd degree polynomial)