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  };
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 
262  OpenDriveElevation(double _s, double _a, double _b, double _c, double _d) :
263  s(_s), a(_a), b(_b), c(_c), d(_d) {}
264 
265  double s;
266  double a;
267  double b;
268  double c;
269  double d;
270  };
271 
274 
275 
280  struct OpenDriveLane {
286  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
287  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
288  speed(0), width(0) { }
289 
290  int id;
291  std::string level;
292  std::string type;
293  int successor;
295  std::vector<std::pair<double, double> > speeds;
296  double speed;
297  double width;
298  };
299 
300 
309  OpenDriveLaneSection(double sArg);
310 
311 
318  void buildLaneMapping(const NBTypeCont& tc);
319 
320 
326  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
327 
328 
329  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
330  OpenDriveLaneSection buildLaneSection(double startPos);
331 
333  double s;
335  std::map<int, int> laneMap;
337  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
339  std::string sumoID;
341  int rightLaneNumber, leftLaneNumber;
343  std::string rightType;
344  std::string leftType;
345  };
346 
347 
348 
362  OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, double sArg)
363  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
364 
365  int id;
366  std::string type;
367  std::string name;
369  bool dynamic;
370  double s;
371  };
372 
373 
378  struct Connection {
379  std::string fromEdge;
380  std::string toEdge;
381  int fromLane;
382  int toLane;
385  bool all;
386  std::string origID;
387  int origLane;
388  };
389 
390 
395  struct OpenDriveEdge {
396  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, double lengthArg) :
397  id(idArg),
398  streetName(streetNameArg),
399  junction(junctionArg),
400  length(lengthArg),
401  from(0),
402  to(0) {
403  isInner = junction != "" && junction != "-1";
404  }
405 
406 
413  int getPriority(OpenDriveXMLTag dir) const;
414 
415 
417  std::string id;
419  std::string streetName;
421  std::string junction;
423  double length;
424  std::vector<OpenDriveLink> links;
425  std::vector<OpenDriveGeometry> geometries;
426  std::vector<OpenDriveElevation> elevations;
427  std::vector<OpenDriveLaneOffset> offsets;
431  std::vector<OpenDriveLaneSection> laneSections;
432  std::vector<OpenDriveSignal> signals;
433  std::set<Connection> connections;
434  bool isInner;
435  };
436 
437 
440  public:
442  explicit sections_by_s_sorter() { }
443 
446  return ls1.s < ls2.s;
447  }
448  };
449 
450  /* @brief A class for search in position/speed tuple vectors for the given position */
452  public:
454  explicit same_position_finder(double pos) : myPosition(pos) { }
455 
457  bool operator()(const std::pair<double, double>& ps) {
458  return ps.first == myPosition;
459  }
460 
461  private:
462  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
463  private:
465  double myPosition;
466 
467  };
468 
469 protected:
474  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
475 
476 
479 
480 
481 
483 
484 
495  void myStartElement(int element, const SUMOSAXAttributes& attrs);
496 
497 
504  void myEndElement(int element);
506 
507 
508 
509 private:
510  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
511  const std::string& contactPoint);
512  void addGeometryShape(GeometryType type, const std::vector<double>& vals);
513  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
514  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into, std::set<Connection>& seen);
515  friend bool operator<(const Connection& c1, const Connection& c2);
516  static std::string revertID(const std::string& id);
519 
520  std::map<std::string, OpenDriveEdge*>& myEdges;
521  std::vector<int> myElementStack;
523  std::string myCurrentJunctionID;
528 
529  static bool myImportAllTypes;
530  static bool myImportWidths;
531 
532 
533 protected:
547  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
548 
549 
550  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
551  static PositionVector geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
552  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
553  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
554  static PositionVector geomFromParamPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
555  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
556  static void calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg);
557  static void calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
558  double ad_r, double ad_length);
559 
560 
564  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
565 
571  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
572 
573  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
574  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
575 
576 
577 
578 
581 
584 
585 
586 
587 };
588 
589 
590 #endif
591 
592 /****************************************************************************/
593 
std::map< std::string, OpenDriveEdge * > & myEdges
std::vector< int > myElementStack
std::string rightType
the composite type built from all used lane types
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)
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:71
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.
OpenDriveElevation(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.
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.
OpenDriveElevation OpenDriveLaneOffset
LaneOffset has the same fields as Elevation.
static PositionVector geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g, double resolution)
const GenericSAXHandler & operator=(const GenericSAXHandler &s)
invalidated assignment operator
std::string type
The lane&#39;s type.
Encapsulated SAX-Attributes.
double width
The lane&#39;s width;.
static Position calculateStraightEndPoint(double hdg, double length, const Position &start)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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.
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:114
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.
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.
Coefficients of an elevation profile (3rd degree polynomial)