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(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
238  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
239  type(OPENDRIVE_GT_UNKNOWN) { }
240 
247  std::vector<SUMOReal> params;
248  };
249 
263  s(_s), a(_a), b(_b), c(_c), d(_d) {}
264 
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<SUMOReal, SUMOReal> > speeds;
298  };
299 
300 
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(SUMOReal startPos);
331 
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, SUMOReal 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;
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, SUMOReal 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;
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(SUMOReal pos) : myPosition(pos) { }
455 
457  bool operator()(const std::pair<SUMOReal, SUMOReal>& 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:
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<SUMOReal>& 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);
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);
552  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
553  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
555  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
556  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
557  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
558  SUMOReal ad_r, SUMOReal 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
static void calculateCurveCenter(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_radius, SUMOReal ad_hdg)
std::vector< int > myElementStack
std::string rightType
the composite type built from all used lane types
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.
std::vector< OpenDriveElevation > elevations
GeometryType
OpenDrive geometry type enumeration.
int rightLaneNumber
The number of lanes on the right and on the left side, respectively.
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:71
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.
OpenDriveElevation OpenDriveLaneOffset
LaneOffset has the same fields as Elevation.
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
OpenDriveElevation(SUMOReal _s, SUMOReal _a, SUMOReal _b, SUMOReal _c, SUMOReal _d)
Constructor.
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
std::vector< OpenDriveLaneOffset > offsets
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:112
Representation of an OpenDrive geometry part.
A storage for options typed value containers)
Definition: OptionsCont.h:99
SUMOReal myPosition
The position to search for.
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
A class for sorting lane sections by their s-value.
static PositionVector geomFromParamPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
#define SUMOReal
Definition: config.h:208
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:63
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.
Coefficients of an elevation profile (3rd degree polynomial)