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-2013 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 
150  };
151 
152 
155  enum LinkType {
158  };
159 
160 
163  enum ElementType {
167  };
168 
169 
176  };
177 
186  };
187 
188 
189 
194  struct OpenDriveLink {
199  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
200  : linkType(linkTypeArg), elementID(elementIDArg),
202 
204  std::string elementID;
207  };
208 
209 
222  OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
223  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
225 
232  std::vector<SUMOReal> params;
233  };
234 
235 
240  struct OpenDriveLane {
246  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
247  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
248  speed(0), width(0) { }
249 
250  int id;
251  std::string level;
252  std::string type;
257  };
258 
259 
260 
270 
271 
275  unsigned int getLaneNumber(OpenDriveXMLTag dir) const;
276 
277 
283  void buildLaneMapping();
284 
285 
286  std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
287 
288 
292  std::map<int, int> laneMap;
294  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
296  std::string sumoID;
297  };
298 
299 
300 
313  OpenDriveSignal(int idArg, const std::string typeArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
314  : id(idArg), type(typeArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
315 
316  int id;
317  std::string type;
319  bool dynamic;
321  };
322 
323 
328  struct Connection {
329  std::string fromEdge;
330  std::string toEdge;
331  int fromLane;
332  int toLane;
335  bool all;
336  std::string origID;
337  int origLane;
338  };
339 
340 
345  struct OpenDriveEdge {
346  OpenDriveEdge(const std::string& idArg, const std::string& junctionArg, SUMOReal lengthArg)
347  : id(idArg), junction(junctionArg), length(lengthArg),
348  from(0), to(0) {
349  isInner = junction != "" && junction != "-1";
350  }
351 
352  unsigned int getMaxLaneNumber(OpenDriveXMLTag dir) const;
353  int getPriority(OpenDriveXMLTag dir) const;
354 
356  std::string id;
358  std::string junction;
361  std::vector<OpenDriveLink> links;
362  std::vector<OpenDriveGeometry> geometries;
366  std::vector<OpenDriveLaneSection> laneSections;
367  std::vector<OpenDriveSignal> signals;
368  std::set<Connection> connections;
369  bool isInner;
370  };
371 
372 
373 
374 protected:
378  NIImporter_OpenDrive(std::map<std::string, OpenDriveEdge*>& edges);
379 
380 
383 
384 
385 
387 
388 
399  void myStartElement(int element,
400  const SUMOSAXAttributes& attrs);
401 
402 
409  void myEndElement(int element);
411 
412 
413 
414 private:
415  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
416  const std::string& contactPoint);
417  void addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals);
418  static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
419  static void buildConnectionsToOuter(const Connection& c, const std::map<std::string, OpenDriveEdge*>& innerEdges, std::vector<Connection>& into);
420  friend bool operator<(const Connection& c1, const Connection& c2);
421  static std::string revertID(const std::string& id);
423 
424  std::map<std::string, OpenDriveEdge*>& myEdges;
425  std::vector<int> myElementStack;
427  std::string myCurrentJunctionID;
432 
433  static std::set<std::string> myLaneTypes2Import;
434  static bool myImportAllTypes;
435  static bool myImportWidths;
436 
437 
438 protected:
452  static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
453 
454 
455  static std::vector<Position> geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
456  static std::vector<Position> geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g);
457  static std::vector<Position> geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
458  static std::vector<Position> geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
459  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
460  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
461  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
462  SUMOReal ad_r, SUMOReal ad_length);
463 
464  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
465  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
466  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
467 
468 
469 
470 
473 
476 
477 
478 
479 };
480 
481 
482 #endif
483 
484 /****************************************************************************/
485 
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
void buildLaneMapping()
Build the mapping from OpenDrive to SUMO lanes.
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.
OpenDriveSignal(int idArg, const std::string typeArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
Constructor.
GeometryType
OpenDrive geometry type enumeration.
static std::vector< Position > geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
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 &quot;link&quot;.
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)
unsigned int getLaneNumber(OpenDriveXMLTag dir) const
Returns the number of lanes for the given direction.
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)
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::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.
int getPriority(OpenDriveXMLTag dir) const
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
unsigned int getMaxLaneNumber(OpenDriveXMLTag dir) const
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.
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 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)
std::vector< OpenDriveSignal > signals
LinkType
OpenDrive link type enumeration.
static void computeShapes(std::map< std::string, OpenDriveEdge * > &edges)
std::map< int, int > getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection &prev)
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
static std::set< std::string > myLaneTypes2Import
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
#define SUMOReal
Definition: config.h:221
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.
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)
NIImporter_OpenDrive(std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
#define UNSET_CONNECTION
void myEndElement(int element)
Called when a closing tag occurs.