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-2016 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 
112  };
113 
114 
152  };
153 
154 
157  enum LinkType {
160  };
161 
162 
165  enum ElementType {
169  };
170 
171 
178  };
179 
188  };
189 
190 
191 
196  struct OpenDriveLink {
201  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
202  : linkType(linkTypeArg), elementID(elementIDArg),
204 
206  std::string elementID;
209  };
210 
211 
224  OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
225  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
226  type(OPENDRIVE_GT_UNKNOWN) { }
227 
234  std::vector<SUMOReal> params;
235  };
236 
237 
242  struct OpenDriveLane {
248  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
249  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
250  speed(0), width(0) { }
251 
252  int id;
253  std::string level;
254  std::string type;
255  int successor;
257  std::vector<std::pair<SUMOReal, SUMOReal> > speeds;
260  };
261 
262 
272 
273 
280  void buildLaneMapping(const NBTypeCont& tc);
281 
282 
288  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
289 
290 
291  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
292  OpenDriveLaneSection buildLaneSection(SUMOReal startPos);
293 
297  std::map<int, int> laneMap;
299  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
301  std::string sumoID;
303  unsigned int rightLaneNumber, leftLaneNumber;
304  };
305 
306 
307 
321  OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
322  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
323 
324  int id;
325  std::string type;
326  std::string name;
328  bool dynamic;
330  };
331 
332 
337  struct Connection {
338  std::string fromEdge;
339  std::string toEdge;
340  int fromLane;
341  int toLane;
344  bool all;
345  std::string origID;
346  int origLane;
347  };
348 
349 
354  struct OpenDriveEdge {
355  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, SUMOReal lengthArg) :
356  id(idArg),
357  streetName(streetNameArg),
358  junction(junctionArg),
359  length(lengthArg),
360  from(0),
361  to(0) {
362  isInner = junction != "" && junction != "-1";
363  }
364 
365 
372  int getPriority(OpenDriveXMLTag dir) const;
373 
374 
376  std::string id;
378  std::string streetName;
380  std::string junction;
383  std::vector<OpenDriveLink> links;
384  std::vector<OpenDriveGeometry> geometries;
388  std::vector<OpenDriveLaneSection> laneSections;
389  std::vector<OpenDriveSignal> signals;
390  std::set<Connection> connections;
391  bool isInner;
392  };
393 
394 
397  public:
399  explicit sections_by_s_sorter() { }
400 
403  return ls1.s < ls2.s;
404  }
405  };
406 
407  /* @brief A class for search in position/speed tuple vectors for the given position */
409  public:
411  explicit same_position_finder(SUMOReal pos) : myPosition(pos) { }
412 
414  bool operator()(const std::pair<SUMOReal, SUMOReal>& ps) {
415  return ps.first == myPosition;
416  }
417 
418  private:
419  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
420  private:
423 
424  };
425 
426 protected:
431  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
432 
433 
436 
437 
438 
440 
441 
452  void myStartElement(int element, const SUMOSAXAttributes& attrs);
453 
454 
461  void myEndElement(int element);
463 
464 
465 
466 private:
467  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
468  const std::string& contactPoint);
469  void addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals);
470  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
471  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into);
472  friend bool operator<(const Connection& c1, const Connection& c2);
473  static std::string revertID(const std::string& id);
476 
477  std::map<std::string, OpenDriveEdge*>& myEdges;
478  std::vector<int> myElementStack;
480  std::string myCurrentJunctionID;
485 
486  static bool myImportAllTypes;
487  static bool myImportWidths;
488 
489 
490 protected:
504  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
505 
506 
507  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
509  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
510  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
511  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
512  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
513  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
514  SUMOReal ad_r, SUMOReal ad_length);
515 
516 
520  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
521 
527  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
528 
529  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
530  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
531 
532 
533 
534 
537 
540 
541 
542 
543 };
544 
545 
546 #endif
547 
548 /****************************************************************************/
549 
std::map< std::string, OpenDriveEdge * > & myEdges
static void calculateCurveCenter(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_radius, SUMOReal ad_hdg)
std::vector< int > myElementStack
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.
ContactPoint
OpenDrive contact type enumeration.
std::string junction
The id of the junction the edge belongs to.
GeometryType
OpenDrive geometry type enumeration.
bool operator()(const std::pair< SUMOReal, SUMOReal > &ps)
the comparing function
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge * > &innerEdges, std::vector< Connection > &into)
Representation of a lane section.
The representation of a single edge during network building.
Definition: NBEdge.h:70
Representation of an openDrive "link".
ContactPoint myCurrentContactPoint
SUMOReal s
The starting offset of this lane section.
static PositionVector geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g)
std::map< OpenDriveXMLTag, std::vector< OpenDriveLane > > lanesByDir
The lanes, sorted by their direction.
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.
OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
Constructor.
int successor
The lane&#39;s successor lane.
OpenDriveXMLTag myCurrentLaneDirection
static void calcPointOnCurve(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY, SUMOReal ad_r, SUMOReal ad_length)
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.
OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
Constructor.
const GenericSAXHandler & operator=(const GenericSAXHandler &s)
invalidated assignment operator
std::string type
The lane&#39;s type.
Encapsulated SAX-Attributes.
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.
NIImporter_OpenDrive(const NBTypeCont &tc, std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
OpenDriveEdge(const std::string &idArg, const std::string &streetNameArg, const std::string &junctionArg, SUMOReal lengthArg)
const NBTypeCont & myTypeContainer
SUMOReal width
The lane&#39;s width;.
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 geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g)
static PositionVector geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
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.
SUMOReal speed
The lane&#39;s speed (set in post-processing)
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
Representation of an OpenDrive geometry part.
A storage for options typed value containers)
Definition: OptionsCont.h:108
SUMOReal myPosition
The position to search for.
unsigned int rightLaneNumber
The number of lanes on the right and on the left side, respectively.
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
A class for sorting lane sections by their s-value.
#define SUMOReal
Definition: config.h:213
static void setNodeSecure(NBNodeCont &nc, OpenDriveEdge &e, const std::string &nodeID, NIImporter_OpenDrive::LinkType lt)
A connection between two roads.
void addGeometryShape(GeometryType type, const std::vector< SUMOReal > &vals)
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
SUMOReal length
The length of the edge.
Importer for networks stored in openDrive format.
int operator()(const OpenDriveLaneSection &ls1, const OpenDriveLaneSection &ls2)
Sorting function; compares OpenDriveLaneSection::s.
std::vector< std::pair< SUMOReal, SUMOReal > > speeds
List of positions/speeds of speed changes.
#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.