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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 
94  // !!! OPENDRIVE_TAG_NEIGHBOR,
95  // !!! OPENDRIVE_TAG_TYPE,
107  };
108 
109 
140  };
141 
142  enum LinkType {
145  };
146 
147  enum ElementType {
151  };
152 
157  };
158 
165  };
166 
171  struct OpenDriveLink {
172  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
173  : linkType(linkTypeArg), elementID(elementIDArg),
175 
177  std::string elementID;
180  };
181 
182 
188  OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
189  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
191 
198  std::vector<SUMOReal> params;
199  };
200 
201 
206  struct OpenDriveLane {
207  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
208  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION) { }
209 
210  int id;
211  std::string level;
212  std::string type;
215  };
216 
217 
224 
225  unsigned int getLaneNumber(OpenDriveXMLTag dir) const;
226 
227  std::map<int, int> buildLaneMapping(OpenDriveXMLTag dir);
228 
230  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
231  };
232 
233 
239  OpenDriveSignal(int idArg, const std::string typeArg, int orientationArg, bool dynamicArg, SUMOReal sArg)
240  : id(idArg), type(typeArg), orientation(orientationArg), dynamic(dynamicArg), s(sArg) { }
241 
242  int id;
243  std::string type;
245  bool dynamic;
247  };
248 
249 
254  struct OpenDriveEdge {
255  OpenDriveEdge(const std::string& idArg, const std::string& junctionArg, SUMOReal lengthArg)
256  : id(idArg), junction(junctionArg), length(lengthArg),
257  from(0), to(0) { }
258 
259  unsigned int getMaxLaneNumber(OpenDriveXMLTag dir) const;
260  int getPriority(OpenDriveXMLTag dir) const;
261 
263  std::string id;
265  std::string junction;
268  std::vector<OpenDriveLink> links;
269  std::vector<OpenDriveGeometry> geometries;
272  std::map<int, int> beginLaneMap;
273  std::map<int, int> endLaneMap;
275  std::vector<OpenDriveLaneSection> laneSections;
276  std::vector<OpenDriveSignal> signals;
277  };
278 
279 
280  struct Connection {
281  Connection(NBEdge* fromArg, const std::string& viaArg, NBEdge* toArg)
282  : from(fromArg), to(toArg), via(viaArg) { }
285  std::string via;
286  std::vector<std::pair<int, int> > lanes;
287  std::string id;
288  };
289 
290 protected:
294  NIImporter_OpenDrive(std::vector<OpenDriveEdge>& innerEdges, std::vector<OpenDriveEdge>& outerEdges);
295 
296 
299 
300 
301 
303 
304 
315  void myStartElement(int element,
316  const SUMOSAXAttributes& attrs);
317 
318 
325  void myEndElement(int element);
327 
328 
329 
330 private:
331  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
332  const std::string& contactPoint);
333 
334  void addGeometryShape(GeometryType type, const std::vector<SUMOReal>& vals);
335 
337 
338  std::vector<OpenDriveEdge>& myInnerEdges;
339  std::vector<OpenDriveEdge>& myOuterEdges;
340  std::vector<int> myElementStack;
342  static std::set<std::string> myLaneTypes2Import;
343 
344 
345 protected:
359  static NBNode* getOrBuildNode(const std::string& id, Position& pos, NBNodeCont& nc);
360 
361 
362  static std::vector<Position> geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g);
363  static std::vector<Position> geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g);
364  static std::vector<Position> geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g);
365  static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
366  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg);
367  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
368  SUMOReal ad_r, SUMOReal ad_length);
369  static NBEdge* getOutgoingDirectionalEdge(const NBEdgeCont& ec, const NBNodeCont& nc,
370  const std::string& edgeID, const std::string& nodeID);
371  static NBEdge* getIncomingDirectionalEdge(const NBEdgeCont& ec, const NBNodeCont& nc,
372  const std::string& edgeID, const std::string& nodeID);
373 
374  static void computeShapes(std::vector<OpenDriveEdge>& edges);
375  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
376  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt);
377 
378  static void addE2EConnectionsSecure(const NBEdgeCont& ec, const NBNode* const node,
379  const OpenDriveEdge& from, const OpenDriveEdge& to,
380  std::vector<NIImporter_OpenDrive::Connection>& connections);
381  static void addViaConnectionSecure(const NBEdgeCont& ec, const NBNode* const node, const OpenDriveEdge& e,
382  LinkType lt, const std::string& via,
383  std::vector<NIImporter_OpenDrive::Connection>& connections);
384 
386  const OpenDriveEdge& from, bool fromAtBegin, OpenDriveXMLTag fromLaneDir,
387  const OpenDriveEdge& to, bool toAtEnd, OpenDriveXMLTag toLaneDir);
388 
390  const OpenDriveEdge& from, bool fromAtBegin, OpenDriveXMLTag fromLaneDir,
391  const OpenDriveEdge& via, bool viaIsReversed, OpenDriveXMLTag viaLaneDir,
392  const OpenDriveEdge& to, bool fromAtEnd, OpenDriveXMLTag toLaneDir);
393 
394 
396  public:
397  explicit edge_by_id_finder(const std::string& id)
398  : myEdgeID(id) { }
399 
400  bool operator()(const OpenDriveEdge& e) {
401  return e.id == myEdgeID;
402  }
403 
404  private:
405  const std::string& myEdgeID;
406 
407  private:
410 
411  };
412 
413 
414 
417 
420 
421 
422 
423 };
424 
425 
426 #endif
427 
428 /****************************************************************************/
429