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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Importer for networks stored in openDrive format
20 /****************************************************************************/
21 #ifndef NIImporter_OpenDrive_h
22 #define NIImporter_OpenDrive_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class NBNetBuilder;
44 class NBEdge;
45 class OptionsCont;
46 class NBNode;
47 class NBNodeCont;
48 
49 
50 #define UNSET_CONNECTION 100000
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
61 public:
77  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
78 
79 
80 protected:
81 
114  };
115 
116 
163  OPENDRIVE_ATTR_UNIT // xodr v1.4
164  };
165 
166 
169  enum LinkType {
172  };
173 
174 
177  enum ElementType {
181  };
182 
183 
190  };
191 
201  };
202 
203 
204 
209  struct OpenDriveLink {
214  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
215  : linkType(linkTypeArg), elementID(elementIDArg),
217 
219  std::string elementID;
222  };
223 
224 
237  OpenDriveGeometry(double lengthArg, double sArg, double xArg, double yArg, double hdgArg)
238  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
239  type(OPENDRIVE_GT_UNKNOWN) { }
240 
241  double length;
242  double s;
243  double x;
244  double y;
245  double hdg;
247  std::vector<double> params;
248  };
249 
254  struct Poly3 {
262  Poly3(double _s, double _a, double _b, double _c, double _d) :
263  s(_s), a(_a), b(_b), c(_c), d(_d) {}
264 
265  double computeAt(double pos) const {
266  const double ds = pos - s;
267  return a + b * ds + c * ds * ds + d * ds * ds * ds;
268  }
269 
270  double s;
271  double a;
272  double b;
273  double c;
274  double d;
275  };
276 
281 
282 
287  struct OpenDriveLane {
293  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg) :
294  id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
295  speed(0), width(NBEdge::UNSPECIFIED_WIDTH) { }
296 
297  int id;
298  std::string level;
299  std::string type;
300  int successor;
302  std::vector<std::pair<double, double> > speeds;
303  double speed;
304  double width; //The lane's maximum width
305  std::vector<OpenDriveWidth> widthData;
306  };
307 
308 
317  OpenDriveLaneSection(double sArg);
318 
319 
326  void buildLaneMapping(const NBTypeCont& tc);
327 
328 
334  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
335 
336 
337  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
338  OpenDriveLaneSection buildLaneSection(double startPos);
339 
341  double s;
343  double sOrig;
345  std::map<int, int> laneMap;
347  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
349  std::string sumoID;
351  int rightLaneNumber, leftLaneNumber;
353  std::string rightType;
354  std::string leftType;
355  };
356 
357 
358 
372  OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
373  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
374 
375  int id;
376  std::string type;
377  std::string name;
379  bool dynamic;
380  double s;
381  };
382 
383 
388  struct Connection {
389  std::string fromEdge;
390  std::string toEdge;
391  int fromLane;
392  int toLane;
395  bool all;
396  std::string origID;
397  int origLane;
398  };
399 
400 
405  struct OpenDriveEdge {
406  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, double lengthArg) :
407  id(idArg),
408  streetName(streetNameArg),
409  junction(junctionArg),
410  length(lengthArg),
411  from(0),
412  to(0) {
413  isInner = junction != "" && junction != "-1";
414  }
415 
416 
423  int getPriority(OpenDriveXMLTag dir) const;
424 
425 
427  std::string id;
429  std::string streetName;
431  std::string junction;
433  double length;
434  std::vector<OpenDriveLink> links;
435  std::vector<OpenDriveGeometry> geometries;
436  std::vector<OpenDriveElevation> elevations;
437  std::vector<OpenDriveLaneOffset> offsets;
441  std::vector<OpenDriveLaneSection> laneSections;
442  std::vector<OpenDriveSignal> signals;
443  std::set<Connection> connections;
444  bool isInner;
445  };
446 
447 
450  public:
452  explicit sections_by_s_sorter() { }
453 
456  return ls1.s < ls2.s;
457  }
458  };
459 
460  /* @brief A class for search in position/speed tuple vectors for the given position */
462  public:
464  explicit same_position_finder(double pos) : myPosition(pos) { }
465 
467  bool operator()(const std::pair<double, double>& ps) {
468  return ps.first == myPosition;
469  }
470 
471  private:
472  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
473  private:
475  double myPosition;
476 
477  };
478 
479 protected:
484  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
485 
486 
489 
490 
491 
493 
494 
505  void myStartElement(int element, const SUMOSAXAttributes& attrs);
506 
507 
514  void myEndElement(int element);
516 
517 
518 
519 private:
520  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
521  const std::string& contactPoint);
522  void addGeometryShape(GeometryType type, const std::vector<double>& vals);
523  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
524  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into, std::set<Connection>& seen);
525  friend bool operator<(const Connection& c1, const Connection& c2);
526  static std::string revertID(const std::string& id);
529 
530  std::map<std::string, OpenDriveEdge*>& myEdges;
531  std::vector<int> myElementStack;
533  std::string myCurrentJunctionID;
538 
539  static bool myImportAllTypes;
540  static bool myImportWidths;
541  static double myMinWidth;
542 
543 
544 protected:
558  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
559 
560 
561  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
562  static PositionVector geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
563  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
564  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
565  static PositionVector geomFromParamPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
566  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
567  static void calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg);
568  static void calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
569  double ad_r, double ad_length);
570 
571 
575  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
576 
582  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
583 
584  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
585  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
586 
587 
588  static void splitMinWidths(OpenDriveEdge* e, const NBTypeCont& tc, double minDist);
589 
590  static void findWidthSplit(const NBTypeCont& tc, std::vector<OpenDriveLane>& lanes,
591  int section, double sectionStart, double sectionEnd,
592  std::vector<double>& splitPositions);
593 
594  static void setStraightConnections(std::vector<OpenDriveLane>& lanes);
595  static void recomputeWidths(OpenDriveLaneSection& sec, double start, double end, double sectionStart, double sectionEnd);
596  static void recomputeWidths(std::vector<OpenDriveLane>& lanes, double start, double end, double sectionStart, double sectionEnd);
597 
600 
603 
604 
605 
606 };
607 
608 
609 #endif
610 
611 /****************************************************************************/
612 
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:70
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)
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)
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:45
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
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 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:115
Representation of an OpenDrive geometry part.
A storage for options typed value containers)
Definition: OptionsCont.h:98
static void setEdgeLinks2(OpenDriveEdge &e, const std::map< std::string, OpenDriveEdge *> &edges)
std::vector< OpenDriveGeometry > geometries
Represents a single node (junction) during network building.
Definition: NBNode.h:74
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:66
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:61
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.