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 
114  };
115 
116 
163  };
164 
165 
168  enum LinkType {
171  };
172 
173 
176  enum ElementType {
180  };
181 
182 
189  };
190 
200  };
201 
202 
203 
208  struct OpenDriveLink {
213  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
214  : linkType(linkTypeArg), elementID(elementIDArg),
216 
218  std::string elementID;
221  };
222 
223 
236  OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
237  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
238  type(OPENDRIVE_GT_UNKNOWN) { }
239 
246  std::vector<SUMOReal> params;
247  };
248 
262  s(_s), a(_a), b(_b), c(_c), d(_d) {}
263 
269  };
270 
271 
276  struct OpenDriveLane {
282  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
283  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
284  speed(0), width(0) { }
285 
286  int id;
287  std::string level;
288  std::string type;
289  int successor;
291  std::vector<std::pair<SUMOReal, SUMOReal> > speeds;
294  };
295 
296 
306 
307 
314  void buildLaneMapping(const NBTypeCont& tc);
315 
316 
322  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
323 
324 
325  bool buildSpeedChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
326  OpenDriveLaneSection buildLaneSection(SUMOReal startPos);
327 
331  std::map<int, int> laneMap;
333  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
335  std::string sumoID;
337  int rightLaneNumber, leftLaneNumber;
339  std::string rightType;
340  std::string leftType;
341  };
342 
343 
344 
358  OpenDriveSignal(int idArg, const std::string typeArg, const std::string nameArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
359  : id(idArg), type(typeArg), name(nameArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
360 
361  int id;
362  std::string type;
363  std::string name;
365  bool dynamic;
367  };
368 
369 
374  struct Connection {
375  std::string fromEdge;
376  std::string toEdge;
377  int fromLane;
378  int toLane;
381  bool all;
382  std::string origID;
383  int origLane;
384  };
385 
386 
391  struct OpenDriveEdge {
392  OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, SUMOReal lengthArg) :
393  id(idArg),
394  streetName(streetNameArg),
395  junction(junctionArg),
396  length(lengthArg),
397  from(0),
398  to(0) {
399  isInner = junction != "" && junction != "-1";
400  }
401 
402 
409  int getPriority(OpenDriveXMLTag dir) const;
410 
411 
413  std::string id;
415  std::string streetName;
417  std::string junction;
420  std::vector<OpenDriveLink> links;
421  std::vector<OpenDriveGeometry> geometries;
422  std::vector<OpenDriveElevation> elevations;
426  std::vector<OpenDriveLaneSection> laneSections;
427  std::vector<OpenDriveSignal> signals;
428  std::set<Connection> connections;
429  bool isInner;
430  };
431 
432 
435  public:
437  explicit sections_by_s_sorter() { }
438 
441  return ls1.s < ls2.s;
442  }
443  };
444 
445  /* @brief A class for search in position/speed tuple vectors for the given position */
447  public:
449  explicit same_position_finder(SUMOReal pos) : myPosition(pos) { }
450 
452  bool operator()(const std::pair<SUMOReal, SUMOReal>& ps) {
453  return ps.first == myPosition;
454  }
455 
456  private:
457  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
458  private:
461 
462  };
463 
464 protected:
469  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
470 
471 
474 
475 
476 
478 
479 
490  void myStartElement(int element, const SUMOSAXAttributes& attrs);
491 
492 
499  void myEndElement(int element);
501 
502 
503 
504 private:
505  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
506  const std::string& contactPoint);
507  void addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals);
508  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
509  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into);
510  friend bool operator<(const Connection& c1, const Connection& c2);
511  static std::string revertID(const std::string& id);
514 
515  std::map<std::string, OpenDriveEdge*>& myEdges;
516  std::vector<int> myElementStack;
518  std::string myCurrentJunctionID;
523 
524  static bool myImportAllTypes;
525  static bool myImportWidths;
526 
527 
528 protected:
542  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
543 
544 
545  static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
547  static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
548  static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
550  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
551  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
552  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
553  SUMOReal ad_r, SUMOReal ad_length);
554 
555 
559  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
560 
566  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
567 
568  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
569  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
570 
571 
572 
573 
576 
579 
580 
581 
582 };
583 
584 
585 #endif
586 
587 /****************************************************************************/
588 
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: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
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
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:74
A class for sorting lane sections by their s-value.
static PositionVector geomFromParamPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
#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: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)