SUMO - Simulation of Urban MObility
NIImporter_OpenDrive.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 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 /****************************************************************************/
17 // Importer for networks stored in openDrive format
18 /****************************************************************************/
19 #ifndef NIImporter_OpenDrive_h
20 #define NIImporter_OpenDrive_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <map>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class NBNetBuilder;
38 class NBEdge;
39 class OptionsCont;
40 class NBNode;
41 class NBNodeCont;
42 
43 
44 #define UNSET_CONNECTION 100000
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
55 public:
71  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
72 
73 
74 protected:
75 
109  };
110 
111 
158  OPENDRIVE_ATTR_UNIT // xodr v1.4
159  };
160 
161 
164  enum LinkType {
167  };
168 
169 
172  enum ElementType {
176  };
177 
178 
185  };
186 
196  };
197 
198 
199 
204  struct OpenDriveLink {
209  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
210  : linkType(linkTypeArg), elementID(elementIDArg),
212 
214  std::string elementID;
217  };
218 
219 
232  OpenDriveGeometry(double lengthArg, double sArg, double xArg, double yArg, double hdgArg)
233  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
234  type(OPENDRIVE_GT_UNKNOWN) { }
235 
236  double length;
237  double s;
238  double x;
239  double y;
240  double hdg;
242  std::vector<double> params;
243  };
244 
249  struct Poly3 {
257  Poly3(double _s, double _a, double _b, double _c, double _d) :
258  s(_s), a(_a), b(_b), c(_c), d(_d) {}
259 
260  double computeAt(double pos) const {
261  const double ds = pos - s;
262  return a + b * ds + c * ds * ds + d * ds * ds * ds;
263  }
264 
265  double s;
266  double a;
267  double b;
268  double c;
269  double d;
270  };
271 
276 
277 
282  struct OpenDriveLane {
288  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg) :
289  id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
290  speed(0), width(NBEdge::UNSPECIFIED_WIDTH) { }
291 
292  int id;
293  std::string level;
294  std::string type;
295  int successor;
297  std::vector<std::pair<double, double> > speeds;
298  double speed;
299  double width; //The lane's maximum width
300  std::vector<OpenDriveWidth> widthData;
301  };
302 
303 
312  OpenDriveLaneSection(double sArg);
313 
314 
321  void buildLaneMapping(const NBTypeCont& tc);
322 
323 
329  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
330 
331 
332  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
333  OpenDriveLaneSection buildLaneSection(double startPos);
334 
336  double s;
338  double sOrig;
340  std::map<int, int> laneMap;
342  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
344  std::string sumoID;
346  int rightLaneNumber, leftLaneNumber;
348  std::string rightType;
349  std::string leftType;
350  };
351 
352 
353 
367  OpenDriveSignal(const std::string& idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
368  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
369 
370  std::string id;
371  std::string type;
372  std::string name;
374  bool dynamic;
375  double s;
376  };
377 
378 
383  struct Connection {
384  std::string fromEdge;
385  std::string toEdge;
386  int fromLane;
387  int toLane;
390  bool all;
391  std::string origID;
392  int origLane;
394 
395  std::string getDescription() const {
396  return "Connection from=" + fromEdge + "_" + toString(fromLane)
397  + " to=" + toEdge + "_" + toString(toLane)
398  + " fromCP=" + (fromCP == OPENDRIVE_CP_START ? "start" : fromCP == OPENDRIVE_CP_END ? "end" : "unknown")
399  + " toCP=" + (toCP == OPENDRIVE_CP_START ? "start" : toCP == OPENDRIVE_CP_END ? "end" : "unknown")
400  + " all=" + toString(all);
401  //+ " origID=" + origID + " origLane=" + toString(origLane);
402  }
403  };
404 
405 
410  struct OpenDriveEdge {
411  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, double lengthArg) :
412  id(idArg),
413  streetName(streetNameArg),
414  junction(junctionArg),
415  length(lengthArg),
416  from(0),
417  to(0) {
418  isInner = junction != "" && junction != "-1";
419  }
420 
421 
428  int getPriority(OpenDriveXMLTag dir) const;
429 
430 
432  std::string id;
434  std::string streetName;
436  std::string junction;
438  double length;
439  std::vector<OpenDriveLink> links;
440  std::vector<OpenDriveGeometry> geometries;
441  std::vector<OpenDriveElevation> elevations;
442  std::vector<OpenDriveLaneOffset> offsets;
446  std::vector<OpenDriveLaneSection> laneSections;
447  std::vector<OpenDriveSignal> signals;
448  std::set<Connection> connections;
449  bool isInner;
450  };
451 
452 
455  public:
457  explicit sections_by_s_sorter() { }
458 
461  return ls1.s < ls2.s;
462  }
463  };
464 
465  /* @brief A class for search in position/speed tuple vectors for the given position */
467  public:
469  explicit same_position_finder(double pos) : myPosition(pos) { }
470 
472  bool operator()(const std::pair<double, double>& ps) {
473  return ps.first == myPosition;
474  }
475 
476  private:
477  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
478  private:
480  double myPosition;
481 
482  };
483 
484 protected:
489  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
490 
491 
494 
495 
496 
498 
499 
510  void myStartElement(int element, const SUMOSAXAttributes& attrs);
511 
520  void myCharacters(int element, const std::string& chars);
521 
522 
529  void myEndElement(int element);
531 
532 
533 
534 private:
535  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
536  const std::string& contactPoint);
537  void addGeometryShape(GeometryType type, const std::vector<double>& vals);
538  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
539  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into, std::set<Connection>& seen);
540  friend bool operator<(const Connection& c1, const Connection& c2);
541  static std::string revertID(const std::string& id);
544 
545  std::map<std::string, OpenDriveEdge*>& myEdges;
546  std::vector<int> myElementStack;
548  std::string myCurrentJunctionID;
553 
554  static bool myImportAllTypes;
555  static bool myImportWidths;
556  static double myMinWidth;
558 
559 
560 protected:
574  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
575 
576 
577  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
578  static PositionVector geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
579  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
580  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
581  static PositionVector geomFromParamPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
582  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
583  static void calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg);
584  static void calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
585  double ad_r, double ad_length);
586 
587 
591  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
592 
598  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
599 
600  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
601  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
602 
603 
604  static void splitMinWidths(OpenDriveEdge* e, const NBTypeCont& tc, double minDist);
605 
606  static void findWidthSplit(const NBTypeCont& tc, std::vector<OpenDriveLane>& lanes,
607  int section, double sectionStart, double sectionEnd,
608  std::vector<double>& splitPositions);
609 
610  static void setStraightConnections(std::vector<OpenDriveLane>& lanes);
611  static void recomputeWidths(OpenDriveLaneSection& sec, double start, double end, double sectionStart, double sectionEnd);
612  static void recomputeWidths(std::vector<OpenDriveLane>& lanes, double start, double end, double sectionStart, double sectionEnd);
613 
616 
619 
620 
621 
622 };
623 
624 
625 #endif
626 
627 /****************************************************************************/
628 
std::map< std::string, OpenDriveEdge * > & myEdges
std::vector< int > myElementStack
std::string rightType
the composite type built from all used lane types
double sOrig
The original starting offset of this lane section (differs from s if the section had to be split) ...
double myPosition
The position to search for.
static PositionVector geomFromLine(const OpenDriveEdge &e, const OpenDriveGeometry &g)
static StringBijection< int >::Entry openDriveAttrs[]
The names of openDrive-XML attributes (for passing to GenericSAXHandler)
std::vector< OpenDriveWidth > widthData
void addLink(LinkType lt, const std::string &elementType, const std::string &elementID, const std::string &contactPoint)
OpenDriveXMLAttr
Numbers representing openDrive-XML - attributes.
static PositionVector geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
ContactPoint
OpenDrive contact type enumeration.
std::string junction
The id of the junction the edge belongs to.
std::vector< OpenDriveElevation > elevations
static void calculateCurveCenter(double *ad_x, double *ad_y, double ad_radius, double ad_hdg)
GeometryType
OpenDrive geometry type enumeration.
int rightLaneNumber
The number of lanes on the right and on the left side, respectively.
static void computeShapes(std::map< std::string, OpenDriveEdge *> &edges)
Computes a polygon representation of each edge&#39;s geometry.
Representation of a lane section.
The representation of a single edge during network building.
Definition: NBEdge.h:65
NIImporter_OpenDrive(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge *> &edges)
Constructor.
Representation of an openDrive "link".
ContactPoint myCurrentContactPoint
std::map< OpenDriveXMLTag, std::vector< OpenDriveLane > > lanesByDir
The lanes, sorted by their direction.
static PositionVector geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
void myCharacters(int element, const std::string &chars)
Callback method for characters to implement by derived classes.
static void calcPointOnCurve(double *ad_x, double *ad_y, double ad_centerX, double ad_centerY, double ad_r, double ad_length)
double length
The length of the edge.
Poly3 OpenDriveElevation
LaneOffset has the same fields as Elevation.
Poly3(double _s, double _a, double _b, double _c, double _d)
Constructor.
friend bool operator<(const Connection &c1, const Connection &c2)
static NBNode * getOrBuildNode(const std::string &id, const Position &pos, NBNodeCont &nc)
Builds a node or returns the already built.
static std::string revertID(const std::string &id)
int predecessor
The lane&#39;s predecessor lane.
static void findWidthSplit(const NBTypeCont &tc, std::vector< OpenDriveLane > &lanes, int section, double sectionStart, double sectionEnd, std::vector< double > &splitPositions)
int successor
The lane&#39;s successor lane.
OpenDriveXMLTag myCurrentLaneDirection
OpenDriveLane(int idArg, const std::string &levelArg, const std::string &typeArg)
Constructor.
std::string level
The lane&#39;s level (not used)
std::vector< OpenDriveLink > links
A handler which converts occuring elements and attributes into enums.
static PositionVector geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
const GenericSAXHandler & operator=(const GenericSAXHandler &s)
invalidated assignment operator
static void setStraightConnections(std::vector< OpenDriveLane > &lanes)
OpenDriveSignal(const std::string &idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
Constructor.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
std::string type
The lane&#39;s type.
Encapsulated SAX-Attributes.
static Position calculateStraightEndPoint(double hdg, double length, const Position &start)
static void recomputeWidths(OpenDriveLaneSection &sec, double start, double end, double sectionStart, double sectionEnd)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string id
The id of the edge.
A list of positions.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
static void splitMinWidths(OpenDriveEdge *e, const NBTypeCont &tc, double minDist)
const NBTypeCont & myTypeContainer
OpenDriveGeometry(double lengthArg, double sArg, double xArg, double yArg, double hdgArg)
Constructor.
std::vector< OpenDriveLaneOffset > offsets
double speed
The lane&#39;s speed (set in post-processing)
std::vector< OpenDriveLaneSection > laneSections
std::map< int, int > laneMap
A mapping from OpenDrive to SUMO-index (the first is signed, the second unsigned) ...
std::string sumoID
The id (generic, without the optionally leading &#39;-&#39;) of the edge generated for this section...
ElementType
OpenDrive element type enumeration.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
OpenDriveXMLTag
Numbers representing openDrive-XML - element names.
static PositionVector geomFromParamPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
static StringBijection< int >::Entry openDriveTags[]
The names of openDrive-XML elements (for passing to GenericSAXHandler)
std::vector< OpenDriveSignal > signals
LinkType
OpenDrive link type enumeration.
static void revisitLaneSections(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge *> &edges)
Rechecks lane sections of the given edges.
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
Representation of an OpenDrive geometry part.
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void setEdgeLinks2(OpenDriveEdge &e, const std::map< std::string, OpenDriveEdge *> &edges)
std::vector< OpenDriveGeometry > geometries
Represents a single node (junction) during network building.
Definition: NBNode.h:68
void addGeometryShape(GeometryType type, const std::vector< double > &vals)
A class for sorting lane sections by their s-value.
double computeAt(double pos) const
static void setNodeSecure(NBNodeCont &nc, OpenDriveEdge &e, const std::string &nodeID, NIImporter_OpenDrive::LinkType lt)
bool operator()(const std::pair< double, double > &ps)
the comparing function
A connection between two roads.
OpenDriveEdge(const std::string &idArg, const std::string &streetNameArg, const std::string &junctionArg, double lengthArg)
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
std::vector< std::pair< double, double > > speeds
List of positions/speeds of speed changes.
Importer for networks stored in openDrive format.
double s
The starting offset of this lane section.
int operator()(const OpenDriveLaneSection &ls1, const OpenDriveLaneSection &ls2)
Sorting function; compares OpenDriveLaneSection::s.
#define UNSET_CONNECTION
A storage for available types of edges.
Definition: NBTypeCont.h:55
std::string streetName
The road name of the edge.
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge *> &innerEdges, std::vector< Connection > &into, std::set< Connection > &seen)
void myEndElement(int element)
Called when a closing tag occurs.