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> geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
457  static std::vector<Position> geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
458  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
459  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
460  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
461  SUMOReal ad_r, SUMOReal ad_length);
462 
463  static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
464  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
465  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
466 
467 
468 
469 
472 
475 
476 
477 
478 };
479 
480 
481 #endif
482 
483 /****************************************************************************/
484