Eclipse SUMO - Simulation of Urban MObility
NIImporter_OpenDrive.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // Importer for networks stored in openDrive format
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 #include <string>
27 #include <cmath>
28 #include <iterator>
32 #include <utils/common/ToString.h>
38 #include <netbuild/NBEdge.h>
39 #include <netbuild/NBEdgeCont.h>
40 #include <netbuild/NBNode.h>
41 #include <netbuild/NBNodeCont.h>
42 #include <netbuild/NBNetBuilder.h>
43 #include <netbuild/NBOwnTLDef.h>
51 #include <utils/xml/XMLSubSys.h>
52 #include <utils/geom/Boundary.h>
53 #include "NILoader.h"
54 #include "NIImporter_OpenDrive.h"
55 
56 //#define DEBUG_VARIABLE_WIDTHS
57 //#define DEBUG_VARIABLE_SPEED
58 //#define DEBUG_CONNECTIONS
59 //#define DEBUG_SPIRAL
60 //#define DEBUG_INTERNALSHAPES
61 
62 #define DEBUG_COND(road) ((road)->id == "175")
63 #define DEBUG_COND2(edgeID) (StringUtils::startsWith((edgeID), "disabled"))
64 #define DEBUG_COND3(roadID) (roadID == "175")
65 
66 // ===========================================================================
67 // definitions
68 // ===========================================================================
69 
70 // ===========================================================================
71 // static variables
72 // ===========================================================================
100 
102 };
103 
104 
153  // towards xodr v1.4 speed:unit
155 
157 };
158 
159 
164 
165 // ===========================================================================
166 // method definitions
167 // ===========================================================================
168 // ---------------------------------------------------------------------------
169 // static methods (interface in this case)
170 // ---------------------------------------------------------------------------
171 void
173  // check whether the option is set (properly)
174  if (!oc.isUsableFileList("opendrive-files")) {
175  return;
176  }
177  // prepare types
178  myImportAllTypes = oc.getBool("opendrive.import-all-lanes");
179  myImportWidths = !oc.getBool("opendrive.ignore-widths");
180  myMinWidth = oc.getFloat("opendrive.min-width");
181  myImportInternalShapes = oc.getBool("opendrive.internal-shapes");
182  NBTypeCont& tc = nb.getTypeCont();
183  // build the handler
184  std::map<std::string, OpenDriveEdge*> edges;
185  NIImporter_OpenDrive handler(nb.getTypeCont(), edges);
186  // parse file(s)
187  std::vector<std::string> files = oc.getStringVector("opendrive-files");
188  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
189  if (!FileHelpers::isReadable(*file)) {
190  WRITE_ERROR("Could not open opendrive file '" + *file + "'.");
191  return;
192  }
193  handler.setFileName(*file);
194  PROGRESS_BEGIN_MESSAGE("Parsing opendrive from '" + *file + "'");
195  XMLSubSys::runParser(handler, *file);
197  }
198  // split inner/outer edges
199  std::map<std::string, OpenDriveEdge*> innerEdges, outerEdges;
200  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
201  if ((*i).second->isInner) {
202  innerEdges[(*i).first] = (*i).second;
203  } else {
204  outerEdges[(*i).first] = (*i).second;
205  }
206  }
207 
208  // convert geometries into a discretised representation
209  computeShapes(edges);
210  // check whether lane sections are valid and whether further must be introduced
211  revisitLaneSections(tc, edges);
212 
213  // -------------------------
214  // node building
215  // -------------------------
216  // build nodes#1
217  // look at all links which belong to a node, collect their bounding boxes
218  // and place the node in the middle of this bounding box
219  std::map<std::string, Boundary> posMap;
220  std::map<std::string, std::string> edge2junction;
221  // compute node positions
222  for (std::map<std::string, OpenDriveEdge*>::iterator i = innerEdges.begin(); i != innerEdges.end(); ++i) {
223  OpenDriveEdge* e = (*i).second;
224  assert(e->junction != "-1" && e->junction != "");
225  edge2junction[e->id] = e->junction;
226  if (posMap.find(e->junction) == posMap.end()) {
227  posMap[e->junction] = Boundary();
228  }
229  posMap[e->junction].add(e->geom.getBoxBoundary());
230  }
231  // build nodes
232  for (std::map<std::string, Boundary>::iterator i = posMap.begin(); i != posMap.end(); ++i) {
233  //std::cout << " import node=" << (*i).first << " z=" << (*i).second.getCenter() << " boundary=" << (*i).second << "\n";
234  if (!nb.getNodeCont().insert((*i).first, (*i).second.getCenter())) {
235  throw ProcessError("Could not add node '" + (*i).first + "'.");
236  }
237  }
238  // assign built nodes
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  const std::string& nid = l.elementID;
244  if (l.elementType != OPENDRIVE_ET_ROAD) {
245  if (nb.getNodeCont().retrieve(nid) == nullptr) {
246  // not yet seen, build (possibly a junction without connections)
247  Position pos = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e->geom[-1] : e->geom[0];
248  if (!nb.getNodeCont().insert(nid, pos)) {
249  throw ProcessError("Could not build node '" + nid + "'.");
250  }
251  }
252  // set node information
254  continue;
255  }
256  if (edge2junction.find(l.elementID) != edge2junction.end()) {
257  // set node information of an internal road
258  setNodeSecure(nb.getNodeCont(), *e, edge2junction[l.elementID], l.linkType);
259  continue;
260  }
261  }
262  }
263  // we should now have all nodes set for links which are not outer edge-to-outer edge links
264 
265 
266  // build nodes#2
267  // build nodes for all outer edge-to-outer edge connections
268  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
269  OpenDriveEdge* e = (*i).second;
270  for (std::vector<OpenDriveLink>::iterator j = e->links.begin(); j != e->links.end(); ++j) {
271  OpenDriveLink& l = *j;
272  if (l.elementType != OPENDRIVE_ET_ROAD || edge2junction.find(l.elementID) != edge2junction.end()) {
273  // is a connection to an internal edge, or a node, skip
274  continue;
275  }
276  // we have a direct connection between to external edges
277  std::string id1 = e->id;
278  std::string id2 = l.elementID;
279  if (id1 < id2) {
280  std::swap(id1, id2);
281  }
282  std::string nid = id1 + "." + id2;
283  if (nb.getNodeCont().retrieve(nid) == nullptr) {
284  // not yet seen, build
285  Position pos = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e->geom[-1] : e->geom[0];
286  if (!nb.getNodeCont().insert(nid, pos)) {
287  throw ProcessError("Could not build node '" + nid + "'.");
288  }
289  }
290  /* debug-stuff
291  else {
292  Position pos = l.linkType==OPENDRIVE_LT_SUCCESSOR ? e.geom[e.geom.size()-1] : e.geom[0];
293  cout << nid << " " << pos << " " << nb.getNodeCont().retrieve(nid)->getPosition() << endl;
294  }
295  */
296  setNodeSecure(nb.getNodeCont(), *e, nid, l.linkType);
297  }
298  }
299  // we should now have start/end nodes for all outer edge-to-outer edge connections
300 
301 
302  // build nodes#3
303  // assign further nodes generated from inner-edges
304  // these nodes have not been assigned earlier, because the connections are referenced in inner-edges
305  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
306  OpenDriveEdge* e = (*i).second;
307  if (e->to != nullptr && e->from != nullptr) {
308  continue;
309  }
310  for (std::map<std::string, OpenDriveEdge*>::iterator j = innerEdges.begin(); j != innerEdges.end(); ++j) {
311  OpenDriveEdge* ie = (*j).second;
312  for (std::vector<OpenDriveLink>::iterator k = ie->links.begin(); k != ie->links.end(); ++k) {
313  OpenDriveLink& il = *k;
314  if (il.elementType != OPENDRIVE_ET_ROAD || il.elementID != e->id) {
315  // not conneted to the currently investigated outer edge
316  continue;
317  }
318  std::string nid = edge2junction[ie->id];
319  if (il.contactPoint == OPENDRIVE_CP_START) {
321  } else {
323  }
324  }
325  }
326 
327  }
328 
329  // build start/end nodes which were not defined previously
330  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
331  OpenDriveEdge* e = (*i).second;
332  if ((e->from == nullptr || e->to == nullptr) && e->geom.size() == 0) {
333  continue;
334  }
335  if (e->from == nullptr) {
336  const std::string nid = e->id + ".begin";
337  e->from = getOrBuildNode(nid, e->geom.front(), nb.getNodeCont());
338  }
339  if (e->to == nullptr) {
340  const std::string nid = e->id + ".end";
341  e->to = getOrBuildNode(nid, e->geom.back(), nb.getNodeCont());
342  }
343  }
344 
345 
346  // -------------------------
347  // edge building
348  // -------------------------
349  const double defaultSpeed = tc.getSpeed("");
350  const bool saveOrigIDs = OptionsCont::getOptions().getBool("output.original-names");
351  // build edges
352  for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
353  OpenDriveEdge* e = (*i).second;
354  if (e->geom.size() < 2) {
355  WRITE_WARNING("Ignoring road '" + e->id + "' without geometry.");
356  continue;
357  }
358  bool lanesBuilt = false;
359 
360  // go along the lane sections, build a node in between of each pair
361 
364 
366  NBNode* sFrom = e->from;
367  NBNode* sTo = e->to;
368  int priorityR = e->getPriority(OPENDRIVE_TAG_RIGHT);
369  int priorityL = e->getPriority(OPENDRIVE_TAG_LEFT);
370  double sB = 0;
371  double sE = e->length;
372  // 0-length geometries are possible if only the inner points are represented
373  PositionVector geomWithOffset = e->geom;
374  if (e->laneOffsets.size() > 0) {
375  try {
376  geomWithOffset.move2side(e->laneOffsets);
377  //std::cout << " e=" << e->id << " offsets=" << e->laneOffsets << " geom=" << e->geom << " geom2=" << geomWithOffset << "\n";
378  } catch (InvalidArgument&) {
379  WRITE_WARNING("Could not apply laneOffsets for edge '" + e->id + "'");
380  }
381  }
382  const double length2D = geomWithOffset.length2D();
383  double cF = length2D == 0 ? 1 : e->length / length2D;
384  NBEdge* prevRight = nullptr;
385  NBEdge* prevLeft = nullptr;
386 
387  // starting at the same node as ending, and no lane sections?
388  if (sFrom == sTo && e->laneSections.size() == 1) {
389  // --> loop, split!
391  ls.s = e->length / 2.;
392  e->laneSections.push_back(ls);
393  WRITE_WARNING("Edge '" + e->id + "' has to be split as it connects same junctions.")
394  }
395  sanitizeWidths(e);
396  if (myMinWidth > 0) {
397  const double minDist = oc.getFloat("opendrive.curve-resolution");
398  splitMinWidths(e, tc, minDist);
399  }
400 
401  // build along lane sections
402  for (std::vector<OpenDriveLaneSection>::iterator j = e->laneSections.begin(); j != e->laneSections.end(); ++j) {
403  // add internal node if needed
404  if (j == e->laneSections.end() - 1) {
405  sTo = e->to;
406  sE = e->length / cF;
407  } else {
408  double nextS = (j + 1)->s;
409  sTo = new NBNode(e->id + "." + toString(nextS), geomWithOffset.positionAtOffset(nextS));
410  if (!nb.getNodeCont().insert(sTo)) {
411  throw ProcessError("Could not add node '" + sTo->getID() + "'.");
412  }
413  sE = nextS / cF;
414  }
415  PositionVector geom = geomWithOffset.getSubpart2D(sB, sE);
416  std::string id = e->id;
417  if (sFrom != e->from || sTo != e->to) {
418  id = id + "." + toString((*j).s);
419  } else if (e->laneSections.size() == 1) {
420  id = id + ".0.00";
421  }
422 #ifdef DEBUG_VARIABLE_WIDTHS
423  if (DEBUG_COND(e)) {
424  std::cout << " id=" << id << " sB=" << sB << " sE=" << sE << " geom=" << geom << "\n";
425  }
426 #endif
427 
428  // build lanes to right
429  NBEdge* currRight = nullptr;
430  if ((*j).rightLaneNumber > 0) {
431  currRight = new NBEdge("-" + id, sFrom, sTo, (*j).rightType, defaultSpeed, (*j).rightLaneNumber, priorityR,
433  lanesBuilt = true;
434  const std::vector<OpenDriveLane>& lanes = (*j).lanesByDir[OPENDRIVE_TAG_RIGHT];
435  for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
436  std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
437  if (lp != (*j).laneMap.end()) {
438  int sumoLaneIndex = lp->second;
439  setLaneAttributes(e, currRight->getLaneStruct(sumoLaneIndex), *k, saveOrigIDs, tc);
440  }
441  }
442  if (!nb.getEdgeCont().insert(currRight, myImportAllTypes)) {
443  throw ProcessError("Could not add edge '" + currRight->getID() + "'.");
444  }
445  if (nb.getEdgeCont().wasIgnored(id)) {
446  prevRight = nullptr;
447  } else {
448  // connect lane sections
449  if (prevRight != nullptr) {
450  std::map<int, int> connections = (*j).getInnerConnections(OPENDRIVE_TAG_RIGHT, *(j - 1));
451  for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
452 #ifdef DEBUG_CONNECTIONS
453  if (DEBUG_COND(e)) {
454  std::cout << "addCon1 from=" << prevRight->getID() << "_" << (*k).first << " to=" << currRight->getID() << "_" << (*k).second << "\n";
455  }
456 #endif
457  prevRight->addLane2LaneConnection((*k).first, currRight, (*k).second, NBEdge::L2L_VALIDATED);
458  }
459  }
460  prevRight = currRight;
461  }
462  }
463 
464  // build lanes to left
465  NBEdge* currLeft = nullptr;
466  if ((*j).leftLaneNumber > 0) {
467  currLeft = new NBEdge(id, sTo, sFrom, (*j).leftType, defaultSpeed, (*j).leftLaneNumber, priorityL,
469  lanesBuilt = true;
470  const std::vector<OpenDriveLane>& lanes = (*j).lanesByDir[OPENDRIVE_TAG_LEFT];
471  for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
472  std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
473  if (lp != (*j).laneMap.end()) {
474  int sumoLaneIndex = lp->second;
475  setLaneAttributes(e, currLeft->getLaneStruct(sumoLaneIndex), *k, saveOrigIDs, tc);
476  }
477  }
478  if (!nb.getEdgeCont().insert(currLeft, myImportAllTypes)) {
479  throw ProcessError("Could not add edge '" + currLeft->getID() + "'.");
480  }
481  if (nb.getEdgeCont().wasIgnored(id)) {
482  prevLeft = nullptr;
483  } else {
484  // connect lane sections
485  if (prevLeft != nullptr) {
486  std::map<int, int> connections = (*j).getInnerConnections(OPENDRIVE_TAG_LEFT, *(j - 1));
487  for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
488 #ifdef DEBUG_CONNECTIONS
489  if (DEBUG_COND(e)) {
490  std::cout << "addCon2 from=" << currLeft->getID() << "_" << (*k).first << " to=" << prevLeft->getID() << "_" << (*k).second << "\n";
491  }
492 #endif
493  currLeft->addLane2LaneConnection((*k).first, prevLeft, (*k).second, NBEdge::L2L_VALIDATED);
494  }
495  }
496  prevLeft = currLeft;
497  }
498  }
499  (*j).sumoID = id;
500 
501 
502  sB = sE;
503  sFrom = sTo;
504  }
505  // optionally write road objects
506  if (oc.isSet("polygon-output")) {
507  const bool writeGeo = GeoConvHelper::getLoaded().usingGeoProjection() && (
508  oc.isDefault("proj.plain-geo") || oc.getBool("proj.plain-geo"));
509  OutputDevice& dev = OutputDevice::getDevice(oc.getString("polygon-output"));
510  dev.writeXMLHeader("additional", "additional_file.xsd");
511  //SUMOPolygon poly("road_" + e->id, "road", RGBColor::BLUE, e->geom, true, false);
512  //poly.writeXML(dev, false);
513  for (auto& o : e->objects) {
514  Position ref = e->geom.positionAtOffset2D(o.s, -o.t);
515  if (o.radius >= 0) {
516  // cicrular shape
517  // GeoConvHelper::getFinal is not ready yet
519  PointOfInterest poly(o.id, o.type, RGBColor::YELLOW, ref, true, "", -1, 0);
520  poly.setParameter("name", o.name);
521  poly.writeXML(dev, writeGeo);
522  } else {
523  // rectangular shape
524  PositionVector centerLine;
525  centerLine.push_back(Position(-o.length / 2, 0));
526  centerLine.push_back(Position(o.length / 2, 0));
527  double roadHdg = e->geom.rotationAtOffset(o.s);
528  centerLine.rotate2D(roadHdg + o.hdg);
529  //PointOfInterest poiRef("ref_" + o.id, "", RGBColor::CYAN, ref, false, "", 0, 0, Shape::DEFAULT_LAYER + 2);
530  //poiRef.writeXML(dev, false);
531  centerLine.add(ref);
532  //SUMOPolygon polyCenter("center_" + o.id, "", RGBColor::MAGENTA, centerLine, true, false, Shape::DEFAULT_LAYER + 1);
533  //polyCenter.writeXML(dev, false);
534  centerLine.move2side(o.width / 2);
535  PositionVector shape = centerLine;
536  centerLine.move2side(-o.width);
537  shape.append(centerLine.reverse(), POSITION_EPS);
538  if (writeGeo) {
539  // GeoConvHelper::getFinal is not ready yet
540  for (int i = 0; i < (int) shape.size(); i++) {
542  }
543  }
544  SUMOPolygon poly(o.id, o.type, RGBColor::YELLOW, shape, true, true, 1);
545  poly.setParameter("name", o.name);
546  poly.writeXML(dev, writeGeo);
547  }
548  }
549  }
550  if (!lanesBuilt) {
551  WRITE_WARNING("Edge '" + e->id + "' has no lanes.");
552  }
553  }
554 
555  // -------------------------
556  // connections building
557  // -------------------------
558  // generate explicit lane-to-lane connections
559  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
560  setEdgeLinks2(*(*i).second, edges);
561  }
562  // compute connections across intersections, if any
563  std::vector<Connection> connections2;
564  for (std::map<std::string, OpenDriveEdge*>::iterator j = edges.begin(); j != edges.end(); ++j) {
565  const std::set<Connection>& conns = (*j).second->connections;
566 
567  for (std::set<Connection>::const_iterator i = conns.begin(); i != conns.end(); ++i) {
568  if (innerEdges.find((*i).fromEdge) != innerEdges.end()) {
569  // connections starting at inner edges are processed by starting from outer edges
570  continue;
571  }
572  if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
573  std::set<Connection> seen;
574  buildConnectionsToOuter(*i, innerEdges, connections2, seen);
575  } else {
576  connections2.push_back(*i);
577  }
578  }
579  }
580  // set connections
581  for (std::vector<Connection>::const_iterator i = connections2.begin(); i != connections2.end(); ++i) {
582 #ifdef DEBUG_CONNECTIONS
583  std::cout << "connections2 " << (*i).getDescription() << "\n";
584 #endif
585  std::string fromEdge = (*i).fromEdge;
586  if (edges.find(fromEdge) == edges.end()) {
587  WRITE_WARNING("While setting connections: from-edge '" + fromEdge + "' is not known.");
588  continue;
589  }
590  OpenDriveEdge* odFrom = edges[fromEdge];
591  int fromLane = (*i).fromLane;
592  bool fromLast = ((*i).fromCP == OPENDRIVE_CP_END) && ((*i).fromLane < 0);
593  fromEdge = fromLast ? odFrom->laneSections.back().sumoID : odFrom->laneSections[0].sumoID;
594 
595  std::string toEdge = (*i).toEdge;
596  if (edges.find(toEdge) == edges.end()) {
597  WRITE_WARNING("While setting connections: to-edge '" + toEdge + "' is not known.");
598  continue;
599  }
600 
601  OpenDriveEdge* odTo = edges[toEdge];
602  int toLane = (*i).toLane;
603  bool toLast = ((*i).toCP == OPENDRIVE_CP_END) || ((*i).toLane > 0);
604  toEdge = toLast ? odTo->laneSections.back().sumoID : odTo->laneSections[0].sumoID;
605 
606  if (fromLane == UNSET_CONNECTION) {
607  continue;
608  }
609  if (fromLane < 0) {
610  fromEdge = revertID(fromEdge);
611  }
612  if (toLane == UNSET_CONNECTION) {
613  continue;
614  }
615  if (toLane < 0) {
616  toEdge = revertID(toEdge);
617  }
618  fromLane = fromLast ? odFrom->laneSections.back().laneMap[fromLane] : odFrom->laneSections[0].laneMap[fromLane];
619  toLane = toLast ? odTo->laneSections.back().laneMap[toLane] : odTo->laneSections[0].laneMap[toLane];
620  NBEdge* from = nb.getEdgeCont().retrieve(fromEdge);
621  NBEdge* to = nb.getEdgeCont().retrieve(toEdge);
622  if (from == nullptr) {
623  WRITE_WARNING("Could not find fromEdge representation of '" + fromEdge + "' in connection '" + (*i).origID + "'.");
624  }
625  if (to == nullptr) {
626  WRITE_WARNING("Could not find fromEdge representation of '" + toEdge + "' in connection '" + (*i).origID + "'.");
627  }
628  if (from == nullptr || to == nullptr) {
629  continue;
630  }
631 
632 #ifdef DEBUG_CONNECTIONS
633  if (DEBUG_COND2(from->getID())) {
634  std::cout << "addCon3 from=" << from->getID() << "_" << fromLane << " to=" << to->getID() << "_" << toLane << "\n";
635  }
636 #endif
637  from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER, false, false, true,
641  (*i).shape);
642 
643  if ((*i).origID != "" && saveOrigIDs) {
644  // @todo: this is the most silly way to determine the connection
645  std::vector<NBEdge::Connection>& cons = from->getConnections();
646  for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); ++k) {
647  if ((*k).fromLane == fromLane && (*k).toEdge == to && (*k).toLane == toLane) {
648  (*k).setParameter(SUMO_PARAM_ORIGID, (*i).origID + "_" + toString((*i).origLane));
649  break;
650  }
651  }
652  }
653  }
654 
655 
656  // -------------------------
657  // traffic lights
658  // -------------------------
659  std::map<std::string, std::string> tlsControlled;
660  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
661  OpenDriveEdge* e = (*i).second;
662  for (std::vector<OpenDriveSignal>::const_iterator j = e->signals.begin(); j != e->signals.end(); ++j) {
663  if ((*j).type != "1000001") { // traffic_light (Section 6.11)
664  continue;
665  }
666  std::vector<OpenDriveLaneSection>::iterator k = e->laneSections.begin();
667  bool found = false;
668  for (; k != e->laneSections.end() - 1 && !found;) {
669  if ((*j).s > (*k).s && (*j).s <= (*(k + 1)).s) {
670  found = true;
671  } else {
672  ++k;
673  }
674  }
675 
676  // @todo: major problem, currently, still not completely solved:
677  // inner edges may have traffic lights, too. Nice on one hand, as directions can be recognized
678  // but hard to follow backwards
679  std::string id = (*k).sumoID;
680  if (id == "") {
681  if (e->junction != "") {
682  //WRITE_WARNING("Found a traffic light signal on an internal edge; will not build it (original edge id='" + e->id + "').");
683  std::string fromID, toID;
684  for (std::vector<OpenDriveLink>::const_iterator l = e->links.begin(); l != e->links.end(); ++l) {
685  if ((*l).linkType == OPENDRIVE_LT_PREDECESSOR && (*l).elementType == OPENDRIVE_ET_ROAD) {
686  if (fromID != "") {
687  WRITE_WARNING("Ambigous start of connection.");
688  }
689  OpenDriveEdge* e = edges[(*l).elementID];
690  if ((*l).contactPoint == OPENDRIVE_CP_START) {
691  fromID = e->laneSections[0].sumoID;
692  if ((*j).orientation < 0) {
693  fromID = "-" + fromID;
694  }
695  } else {
696  fromID = e->laneSections.back().sumoID;
697  if ((*j).orientation > 0) {
698  fromID = "-" + fromID;
699  }
700  }
701  }
702  if ((*l).linkType == OPENDRIVE_LT_SUCCESSOR && (*l).elementType == OPENDRIVE_ET_ROAD) {
703  if (toID != "") {
704  WRITE_WARNING("Ambigous end of connection.");
705  }
706  OpenDriveEdge* e = edges[(*l).elementID];
707  toID = (*l).contactPoint == OPENDRIVE_CP_START ? e->laneSections[0].sumoID : e->laneSections.back().sumoID;
708  }
709  }
710  id = fromID + "->" + toID;
711  } else {
712  WRITE_WARNING("Found a traffic light signal on an unknown edge (original edge id='" + e->id + "').");
713  continue;
714  }
715  } else {
716  if ((*j).orientation > 0) {
717  id = "-" + id;
718  }
719  }
720  tlsControlled[id] = (*j).name;
721  }
722  }
723 
724  for (std::map<std::string, std::string>::iterator i = tlsControlled.begin(); i != tlsControlled.end(); ++i) {
725  std::string id = (*i).first;
726  if (id.find("->") != std::string::npos) {
727  id = id.substr(0, id.find("->"));
728  }
729  NBEdge* e = nb.getEdgeCont().retrieve(id);
730  if (e == nullptr) {
731  WRITE_WARNING("Could not find edge '" + id + "' while building its traffic light.");
732  continue;
733  }
734  NBNode* toNode = e->getToNode();
735  if (!toNode->isTLControlled()) {
737  NBOwnTLDef* tlDef = new NBOwnTLDef(toNode->getID(), toNode, 0, type);
738  if (!nb.getTLLogicCont().insert(tlDef)) {
739  // actually, nothing should fail here
740  delete tlDef;
741  throw ProcessError();
742  }
743  toNode->addTrafficLight(tlDef);
744  //tlDef->setSinglePhase();
745  }
746  NBTrafficLightDefinition* tlDef = *toNode->getControllingTLS().begin();
747  tlDef->setParameter("connection:" + id, (*i).second);
748  }
749 
750  // -------------------------
751  // clean up
752  // -------------------------
753  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
754  delete (*i).second;
755  }
756 }
757 
758 void
759 NIImporter_OpenDrive::setLaneAttributes(const OpenDriveEdge* e, NBEdge::Lane& sumoLane, const OpenDriveLane& odLane, bool saveOrigIDs, const NBTypeCont& tc) {
760  if (saveOrigIDs) {
761  sumoLane.setParameter(SUMO_PARAM_ORIGID, e->id + "_" + toString(odLane.id));
762  }
763  sumoLane.speed = odLane.speed != 0 ? odLane.speed : tc.getSpeed(odLane.type);
764  sumoLane.permissions = tc.getPermissions(odLane.type);
765  sumoLane.width = myImportWidths && odLane.width != NBEdge::UNSPECIFIED_WIDTH ? odLane.width : tc.getWidth(odLane.type);
766  sumoLane.type = odLane.type;
767 
768  const double widthResolution = tc.getWidthResolution(odLane.type);
769  const double maxWidth = tc.getMaxWidth(odLane.type);
770 
771  const bool forbiddenNarrow = (sumoLane.width < myMinWidth
772  && (sumoLane.permissions & SVC_PASSENGER) != 0
773  && sumoLane.width < tc.getWidth(odLane.type));
774 
775  if (sumoLane.width >= 0 && widthResolution > 0) {
776  sumoLane.width = floor(sumoLane.width / widthResolution + 0.5) * widthResolution;
777  if (forbiddenNarrow && sumoLane.width >= myMinWidth) {
778  sumoLane.width -= widthResolution;
779  if (sumoLane.width <= 0) {
781  }
782  } else if (sumoLane.width == 0) {
783  // round up when close to 0
784  sumoLane.width = widthResolution;
785  }
786  }
787  if (maxWidth > 0) {
788  sumoLane.width = MIN2(sumoLane.width, maxWidth);
789  }
790  if (forbiddenNarrow) {
791  // avoid narrow passenger car lanes (especially at sections with varying width)
793  }
794 }
795 
796 void
797 NIImporter_OpenDrive::buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into, std::set<Connection>& seen) {
798 
799  OpenDriveEdge* dest = innerEdges.find(c.toEdge)->second;
800 #ifdef DEBUG_CONNECTIONS
801  if (DEBUG_COND3(c.fromEdge)) {
802  std::cout << " buildConnectionsToOuter " << c.getDescription() << "\n";
803  std::cout << " dest=" << (dest == nullptr ? "NULL" : dest->id) << " seenlist=";
804  for (std::set<Connection>::const_iterator i = seen.begin(); i != seen.end(); ++i) {
805  std::cout << " " << (*i).fromEdge << "," << (*i).toEdge << " ";
806  }
807  std::cout << "\n";
808  }
809 #endif
810  if (dest == nullptr) {
812  return;
813  }
814  seen.insert(c);
815  const std::set<Connection>& conts = dest->connections;
816  for (std::set<Connection>::const_iterator i = conts.begin(); i != conts.end(); ++i) {
817  auto innerEdgesIt = innerEdges.find((*i).toEdge);
818 #ifdef DEBUG_CONNECTIONS
819  if (DEBUG_COND3(c.fromEdge)) {
820  std::cout << " toInner=" << (innerEdgesIt != innerEdges.end()) << " destCon " << (*i).getDescription() << "\n";
821  }
822 #endif
823  if (innerEdgesIt != innerEdges.end()) {
824  std::vector<Connection> t;
825  if (seen.count(*i) == 0) {
826  buildConnectionsToOuter(*i, innerEdges, t, seen);
827  for (std::vector<Connection>::const_iterator j = t.begin(); j != t.end(); ++j) {
828  // @todo this section is unverified
829  Connection cn = (*j);
830  cn.fromEdge = c.fromEdge;
831  cn.fromLane = c.fromLane;
832  cn.fromCP = c.fromCP;
833  cn.all = c.all; // @todo "all" is a hack trying to avoid the "from is zero" problem;
835  cn.shape = innerEdgesIt->second->geom + c.shape;
836  }
837  into.push_back(cn);
838  }
839  } else {
840  WRITE_WARNING("Circular connections in junction including roads '" + c.fromEdge + "' and '" + c.toEdge + "', loop size " + toString(seen.size()));
841  }
842  } else {
843  if (laneSectionsConnected(dest, c.toLane, (*i).fromLane)) {
844  Connection cn = (*i);
845  cn.fromEdge = c.fromEdge;
846  cn.fromLane = c.fromLane;
847  cn.fromCP = c.fromCP;
848  cn.all = c.all;
849  cn.origID = c.toEdge;
850  cn.origLane = c.toLane;
852  OpenDriveXMLTag lanesDir;
853  cn.shape = dest->geom;
854  // determine which lane of dest belongs to this connection
855  int referenceLane = 0;
856  int offsetFactor = 1;
857  if (c.toCP == OPENDRIVE_CP_END) {
858  offsetFactor = -1;
859  lanesDir = OPENDRIVE_TAG_LEFT;
860  for (const auto& destLane : dest->laneSections.front().lanesByDir[lanesDir]) {
861  if (destLane.successor == c.fromLane) {
862  referenceLane = destLane.id;
863  break;
864  }
865  }
866  } else {
867  lanesDir = OPENDRIVE_TAG_RIGHT;
868  for (const auto& destLane : dest->laneSections.front().lanesByDir[lanesDir]) {
869  if (destLane.predecessor == c.fromLane) {
870  referenceLane = destLane.id;
871  break;
872  }
873  }
874  }
875  // compute offsets
876  //if (cn.fromEdge == "1014000" && dest->id == "3001022") {
877  // std::cout << "computeOffsets\n";
878  //}
879  std::vector<double> offsets(dest->geom.size(), 0);
880  if (dest->laneOffsets.size() > 0) {
881  offsets = dest->laneOffsets;
882  }
883 #ifdef DEBUG_INTERNALSHAPES
884  std::string destPred;
885 #endif
886  double s = 0;
887  int iShape = 0;
888  for (int laneSectionIndex = 0; laneSectionIndex < (int)dest->laneSections.size(); laneSectionIndex++) {
889  auto& laneSection = dest->laneSections[laneSectionIndex];
890  const double nextS = laneSectionIndex + 1 < (int)dest->laneSections.size() ? dest->laneSections[laneSectionIndex + 1].s : std::numeric_limits<double>::max();
891  int i = iShape; // shape index at the start of the current lane section
892  double sStart = s; // distance offset a the start of the current lane section
893  double finalS = s; // final distance value after processing this segment
894  int finalI = i;
895  for (const OpenDriveLane& destLane : laneSection.lanesByDir[lanesDir]) {
896  // each lane of the current segment repeats the same section of shape points and distance offsets
897  double sectionS = 0;
898  i = iShape;
899  s = sStart;
900 #ifdef DEBUG_INTERNALSHAPES
901  destPred += " lane=" + toString(destLane.id)
902  + " pred=" + toString(destLane.predecessor)
903  + " succ=" + toString(destLane.successor)
904  + " wStart=" + toString(destLane.widthData.front().computeAt(0))
905  + " wEnd=" + toString(destLane.widthData.front().computeAt(cn.shape.length2D()))
906  + " width=" + toString(destLane.width) + "\n";
907 #endif
908  if (abs(destLane.id) <= abs(referenceLane)) {
909  const double multiplier = offsetFactor * (destLane.id == referenceLane ? 0.5 : 1);
910 #ifdef DEBUG_INTERNALSHAPES
911  destPred += " multiplier=" + toString(multiplier) + "\n";
912 #endif
913  int widthDataIndex = 0;
914  while (s < nextS && i < (int)cn.shape.size()) {
915  if (i > 0) {
916  const double dist = cn.shape[i - 1].distanceTo2D(cn.shape[i]);
917  s += dist;
918  sectionS += dist;
919 
920  }
921  while (widthDataIndex + 1 < (int)destLane.widthData.size()
922  && sectionS >= destLane.widthData[widthDataIndex + 1].s) {
923  widthDataIndex++;
924  }
925  offsets[i] += destLane.widthData[widthDataIndex].computeAt(sectionS) * multiplier;
926  //if (cn.fromEdge == "1014000" && dest->id == "3001022") {
927  // std::cout << " i=" << i << " s=" << s << " lane=" << destLane.id << " rlane=" << referenceLane /*<< " nextS=" << nextS << */ << " lsIndex=" << laneSectionIndex << " wI=" << widthDataIndex << " wSize=" << destLane.widthData.size() << " m=" << multiplier << " o=" << offsets[i] << "\n";
928  //}
929  i++;
930  }
931  finalS = s;
932  finalI = i;
933  } else if (finalS == s) {
934  // update finalS without changing offsets
935  while (s < nextS && i < (int)cn.shape.size()) {
936  if (i > 0) {
937  const double dist = cn.shape[i - 1].distanceTo2D(cn.shape[i]);
938  s += dist;
939  finalS += dist;
940 
941  }
942  i++;
943  }
944  finalI = i;
945 
946  }
947  }
948  // advance values for the next lane section
949  iShape = finalI;
950  s = finalS;
951  }
952  try {
953  cn.shape.move2side(offsets);
954  } catch (InvalidArgument&) {
955  WRITE_WARNING("Could not import internal lane shape from edge '" + c.fromEdge + "' to edge '" + c.toEdge);
956  cn.shape.clear();
957  }
958 #ifdef DEBUG_INTERNALSHAPES
959  std::cout << "internalShape "
960  << c.getDescription()
961  << " dest=" << dest->id
962  << " refLane=" << referenceLane
963  << " destPred\n" << destPred
964  << " offsets=" << offsets
965  << "\n shape=" << dest->geom
966  << "\n shape2=" << cn.shape
967  << "\n";
968 #endif
969  if (c.toCP == OPENDRIVE_CP_END) {
970  cn.shape = cn.shape.reverse();
971  }
972  }
973 #ifdef DEBUG_CONNECTIONS
974  if (DEBUG_COND3(c.fromEdge)) {
975  std::cout << " added connection\n";
976  }
977 #endif
978  into.push_back(cn);
979  }
980  }
981  }
982 }
983 
984 
985 bool
987  if (edge->laneSections.size() == 1) {
988  return in == out;
989  } else {
990  // there could be spacing lanes (type 'none') that lead to a shift in lane index
991  for (auto it = edge->laneSections.begin(); it + 1 < edge->laneSections.end(); it++) {
992  OpenDriveLaneSection& laneSection = *it;
993  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT) != laneSection.lanesByDir.end()) {
994  for (OpenDriveLane& lane : laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT)->second) {
995  if (lane.id == in) {
996  in = lane.successor;
997  }
998  }
999  }
1000  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT) != laneSection.lanesByDir.end()) {
1001  for (OpenDriveLane& lane : laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT)->second) {
1002  if (lane.id == in) {
1003  in = lane.successor;
1004  }
1005  }
1006  }
1007  }
1008  return in == out;
1009  }
1010 }
1011 
1012 
1013 void
1014 NIImporter_OpenDrive::setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges) {
1015  for (std::vector<OpenDriveLink>::iterator i = e.links.begin(); i != e.links.end(); ++i) {
1016  OpenDriveLink& l = *i;
1017  if (l.elementType != OPENDRIVE_ET_ROAD) {
1018  // we assume that links to nodes are later given as connections to edges
1019  continue;
1020  }
1021  // get the right direction of the connected edge
1022  std::string connectedEdge = l.elementID;
1023  std::string edgeID = e.id;
1024 
1025  OpenDriveLaneSection& laneSection = l.linkType == OPENDRIVE_LT_SUCCESSOR ? e.laneSections.back() : e.laneSections[0];
1026  const std::map<int, int>& laneMap = laneSection.laneMap;
1027 #ifdef DEBUG_CONNECTIONS
1028  if (DEBUG_COND(&e)) {
1029  std::cout << "edge=" << e.id << " eType=" << l.elementType << " lType=" << l.linkType << " connectedEdge=" << connectedEdge << " laneSection=" << laneSection.s << " map:\n";
1030  std::cout << joinToString(laneMap, "\n", ":") << "\n";
1031  }
1032 #endif
1033  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT) != laneSection.lanesByDir.end()) {
1034  const std::vector<OpenDriveLane>& lanes = laneSection.lanesByDir.find(OPENDRIVE_TAG_RIGHT)->second;
1035  for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1036  if (!myImportAllTypes && laneMap.find((*j).id) == laneMap.end()) {
1037  continue;
1038  }
1039  Connection c; // @todo: give Connection a new name and a constructor
1040  c.fromEdge = e.id;
1041  c.fromLane = (*j).id;
1043  c.toLane = l.linkType == OPENDRIVE_LT_SUCCESSOR ? (*j).successor : (*j).predecessor;
1044  c.toEdge = connectedEdge;
1045  c.toCP = l.contactPoint;
1046  c.all = false;
1047  if (l.linkType != OPENDRIVE_LT_SUCCESSOR) {
1048  std::swap(c.fromEdge, c.toEdge);
1049  std::swap(c.fromLane, c.toLane);
1050  std::swap(c.fromCP, c.toCP);
1051  }
1052  if (edges.find(c.fromEdge) == edges.end()) {
1053  WRITE_ERROR("While setting connections: incoming road '" + c.fromEdge + "' is not known.");
1054  } else {
1055  OpenDriveEdge* src = edges.find(c.fromEdge)->second;
1056  src->connections.insert(c);
1057 #ifdef DEBUG_CONNECTIONS
1058  if (DEBUG_COND(src)) {
1059  std::cout << "insertConRight from=" << src->id << "_" << c.fromLane << " to=" << c.toEdge << "_" << c.toLane << "\n";
1060  }
1061 #endif
1062  }
1063  }
1064  }
1065  if (laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT) != laneSection.lanesByDir.end()) {
1066  const std::vector<OpenDriveLane>& lanes = laneSection.lanesByDir.find(OPENDRIVE_TAG_LEFT)->second;
1067  for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1068  if (!myImportAllTypes && laneMap.find((*j).id) == laneMap.end()) {
1069  continue;
1070  }
1071  Connection c;
1072  c.toEdge = e.id;
1073  c.toLane = (*j).id;
1074  c.toCP = OPENDRIVE_CP_END;
1075  c.fromLane = l.linkType == OPENDRIVE_LT_SUCCESSOR ? (*j).successor : (*j).predecessor;
1076  c.fromEdge = connectedEdge;
1077  c.fromCP = l.contactPoint;
1078  c.all = false;
1079  if (l.linkType != OPENDRIVE_LT_SUCCESSOR) {
1080  std::swap(c.fromEdge, c.toEdge);
1081  std::swap(c.fromLane, c.toLane);
1082  std::swap(c.fromCP, c.toCP);
1083  }
1084  if (edges.find(c.fromEdge) == edges.end()) {
1085  WRITE_ERROR("While setting connections: incoming road '" + c.fromEdge + "' is not known.");
1086  } else {
1087  OpenDriveEdge* src = edges.find(c.fromEdge)->second;
1088  src->connections.insert(c);
1089 #ifdef DEBUG_CONNECTIONS
1090  if (DEBUG_COND(src)) {
1091  std::cout << "insertConLeft from=" << src->id << "_" << c.fromLane << " to=" << c.toEdge << "_" << c.toLane << "\n";
1092  }
1093 #endif
1094  }
1095  }
1096  }
1097  }
1098 }
1099 
1100 
1101 std::string NIImporter_OpenDrive::revertID(const std::string& id) {
1102  if (id[0] == '-') {
1103  return id.substr(1);
1104  }
1105  return "-" + id;
1106 }
1107 
1108 
1109 NBNode*
1110 NIImporter_OpenDrive::getOrBuildNode(const std::string& id, const Position& pos,
1111  NBNodeCont& nc) {
1112  if (nc.retrieve(id) == nullptr) {
1113  // not yet built; build now
1114  if (!nc.insert(id, pos)) {
1115  // !!! clean up
1116  throw ProcessError("Could not add node '" + id + "'.");
1117  }
1118  }
1119  return nc.retrieve(id);
1120 }
1121 
1122 
1123 void
1125  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt) {
1126  NBNode* n = nc.retrieve(nodeID);
1127  if (n == nullptr) {
1128  throw ProcessError("Could not find node '" + nodeID + "'.");
1129  }
1130  if (lt == OPENDRIVE_LT_SUCCESSOR) {
1131  if (e.to != nullptr && e.to != n) {
1132  throw ProcessError("Edge '" + e.id + "' has two end nodes ('" + e.to->getID() + "' and '" + nodeID + "').");
1133  }
1134  e.to = n;
1135  } else {
1136  if (e.from != nullptr && e.from != n) {
1137  throw ProcessError("Edge '" + e.id + "' has two start nodes ('" + e.from->getID() + "' and '" + nodeID + "').");
1138  }
1139  e.from = n;
1140  }
1141 }
1142 
1143 bool
1145  if (e.elevations.size() > 1) {
1146  return true;
1147  }
1148  for (OpenDriveElevation& el : e.elevations) {
1149  if (el.c != 0 || el.d != 0) {
1150  return true;
1151  }
1152  }
1153  return false;
1154 }
1155 
1156 void
1157 NIImporter_OpenDrive::computeShapes(std::map<std::string, OpenDriveEdge*>& edges) {
1159  const double res = oc.getFloat("opendrive.curve-resolution");
1160  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
1161  OpenDriveEdge& e = *(*i).second;
1163  const double lineRes = hasNonLinearElevation(e) ? res : -1;
1164  Position last;
1165  for (std::vector<OpenDriveGeometry>::iterator j = e.geometries.begin(); j != e.geometries.end(); ++j) {
1166  OpenDriveGeometry& g = *j;
1167  PositionVector geom;
1168  switch (g.type) {
1169  case OPENDRIVE_GT_UNKNOWN:
1170  break;
1171  case OPENDRIVE_GT_LINE:
1172  geom = geomFromLine(e, g, lineRes);
1173  break;
1174  case OPENDRIVE_GT_SPIRAL:
1175  geom = geomFromSpiral(e, g, res);
1176  break;
1177  case OPENDRIVE_GT_ARC:
1178  geom = geomFromArc(e, g, res);
1179  break;
1180  case OPENDRIVE_GT_POLY3:
1181  geom = geomFromPoly(e, g, res);
1182  break;
1184  geom = geomFromParamPoly(e, g, res);
1185  break;
1186  default:
1187  break;
1188  }
1189  if (e.geom.size() > 0 && prevType == OPENDRIVE_GT_LINE) {
1190  // remove redundant end point of the previous geometry segment
1191  // (the start point of the current segment should have the same value)
1192  // this avoids geometry errors due to imprecision
1193  if (!e.geom.back().almostSame(geom.front())) {
1194  const int index = (int)(j - e.geometries.begin());
1195  WRITE_WARNING("Mismatched geometry for edge '" + e.id + "' between geometry segments " + toString(index - 1) + " and " + toString(index) + ".");
1196  }
1197  e.geom.pop_back();
1198  }
1199  //std::cout << " adding geometry to road=" << e.id << " old=" << e.geom << " new=" << geom << "\n";
1200  for (PositionVector::iterator k = geom.begin(); k != geom.end(); ++k) {
1201  last = *k;
1203  }
1204  prevType = g.type;
1205  }
1206  if (e.geom.size() == 1 && e.geom.front() != last) {
1207  // avoid length-1 geometry due to almostSame check
1208  e.geom.push_back(last);
1209  }
1210  if (oc.exists("geometry.min-dist") && !oc.isDefault("geometry.min-dist")) {
1211  e.geom.removeDoublePoints(oc.getFloat("geometry.min-dist"), true);
1212  }
1214  WRITE_ERROR("Unable to project coordinates for edge '" + e.id + "'.");
1215  }
1216  // add z-data
1217  int k = 0;
1218  double pos = 0;
1219  //std::cout << " edge=" << e.id << " geom.size=" << e.geom.size() << " geom.len=" << e.geom.length2D() << " ele.size=" << e.elevations.size() << "\n";
1220  for (std::vector<OpenDriveElevation>::iterator j = e.elevations.begin(); j != e.elevations.end(); ++j) {
1221  const OpenDriveElevation& el = *j;
1222  const double sNext = (j + 1) == e.elevations.end() ? std::numeric_limits<double>::max() : (*(j + 1)).s;
1223  while (k < (int)e.geom.size() && pos < sNext) {
1224  const double z = el.computeAt(pos);
1225  //std::cout << " edge=" << e.id << " k=" << k << " sNext=" << sNext << " pos=" << pos << " z=" << z << " el.s=" << el.s << " el.a=" << el.a << " el.b=" << el.b << " el.c=" << el.c << " el.d=" << el.d << "\n";
1226  e.geom[k].add(0, 0, z);
1227  k++;
1228  if (k < (int)e.geom.size()) {
1229  // XXX pos understimates the actual position since the
1230  // actual geometry between k-1 and k could be curved
1231  pos += e.geom[k - 1].distanceTo2D(e.geom[k]);
1232  }
1233  }
1234  }
1235  // add laneoffset
1236  if (e.offsets.size() > 0) {
1237  // make sure there are intermediate points for each offset-section
1238  for (std::vector<OpenDriveLaneOffset>::iterator j = e.offsets.begin(); j != e.offsets.end(); ++j) {
1239  const OpenDriveLaneOffset& el = *j;
1240  // check wether we need to insert a new point at dist
1241  Position pS = e.geom.positionAtOffset2D(el.s);
1242  int iS = e.geom.indexOfClosest(pS);
1243  // prevent close spacing to reduce impact of rounding errors in z-axis
1244  if (pS.distanceTo2D(e.geom[iS]) > POSITION_EPS) {
1245  e.geom.insertAtClosest(pS);
1246  //std::cout << " edge=" << e.id << " inserting pos=" << pS << " s=" << el.s << " iS=" << iS << " dist=" << pS.distanceTo2D(e.geom[iS]) << "\n";
1247  }
1248  }
1249  // XXX add further points for sections with non-constant offset
1250  // shift each point orthogonally by the specified offset
1251  int k = 0;
1252  double pos = 0;
1253  for (std::vector<OpenDriveLaneOffset>::iterator j = e.offsets.begin(); j != e.offsets.end(); ++j) {
1254  const OpenDriveLaneOffset& el = *j;
1255  const double sNext = (j + 1) == e.offsets.end() ? std::numeric_limits<double>::max() : (*(j + 1)).s;
1256  while (k < (int)e.geom.size() && pos < sNext) {
1257  const double offset = el.computeAt(pos);
1258  e.laneOffsets.push_back(fabs(offset) > POSITION_EPS ? -offset : 0);
1259  k++;
1260  if (k < (int)e.geom.size()) {
1261  // XXX pos understimates the actual position since the
1262  // actual geometry between k-1 and k could be curved
1263  pos += e.geom[k - 1].distanceTo2D(e.geom[k]);
1264  }
1265  }
1266  }
1267  }
1268  //std::cout << " loaded geometry " << e.id << "=" << e.geom << "\n";
1269  }
1270 }
1271 
1272 
1273 void
1274 NIImporter_OpenDrive::revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges) {
1275  for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
1276  OpenDriveEdge& e = *(*i).second;
1277 #ifdef DEBUG_VARIABLE_SPEED
1278  if (DEBUG_COND(&e)) {
1279  gDebugFlag1 = true;
1280  std::cout << "revisitLaneSections e=" << e.id << "\n";
1281  }
1282 #endif
1283  std::vector<OpenDriveLaneSection>& laneSections = e.laneSections;
1284  // split by speed limits
1285  std::vector<OpenDriveLaneSection> newSections;
1286  for (std::vector<OpenDriveLaneSection>::iterator j = laneSections.begin(); j != laneSections.end(); ++j) {
1287  std::vector<OpenDriveLaneSection> splitSections;
1288  bool splitBySpeed = (*j).buildSpeedChanges(tc, splitSections);
1289  if (!splitBySpeed) {
1290  newSections.push_back(*j);
1291  } else {
1292  std::copy(splitSections.begin(), splitSections.end(), back_inserter(newSections));
1293  }
1294  }
1295 
1296  e.laneSections = newSections;
1297  laneSections = e.laneSections;
1298  double lastS = -1;
1299  // check whether the lane sections are in the right order
1300  bool sorted = true;
1301  for (std::vector<OpenDriveLaneSection>::const_iterator j = laneSections.begin(); j != laneSections.end() && sorted; ++j) {
1302  if ((*j).s <= lastS) {
1303  sorted = false;
1304  }
1305  lastS = (*j).s;
1306  }
1307  if (!sorted) {
1308  WRITE_WARNING("The sections of edge '" + e.id + "' are not sorted properly.");
1309  sort(e.laneSections.begin(), e.laneSections.end(), sections_by_s_sorter());
1310  }
1311  // check whether no duplicates of s-value occure
1312  lastS = -1;
1313  laneSections = e.laneSections;
1314  for (std::vector<OpenDriveLaneSection>::iterator j = laneSections.begin(); j != laneSections.end();) {
1315  bool simlarToLast = fabs((*j).s - lastS) < POSITION_EPS;
1316  lastS = (*j).s;
1317  // keep all lane sections for connecting roads because they are
1318  // needed to establish connectivity (laneSectionsConnected)
1319  if (simlarToLast && !e.isInner) {
1320  WRITE_WARNING("Almost duplicate s-value '" + toString(lastS) + "' for lane sections occurred at edge '" + e.id + "'; second entry was removed.");
1321  j = laneSections.erase(j);
1322  } else {
1323  ++j;
1324  }
1325  }
1326 #ifdef DEBUG_VARIABLE_SPEED
1327  gDebugFlag1 = false;
1328 #endif
1329  }
1330 }
1331 
1332 
1335  UNUSED_PARAMETER(e);
1336  PositionVector ret;
1337  Position start(g.x, g.y);
1338  Position end = calculateStraightEndPoint(g.hdg, g.length, start);
1339  if (resolution > 0 && g.length > 0) {
1340  const int numPoints = (int)ceil(g.length / resolution) + 1;
1341  double dx = (end.x() - start.x()) / (numPoints - 1);
1342  double dy = (end.y() - start.y()) / (numPoints - 1);
1343  for (int i = 0; i < numPoints; i++) {
1344  ret.push_back(Position(g.x + i * dx, g.y + i * dy));
1345  }
1346  } else {
1347  ret.push_back(start);
1348  ret.push_back(end);
1349  }
1350  return ret;
1351 }
1352 
1353 
1356  UNUSED_PARAMETER(e);
1357  PositionVector ret;
1358  double curveStart = g.params[0];
1359  double curveEnd = g.params[1];
1360  try {
1361  double cDot = (curveEnd - curveStart) / g.length;
1362  if (cDot == 0 || g.length == 0) {
1363  WRITE_WARNING("Could not compute spiral geometry for edge '" + e.id + "' (cDot=" + toString(cDot) + " length=" + toString(g.length) + ").");
1364  ret.push_back(Position(g.x, g.y));
1365  return ret;
1366  }
1367  double sStart = curveStart / cDot;
1368  double sEnd = curveEnd / cDot;
1369  double x = 0;
1370  double y = 0;
1371  double t = 0;
1372  double tStart = 0;
1373  double s;
1374  odrSpiral(sStart, cDot, &x, &y, &tStart);
1375  for (s = sStart; s <= sEnd; s += resolution) {
1376  odrSpiral(s, cDot, &x, &y, &t);
1377  ret.push_back(Position(x, y));
1378  }
1379  if (s != sEnd /*&& ret.size() == 1*/) {
1380  odrSpiral(sEnd, cDot, &x, &y, &t);
1381  ret.push_back(Position(x, y));
1382  }
1383  //if (s != sEnd && ret.size() > 2) {
1384  // ret.pop_back();
1385  //}
1386  assert(ret.size() >= 2);
1387  assert(ret[0] != ret[1]);
1388  // shift start to coordinate origin
1389  PositionVector ret1 = ret;
1390  ret.add(ret.front() * -1);
1391  // rotate
1392  PositionVector ret2 = ret;
1393  ret.rotate2D(g.hdg - tStart);
1394 #ifdef DEBUG_SPIRAL
1395  std::cout
1396  << std::setprecision(4)
1397  << "edge=" << e.id << " s=" << g.s
1398  << " cStart=" << curveStart
1399  << " cEnd=" << curveEnd
1400  << " cDot=" << cDot
1401  << " sStart=" << sStart
1402  << " sEnd=" << sEnd
1403  << " g.hdg=" << GeomHelper::naviDegree(g.hdg)
1404  << " tStart=" << GeomHelper::naviDegree(tStart)
1405  << "\n beforeShift=" << ret1
1406  << "\n beforeRot=" << ret2
1407  << "\n";
1408 #endif
1409  // shift to geometry start
1410  ret.add(g.x, g.y, 0);
1411  } catch (const std::runtime_error& error) {
1412  WRITE_WARNING("Could not compute spiral geometry for edge '" + e.id + "' (" + error.what() + ").");
1413  ret.push_back(Position(g.x, g.y));
1414  }
1415  return ret.getSubpart2D(0, g.length);
1416 }
1417 
1418 
1421  UNUSED_PARAMETER(e);
1422  PositionVector ret;
1423  double dist = 0.0;
1424  double centerX = g.x;
1425  double centerY = g.y;
1426  // left: positive value
1427  double curvature = g.params[0];
1428  double radius = 1. / curvature;
1429  // center point
1430  calculateCurveCenter(&centerX, &centerY, radius, g.hdg);
1431  double endX = g.x;
1432  double endY = g.y;
1433  double startX = g.x;
1434  double startY = g.y;
1435  double geo_posS = g.s;
1436  double geo_posE = g.s;
1437  bool end = false;
1438  do {
1439  geo_posE += resolution;
1440  if (geo_posE - g.s > g.length) {
1441  geo_posE = g.s + g.length;
1442  }
1443  if (geo_posE - g.s > g.length) {
1444  geo_posE = g.s + g.length;
1445  }
1446  calcPointOnCurve(&endX, &endY, centerX, centerY, radius, geo_posE - geo_posS);
1447 
1448  dist += (geo_posE - geo_posS);
1449  //
1450  ret.push_back(Position(startX, startY));
1451  //
1452  startX = endX;
1453  startY = endY;
1454  geo_posS = geo_posE;
1455 
1456  if (geo_posE - (g.s + g.length) < 0.001 && geo_posE - (g.s + g.length) > -0.001) {
1457  end = true;
1458  }
1459  } while (!end);
1460  return ret.getSubpart2D(0, g.length);
1461 }
1462 
1463 
1466  UNUSED_PARAMETER(e);
1467  const double s = sin(g.hdg);
1468  const double c = cos(g.hdg);
1469  PositionVector ret;
1470  for (double off = 0; off < g.length + 2.; off += resolution) {
1471  double x = off;
1472  double y = g.params[0] + g.params[1] * off + g.params[2] * pow(off, 2.) + g.params[3] * pow(off, 3.);
1473  double xnew = x * c - y * s;
1474  double ynew = x * s + y * c;
1475  ret.push_back(Position(g.x + xnew, g.y + ynew));
1476  }
1477  return ret.getSubpart2D(0, g.length);
1478 }
1479 
1480 
1483  UNUSED_PARAMETER(e);
1484  const double s = sin(g.hdg);
1485  const double c = cos(g.hdg);
1486  const double pMax = g.params[8] <= 0 ? g.length : g.params[8];
1487  const double pStep = pMax / ceil(g.length / resolution);
1488  PositionVector ret;
1489  for (double p = 0; p <= pMax + pStep; p += pStep) {
1490  double x = g.params[0] + g.params[1] * p + g.params[2] * pow(p, 2.) + g.params[3] * pow(p, 3.);
1491  double y = g.params[4] + g.params[5] * p + g.params[6] * pow(p, 2.) + g.params[7] * pow(p, 3.);
1492  double xnew = x * c - y * s;
1493  double ynew = x * s + y * c;
1494  ret.push_back(Position(g.x + xnew, g.y + ynew));
1495  }
1496  return ret.getSubpart2D(0, g.length);
1497 }
1498 
1499 
1500 Position
1501 NIImporter_OpenDrive::calculateStraightEndPoint(double hdg, double length, const Position& start) {
1502  double normx = 1.0f;
1503  double normy = 0.0f;
1504  double x2 = normx * cos(hdg) - normy * sin(hdg);
1505  double y2 = normx * sin(hdg) + normy * cos(hdg);
1506  normx = x2 * length;
1507  normy = y2 * length;
1508  return Position(start.x() + normx, start.y() + normy);
1509 }
1510 
1511 
1512 void
1513 NIImporter_OpenDrive::calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg) {
1514  double normX = 1.0;
1515  double normY = 0.0;
1516  double tmpX;
1517  double turn;
1518  if (ad_radius > 0) {
1519  turn = -1.0;
1520  } else {
1521  turn = 1.0;
1522  }
1523 
1524  tmpX = normX;
1525  normX = normX * cos(ad_hdg) + normY * sin(ad_hdg);
1526  normY = tmpX * sin(ad_hdg) + normY * cos(ad_hdg);
1527 
1528  tmpX = normX;
1529  normX = turn * normY;
1530  normY = -turn * tmpX;
1531 
1532  normX = fabs(ad_radius) * normX;
1533  normY = fabs(ad_radius) * normY;
1534 
1535  *ad_x += normX;
1536  *ad_y += normY;
1537 }
1538 
1539 
1540 void
1541 NIImporter_OpenDrive::calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
1542  double ad_r, double ad_length) {
1543  double rotAngle = ad_length / fabs(ad_r);
1544  double vx = *ad_x - ad_centerX;
1545  double vy = *ad_y - ad_centerY;
1546  double tmpx;
1547 
1548  double turn;
1549  if (ad_r > 0) {
1550  turn = -1; //left
1551  } else {
1552  turn = 1; //right
1553  }
1554  tmpx = vx;
1555  vx = vx * cos(rotAngle) + turn * vy * sin(rotAngle);
1556  vy = -1 * turn * tmpx * sin(rotAngle) + vy * cos(rotAngle);
1557  *ad_x = vx + ad_centerX;
1558  *ad_y = vy + ad_centerY;
1559 }
1560 
1561 
1562 // ---------------------------------------------------------------------------
1563 // section
1564 // ---------------------------------------------------------------------------
1566  lanesByDir[OPENDRIVE_TAG_LEFT] = std::vector<OpenDriveLane>();
1567  lanesByDir[OPENDRIVE_TAG_RIGHT] = std::vector<OpenDriveLane>();
1568  lanesByDir[OPENDRIVE_TAG_CENTER] = std::vector<OpenDriveLane>();
1569 }
1570 
1571 
1572 void
1574  int sumoLane = 0;
1575  bool singleType = true;
1576  std::vector<std::string> types;
1577  const std::vector<OpenDriveLane>& dirLanesR = lanesByDir.find(OPENDRIVE_TAG_RIGHT)->second;
1578  for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanesR.rbegin(); i != dirLanesR.rend(); ++i) {
1579  if (myImportAllTypes || (tc.knows((*i).type) && !tc.getShallBeDiscarded((*i).type))) {
1580  laneMap[(*i).id] = sumoLane++;
1581  types.push_back((*i).type);
1582  if (types.front() != types.back()) {
1583  singleType = false;
1584  }
1585  }
1586  }
1587  rightLaneNumber = sumoLane;
1588  rightType = sumoLane > 0 ? (singleType ? types.front() : joinToString(types, "|")) : "";
1589  sumoLane = 0;
1590  singleType = true;
1591  types.clear();
1592  const std::vector<OpenDriveLane>& dirLanesL = lanesByDir.find(OPENDRIVE_TAG_LEFT)->second;
1593  for (std::vector<OpenDriveLane>::const_iterator i = dirLanesL.begin(); i != dirLanesL.end(); ++i) {
1594  if (myImportAllTypes || (tc.knows((*i).type) && !tc.getShallBeDiscarded((*i).type))) {
1595  laneMap[(*i).id] = sumoLane++;
1596  types.push_back((*i).type);
1597  if (types.front() != types.back()) {
1598  singleType = false;
1599  }
1600  }
1601  }
1602  leftLaneNumber = sumoLane;
1603  leftType = sumoLane > 0 ? (singleType ? types.front() : joinToString(types, "|")) : "";
1604 }
1605 
1606 
1607 std::map<int, int>
1609  std::map<int, int> ret;
1610  const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
1611  for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
1612  std::map<int, int>::const_iterator toP = laneMap.find((*i).id);
1613  if (toP == laneMap.end()) {
1614  // the current lane is not available in SUMO
1615  continue;
1616  }
1617  int to = (*toP).second;
1618  int from = UNSET_CONNECTION;
1619  if ((*i).predecessor != UNSET_CONNECTION) {
1620  from = (*i).predecessor;
1621  }
1622  if (from != UNSET_CONNECTION) {
1623  std::map<int, int>::const_iterator fromP = prev.laneMap.find(from);
1624  if (fromP != prev.laneMap.end()) {
1625  from = (*fromP).second;
1626  } else {
1627  from = UNSET_CONNECTION;
1628  }
1629  }
1630  if (from != UNSET_CONNECTION && to != UNSET_CONNECTION) {
1631  if (ret.find(from) != ret.end()) {
1632 // WRITE_WARNING("double connection");
1633  }
1634  if (dir == OPENDRIVE_TAG_LEFT) {
1635  std::swap(from, to);
1636  }
1637  ret[from] = to;
1638  } else {
1639 // WRITE_WARNING("missing connection");
1640  }
1641  }
1642  return ret;
1643 }
1644 
1645 
1648  OpenDriveLaneSection ret(*this);
1649  ret.s += startPos;
1650  for (int k = 0; k < (int)ret.lanesByDir[OPENDRIVE_TAG_RIGHT].size(); ++k) {
1652  l.speed = 0;
1653  std::vector<std::pair<double, double> >::const_iterator i = std::find_if(l.speeds.begin(), l.speeds.end(), same_position_finder(startPos));
1654  if (i != l.speeds.end()) {
1655  l.speed = (*i).second;
1656  }
1657  }
1658  for (int k = 0; k < (int)ret.lanesByDir[OPENDRIVE_TAG_LEFT].size(); ++k) {
1660  std::vector<std::pair<double, double> >::const_iterator i = std::find_if(l.speeds.begin(), l.speeds.end(), same_position_finder(startPos));
1661  l.speed = 0;
1662  if (i != l.speeds.end()) {
1663  l.speed = (*i).second;
1664  }
1665  }
1666  return ret;
1667 }
1668 
1669 
1670 bool
1671 NIImporter_OpenDrive::OpenDriveLaneSection::buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections) {
1672  std::set<double> speedChangePositions;
1673  // collect speed change positions and apply initial speed to the begin
1674  for (std::vector<OpenDriveLane>::iterator k = lanesByDir[OPENDRIVE_TAG_RIGHT].begin(); k != lanesByDir[OPENDRIVE_TAG_RIGHT].end(); ++k) {
1675  for (std::vector<std::pair<double, double> >::const_iterator l = (*k).speeds.begin(); l != (*k).speeds.end(); ++l) {
1676  speedChangePositions.insert((*l).first);
1677  if ((*l).first == 0) {
1678  (*k).speed = (*l).second;
1679  }
1680  }
1681  }
1682  for (std::vector<OpenDriveLane>::iterator k = lanesByDir[OPENDRIVE_TAG_LEFT].begin(); k != lanesByDir[OPENDRIVE_TAG_LEFT].end(); ++k) {
1683  for (std::vector<std::pair<double, double> >::const_iterator l = (*k).speeds.begin(); l != (*k).speeds.end(); ++l) {
1684  speedChangePositions.insert((*l).first);
1685  if ((*l).first == 0) {
1686  (*k).speed = (*l).second;
1687  }
1688  }
1689  }
1690  // do nothing if there is none
1691  if (speedChangePositions.size() == 0) {
1692  return false;
1693  }
1694  if (*speedChangePositions.begin() > 0) {
1695  speedChangePositions.insert(0);
1696  }
1697 #ifdef DEBUG_VARIABLE_SPEED
1698  if (gDebugFlag1) std::cout
1699  << " buildSpeedChanges sectionStart=" << s
1700  << " speedChangePositions=" << joinToString(speedChangePositions, ", ")
1701  << "\n";
1702 #endif
1703  for (std::set<double>::iterator i = speedChangePositions.begin(); i != speedChangePositions.end(); ++i) {
1704  if (i == speedChangePositions.begin()) {
1705  newSections.push_back(*this);
1706  } else {
1707  newSections.push_back(buildLaneSection(*i));
1708  }
1709  }
1710  // propagate speeds
1711  for (int i = 0; i != (int)newSections.size(); ++i) {
1712  OpenDriveLaneSection& ls = newSections[i];
1713  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> >& lanesByDir = ls.lanesByDir;
1714  for (std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> >::iterator k = lanesByDir.begin(); k != lanesByDir.end(); ++k) {
1715  std::vector<OpenDriveLane>& lanes = (*k).second;
1716  for (int j = 0; j != (int)lanes.size(); ++j) {
1717  OpenDriveLane& l = lanes[j];
1718  if (l.speed != 0) {
1719  continue;
1720  }
1721  if (i > 0) {
1722  l.speed = newSections[i - 1].lanesByDir[(*k).first][j].speed;
1723  } else {
1724  tc.getSpeed(l.type);
1725  }
1726  }
1727  }
1728  }
1729  return true;
1730 }
1731 
1732 
1733 
1734 // ---------------------------------------------------------------------------
1735 // edge
1736 // ---------------------------------------------------------------------------
1737 int
1739  // for signal interpretations see https://de.wikipedia.org/wiki/Bildtafel_der_Verkehrszeichen_in_der_Bundesrepublik_Deutschland_seit_2013
1740  int prio = 1;
1741  for (std::vector<OpenDriveSignal>::const_iterator i = signals.begin(); i != signals.end(); ++i) {
1742  int tmp = 1;
1743  if ((*i).type == "301" || (*i).type == "306") { // priority road or local priority
1744  tmp = 2;
1745  }
1746  if ((*i).type == "205" /*|| (*i).type == "206"*/) { // yield or stop
1747  tmp = 0;
1748  }
1749  if (tmp != 1 && dir == OPENDRIVE_TAG_RIGHT && (*i).orientation > 0) {
1750  prio = tmp;
1751  }
1752  if (tmp != 1 && dir == OPENDRIVE_TAG_LEFT && (*i).orientation < 0) {
1753  prio = tmp;
1754  }
1755 
1756  }
1757  return prio;
1758 }
1759 
1760 
1761 
1762 // ---------------------------------------------------------------------------
1763 // loader methods
1764 // ---------------------------------------------------------------------------
1765 NIImporter_OpenDrive::NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges)
1767  myTypeContainer(tc), myCurrentEdge("", "", "", -1), myEdges(edges) {
1768 }
1769 
1770 
1772 }
1773 
1774 
1775 void
1777  const SUMOSAXAttributes& attrs) {
1778  bool ok = true;
1779  switch (element) {
1780  case OPENDRIVE_TAG_HEADER: {
1781  int majorVersion = attrs.get<int>(OPENDRIVE_ATTR_REVMAJOR, nullptr, ok);
1782  int minorVersion = attrs.get<int>(OPENDRIVE_ATTR_REVMINOR, nullptr, ok);
1783  if (majorVersion != 1 || minorVersion != 2) {
1784  // TODO: leave note of exceptions
1785  WRITE_WARNING("Given openDrive file '" + getFileName() + "' uses version " + toString(majorVersion) + "." + toString(minorVersion) + ";\n Version 1.2 is supported.");
1786  }
1787  }
1788  break;
1789  case OPENDRIVE_TAG_ROAD: {
1790  std::string id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, nullptr, ok);
1791  std::string streetName = attrs.getOpt<std::string>(OPENDRIVE_ATTR_NAME, nullptr, ok, "", false);
1792  std::string junction = attrs.get<std::string>(OPENDRIVE_ATTR_JUNCTION, id.c_str(), ok);
1793  double length = attrs.get<double>(OPENDRIVE_ATTR_LENGTH, id.c_str(), ok);
1794  myCurrentEdge = OpenDriveEdge(id, streetName, junction, length);
1795  }
1796  break;
1798  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_ROAD) {
1799  std::string elementType = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTTYPE, myCurrentEdge.id.c_str(), ok);
1800  std::string elementID = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTID, myCurrentEdge.id.c_str(), ok);
1801  std::string contactPoint = attrs.hasAttribute(OPENDRIVE_ATTR_CONTACTPOINT)
1802  ? attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentEdge.id.c_str(), ok)
1803  : "end";
1804  addLink(OPENDRIVE_LT_PREDECESSOR, elementType, elementID, contactPoint);
1805  }
1806  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_LANE) {
1807  int no = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1808  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1809  l.predecessor = no;
1810  }
1811  }
1812  break;
1813  case OPENDRIVE_TAG_SUCCESSOR: {
1814  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_ROAD) {
1815  std::string elementType = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTTYPE, myCurrentEdge.id.c_str(), ok);
1816  std::string elementID = attrs.get<std::string>(OPENDRIVE_ATTR_ELEMENTID, myCurrentEdge.id.c_str(), ok);
1817  std::string contactPoint = attrs.hasAttribute(OPENDRIVE_ATTR_CONTACTPOINT)
1818  ? attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentEdge.id.c_str(), ok)
1819  : "start";
1820  addLink(OPENDRIVE_LT_SUCCESSOR, elementType, elementID, contactPoint);
1821  }
1822  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 2] == OPENDRIVE_TAG_LANE) {
1823  int no = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1824  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1825  l.successor = no;
1826  }
1827  }
1828  break;
1829  case OPENDRIVE_TAG_GEOMETRY: {
1830  double length = attrs.get<double>(OPENDRIVE_ATTR_LENGTH, myCurrentEdge.id.c_str(), ok);
1831  double s = attrs.get<double>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1832  double x = attrs.get<double>(OPENDRIVE_ATTR_X, myCurrentEdge.id.c_str(), ok);
1833  double y = attrs.get<double>(OPENDRIVE_ATTR_Y, myCurrentEdge.id.c_str(), ok);
1834  double hdg = attrs.get<double>(OPENDRIVE_ATTR_HDG, myCurrentEdge.id.c_str(), ok);
1835  myCurrentEdge.geometries.push_back(OpenDriveGeometry(length, s, x, y, hdg));
1836  }
1837  break;
1838  case OPENDRIVE_TAG_ELEVATION: {
1839  double s = attrs.get<double>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1840  double a = attrs.get<double>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok);
1841  double b = attrs.get<double>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok);
1842  double c = attrs.get<double>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok);
1843  double d = attrs.get<double>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok);
1844  myCurrentEdge.elevations.push_back(OpenDriveElevation(s, a, b, c, d));
1845  }
1846  break;
1847  case OPENDRIVE_TAG_LINE: {
1848  if (myElementStack.size() > 0 && myElementStack.back() == OPENDRIVE_TAG_GEOMETRY) {
1849  std::vector<double> vals;
1851  }
1852  }
1853  break;
1854  case OPENDRIVE_TAG_SPIRAL: {
1855  std::vector<double> vals;
1856  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_CURVSTART, myCurrentEdge.id.c_str(), ok));
1857  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_CURVEND, myCurrentEdge.id.c_str(), ok));
1859  }
1860  break;
1861  case OPENDRIVE_TAG_ARC: {
1862  std::vector<double> vals;
1863  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_CURVATURE, myCurrentEdge.id.c_str(), ok));
1865  }
1866  break;
1867  case OPENDRIVE_TAG_POLY3: {
1868  std::vector<double> vals;
1869  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok));
1870  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok));
1871  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok));
1872  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok));
1874  }
1875  break;
1876  case OPENDRIVE_TAG_PARAMPOLY3: {
1877  std::vector<double> vals;
1878  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_AU, myCurrentEdge.id.c_str(), ok));
1879  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_BU, myCurrentEdge.id.c_str(), ok));
1880  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_CU, myCurrentEdge.id.c_str(), ok));
1881  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_DU, myCurrentEdge.id.c_str(), ok));
1882  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_AV, myCurrentEdge.id.c_str(), ok));
1883  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_BV, myCurrentEdge.id.c_str(), ok));
1884  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_CV, myCurrentEdge.id.c_str(), ok));
1885  vals.push_back(attrs.get<double>(OPENDRIVE_ATTR_DV, myCurrentEdge.id.c_str(), ok));
1886  const std::string pRange = attrs.getOpt<std::string>(OPENDRIVE_ATTR_PRANGE, myCurrentEdge.id.c_str(), ok, "normalized", false);
1887  if (pRange == "normalized") {
1888  vals.push_back(1.0);
1889  } else if (pRange == "arcLength") {
1890  vals.push_back(-1.0);
1891  } else {
1892  WRITE_WARNING("Ignoring invalid pRange value '" + pRange + "' for road '" + myCurrentEdge.id + "'.");
1893  vals.push_back(1.0);
1894  }
1896  }
1897  break;
1899  double s = attrs.get<double>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1900  if (myCurrentEdge.laneSections.size() > 0) {
1901  myCurrentEdge.laneSections.back().length = s - myCurrentEdge.laneSections.back().s;
1902  }
1904  // possibly updated by the next laneSection
1905  myCurrentEdge.laneSections.back().length = myCurrentEdge.length - s;
1906  }
1907  break;
1908  case OPENDRIVE_TAG_LANEOFFSET: {
1909  double s = attrs.get<double>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1910  double a = attrs.get<double>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok);
1911  double b = attrs.get<double>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok);
1912  double c = attrs.get<double>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok);
1913  double d = attrs.get<double>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok);
1914  myCurrentEdge.offsets.push_back(OpenDriveLaneOffset(s, a, b, c, d));
1915  }
1916  break;
1917  case OPENDRIVE_TAG_LEFT:
1919  break;
1920  case OPENDRIVE_TAG_CENTER:
1922  break;
1923  case OPENDRIVE_TAG_RIGHT:
1925  break;
1926  case OPENDRIVE_TAG_LANE: {
1927  std::string type = attrs.get<std::string>(OPENDRIVE_ATTR_TYPE, myCurrentEdge.id.c_str(), ok);
1928  int id = attrs.get<int>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1929  std::string level = attrs.hasAttribute(OPENDRIVE_ATTR_LEVEL)
1930  ? attrs.get<std::string>(OPENDRIVE_ATTR_LEVEL, myCurrentEdge.id.c_str(), ok)
1931  : "";
1933  ls.lanesByDir[myCurrentLaneDirection].push_back(OpenDriveLane(id, level, type));
1934  }
1935  break;
1936  case OPENDRIVE_TAG_SIGNAL: {
1937  std::string id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, myCurrentEdge.id.c_str(), ok);
1938  std::string type = attrs.get<std::string>(OPENDRIVE_ATTR_TYPE, myCurrentEdge.id.c_str(), ok);
1939  std::string name = attrs.getOpt<std::string>(OPENDRIVE_ATTR_NAME, myCurrentEdge.id.c_str(), ok, "", false);
1940  int orientation = attrs.get<std::string>(OPENDRIVE_ATTR_ORIENTATION, myCurrentEdge.id.c_str(), ok) == "-" ? -1 : 1;
1941  double s = attrs.get<double>(OPENDRIVE_ATTR_S, myCurrentEdge.id.c_str(), ok);
1942  bool dynamic = attrs.get<std::string>(OPENDRIVE_ATTR_DYNAMIC, myCurrentEdge.id.c_str(), ok) == "no" ? false : true;
1943  myCurrentEdge.signals.push_back(OpenDriveSignal(id, type, name, orientation, dynamic, s));
1944  }
1945  break;
1947  myCurrentJunctionID = attrs.get<std::string>(OPENDRIVE_ATTR_ID, myCurrentJunctionID.c_str(), ok);
1948  break;
1949  case OPENDRIVE_TAG_CONNECTION: {
1950  std::string id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, myCurrentJunctionID.c_str(), ok);
1951  myCurrentIncomingRoad = attrs.get<std::string>(OPENDRIVE_ATTR_INCOMINGROAD, myCurrentJunctionID.c_str(), ok);
1953  std::string cp = attrs.get<std::string>(OPENDRIVE_ATTR_CONTACTPOINT, myCurrentJunctionID.c_str(), ok);
1955  myConnectionWasEmpty = true;
1956  }
1957  break;
1958  case OPENDRIVE_TAG_LANELINK: {
1959  int from = attrs.get<int>(OPENDRIVE_ATTR_FROM, myCurrentJunctionID.c_str(), ok);
1960  int to = attrs.get<int>(OPENDRIVE_ATTR_TO, myCurrentJunctionID.c_str(), ok);
1961  Connection c;
1963  c.toEdge = myCurrentConnectingRoad;
1964  c.fromLane = from;
1965  c.toLane = to;
1966  c.fromCP = OPENDRIVE_CP_END;
1967  c.toCP = myCurrentContactPoint;
1968  c.all = false;
1969  if (myEdges.find(c.fromEdge) == myEdges.end()) {
1970  WRITE_ERROR("In laneLink-element: incoming road '" + c.fromEdge + "' is not known.");
1971  } else {
1972  OpenDriveEdge* e = myEdges.find(c.fromEdge)->second;
1973  e->connections.insert(c);
1974  myConnectionWasEmpty = false;
1975  }
1976  }
1977  break;
1978  case OPENDRIVE_TAG_WIDTH: {
1979  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 1] == OPENDRIVE_TAG_LANE) {
1980  const double s = attrs.get<double>(OPENDRIVE_ATTR_SOFFSET, myCurrentEdge.id.c_str(), ok);
1981  const double a = attrs.get<double>(OPENDRIVE_ATTR_A, myCurrentEdge.id.c_str(), ok);
1982  const double b = attrs.get<double>(OPENDRIVE_ATTR_B, myCurrentEdge.id.c_str(), ok);
1983  const double c = attrs.get<double>(OPENDRIVE_ATTR_C, myCurrentEdge.id.c_str(), ok);
1984  const double d = attrs.get<double>(OPENDRIVE_ATTR_D, myCurrentEdge.id.c_str(), ok);
1985  OpenDriveLane& l = myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back();
1986  l.width = MAX2(l.width, a);
1987  l.widthData.push_back(OpenDriveWidth(s, a, b, c, d));
1988 #ifdef DEBUG_VARIABLE_WIDTHS
1989  if (DEBUG_COND(&myCurrentEdge)) {
1990  std::cout << " road=" << myCurrentEdge.id
1991  << std::setprecision(gPrecision)
1992  << " junction=" << myCurrentEdge.junction
1993  << " section=" << myCurrentEdge.laneSections.size() - 1
1994  << " dir=" << myCurrentLaneDirection << " lane=" << l.id
1995  << " type=" << l.type
1996  << " width=" << l.width
1997  << " a=" << a
1998  << " b=" << b
1999  << " c=" << c
2000  << " d=" << d
2001  << " s=" << s
2002  << " entries=" << l.widthData.size()
2003  << "\n";
2004  }
2005 #endif
2006  }
2007  }
2008  break;
2009  case OPENDRIVE_TAG_SPEED: {
2010  if (myElementStack.size() >= 2 && myElementStack[myElementStack.size() - 1] == OPENDRIVE_TAG_LANE) {
2011  double speed = attrs.get<double>(OPENDRIVE_ATTR_MAX, myCurrentEdge.id.c_str(), ok);
2012  double pos = attrs.get<double>(OPENDRIVE_ATTR_SOFFSET, myCurrentEdge.id.c_str(), ok);
2013  // required for xodr v1.4
2014  const std::string unit = attrs.getOpt<std::string>(OPENDRIVE_ATTR_UNIT, myCurrentEdge.id.c_str(), ok, "", false);
2015  // now convert the speed to reasonable default SI [m/s]
2016  if (!unit.empty()) {
2017  // something to be done at all ?
2018  if (unit == "km/h") {
2019  speed /= 3.6;
2020  }
2021  if (unit == "mph") {
2022  speed *= 1.609344 / 3.6;
2023  }
2024  // IGNORING unknown units.
2025  }
2026  myCurrentEdge.laneSections.back().lanesByDir[myCurrentLaneDirection].back().speeds.push_back(std::make_pair(pos, speed));
2027  }
2028  }
2029  break;
2030  case OPENDRIVE_TAG_OBJECT: {
2031  if (!attrs.hasAttribute(OPENDRIVE_ATTR_ID)) {
2032  WRITE_WARNING("Ignoring object without id at edge '" + toString(myCurrentEdge.id) + "'.");
2033  break;
2034  }
2035  OpenDriveObject o;
2036  o.id = attrs.get<std::string>(OPENDRIVE_ATTR_ID, 0, ok);
2037  o.type = attrs.getOpt<std::string>(OPENDRIVE_ATTR_TYPE, o.id.c_str(), ok, "", false);
2038  o.name = attrs.getOpt<std::string>(OPENDRIVE_ATTR_NAME, o.id.c_str(), ok, "", false);
2039  o.s = attrs.get<double>(OPENDRIVE_ATTR_S, o.id.c_str(), ok);
2040  o.t = attrs.get<double>(OPENDRIVE_ATTR_T, o.id.c_str(), ok);
2041  o.width = attrs.getOpt<double>(OPENDRIVE_ATTR_WIDTH, o.id.c_str(), ok, -1);
2042  o.length = attrs.getOpt<double>(OPENDRIVE_ATTR_LENGTH, o.id.c_str(), ok, -1);
2043  o.radius = attrs.getOpt<double>(OPENDRIVE_ATTR_RADIUS, o.id.c_str(), ok, -1);
2044  o.hdg = attrs.getOpt<double>(OPENDRIVE_ATTR_HDG, o.id.c_str(), ok, 0);
2045  myCurrentEdge.objects.push_back(o);
2046  }
2047  break;
2048  case OPENDRIVE_TAG_REPEAT: {
2049  if (myCurrentEdge.objects.empty()) {
2050  WRITE_ERROR("Repeat without object at edge '" + toString(myCurrentEdge.id) + "'.");
2051  ok = false;
2052  } else {
2054  const std::string baseID = o.id;
2055  double dist = attrs.get<double>(OPENDRIVE_ATTR_DISTANCE, o.id.c_str(), ok);
2056  if (dist == 0) {
2057  // continuous feature. Split into parts (XXX exmport as a single polygon #5235)
2058  dist = OptionsCont::getOptions().getFloat("opendrive.curve-resolution");
2059  }
2060 
2061  myCurrentEdge.objects.pop_back();
2062  const double length = attrs.get<double>(OPENDRIVE_ATTR_LENGTH, o.id.c_str(), ok);
2063  o.s = attrs.getOpt<double>(OPENDRIVE_ATTR_S, o.id.c_str(), ok, o.s);
2064  double wStart = attrs.getOpt<double>(OPENDRIVE_ATTR_WIDTHSTART, o.id.c_str(), ok, o.width);
2065  double wEnd = attrs.getOpt<double>(OPENDRIVE_ATTR_WIDTHEND, o.id.c_str(), ok, o.width);
2066  double tStart = attrs.getOpt<double>(OPENDRIVE_ATTR_TSTART, o.id.c_str(), ok, o.t);
2067  double tEnd = attrs.getOpt<double>(OPENDRIVE_ATTR_TEND, o.id.c_str(), ok, o.t);
2068  int index = 0;
2069  for (double x = 0; x <= length + NUMERICAL_EPS; x += dist) {
2070  o.id = baseID + "#" + toString(index++);
2071  const double a = x / length;
2072  o.width = wStart * (1 - a) + wEnd * a;
2073  o.t = tStart * (1 - a) + tEnd * a;
2074  myCurrentEdge.objects.push_back(o);
2075  o.s += dist;
2076  }
2077  }
2078  }
2079  break;
2080  default:
2081  break;
2082  }
2083  myElementStack.push_back(element);
2084 }
2085 
2086 
2087 void
2088 NIImporter_OpenDrive::myCharacters(int element, const std::string& cdata) {
2089  if (element == OPENDRIVE_TAG_GEOREFERENCE) {
2090  size_t i = cdata.find("+proj");
2091  if (i != std::string::npos) {
2092  const std::string proj = cdata.substr(i);
2093  if (proj != "") {
2094  GeoConvHelper* result = nullptr;
2095  Boundary convBoundary;
2096  Boundary origBoundary;
2097  Position networkOffset(0, 0);
2098  // XXX read values from the header
2099  convBoundary.add(Position(0, 0));
2100  origBoundary.add(Position(0, 0));
2101  try {
2102  result = new GeoConvHelper(proj, networkOffset, origBoundary, convBoundary);
2103  GeoConvHelper::setLoaded(*result);
2104  } catch (ProcessError& e) {
2105  WRITE_ERROR("Could not set projection. (" + std::string(e.what()) + ")");
2106  }
2107  }
2108  } else {
2109  WRITE_WARNING("geoReference format '" + cdata + "' currently not supported");
2110  }
2111  }
2112 }
2113 
2114 
2115 void
2117  myElementStack.pop_back();
2118  switch (element) {
2119  case OPENDRIVE_TAG_ROAD:
2121  break;
2123  if (myConnectionWasEmpty) {
2124  Connection c;
2127  c.fromLane = 0;
2128  c.toLane = 0;
2131  c.all = true;
2132  if (myEdges.find(c.fromEdge) == myEdges.end()) {
2133  WRITE_ERROR("In laneLink-element: incoming road '" + c.fromEdge + "' is not known.");
2134  } else {
2135  OpenDriveEdge* e = myEdges.find(c.fromEdge)->second;
2136  e->connections.insert(c);
2137  }
2138  }
2139  break;
2141  myCurrentEdge.laneSections.back().buildLaneMapping(myTypeContainer);
2142  }
2143  break;
2144  default:
2145  break;
2146  }
2147 }
2148 
2149 
2150 
2151 void
2152 NIImporter_OpenDrive::addLink(LinkType lt, const std::string& elementType,
2153  const std::string& elementID,
2154  const std::string& contactPoint) {
2155  OpenDriveLink l(lt, elementID);
2156  // elementType
2157  if (elementType == "road") {
2159  } else if (elementType == "junction") {
2161  }
2162  // contact point
2163  if (contactPoint == "start") {
2165  } else if (contactPoint == "end") {
2167  }
2168  // add
2169  myCurrentEdge.links.push_back(l);
2170 }
2171 
2172 
2173 void
2174 NIImporter_OpenDrive::addGeometryShape(GeometryType type, const std::vector<double>& vals) {
2175  // checks
2176  if (myCurrentEdge.geometries.size() == 0) {
2177  throw ProcessError("Mismatching paranthesis in geometry definition for road '" + myCurrentEdge.id + "'");
2178  }
2180  if (last.type != OPENDRIVE_GT_UNKNOWN) {
2181  throw ProcessError("Double geometry information for road '" + myCurrentEdge.id + "'");
2182  }
2183  // set
2184  last.type = type;
2185  last.params = vals;
2186 }
2187 
2188 
2189 bool
2191  if (c1.fromEdge != c2.fromEdge) {
2192  return c1.fromEdge < c2.fromEdge;
2193  }
2194  if (c1.toEdge != c2.toEdge) {
2195  return c1.toEdge < c2.toEdge;
2196  }
2197  if (c1.fromLane != c2.fromLane) {
2198  return c1.fromLane < c2.fromLane;
2199  }
2200  return c1.toLane < c2.toLane;
2201 }
2202 
2203 void
2205 #ifdef DEBUG_VARIABLE_WIDTHS
2206  if (DEBUG_COND(e)) {
2207  gDebugFlag1 = true;
2208  std::cout << "sanitizeWidths e=" << e->id << " sections=" << e->laneSections.size() << "\n";
2209  }
2210 #endif
2211  for (OpenDriveLaneSection& sec : e->laneSections) {
2212  // filter widths within the current section (#5888).
2213  // @note, Short laneSections could also be worth filtering alltogether
2214  if (sec.rightLaneNumber > 0) {
2216  }
2217  if (sec.leftLaneNumber > 0) {
2219  }
2220  }
2221 }
2222 
2223 void
2224 NIImporter_OpenDrive::sanitizeWidths(std::vector<OpenDriveLane>& lanes, double length) {
2225  for (OpenDriveLane& l : lanes) {
2226  if (l.widthData.size() > 0) {
2227  auto& wd = l.widthData;
2228  const double threshold = POSITION_EPS;
2229  double maxNoShort = -std::numeric_limits<double>::max();
2230  double seen = 0;
2231  for (int i = 0; i < (int)wd.size(); i++) {
2232  const double wdLength = i < (int)wd.size() - 1 ? wd[i + 1].s - wd[i].s : length - seen;
2233  seen += wdLength;
2234  if (wdLength > threshold) {
2235  maxNoShort = MAX2(maxNoShort, wd[i].a);
2236  }
2237  }
2238  if (maxNoShort > 0) {
2239  l.width = maxNoShort;
2240  }
2241  }
2242  }
2243 }
2244 
2245 
2246 void
2248  std::vector<OpenDriveLaneSection> newSections;
2249 #ifdef DEBUG_VARIABLE_WIDTHS
2250  if (DEBUG_COND(e)) {
2251  gDebugFlag1 = true;
2252  std::cout << "splitMinWidths e=" << e->id << " sections=" << e->laneSections.size() << "\n";
2253  }
2254 #endif
2255  for (std::vector<OpenDriveLaneSection>::iterator j = e->laneSections.begin(); j != e->laneSections.end(); ++j) {
2256  OpenDriveLaneSection& sec = *j;
2257  std::vector<double> splitPositions;
2258  const double sectionEnd = (j + 1) == e->laneSections.end() ? e->length : (*(j + 1)).s;
2259  const int section = (int)(j - e->laneSections.begin());
2260 #ifdef DEBUG_VARIABLE_WIDTHS
2261  if (DEBUG_COND(e)) {
2262  std::cout << " findWidthSplit section=" << section << " sectionStart=" << sec.s << " sectionOrigStart=" << sec.sOrig << " sectionEnd=" << sectionEnd << "\n";
2263  }
2264 #endif
2265  if (sec.rightLaneNumber > 0) {
2266  findWidthSplit(tc, sec.lanesByDir[OPENDRIVE_TAG_RIGHT], section, sec.sOrig, sectionEnd, splitPositions);
2267  }
2268  if (sec.leftLaneNumber > 0) {
2269  findWidthSplit(tc, sec.lanesByDir[OPENDRIVE_TAG_LEFT], section, sec.sOrig, sectionEnd, splitPositions);
2270  }
2271  newSections.push_back(sec);
2272  std::sort(splitPositions.begin(), splitPositions.end());
2273  // filter out tiny splits
2274  double prevSplit = sec.s;
2275  for (std::vector<double>::iterator it = splitPositions.begin(); it != splitPositions.end();) {
2276  if ((*it) - prevSplit < minDist || sectionEnd - (*it) < minDist) {
2277  // avoid tiny (or duplicate) splits
2278 #ifdef DEBUG_VARIABLE_WIDTHS
2279  if (DEBUG_COND(e)) {
2280  std::cout << " skip close split=" << (*it) << " prevSplit=" << prevSplit << "\n";
2281  }
2282 #endif
2283  it = splitPositions.erase(it);
2284  } else if ((*it) < sec.s) {
2285  // avoid splits for another section
2286 #ifdef DEBUG_VARIABLE_WIDTHS
2287  if (DEBUG_COND(e)) {
2288  std::cout << " skip early split=" << (*it) << " s=" << sec.s << "\n";
2289  }
2290 #endif
2291  it = splitPositions.erase(it);
2292  } else {
2293  prevSplit = *it;
2294  it++;
2295  }
2296  }
2297 
2298  if (splitPositions.size() > 0) {
2299 #ifdef DEBUG_VARIABLE_WIDTHS
2300  if (DEBUG_COND(e)) {
2301  std::cout << " road=" << e->id << " splitMinWidths section=" << section
2302  << " start=" << sec.s
2303  << " origStart=" << sec.sOrig
2304  << " end=" << sectionEnd << " minDist=" << minDist
2305  << " splitPositions=" << toString(splitPositions) << "\n";
2306  }
2307 #endif
2308 #ifdef DEBUG_VARIABLE_WIDTHS
2309  if (DEBUG_COND(e)) {
2310  std::cout << "first section...\n";
2311  }
2312 #endif
2313  recomputeWidths(newSections.back(), sec.sOrig, splitPositions.front(), sec.sOrig, sectionEnd);
2314  for (std::vector<double>::iterator it = splitPositions.begin(); it != splitPositions.end(); ++it) {
2315  OpenDriveLaneSection secNew = sec;
2316  secNew.s = *it;
2317 #ifdef DEBUG_VARIABLE_WIDTHS
2318  if (DEBUG_COND(e)) {
2319  std::cout << "splitAt " << secNew.s << "\n";
2320  }
2321 #endif
2322  newSections.push_back(secNew);
2323  if (secNew.rightLaneNumber > 0) {
2324  setStraightConnections(newSections.back().lanesByDir[OPENDRIVE_TAG_RIGHT]);
2325  }
2326  if (secNew.leftLaneNumber > 0) {
2327  setStraightConnections(newSections.back().lanesByDir[OPENDRIVE_TAG_LEFT]);
2328  }
2329  double end = (it + 1) == splitPositions.end() ? sectionEnd : *(it + 1);
2330  recomputeWidths(newSections.back(), secNew.s, end, sec.sOrig, sectionEnd);
2331  }
2332  }
2333  }
2334  gDebugFlag1 = false;
2335  e->laneSections = newSections;
2336 }
2337 
2338 
2339 void
2340 NIImporter_OpenDrive::findWidthSplit(const NBTypeCont& tc, std::vector<OpenDriveLane>& lanes,
2341  int section, double sectionStart, double sectionEnd,
2342  std::vector<double>& splitPositions) {
2343  UNUSED_PARAMETER(section);
2344  for (std::vector<OpenDriveLane>::iterator k = lanes.begin(); k != lanes.end(); ++k) {
2345  OpenDriveLane& l = *k;
2346  SVCPermissions permissions = tc.getPermissions(l.type) & ~(SVC_PEDESTRIAN | SVC_BICYCLE);
2347  if (l.widthData.size() > 0 && tc.knows(l.type) && !tc.getShallBeDiscarded(l.type) && permissions != 0) {
2348  double sPrev = l.widthData.front().s;
2349  double wPrev = l.widthData.front().computeAt(sPrev);
2350  if (gDebugFlag1) std::cout
2351  << "findWidthSplit section=" << section
2352  << " sectionStart=" << sectionStart
2353  << " sectionEnd=" << sectionEnd
2354  << " lane=" << l.id
2355  << " type=" << l.type
2356  << " widthEntries=" << l.widthData.size() << "\n"
2357  << " s=" << sPrev
2358  << " w=" << wPrev
2359  << "\n";
2360  for (std::vector<OpenDriveWidth>::iterator it_w = l.widthData.begin(); it_w != l.widthData.end(); ++it_w) {
2361  double sEnd = (it_w + 1) != l.widthData.end() ? (*(it_w + 1)).s : sectionEnd - sectionStart;
2362  double w = (*it_w).computeAt(sEnd);
2363  if (gDebugFlag1) std::cout
2364  << " sEnd=" << sEnd
2365  << " s=" << (*it_w).s
2366  << " a=" << (*it_w).a << " b=" << (*it_w).b << " c=" << (*it_w).c << " d=" << (*it_w).d
2367  << " w=" << w
2368  << "\n";
2369  const double changeDist = fabs(myMinWidth - wPrev);
2370  if (((wPrev < myMinWidth) && (w > myMinWidth))
2371  || ((wPrev > myMinWidth) && (w < myMinWidth))) {
2372  double splitPos = sPrev + (sEnd - sPrev) / fabs(w - wPrev) * changeDist;
2373  double wSplit = (*it_w).computeAt(splitPos);
2374  if (gDebugFlag1) {
2375  std::cout << " candidate splitPos=" << splitPos << " w=" << wSplit << "\n";
2376  }
2377  // ensure that the thin part is actually thin enough
2378  while (wSplit > myMinWidth) {
2379  if (wPrev < myMinWidth) {
2380  // getting wider
2381  splitPos -= POSITION_EPS;
2382  if (splitPos < sPrev) {
2383  if (gDebugFlag1) {
2384  std::cout << " aborting search splitPos=" << splitPos << " wSplit=" << wSplit << " sPrev=" << sPrev << " wPrev=" << wPrev << "\n";
2385  }
2386  splitPos = sPrev;
2387  break;
2388  }
2389  } else {
2390  // getting thinner
2391  splitPos += POSITION_EPS;
2392  if (splitPos > sEnd) {
2393  if (gDebugFlag1) {
2394  std::cout << " aborting search splitPos=" << splitPos << " wSplit=" << wSplit << " sEnd=" << sEnd << " w=" << w << "\n";
2395  }
2396  splitPos = sEnd;
2397  break;
2398  }
2399  }
2400  wSplit = (*it_w).computeAt(splitPos);
2401  if (gDebugFlag1) {
2402  std::cout << " refined splitPos=" << splitPos << " w=" << wSplit << "\n";
2403  }
2404  }
2405  splitPositions.push_back(sectionStart + splitPos);
2406  }
2407  // //wPrev = wSplit;
2408  //} else if ((fabs(wPrev) < NUMERICAL_EPS && w > POSITION_EPS)
2409  // || (wPrev > POSITION_EPS && fabs(w) < NUMERICAL_EPS)) {
2410  // splitPositions.push_back(sectionStart + sPrev);
2411  // if (gDebugFlag1) std::cout << " laneDisappears candidate splitPos=" << sPrev << " wPrev=" << wPrev << " w=" << w<< "\n";
2412  //}
2413  wPrev = w;
2414  sPrev = sEnd;
2415  }
2416  }
2417  }
2418 }
2419 
2420 
2421 void
2422 NIImporter_OpenDrive::setStraightConnections(std::vector<OpenDriveLane>& lanes) {
2423  for (std::vector<OpenDriveLane>::iterator k = lanes.begin(); k != lanes.end(); ++k) {
2424  (*k).predecessor = (*k).id;
2425  }
2426 }
2427 
2428 
2429 void
2430 NIImporter_OpenDrive::recomputeWidths(OpenDriveLaneSection& sec, double start, double end, double sectionStart, double sectionEnd) {
2431  if (sec.rightLaneNumber > 0) {
2432  recomputeWidths(sec.lanesByDir[OPENDRIVE_TAG_RIGHT], start, end, sectionStart, sectionEnd);
2433  }
2434  if (sec.leftLaneNumber > 0) {
2435  recomputeWidths(sec.lanesByDir[OPENDRIVE_TAG_LEFT], start, end, sectionStart, sectionEnd);
2436  }
2437 }
2438 
2439 
2440 void
2441 NIImporter_OpenDrive::recomputeWidths(std::vector<OpenDriveLane>& lanes, double start, double end, double sectionStart, double sectionEnd) {
2442  for (std::vector<OpenDriveLane>::iterator k = lanes.begin(); k != lanes.end(); ++k) {
2443  OpenDriveLane& l = *k;
2444  if (l.widthData.size() > 0) {
2445 #ifdef DEBUG_VARIABLE_WIDTHS
2446  if (gDebugFlag1) std::cout
2447  << "recomputeWidths lane=" << l.id
2448  << " type=" << l.type
2449  << " start=" << start
2450  << " end=" << end
2451  << " sectionStart=" << sectionStart
2452  << " sectionEnd=" << sectionEnd
2453  << " widthEntries=" << l.widthData.size() << "\n"
2454  << "\n";
2455 #endif
2456  l.width = 0;
2457  double sPrev = l.widthData.front().s;
2458  double sPrevAbs = sPrev + sectionStart;
2459  for (std::vector<OpenDriveWidth>::iterator it_w = l.widthData.begin(); it_w != l.widthData.end(); ++it_w) {
2460  double sEnd = (it_w + 1) != l.widthData.end() ? (*(it_w + 1)).s : sectionEnd - sectionStart;
2461  double sEndAbs = sEnd + sectionStart;
2462 #ifdef DEBUG_VARIABLE_WIDTHS
2463  if (gDebugFlag1) std::cout
2464  << " sPrev=" << sPrev << " sPrevAbs=" << sPrevAbs
2465  << " sEnd=" << sEnd << " sEndAbs=" << sEndAbs
2466  << " widthData s=" << (*it_w).s
2467  << " a=" << (*it_w).a
2468  << " b=" << (*it_w).b
2469  << " c=" << (*it_w).c
2470  << " d=" << (*it_w).d
2471  << "\n";
2472 #endif
2473  if (sPrevAbs <= start && sEndAbs >= start) {
2474 #ifdef DEBUG_VARIABLE_WIDTHS
2475  if (gDebugFlag1) {
2476  std::cout << " atStart=" << start << " pos=" << start - sectionStart << " w=" << (*it_w).computeAt(start - sectionStart) << "\n";
2477  }
2478 #endif
2479  l.width = MAX2(l.width, (*it_w).computeAt(start - sectionStart));
2480  }
2481  if (sPrevAbs <= end && sEndAbs >= end) {
2482 #ifdef DEBUG_VARIABLE_WIDTHS
2483  if (gDebugFlag1) {
2484  std::cout << " atEnd=" << end << " pos=" << end - sectionStart << " w=" << (*it_w).computeAt(end - sectionStart) << "\n";
2485  }
2486 #endif
2487  l.width = MAX2(l.width, (*it_w).computeAt(end - sectionStart));
2488  }
2489  if (start <= sPrevAbs && end >= sPrevAbs) {
2490 #ifdef DEBUG_VARIABLE_WIDTHS
2491  if (gDebugFlag1) {
2492  std::cout << " atSPrev=" << sPrev << " w=" << (*it_w).computeAt(sPrev) << "\n";
2493  }
2494 #endif
2495  l.width = MAX2(l.width, (*it_w).computeAt(sPrev));
2496  }
2497  if (start <= sEndAbs && end >= sEndAbs) {
2498 #ifdef DEBUG_VARIABLE_WIDTHS
2499  if (gDebugFlag1) {
2500  std::cout << " atSEnd=" << sEnd << " w=" << (*it_w).computeAt(sEnd) << "\n";
2501  }
2502 #endif
2503  l.width = MAX2(l.width, (*it_w).computeAt(sEnd));
2504  }
2505 #ifdef DEBUG_VARIABLE_WIDTHS
2506  if (gDebugFlag1) {
2507  std::cout << " sPrev=" << sPrev << " sEnd=" << sEnd << " l.width=" << l.width << "\n";
2508  }
2509 #endif
2510  sPrev = sEnd;
2511  sPrevAbs = sEndAbs;
2512  }
2513  }
2514  }
2515 }
2516 
2517 /****************************************************************************/
2518 
NIImporter_OpenDrive::OpenDriveEdge::getPriority
int getPriority(OpenDriveXMLTag dir) const
Returns the edge's priority, regarding the direction.
Definition: NIImporter_OpenDrive.cpp:1738
NIImporter_OpenDrive::OpenDriveSignal
Representation of a signal.
Definition: NIImporter_OpenDrive.h:370
NIImporter_OpenDrive::OpenDriveEdge::to
NBNode * to
Definition: NIImporter_OpenDrive.h:475
NIImporter_OpenDrive::OPENDRIVE_TAG_SIGNAL
Definition: NIImporter_OpenDrive.h:101
NIImporter_OpenDrive::OPENDRIVE_TAG_CENTER
Definition: NIImporter_OpenDrive.h:98
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
Boundary.h
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
NBEdge::UNSPECIFIED_OFFSET
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:306
NIImporter_OpenDrive::addLink
void addLink(LinkType lt, const std::string &elementType, const std::string &elementID, const std::string &contactPoint)
Definition: NIImporter_OpenDrive.cpp:2152
NIImporter_OpenDrive::myImportInternalShapes
static bool myImportInternalShapes
Definition: NIImporter_OpenDrive.h:591
SVC_PEDESTRIAN
pedestrian
Definition: SUMOVehicleClass.h:157
NIImporter_OpenDrive::OPENDRIVE_ATTR_LEVEL
Definition: NIImporter_OpenDrive.h:158
NIImporter_OpenDrive::OpenDriveEdge
Representation of an openDrive "link".
Definition: NIImporter_OpenDrive.h:441
NIImporter_OpenDrive::OPENDRIVE_TAG_SUCCESSOR
Definition: NIImporter_OpenDrive.h:86
NIImporter_OpenDrive::OpenDriveLaneSection::sOrig
double sOrig
The original starting offset of this lane section (differs from s if the section had to be split)
Definition: NIImporter_OpenDrive.h:348
ToString.h
XMLSubSys::runParser
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:113
NIImporter_OpenDrive::myTypeContainer
const NBTypeCont & myTypeContainer
Definition: NIImporter_OpenDrive.h:576
NIImporter_OpenDrive::OpenDriveLaneSection::getInnerConnections
std::map< int, int > getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection &prev)
Returns the links from the previous to this lane section.
Definition: NIImporter_OpenDrive.cpp:1608
NBEdge::Lane::speed
double speed
The speed allowed on this lane.
Definition: NBEdge.h:145
SUMOSAXAttributes::hasAttribute
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:74
NIImporter_OpenDrive::Poly3::computeAt
double computeAt(double pos) const
Definition: NIImporter_OpenDrive.h:270
SVC_EMERGENCY
public emergency vehicles
Definition: SUMOVehicleClass.h:144
NBEdgeCont::retrieve
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:245
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
NIImporter_OpenDrive::OpenDriveLaneSection::laneMap
std::map< int, int > laneMap
A mapping from OpenDrive to SUMO-index (the first is signed, the second unsigned)
Definition: NIImporter_OpenDrive.h:352
SUMOPolygon::writeXML
void writeXML(OutputDevice &out, bool geo=false)
Definition: SUMOPolygon.cpp:50
NIImporter_OpenDrive::geomFromPoly
static PositionVector geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
Definition: NIImporter_OpenDrive.cpp:1465
NIImporter_OpenDrive::OPENDRIVE_GT_SPIRAL
Definition: NIImporter_OpenDrive.h:202
NIImporter_OpenDrive::myCurrentLaneDirection
OpenDriveXMLTag myCurrentLaneDirection
Definition: NIImporter_OpenDrive.h:581
NBEdge::Lane::type
std::string type
the type of this lane
Definition: NBEdge.h:177
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
NIImporter_OpenDrive::OPENDRIVE_TAG_CONNECTION
Definition: NIImporter_OpenDrive.h:103
NIImporter_OpenDrive::OPENDRIVE_ATTR_FROM
Definition: NIImporter_OpenDrive.h:163
NIImporter_OpenDrive::OpenDriveEdge::junction
std::string junction
The id of the junction the edge belongs to.
Definition: NIImporter_OpenDrive.h:467
NIImporter_OpenDrive::OPENDRIVE_GT_UNKNOWN
Definition: NIImporter_OpenDrive.h:200
NIImporter_OpenDrive::OpenDriveLaneSection::length
double length
The length of this lane section.
Definition: NIImporter_OpenDrive.h:350
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
GeomConvHelper.h
NIImporter_OpenDrive::OPENDRIVE_TAG_LANELINK
Definition: NIImporter_OpenDrive.h:104
NIImporter_OpenDrive::OpenDriveGeometry::x
double x
Definition: NIImporter_OpenDrive.h:248
NUMERICAL_EPS
#define NUMERICAL_EPS
Definition: config.h:145
PositionVector::getSubpart2D
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
Definition: PositionVector.cpp:738
PositionVector::insertAtClosest
int insertAtClosest(const Position &p)
inserts p between the two closest positions and returns the insertion index
Definition: PositionVector.cpp:951
OptionsCont.h
PositionVector::rotate2D
void rotate2D(double angle)
Definition: PositionVector.cpp:1460
NIImporter_OpenDrive::OpenDriveLane::width
double width
Definition: NIImporter_OpenDrive.h:309
LANESPREAD_RIGHT
Definition: SUMOXMLDefinitions.h:1093
NIImporter_OpenDrive::OPENDRIVE_ATTR_DISTANCE
Definition: NIImporter_OpenDrive.h:127
SUMOSAXAttributes::get
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:493
NIImporter_OpenDrive::OPENDRIVE_TAG_GEOMETRY
Definition: NIImporter_OpenDrive.h:89
MsgHandler.h
NIImporter_OpenDrive::OpenDriveEdge::connections
std::set< Connection > connections
Definition: NIImporter_OpenDrive.h:480
NIImporter_OpenDrive::OpenDriveEdge::laneSections
std::vector< OpenDriveLaneSection > laneSections
Definition: NIImporter_OpenDrive.h:478
NIImporter_OpenDrive::geomFromSpiral
static PositionVector geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
Definition: NIImporter_OpenDrive.cpp:1355
RGBColor::YELLOW
static const RGBColor YELLOW
Definition: RGBColor.h:193
NIImporter_OpenDrive::OpenDriveLaneSection
Representation of a lane section.
Definition: NIImporter_OpenDrive.h:318
GeoConvHelper::setLoaded
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
Definition: GeoConvHelper.cpp:540
NIImporter_OpenDrive::Connection::fromLane
int fromLane
Definition: NIImporter_OpenDrive.h:398
NIImporter_OpenDrive::sanitizeWidths
static void sanitizeWidths(OpenDriveEdge *e)
Definition: NIImporter_OpenDrive.cpp:2204
NBNodeCont::insert
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
NIImporter_OpenDrive::Connection::all
bool all
Definition: NIImporter_OpenDrive.h:402
NIImporter_OpenDrive::NIImporter_OpenDrive
NIImporter_OpenDrive(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
Definition: NIImporter_OpenDrive.cpp:1765
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:202
PointOfInterest::writeXML
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const double posLat=0.)
Definition: PointOfInterest.h:124
SUMOSAXHandler.h
NIImporter_OpenDrive::OPENDRIVE_TAG_ELEVATION
Definition: NIImporter_OpenDrive.h:107
FileHelpers.h
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
cn
static double cn[6]
Definition: odrSpiral.cpp:63
NIImporter_OpenDrive::OpenDriveObject::length
double length
Definition: NIImporter_OpenDrive.h:428
NBNetBuilder::transformCoordinates
static bool transformCoordinates(PositionVector &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
Definition: NBNetBuilder.cpp:690
NIImporter_OpenDrive::OPENDRIVE_ATTR_C
Definition: NIImporter_OpenDrive.h:146
OptionsCont::exists
bool exists(const std::string &name) const
Returns the information whether the named option is known.
Definition: OptionsCont.cpp:130
NIImporter_OpenDrive::OPENDRIVE_ATTR_CONTACTPOINT
Definition: NIImporter_OpenDrive.h:135
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
NBEdgeCont.h
GeoConvHelper.h
NIImporter_OpenDrive::OpenDriveLane
Representation of a lane.
Definition: NIImporter_OpenDrive.h:292
NIImporter_OpenDrive::OpenDriveLane::speed
double speed
The lane's speed (set in post-processing)
Definition: NIImporter_OpenDrive.h:308
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:223
NBOwnTLDef
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:180
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
NIImporter_OpenDrive::myCharacters
void myCharacters(int element, const std::string &chars)
Callback method for characters to implement by derived classes.
Definition: NIImporter_OpenDrive.cpp:2088
NBTypeCont::getMaxWidth
double getMaxWidth(const std::string &type) const
Returns the maximum edge/lane widths of the given type.
Definition: NBTypeCont.cpp:206
NIImporter_OpenDrive.h
NBEdgeCont::insert
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:152
NIImporter_OpenDrive::OPENDRIVE_ATTR_A
Definition: NIImporter_OpenDrive.h:144
NIImporter_OpenDrive::OPENDRIVE_ATTR_DU
Definition: NIImporter_OpenDrive.h:151
GeoConvHelper::getLoaded
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
Definition: GeoConvHelper.h:92
NIImporter_OpenDrive::calculateStraightEndPoint
static Position calculateStraightEndPoint(double hdg, double length, const Position &start)
Definition: NIImporter_OpenDrive.cpp:1501
NIImporter_OpenDrive::OPENDRIVE_TAG_SPIRAL
Definition: NIImporter_OpenDrive.h:91
NIImporter_OpenDrive::OpenDriveObject::t
double t
Definition: NIImporter_OpenDrive.h:426
NIImporter_OpenDrive::OpenDriveEdge::signals
std::vector< OpenDriveSignal > signals
Definition: NIImporter_OpenDrive.h:479
NIImporter_OpenDrive::OPENDRIVE_ATTR_INCOMINGROAD
Definition: NIImporter_OpenDrive.h:161
NIImporter_OpenDrive::OpenDriveLaneOffset
Poly3 OpenDriveLaneOffset
Definition: NIImporter_OpenDrive.h:284
NIImporter_OpenDrive::OPENDRIVE_ATTR_AU
Definition: NIImporter_OpenDrive.h:148
NIImporter_OpenDrive::OPENDRIVE_ATTR_WIDTH
Definition: NIImporter_OpenDrive.h:125
NBEdge::L2L_USER
The connection was given by the user.
Definition: NBEdge.h:128
PositionVector
A list of positions.
Definition: PositionVector.h:46
NIImporter_OpenDrive::Connection::fromEdge
std::string fromEdge
Definition: NIImporter_OpenDrive.h:396
odrSpiral
void odrSpiral(double s, double cDot, double *x, double *y, double *t)
Definition: odrSpiral.cpp:231
NBTypeCont::knows
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:72
NIImporter_OpenDrive::OPENDRIVE_ATTR_S
Definition: NIImporter_OpenDrive.h:136
NIImporter_OpenDrive::OpenDriveObject::radius
double radius
Definition: NIImporter_OpenDrive.h:431
NIImporter_OpenDrive::OpenDriveXMLTag
OpenDriveXMLTag
Numbers representing openDrive-XML - element names.
Definition: NIImporter_OpenDrive.h:81
GeoConvHelper
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:56
NIImporter_OpenDrive::OPENDRIVE_GT_ARC
Definition: NIImporter_OpenDrive.h:203
NIImporter_OpenDrive::OPENDRIVE_TAG_REPEAT
Definition: NIImporter_OpenDrive.h:110
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:382
GeoConvHelper::usingGeoProjection
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Definition: GeoConvHelper.cpp:282
NIImporter_OpenDrive::myConnectionWasEmpty
bool myConnectionWasEmpty
Definition: NIImporter_OpenDrive.h:586
SVC_AUTHORITY
authorities vehicles
Definition: SUMOVehicleClass.h:146
NIImporter_OpenDrive::OPENDRIVE_ATTR_WIDTHSTART
Definition: NIImporter_OpenDrive.h:130
NIImporter_OpenDrive::OPENDRIVE_ATTR_CV
Definition: NIImporter_OpenDrive.h:154
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
NBNetBuilder::getEdgeCont
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:151
NIImporter_OpenDrive::revisitLaneSections
static void revisitLaneSections(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Rechecks lane sections of the given edges.
Definition: NIImporter_OpenDrive.cpp:1274
NIImporter_OpenDrive::OPENDRIVE_ATTR_TEND
Definition: NIImporter_OpenDrive.h:129
NIImporter_OpenDrive::OpenDriveLane::type
std::string type
The lane's type.
Definition: NIImporter_OpenDrive.h:304
NBTypeCont::getWidthResolution
double getWidthResolution(const std::string &type) const
Returns the resolution for interpreting edge/lane widths of the given type.
Definition: NBTypeCont.cpp:201
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NIImporter_OpenDrive::geomFromLine
static PositionVector geomFromLine(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
Definition: NIImporter_OpenDrive.cpp:1334
NIImporter_OpenDrive::OpenDriveObject::id
std::string id
Definition: NIImporter_OpenDrive.h:424
NIImporter_OpenDrive::OpenDriveGeometry::s
double s
Definition: NIImporter_OpenDrive.h:247
NIImporter_OpenDrive::OpenDriveObject::s
double s
Definition: NIImporter_OpenDrive.h:425
NIImporter_OpenDrive::OPENDRIVE_ATTR_ELEMENTID
Definition: NIImporter_OpenDrive.h:134
NIImporter_OpenDrive::OPENDRIVE_ATTR_PRANGE
Definition: NIImporter_OpenDrive.h:156
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:80
PositionVector::add
void add(double xoff, double yoff, double zoff)
Definition: PositionVector.cpp:609
NIImporter_OpenDrive::OpenDriveElevation
Poly3 OpenDriveElevation
LaneOffset has the same fields as Elevation.
Definition: NIImporter_OpenDrive.h:283
NIImporter_OpenDrive::OPENDRIVE_ATTR_ID
Definition: NIImporter_OpenDrive.h:123
DEBUG_COND2
#define DEBUG_COND2(edgeID)
Definition: NIImporter_OpenDrive.cpp:63
NIImporter_OpenDrive::OpenDriveLane::id
int id
The lane's id.
Definition: NIImporter_OpenDrive.h:302
NIImporter_OpenDrive::OPENDRIVE_ATTR_CURVSTART
Definition: NIImporter_OpenDrive.h:141
NIImporter_OpenDrive::Connection
A connection between two roads.
Definition: NIImporter_OpenDrive.h:395
NIImporter_OpenDrive
Importer for networks stored in openDrive format.
Definition: NIImporter_OpenDrive.h:54
NIImporter_OpenDrive::OPENDRIVE_TAG_ROAD
Definition: NIImporter_OpenDrive.h:84
NIImporter_OpenDrive::OPENDRIVE_TAG_OBJECT
Definition: NIImporter_OpenDrive.h:109
odrSpiral.h
NIImporter_OpenDrive::Connection::getDescription
std::string getDescription() const
Definition: NIImporter_OpenDrive.h:407
NBEdge::getToNode
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:486
NIImporter_OpenDrive::OPENDRIVE_ATTR_ELEMENTTYPE
Definition: NIImporter_OpenDrive.h:133
NBNode::isTLControlled
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:317
NIImporter_OpenDrive::Poly3::d
double d
Definition: NIImporter_OpenDrive.h:279
OptionsCont::isUsableFileList
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
Definition: OptionsCont.cpp:360
NIImporter_OpenDrive::Poly3::c
double c
Definition: NIImporter_OpenDrive.h:278
NIImporter_OpenDrive::OPENDRIVE_ATTR_WIDTHEND
Definition: NIImporter_OpenDrive.h:131
NIImporter_OpenDrive::OPENDRIVE_ATTR_CURVATURE
Definition: NIImporter_OpenDrive.h:143
NBEdge::addLane2LaneConnection
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED)
Adds a connection between the specified this edge's lane and an approached one.
Definition: NBEdge.cpp:1014
NIImporter_OpenDrive::OpenDriveGeometry::y
double y
Definition: NIImporter_OpenDrive.h:249
PositionVector::push_back_noDoublePos
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Definition: PositionVector.cpp:1258
NIImporter_OpenDrive::OPENDRIVE_GT_LINE
Definition: NIImporter_OpenDrive.h:201
NIImporter_OpenDrive::OPENDRIVE_ATTR_BV
Definition: NIImporter_OpenDrive.h:153
NIImporter_OpenDrive::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: NIImporter_OpenDrive.cpp:2116
StringBijection
Definition: StringBijection.h:44
NIImporter_OpenDrive::OpenDriveEdge::isInner
bool isInner
Definition: NIImporter_OpenDrive.h:482
NIImporter_OpenDrive::geomFromParamPoly
static PositionVector geomFromParamPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
Definition: NIImporter_OpenDrive.cpp:1482
NIImporter_OpenDrive::OPENDRIVE_ATTR_X
Definition: NIImporter_OpenDrive.h:138
NIImporter_OpenDrive::OpenDriveGeometry
Representation of an OpenDrive geometry part.
Definition: NIImporter_OpenDrive.h:234
NIImporter_OpenDrive::OpenDriveEdge::objects
std::vector< OpenDriveObject > objects
Definition: NIImporter_OpenDrive.h:481
NIImporter_OpenDrive::OpenDriveEdge::length
double length
The length of the edge.
Definition: NIImporter_OpenDrive.h:469
NIImporter_OpenDrive::OPENDRIVE_ATTR_DYNAMIC
Definition: NIImporter_OpenDrive.h:160
NIImporter_OpenDrive::splitMinWidths
static void splitMinWidths(OpenDriveEdge *e, const NBTypeCont &tc, double minDist)
Definition: NIImporter_OpenDrive.cpp:2247
NIImporter_OpenDrive::OPENDRIVE_ATTR_T
Definition: NIImporter_OpenDrive.h:137
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:219
NIImporter_OpenDrive::calcPointOnCurve
static void calcPointOnCurve(double *ad_x, double *ad_y, double ad_centerX, double ad_centerY, double ad_r, double ad_length)
Definition: NIImporter_OpenDrive.cpp:1541
NIImporter_OpenDrive::OPENDRIVE_TAG_LANE
Definition: NIImporter_OpenDrive.h:100
NBEdge::UNSPECIFIED_CONTPOS
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:312
NBTypeCont::getSpeed
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:178
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:98
NIImporter_OpenDrive::OPENDRIVE_ATTR_RADIUS
Definition: NIImporter_OpenDrive.h:126
NIImporter_OpenDrive::buildConnectionsToOuter
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge * > &innerEdges, std::vector< Connection > &into, std::set< Connection > &seen)
Definition: NIImporter_OpenDrive.cpp:797
NIImporter_OpenDrive::OpenDriveLaneSection::rightLaneNumber
int rightLaneNumber
The number of lanes on the right and on the left side, respectively.
Definition: NIImporter_OpenDrive.h:358
SUMO_PARAM_ORIGID
const std::string SUMO_PARAM_ORIGID
SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
Definition: SUMOVehicleClass.h:160
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:246
NIImporter_OpenDrive::OpenDriveGeometry::hdg
double hdg
Definition: NIImporter_OpenDrive.h:250
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
NIImporter_OpenDrive::OpenDriveObject::name
std::string name
Definition: NIImporter_OpenDrive.h:423
OutputDevice.h
NBNetBuilder.h
NIImporter_OpenDrive::OPENDRIVE_TAG_LANEOFFSET
Definition: NIImporter_OpenDrive.h:96
ProcessError
Definition: UtilExceptions.h:40
NIImporter_OpenDrive::myImportWidths
static bool myImportWidths
Definition: NIImporter_OpenDrive.h:589
NIImporter_OpenDrive::OPENDRIVE_TAG_RIGHT
Definition: NIImporter_OpenDrive.h:99
NIImporter_OpenDrive::Poly3
Definition: NIImporter_OpenDrive.h:259
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:294
NIImporter_OpenDrive::OpenDriveEdge::offsets
std::vector< OpenDriveLaneOffset > offsets
Definition: NIImporter_OpenDrive.h:473
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
NBNode::addTrafficLight
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:359
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
NIImporter_OpenDrive::OpenDriveEdge::links
std::vector< OpenDriveLink > links
Definition: NIImporter_OpenDrive.h:470
Boundary::add
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
NIImporter_OpenDrive::OpenDriveLaneSection::buildSpeedChanges
bool buildSpeedChanges(const NBTypeCont &tc, std::vector< OpenDriveLaneSection > &newSections)
Definition: NIImporter_OpenDrive.cpp:1671
NIImporter_OpenDrive::OPENDRIVE_ATTR_TYPE
Definition: NIImporter_OpenDrive.h:157
PositionVector::append
void append(const PositionVector &v, double sameThreshold=2.0)
Definition: PositionVector.cpp:688
NIImporter_OpenDrive::OPENDRIVE_TAG_PREDECESSOR
Definition: NIImporter_OpenDrive.h:85
UtilExceptions.h
NIImporter_OpenDrive::OPENDRIVE_TAG_LINE
Definition: NIImporter_OpenDrive.h:90
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
NBTypeCont::getShallBeDiscarded
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:196
NBEdge::getLaneStruct
Lane & getLaneStruct(int lane)
Definition: NBEdge.h:1271
NBEdge::Lane::width
double width
This lane's width.
Definition: NBEdge.h:161
NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition: NBEdge.h:315
NIImporter_OpenDrive::myEdges
std::map< std::string, OpenDriveEdge * > & myEdges
Definition: NIImporter_OpenDrive.h:579
SUMOSAXAttributes::getOpt
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.
Definition: SUMOSAXAttributes.h:519
NIImporter_OpenDrive::OPENDRIVE_TAG_NOTHING
Definition: NIImporter_OpenDrive.h:82
NIImporter_OpenDrive::OPENDRIVE_ATTR_NAME
Definition: NIImporter_OpenDrive.h:167
PositionVector::indexOfClosest
int indexOfClosest(const Position &p) const
index of the closest position to p
Definition: PositionVector.cpp:932
PositionVector::length2D
double length2D() const
Returns the length.
Definition: PositionVector.cpp:489
NBEdge::UNSPECIFIED_SPEED
static const double UNSPECIFIED_SPEED
unspecified lane speed
Definition: NBEdge.h:309
NIImporter_OpenDrive::OPENDRIVE_TAG_GEOREFERENCE
Definition: NIImporter_OpenDrive.h:108
NIImporter_OpenDrive::GeometryType
GeometryType
OpenDrive geometry type enumeration.
Definition: NIImporter_OpenDrive.h:199
NIImporter_OpenDrive::OPENDRIVE_ATTR_Y
Definition: NIImporter_OpenDrive.h:139
NBEdge::L2L_VALIDATED
The connection was computed and validated.
Definition: NBEdge.h:130
NIImporter_OpenDrive::myCurrentIncomingRoad
std::string myCurrentIncomingRoad
Definition: NIImporter_OpenDrive.h:583
NIImporter_OpenDrive::OPENDRIVE_TAG_LEFT
Definition: NIImporter_OpenDrive.h:97
NBNodeCont::retrieve
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
OptionsCont::isDefault
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Definition: OptionsCont.cpp:164
NIImporter_OpenDrive::OpenDriveEdge::laneOffsets
std::vector< double > laneOffsets
Definition: NIImporter_OpenDrive.h:477
NIImporter_OpenDrive::OpenDriveObject::hdg
double hdg
Definition: NIImporter_OpenDrive.h:432
NIImporter_OpenDrive::OPENDRIVE_ATTR_HDG
Definition: NIImporter_OpenDrive.h:140
NIImporter_OpenDrive::OPENDRIVE_TAG_LANESECTION
Definition: NIImporter_OpenDrive.h:95
NIImporter_OpenDrive::OpenDriveObject::width
double width
Definition: NIImporter_OpenDrive.h:429
DEBUG_COND3
#define DEBUG_COND3(roadID)
Definition: NIImporter_OpenDrive.cpp:64
NIImporter_OpenDrive::setEdgeLinks2
static void setEdgeLinks2(OpenDriveEdge &e, const std::map< std::string, OpenDriveEdge * > &edges)
Definition: NIImporter_OpenDrive.cpp:1014
NIImporter_OpenDrive::OpenDriveEdge::id
std::string id
The id of the edge.
Definition: NIImporter_OpenDrive.h:463
Position::distanceTo2D
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
NIImporter_OpenDrive::OpenDriveEdge::elevations
std::vector< OpenDriveElevation > elevations
Definition: NIImporter_OpenDrive.h:472
NIImporter_OpenDrive::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: NIImporter_OpenDrive.cpp:1776
NIImporter_OpenDrive::OPENDRIVE_LT_SUCCESSOR
Definition: NIImporter_OpenDrive.h:175
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:209
NIImporter_OpenDrive::myCurrentEdge
OpenDriveEdge myCurrentEdge
Definition: NIImporter_OpenDrive.h:577
SUMOPolygon
Definition: SUMOPolygon.h:47
NBNodeCont.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
StringUtils.h
NIImporter_OpenDrive::revertID
static std::string revertID(const std::string &id)
Definition: NIImporter_OpenDrive.cpp:1101
NIImporter_OpenDrive::OpenDriveGeometry::length
double length
Definition: NIImporter_OpenDrive.h:246
PointOfInterest.h
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:55
NILoader.h
NIImporter_OpenDrive::myElementStack
std::vector< int > myElementStack
Definition: NIImporter_OpenDrive.h:580
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
PROGRESS_BEGIN_MESSAGE
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:241
operator<
bool operator<(const NIImporter_OpenDrive::Connection &c1, const NIImporter_OpenDrive::Connection &c2)
Definition: NIImporter_OpenDrive.cpp:2190
NIImporter_OpenDrive::OpenDriveLaneSection::lanesByDir
std::map< OpenDriveXMLTag, std::vector< OpenDriveLane > > lanesByDir
The lanes, sorted by their direction.
Definition: NIImporter_OpenDrive.h:354
NIImporter_OpenDrive::OPENDRIVE_ATTR_REVMAJOR
Definition: NIImporter_OpenDrive.h:121
NIImporter_OpenDrive::OpenDriveLaneSection::OpenDriveLaneSection
OpenDriveLaneSection(double sArg)
Constructor.
Definition: NIImporter_OpenDrive.cpp:1565
NIImporter_OpenDrive::OPENDRIVE_CP_START
Definition: NIImporter_OpenDrive.h:193
NBTypeCont::getPermissions
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:222
PositionVector::positionAtOffset2D
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:268
NIImporter_OpenDrive::OPENDRIVE_ATTR_CURVEND
Definition: NIImporter_OpenDrive.h:142
NIImporter_OpenDrive::geomFromArc
static PositionVector geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
Definition: NIImporter_OpenDrive.cpp:1420
NBTypeCont
A storage for available types of edges.
Definition: NBTypeCont.h:55
NIImporter_OpenDrive::OPENDRIVE_CP_END
Definition: NIImporter_OpenDrive.h:194
PositionVector::reverse
PositionVector reverse() const
reverse position vector
Definition: PositionVector.cpp:1069
NBNetBuilder::getTLLogicCont
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:166
PositionVector::rotationAtOffset
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:286
NIImporter_OpenDrive::OPENDRIVE_ATTR_SOFFSET
Definition: NIImporter_OpenDrive.h:166
NIImporter_OpenDrive::hasNonLinearElevation
static bool hasNonLinearElevation(OpenDriveEdge &e)
Definition: NIImporter_OpenDrive.cpp:1144
NIImporter_OpenDrive::OPENDRIVE_ATTR_D
Definition: NIImporter_OpenDrive.h:147
NBNode::getControllingTLS
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node)
Definition: NBNode.h:322
NIImporter_OpenDrive::calculateCurveCenter
static void calculateCurveCenter(double *ad_x, double *ad_y, double ad_radius, double ad_hdg)
Definition: NIImporter_OpenDrive.cpp:1513
InvalidArgument
Definition: UtilExceptions.h:57
NBEdge::Lane
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:137
GenericSAXHandler::getFileName
const std::string & getFileName() const
returns the current file name
Definition: GenericSAXHandler.cpp:75
NIImporter_OpenDrive::OPENDRIVE_ATTR_NOTHING
Definition: NIImporter_OpenDrive.h:120
NIImporter_OpenDrive::OPENDRIVE_ATTR_DV
Definition: NIImporter_OpenDrive.h:155
NIImporter_OpenDrive::myMinWidth
static double myMinWidth
Definition: NIImporter_OpenDrive.h:590
NIImporter_OpenDrive::Connection::fromCP
ContactPoint fromCP
Definition: NIImporter_OpenDrive.h:400
NIImporter_OpenDrive::OpenDriveGeometry::params
std::vector< double > params
Definition: NIImporter_OpenDrive.h:252
NIImporter_OpenDrive::OpenDriveLaneSection::s
double s
The starting offset of this lane section.
Definition: NIImporter_OpenDrive.h:346
NIImporter_OpenDrive::OPENDRIVE_TAG_WIDTH
Definition: NIImporter_OpenDrive.h:105
NIImporter_OpenDrive::same_position_finder
Definition: NIImporter_OpenDrive.h:499
NIImporter_OpenDrive::myCurrentContactPoint
ContactPoint myCurrentContactPoint
Definition: NIImporter_OpenDrive.h:585
PROGRESS_DONE_MESSAGE
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:242
NBTypeCont::getWidth
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:228
NIImporter_OpenDrive::OpenDriveLane::speeds
std::vector< std::pair< double, double > > speeds
List of positions/speeds of speed changes.
Definition: NIImporter_OpenDrive.h:307
NBEdge::Lane::permissions
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:148
NIImporter_OpenDrive::OpenDriveWidth
Poly3 OpenDriveWidth
Definition: NIImporter_OpenDrive.h:285
NIImporter_OpenDrive::getOrBuildNode
static NBNode * getOrBuildNode(const std::string &id, const Position &pos, NBNodeCont &nc)
Builds a node or returns the already built.
Definition: NIImporter_OpenDrive.cpp:1110
NIImporter_OpenDrive::recomputeWidths
static void recomputeWidths(OpenDriveLaneSection &sec, double start, double end, double sectionStart, double sectionEnd)
Definition: NIImporter_OpenDrive.cpp:2430
NIImporter_OpenDrive::setStraightConnections
static void setStraightConnections(std::vector< OpenDriveLane > &lanes)
Definition: NIImporter_OpenDrive.cpp:2422
joinToString
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:247
NBEdge::UNSPECIFIED_WIDTH
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:303
NIImporter_OpenDrive::OPENDRIVE_TAG_SPEED
Definition: NIImporter_OpenDrive.h:106
DEBUG_COND
#define DEBUG_COND(road)
Definition: NIImporter_OpenDrive.cpp:62
NIImporter_OpenDrive::laneSectionsConnected
static bool laneSectionsConnected(OpenDriveEdge *edge, int in, int out)
Definition: NIImporter_OpenDrive.cpp:986
Parameterised::setParameter
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Definition: Parameterised.cpp:45
SUMOXMLDefinitions::TrafficLightTypes
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
Definition: SUMOXMLDefinitions.h:1387
NIImporter_OpenDrive::OPENDRIVE_ET_ROAD
Definition: NIImporter_OpenDrive.h:184
NIImporter_OpenDrive::OPENDRIVE_ATTR_TSTART
Definition: NIImporter_OpenDrive.h:128
NIImporter_OpenDrive::OPENDRIVE_ATTR_REVMINOR
Definition: NIImporter_OpenDrive.h:122
NIImporter_OpenDrive::openDriveAttrs
static StringBijection< int >::Entry openDriveAttrs[]
The names of openDrive-XML attributes (for passing to GenericSAXHandler)
Definition: NIImporter_OpenDrive.h:658
UNSET_CONNECTION
#define UNSET_CONNECTION
Definition: NIImporter_OpenDrive.h:44
GenericSAXHandler::error
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
Definition: GenericSAXHandler.cpp:206
FileHelpers::isReadable
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
NIImporter_OpenDrive::OPENDRIVE_ATTR_MAX
Definition: NIImporter_OpenDrive.h:165
NIImporter_OpenDrive::OPENDRIVE_GT_POLY3
Definition: NIImporter_OpenDrive.h:204
config.h
NIImporter_OpenDrive::OpenDriveLaneSection::leftLaneNumber
int leftLaneNumber
Definition: NIImporter_OpenDrive.h:358
NIImporter_OpenDrive::OPENDRIVE_ATTR_AV
Definition: NIImporter_OpenDrive.h:152
NIImporter_OpenDrive::setLaneAttributes
static void setLaneAttributes(const OpenDriveEdge *e, NBEdge::Lane &sumoLane, const OpenDriveLane &odLane, bool saveOrigIDs, const NBTypeCont &tc)
Definition: NIImporter_OpenDrive.cpp:759
NIImporter_OpenDrive::OPENDRIVE_TAG_POLY3
Definition: NIImporter_OpenDrive.h:93
NIImporter_OpenDrive::Poly3::s
double s
Definition: NIImporter_OpenDrive.h:275
gDebugFlag1
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:33
PointOfInterest
A point-of-interest.
Definition: PointOfInterest.h:44
NIImporter_OpenDrive::OPENDRIVE_ATTR_CONNECTINGROAD
Definition: NIImporter_OpenDrive.h:162
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
NIImporter_OpenDrive::OPENDRIVE_TAG_HEADER
Definition: NIImporter_OpenDrive.h:83
NIImporter_OpenDrive::LinkType
LinkType
OpenDrive link type enumeration.
Definition: NIImporter_OpenDrive.h:174
NIImporter_OpenDrive::OPENDRIVE_ATTR_JUNCTION
Definition: NIImporter_OpenDrive.h:132
NIImporter_OpenDrive::OpenDriveEdge::geometries
std::vector< OpenDriveGeometry > geometries
Definition: NIImporter_OpenDrive.h:471
NIImporter_OpenDrive::Connection::shape
PositionVector shape
Definition: NIImporter_OpenDrive.h:405
NIImporter_OpenDrive::OpenDriveObject
Definition: NIImporter_OpenDrive.h:421
NIImporter_OpenDrive::OPENDRIVE_TAG_JUNCTION
Definition: NIImporter_OpenDrive.h:102
NIImporter_OpenDrive::~NIImporter_OpenDrive
~NIImporter_OpenDrive()
Destructor.
Definition: NIImporter_OpenDrive.cpp:1771
NIImporter_OpenDrive::OPENDRIVE_ATTR_B
Definition: NIImporter_OpenDrive.h:145
NIImporter_OpenDrive::OPENDRIVE_ET_JUNCTION
Definition: NIImporter_OpenDrive.h:185
OutputDevice::writeXMLHeader
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Definition: OutputDevice.cpp:228
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBOwnTLDef.h
NIImporter_OpenDrive::OpenDriveObject::type
std::string type
Definition: NIImporter_OpenDrive.h:422
NBTrafficLightLogicCont.h
SUMOPolygon.h
NIImporter_OpenDrive::OPENDRIVE_GT_PARAMPOLY3
Definition: NIImporter_OpenDrive.h:205
NIImporter_OpenDrive::OpenDriveLaneSection::buildLaneSection
OpenDriveLaneSection buildLaneSection(double startPos)
Definition: NIImporter_OpenDrive.cpp:1647
NIImporter_OpenDrive::OPENDRIVE_LT_PREDECESSOR
Definition: NIImporter_OpenDrive.h:176
NIImporter_OpenDrive::OPENDRIVE_ATTR_TO
Definition: NIImporter_OpenDrive.h:164
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:156
GenericSAXHandler
A handler which converts occuring elements and attributes into enums.
Definition: GenericSAXHandler.h:68
NIImporter_OpenDrive::addGeometryShape
void addGeometryShape(GeometryType type, const std::vector< double > &vals)
Definition: NIImporter_OpenDrive.cpp:2174
NIImporter_OpenDrive::OPENDRIVE_ATTR_BU
Definition: NIImporter_OpenDrive.h:149
NBTrafficLightLogicCont::insert
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Definition: NBTrafficLightLogicCont.cpp:74
NIImporter_OpenDrive::setNodeSecure
static void setNodeSecure(NBNodeCont &nc, OpenDriveEdge &e, const std::string &nodeID, NIImporter_OpenDrive::LinkType lt)
Definition: NIImporter_OpenDrive.cpp:1124
NBNetBuilder::getTypeCont
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:161
NIImporter_OpenDrive::OPENDRIVE_ATTR_ORIENTATION
Definition: NIImporter_OpenDrive.h:159
NBNode.h
NIImporter_OpenDrive::Connection::toCP
ContactPoint toCP
Definition: NIImporter_OpenDrive.h:401
NIImporter_OpenDrive::OpenDriveEdge::geom
PositionVector geom
Definition: NIImporter_OpenDrive.h:476
NIImporter_OpenDrive::OPENDRIVE_TAG_ARC
Definition: NIImporter_OpenDrive.h:92
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
NIImporter_OpenDrive::OPENDRIVE_ATTR_UNIT
Definition: NIImporter_OpenDrive.h:168
NIImporter_OpenDrive::OPENDRIVE_ATTR_LENGTH
Definition: NIImporter_OpenDrive.h:124
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
POSITION_EPS
#define POSITION_EPS
Definition: config.h:169
NIImporter_OpenDrive::myCurrentConnectingRoad
std::string myCurrentConnectingRoad
Definition: NIImporter_OpenDrive.h:584
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
NIImporter_OpenDrive::OpenDriveEdge::from
NBNode * from
Definition: NIImporter_OpenDrive.h:474
NIImporter_OpenDrive::OpenDriveLaneSection::buildLaneMapping
void buildLaneMapping(const NBTypeCont &tc)
Build the mapping from OpenDrive to SUMO lanes.
Definition: NIImporter_OpenDrive.cpp:1573
NBEdge::getConnections
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:924
NIImporter_OpenDrive::OPENDRIVE_TAG_PARAMPOLY3
Definition: NIImporter_OpenDrive.h:94
NIImporter_OpenDrive::sections_by_s_sorter
A class for sorting lane sections by their s-value.
Definition: NIImporter_OpenDrive.h:487
OptionsCont::getStringVector
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)
Definition: OptionsCont.cpp:921
NIImporter_OpenDrive::loadNetwork
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
Definition: NIImporter_OpenDrive.cpp:172
SUMOXMLDefinitions.h
NIImporter_OpenDrive::Connection::toEdge
std::string toEdge
Definition: NIImporter_OpenDrive.h:397
NBEdgeCont::wasIgnored
bool wasIgnored(std::string id) const
Returns whether the edge with the id was ignored during parsing.
Definition: NBEdgeCont.h:503
NIImporter_OpenDrive::myImportAllTypes
static bool myImportAllTypes
Definition: NIImporter_OpenDrive.h:588
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1086
NIImporter_OpenDrive::findWidthSplit
static void findWidthSplit(const NBTypeCont &tc, std::vector< OpenDriveLane > &lanes, int section, double sectionStart, double sectionEnd, std::vector< double > &splitPositions)
Definition: NIImporter_OpenDrive.cpp:2340
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:68
NIImporter_OpenDrive::OPENDRIVE_ATTR_CU
Definition: NIImporter_OpenDrive.h:150
PositionVector::removeDoublePoints
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
Definition: PositionVector.cpp:1307
NBEdge.h
XMLSubSys.h
NIImporter_OpenDrive::OpenDriveGeometry::type
GeometryType type
Definition: NIImporter_OpenDrive.h:251
NIImporter_OpenDrive::OpenDriveLane::widthData
std::vector< OpenDriveWidth > widthData
Definition: NIImporter_OpenDrive.h:310
NIImporter_OpenDrive::myCurrentJunctionID
std::string myCurrentJunctionID
Definition: NIImporter_OpenDrive.h:582
NIImporter_OpenDrive::OpenDriveEdge::streetName
std::string streetName
The road name of the edge.
Definition: NIImporter_OpenDrive.h:465
NIImporter_OpenDrive::Connection::toLane
int toLane
Definition: NIImporter_OpenDrive.h:399
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1364
NIImporter_OpenDrive::computeShapes
static void computeShapes(std::map< std::string, OpenDriveEdge * > &edges)
Computes a polygon representation of each edge's geometry.
Definition: NIImporter_OpenDrive.cpp:1157
NIImporter_OpenDrive::openDriveTags
static StringBijection< int >::Entry openDriveTags[]
The names of openDrive-XML elements (for passing to GenericSAXHandler)
Definition: NIImporter_OpenDrive.h:655