SUMO - Simulation of Urban MObility
NIImporter_OpenDrive.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Importer for networks stored in openDrive format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NIImporter_OpenDrive_h
23 #define NIImporter_OpenDrive_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <map>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class NBNetBuilder;
45 class NBEdge;
46 class OptionsCont;
47 class NBNode;
48 class NBNodeCont;
49 
50 
51 #define UNSET_CONNECTION 100000
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
62 public:
78  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
79 
80 
81 protected:
82 
115  };
116 
117 
164  OPENDRIVE_ATTR_UNIT // xodr v1.4
165  };
166 
167 
170  enum LinkType {
173  };
174 
175 
178  enum ElementType {
182  };
183 
184 
191  };
192 
202  };
203 
204 
205 
210  struct OpenDriveLink {
215  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
216  : linkType(linkTypeArg), elementID(elementIDArg),
218 
220  std::string elementID;
223  };
224 
225 
238  OpenDriveGeometry(double lengthArg, double sArg, double xArg, double yArg, double hdgArg)
239  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
240  type(OPENDRIVE_GT_UNKNOWN) { }
241 
242  double length;
243  double s;
244  double x;
245  double y;
246  double hdg;
248  std::vector<double> params;
249  };
250 
255  struct Poly3 {
263  Poly3(double _s, double _a, double _b, double _c, double _d) :
264  s(_s), a(_a), b(_b), c(_c), d(_d) {}
265 
266  double computeAt(double pos) const {
267  const double ds = pos - s;
268  return a + b * ds + c * ds * ds + d * ds * ds * ds;
269  }
270 
271  double s;
272  double a;
273  double b;
274  double c;
275  double d;
276  };
277 
282 
283 
288  struct OpenDriveLane {
294  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg) :
295  id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
296  speed(0), width(NBEdge::UNSPECIFIED_WIDTH) { }
297 
298  int id;
299  std::string level;
300  std::string type;
301  int successor;
303  std::vector<std::pair<double, double> > speeds;
304  double speed;
305  double width; //The lane's maximum width
306  std::vector<OpenDriveWidth> widthData;
307  };
308 
309 
318  OpenDriveLaneSection(double sArg);
319 
320 
327  void buildLaneMapping(const NBTypeCont& tc);
328 
329 
335  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
336 
337 
338  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
339  OpenDriveLaneSection buildLaneSection(double startPos);
340 
342  double s;
344  double sOrig;
346  std::map<int, int> laneMap;
348  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
350  std::string sumoID;
352  int rightLaneNumber, leftLaneNumber;
354  std::string rightType;
355  std::string leftType;
356  };
357 
358 
359 
373  OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
374  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
375 
376  int id;
377  std::string type;
378  std::string name;
380  bool dynamic;
381  double s;
382  };
383 
384 
389  struct Connection {
390  std::string fromEdge;
391  std::string toEdge;
392  int fromLane;
393  int toLane;
396  bool all;
397  std::string origID;
398  int origLane;
399  };
400 
401 
406  struct OpenDriveEdge {
407  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, double lengthArg) :
408  id(idArg),
409  streetName(streetNameArg),
410  junction(junctionArg),
411  length(lengthArg),
412  from(0),
413  to(0) {
414  isInner = junction != "" && junction != "-1";
415  }
416 
417 
424  int getPriority(OpenDriveXMLTag dir) const;
425 
426 
428  std::string id;
430  std::string streetName;
432  std::string junction;
434  double length;
435  std::vector<OpenDriveLink> links;
436  std::vector<OpenDriveGeometry> geometries;
437  std::vector<OpenDriveElevation> elevations;
438  std::vector<OpenDriveLaneOffset> offsets;
442  std::vector<OpenDriveLaneSection> laneSections;
443  std::vector<OpenDriveSignal> signals;
444  std::set<Connection> connections;
445  bool isInner;
446  };
447 
448 
451  public:
453  explicit sections_by_s_sorter() { }
454 
457  return ls1.s < ls2.s;
458  }
459  };
460 
461  /* @brief A class for search in position/speed tuple vectors for the given position */
463  public:
465  explicit same_position_finder(double pos) : myPosition(pos) { }
466 
468  bool operator()(const std::pair<double, double>& ps) {
469  return ps.first == myPosition;
470  }
471 
472  private:
473  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
474  private:
476  double myPosition;
477 
478  };
479 
480 protected:
485  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
486 
487 
490 
491 
492 
494 
495 
506  void myStartElement(int element, const SUMOSAXAttributes& attrs);
507 
508 
515  void myEndElement(int element);
517 
518 
519 
520 private:
521  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
522  const std::string& contactPoint);
523  void addGeometryShape(GeometryType type, const std::vector<double>& vals);
524  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
525  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into, std::set<Connection>& seen);
526  friend bool operator<(const Connection& c1, const Connection& c2);
527  static std::string revertID(const std::string& id);
530 
531  std::map<std::string, OpenDriveEdge*>& myEdges;
532  std::vector<int> myElementStack;
534  std::string myCurrentJunctionID;
539 
540  static bool myImportAllTypes;
541  static bool myImportWidths;
542  static double myMinWidth;
543 
544 
545 protected:
559  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
560 
561 
562  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
563  static PositionVector geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
564  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
565  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
566  static PositionVector geomFromParamPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
567  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
568  static void calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg);
569  static void calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
570  double ad_r, double ad_length);
571 
572 
576  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
577 
583  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
584 
585  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
586  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
587 
588 
589  static void splitMinWidths(OpenDriveEdge* e, const NBTypeCont& tc, double minDist);
590 
591  static void findWidthSplit(const NBTypeCont& tc, std::vector<OpenDriveLane>& lanes,
592  int section, double sectionStart, double sectionEnd,
593  std::vector<double>& splitPositions);
594 
595  static void setStraightConnections(std::vector<OpenDriveLane>& lanes);
596  static void recomputeWidths(OpenDriveLaneSection& sec, double start, double end, double sectionStart, double sectionEnd);
597  static void recomputeWidths(std::vector<OpenDriveLane>& lanes, double start, double end, double sectionStart, double sectionEnd);
598 
601 
604 
605 
606 
607 };
608 
609 
610 #endif
611 
612 /****************************************************************************/
613 
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
double computeAt(double pos) const
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.
Representation of a lane section.
The representation of a single edge during network building.
Definition: NBEdge.h:71
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)
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)
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge * > &innerEdges, std::vector< Connection > &into, std::set< Connection > &seen)
const GenericSAXHandler & operator=(const GenericSAXHandler &s)
invalidated assignment operator
static void setStraightConnections(std::vector< OpenDriveLane > &lanes)
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:46
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.
NIImporter_OpenDrive(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
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
OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
Constructor.
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 computeShapes(std::map< std::string, OpenDriveEdge * > &edges)
Computes a polygon representation of each edge&#39;s geometry.
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
Representation of an OpenDrive geometry part.
A storage for options typed value containers)
Definition: OptionsCont.h:99
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:75
void addGeometryShape(GeometryType type, const std::vector< double > &vals)
A class for sorting lane sections by their s-value.
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:63
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:62
std::string streetName
The road name of the edge.
void myEndElement(int element)
Called when a closing tag occurs.
static void revisitLaneSections(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Rechecks lane sections of the given edges.