SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2014 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),
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);
293 
297  std::map<int, int> laneMap;
299  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
301  std::string sumoID;
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& junctionArg, SUMOReal lengthArg)
356  : id(idArg), junction(junctionArg), length(lengthArg),
357  from(0), to(0) {
358  isInner = junction != "" && junction != "-1";
359  }
360 
361 
368  int getPriority(OpenDriveXMLTag dir) const;
369 
370 
372  std::string id;
374  std::string junction;
377  std::vector<OpenDriveLink> links;
378  std::vector<OpenDriveGeometry> geometries;
382  std::vector<OpenDriveLaneSection> laneSections;
383  std::vector<OpenDriveSignal> signals;
384  std::set<Connection> connections;
385  bool isInner;
386  };
387 
388 
391  public:
393  explicit sections_by_s_sorter() { }
394 
397  return ls1.s < ls2.s;
398  }
399  };
400 
401  /* @brief A class for search in position/speed tuple vectors for the given position */
403  public:
405  explicit same_position_finder(SUMOReal pos) : myPosition(pos) { }
406 
408  bool operator()(const std::pair<SUMOReal, SUMOReal>& ps) {
409  return ps.first == myPosition;
410  }
411 
412  private:
413  same_position_finder& operator=(const same_position_finder&); // just to avoid a compiler warning
414  private:
417 
418  };
419 
420 protected:
425  NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
426 
427 
430 
431 
432 
434 
435 
446  void myStartElement(int element, const SUMOSAXAttributes& attrs);
447 
448 
455  void myEndElement(int element);
457 
458 
459 
460 private:
461  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
462  const std::string& contactPoint);
463  void addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals);
464  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
465  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into);
466  friend bool operator<(const Connection& c1, const Connection& c2);
467  static std::string revertID(const std::string& id);
470 
471  std::map<std::string, OpenDriveEdge*>& myEdges;
472  std::vector<int> myElementStack;
474  std::string myCurrentJunctionID;
479 
480  static bool myImportAllTypes;
481  static bool myImportWidths;
482 
483 
484 protected:
498  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
499 
500 
501  static std::vector<Position> geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
502  static std::vector<Position> geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g);
503  static std::vector<Position> geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
504  static std::vector<Position> geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
505  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
506  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
507  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
508  SUMOReal ad_r, SUMOReal ad_length);
509 
510 
514  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
515 
521  static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
522 
523  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
524  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
525 
526 
527 
528 
531 
534 
535 
536 
537 };
538 
539 
540 #endif
541 
542 /****************************************************************************/
543 
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 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.
static std::vector< Position > geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
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.
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'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'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's level (not used)
std::vector< OpenDriveLink > links
A handler which converts occuring elements and attributes into enums.
OpenDriveLaneSection buildLaneSection(SUMOReal startPos)
OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
Constructor.
std::string type
The lane's type.
int getPriority(OpenDriveXMLTag dir) const
Returns the edge's priority, regarding the direction.
Encapsulated SAX-Attributes.
same_position_finder & operator=(const same_position_finder &)
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.
bool buildSpeedChanges(const NBTypeCont &tc, std::vector< OpenDriveLaneSection > &newSections)
const NBTypeCont & myTypeContainer
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 '-') 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 StringBijection< int >::Entry openDriveTags[]
The names of openDrive-XML elements (for passing to GenericSAXHandler)
static std::vector< Position > geomFromLine(const OpenDriveEdge &e, const OpenDriveGeometry &g)
void buildLaneMapping(const NBTypeCont &tc)
Build the mapping from OpenDrive to SUMO lanes.
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's geometry.
std::map< int, int > getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection &prev)
Returns the links from the previous to this lane section.
SUMOReal speed
The lane'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:215
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.
static std::vector< Position > geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g)
Importer for networks stored in openDrive format.
OpenDriveEdge(const std::string &idArg, const std::string &junctionArg, SUMOReal lengthArg)
static std::vector< Position > geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g)
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:56
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.