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,
106  };
107 
108 
137  };
138 
139  enum LinkType {
142  };
143 
144  enum ElementType {
148  };
149 
154  };
155 
162  };
163 
168  struct OpenDriveLink {
169  OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
170  : linkType(linkTypeArg), elementID(elementIDArg),
172 
174  std::string elementID;
177  };
178 
179 
185  OpenDriveGeometry(SUMOReal lengthArg, SUMOReal sArg, SUMOReal xArg, SUMOReal yArg, SUMOReal hdgArg)
186  : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
188 
195  std::vector<SUMOReal> params;
196  };
197 
198 
203  struct OpenDriveLane {
204  OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg)
205  : id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION) { }
206 
207  int id;
208  std::string level;
209  std::string type;
212  };
213 
214 
221  : s(sArg) {
222  lanesByDir[OPENDRIVE_TAG_LEFT] = std::vector<OpenDriveLane>();
223  lanesByDir[OPENDRIVE_TAG_RIGHT] = std::vector<OpenDriveLane>();
224  lanesByDir[OPENDRIVE_TAG_CENTER] = std::vector<OpenDriveLane>();
225  }
226 
227  unsigned int getLaneNumber(OpenDriveXMLTag dir) const {
228  unsigned int laneNum = 0;
229  const std::vector<OpenDriveLane> &dirLanes = lanesByDir.find(dir)->second;
230  for (std::vector<OpenDriveLane>::const_iterator i = dirLanes.begin(); i != dirLanes.end(); ++i) {
231  if ((*i).type == "driving") {
232  ++laneNum;
233  }
234  }
235  return laneNum;
236  }
237 
238  std::map<int, int> buildLaneMapping(OpenDriveXMLTag dir) {
239  std::map<int, int> ret;
240  unsigned int sumoLane = 0;
241  const std::vector<OpenDriveLane> &dirLanes = lanesByDir.find(dir)->second;
242  if (dir == OPENDRIVE_TAG_RIGHT) {
243  for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
244  if ((*i).type == "driving") {
245  ret[(*i).id] = sumoLane++;
246  }
247  }
248  } else {
249  for (std::vector<OpenDriveLane>::const_iterator i = dirLanes.begin(); i != dirLanes.end(); ++i) {
250  if ((*i).type == "driving") {
251  ret[(*i).id] = sumoLane++;
252  }
253  }
254  }
255  return ret;
256  }
257 
259  std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
260  };
261 
262 
267  struct OpenDriveEdge {
268  OpenDriveEdge(const std::string& idArg, const std::string& junctionArg, SUMOReal lengthArg)
269  : id(idArg), junction(junctionArg), length(lengthArg),
270  from(0), to(0) { }
271 
272  unsigned int getMaxLaneNumber(OpenDriveXMLTag dir) const {
273  unsigned int maxLaneNum = 0;
274  for (std::vector<OpenDriveLaneSection>::const_iterator i = laneSections.begin(); i != laneSections.end(); ++i) {
275  maxLaneNum = MAX2(maxLaneNum, (*i).getLaneNumber(dir));
276  }
277  return maxLaneNum;
278  }
279 
281  std::string id;
283  std::string junction;
286  std::vector<OpenDriveLink> links;
287  std::vector<OpenDriveGeometry> geometries;
290  std::map<int, int> beginLaneMap;
291  std::map<int, int> endLaneMap;
293  std::vector<OpenDriveLaneSection> laneSections;
294  };
295 
296 
297  struct Connection {
298  Connection(NBEdge* fromArg, const std::string& viaArg, NBEdge* toArg)
299  : from(fromArg), to(toArg), via(viaArg) { }
302  std::string via;
303  std::vector<std::pair<int, int> > lanes;
304  };
305 
306 protected:
310  NIImporter_OpenDrive(std::vector<OpenDriveEdge> &innerEdges, std::vector<OpenDriveEdge> &outerEdges);
311 
312 
315 
316 
317 
319 
320 
331  void myStartElement(int element,
332  const SUMOSAXAttributes& attrs) ;
333 
334 
342  void myCharacters(int element,
343  const std::string& chars) ;
344 
345 
352  void myEndElement(int element) ;
354 
355 
356 
357 private:
358  void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
359  const std::string& contactPoint) ;
360 
361  void addGeometryShape(GeometryType type, const std::vector<SUMOReal> &vals) ;
362 
364 
365  std::vector<OpenDriveEdge> &myInnerEdges;
366  std::vector<OpenDriveEdge> &myOuterEdges;
367  std::vector<int> myElementStack;
369 
370 
371 protected:
385  static NBNode* getOrBuildNode(const std::string& id, Position& pos, NBNodeCont& nc) ;
386 
387 
388  static std::vector<Position> geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g) ;
389  static std::vector<Position> geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g) ;
390  static std::vector<Position> geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g) ;
391  static Position calculateStraightEndPoint(double hdg, double length, const Position& start) ;
392  static void calculateCurveCenter(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_radius, SUMOReal ad_hdg) ;
393  static void calcPointOnCurve(SUMOReal* ad_x, SUMOReal* ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY,
394  SUMOReal ad_r, SUMOReal ad_length) ;
395  static NBEdge* getOutgoingDirectionalEdge(const NBEdgeCont& ec, const NBNodeCont& nc,
396  const std::string& edgeID, const std::string& nodeID) ;
397  static NBEdge* getIncomingDirectionalEdge(const NBEdgeCont& ec, const NBNodeCont& nc,
398  const std::string& edgeID, const std::string& nodeID) ;
399 
400  static void computeShapes(std::vector<OpenDriveEdge> &edges) ;
401  static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
402  const std::string& nodeID, NIImporter_OpenDrive::LinkType lt) ;
403 
404  static void addE2EConnectionsSecure(const NBEdgeCont& ec, const NBNode* const node,
405  const OpenDriveEdge& from, const OpenDriveEdge& to,
406  std::vector<NIImporter_OpenDrive::Connection> &connections);
407  static void addViaConnectionSecure(const NBEdgeCont& ec, const NBNode* const node, const OpenDriveEdge& e,
408  LinkType lt, const std::string& via,
409  std::vector<NIImporter_OpenDrive::Connection> &connections);
410 
412  const OpenDriveEdge& from, bool fromAtBegin, OpenDriveXMLTag fromLaneDir,
413  const OpenDriveEdge& to, bool toAtEnd, OpenDriveXMLTag toLaneDir);
414 
416  const OpenDriveEdge& from, bool fromAtBegin, OpenDriveXMLTag fromLaneDir,
417  const OpenDriveEdge& via, bool viaIsReversed, OpenDriveXMLTag viaLaneDir,
418  const OpenDriveEdge& to, bool fromAtEnd, OpenDriveXMLTag toLaneDir);
419 
420 
422  public:
423  explicit edge_by_id_finder(const std::string& id)
424  : myEdgeID(id) { }
425 
426  bool operator()(const OpenDriveEdge& e) {
427  return e.id == myEdgeID;
428  }
429 
430  private:
431  const std::string& myEdgeID;
432 
433  };
434 
435 
436 
439 
442 
443 
444 
445 };
446 
447 
448 #endif
449 
450 /****************************************************************************/
451