SUMO - Simulation of Urban MObility
NIImporter_SUMO.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Importer for networks stored in SUMO format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 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_SUMO_h
23 #define NIImporter_SUMO_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>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class NBNetBuilder;
46 class NBEdge;
47 class OptionsCont;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
59 public:
75  static void loadNetwork(OptionsCont& oc, NBNetBuilder& nb);
76 
79 
81  static void addPhase(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
82 
84  static GeoConvHelper* loadLocation(const SUMOSAXAttributes& attrs);
85 
91  static void interpretLaneID(const std::string& lane_id, std::string& edge_id, int& index);
92 
93 protected:
98 
99 
102 
103 
104 
106 
107 
118  void myStartElement(int element,
119  const SUMOSAXAttributes& attrs);
120 
121 
128  void myEndElement(int element);
130 
131 
132 private:
134  void _loadNetwork(OptionsCont& oc);
135 
137 
138 
142  void addEdge(const SUMOSAXAttributes& attrs);
143 
144 
148  void addLane(const SUMOSAXAttributes& attrs);
149 
150 
154  void addJunction(const SUMOSAXAttributes& attrs);
155 
156 
160  void addRequest(const SUMOSAXAttributes& attrs);
161 
162 
167  void addConnection(const SUMOSAXAttributes& attrs);
168 
172  void addProhibition(const SUMOSAXAttributes& attrs);
173 
177  void addRoundabout(const SUMOSAXAttributes& attrs);
178 
180 
181 
182 
183 private:
188  struct Connection {
190  std::string toEdgeID;
194  std::string tlID;
196  int tlLinkNo;
200  bool keepClear;
202  double contPos;
204  double visibility;
205  };
206 
207 
211  struct LaneAttrs {
213  double maxSpeed;
217  std::vector<Connection> connections;
219  std::string allow;
221  std::string disallow;
223  double width;
225  double endOffset;
227  bool accelRamp;
229  std::string oppositeID;
232  };
233 
234 
238  struct EdgeAttrs {
240  std::string id;
242  std::string streetName;
244  std::string type;
248  std::string fromNode;
250  std::string toNode;
254  double length;
256  int priority;
258  double maxSpeed;
260  std::vector<LaneAttrs*> lanes;
265  };
266 
267 
271  struct Prohibition {
272  std::string prohibitorFrom;
273  std::string prohibitorTo;
274  std::string prohibitedFrom;
275  std::string prohibitedTo;
276  };
277 
281  struct Crossing {
282  std::string edgeID;
283  std::vector<std::string> crossingEdges;
284  double width;
285  bool priority;
286  };
287 
291  struct JunctionAttrs {
293  // @the list of internal lanes corresponding to each link
294  std::vector<std::string> intLanes;
295  // @brief the complete response definition for all links
296  std::vector<std::string> response;
297  };
298 
300  std::map<std::string, EdgeAttrs*> myEdges;
301 
303  std::vector<Prohibition> myProhibitions;
304 
307 
310 
313 
316 
319 
322 
325 
328 
330  std::map<std::string, std::vector<Crossing> > myPedestrianCrossings;
331 
334 
337 
340 
343 
346 
349 
351  std::vector<std::vector<std::string> > myRoundabouts;
352 
354  std::map<std::string, NBNode::CustomShapeMap> myCustomShapeMaps;
355 
357  std::set<std::string> myRailSignals;
358 
363  LaneAttrs* getLaneAttrsFromID(EdgeAttrs* edge, std::string lane_id);
364 
370  static PositionVector reconstructEdgeShape(const EdgeAttrs* edge, const Position& from, const Position& to);
371 
373  static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
374 
381  void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
382 };
383 
384 
385 #endif
386 
387 /****************************************************************************/
388 
std::map< std::string, EdgeAttrs * > myEdges
Loaded edge definitions.
LaneAttrs * myCurrentLane
The currently parsed lanes&#39;s definition (to add the shape to)
PositionVector shape
This edges&#39;s shape.
std::vector< Prohibition > myProhibitions
Loaded prohibitions.
static void addPhase(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
adds a phase to the traffic lights logic currently build
bool accelRamp
Whether this lane is an acceleration lane.
NBNodeCont & myNodeCont
The node container to fill.
void addEdge(const SUMOSAXAttributes &attrs)
Parses an edge and stores the values in "myCurrentEdge".
void addRoundabout(const SUMOSAXAttributes &attrs)
Parses a roundabout and stores it in myEdgeCont.
A loaded (complete) traffic light logic.
std::vector< LaneAttrs * > lanes
This edge&#39;s lanes.
A container for traffic light definitions and built programs.
Describes a pedestrian crossing.
double maxSpeed
The maximum velocity allowed on this lane.
The representation of a single edge during network building.
Definition: NBEdge.h:71
A connection description.
std::vector< std::string > response
double width
The width of this lane.
bool myAmLefthand
whether the loaded network was built for lefthand traffic
static NBLoadedSUMOTLDef * initTrafficLightLogic(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
begins the reading of a traffic lights logic
SAX-handler base for SUMO-files.
NIImporter_SUMO(NBNetBuilder &nb)
Constructor.
std::map< std::string, NBNode::CustomShapeMap > myCustomShapeMaps
customLaneShape (cannot be added to the NBNode when parsed since the node doesn&#39;t yet exist ...
Describes the values found in a lane&#39;s definition.
LaneAttrs * getLaneAttrsFromID(EdgeAttrs *edge, std::string lane_id)
Parses lane index from lane ID an retrieve lane from EdgeAttrs.
std::string toEdgeID
The id of the target edge.
bool myHaveSeenInternalEdge
whether the loaded network contains internal lanes
int tlLinkNo
The index of this connection within the controlling traffic light.
double maxSpeed
The maximum velocity allowed on this edge (!!!)
void addLane(const SUMOSAXAttributes &attrs)
Parses a lane and stores the values in "myCurrentLane".
NBNetBuilder & myNetBuilder
The network builder to fill.
std::vector< std::vector< std::string > > myRoundabouts
loaded roundabout edges
void addConnection(const SUMOSAXAttributes &attrs)
Parses a connection and saves it into the lane&#39;s definition stored in "myCurrentLane".
std::string toNode
The node this edge ends at.
Describes the values found in an edge&#39;s definition and this edge&#39;s lanes.
int myLinkDetail
the level of geometry detail for internal lanes in the loaded network
JunctionAttrs myCurrentJunction
The currently parsed junction definition to help in reconstructing crossings.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:60
std::vector< std::string > crossingEdges
std::string allow
This lane&#39;s allowed vehicle classes.
Describes the values found in a junction.
Encapsulated SAX-Attributes.
static GeoConvHelper * loadLocation(const SUMOSAXAttributes &attrs)
Parses network location description and registers it with GeoConveHelper::setLoaded.
Describes the values found in a prohibition.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
Importer for networks stored in SUMO format.
std::string tlID
The id of the traffic light that controls this connection.
EdgeAttrs * myCurrentEdge
The currently parsed edge&#39;s definition (to add loaded lanes to)
A list of positions.
void parseProhibitionConnection(const std::string &attr, std::string &from, std::string &to, bool &ok)
parses connection string of a prohibition (very old school)
bool myRectLaneCut
whether all lanes of an edge should have the same stop line
double visibility
custom foe visibility for connection
LaneSpreadFunction lsf
The lane spread function.
bool customShape
Whether this lane has a custom shape.
double length
The length of the edge if set explicitly.
std::string disallow
This lane&#39;s disallowed vehicle classes.
NBEdge * builtEdge
The built edge.
static PositionVector reconstructEdgeShape(const EdgeAttrs *edge, const Position &from, const Position &to)
reconstructs the edge shape from the node positions and the given lane shapes since we do not know th...
SumoXMLEdgeFunc func
This edge&#39;s function.
std::string oppositeID
This lane&#39;s opposite lane.
void _loadNetwork(OptionsCont &oc)
load the network
bool keepClear
Whether the junction must be kept clear coming from this connection.
std::vector< std::string > intLanes
double endOffset
This lane&#39;s offset from the intersection.
std::string streetName
This edge&#39;s street name.
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
std::vector< Connection > connections
This lane&#39;s connections.
void addJunction(const SUMOSAXAttributes &attrs)
Parses a junction and saves it in the node control.
std::string type
This edge&#39;s type.
static void interpretLaneID(const std::string &lane_id, std::string &edge_id, int &index)
parses edge-id and index from lane-id
double contPos
custom position for internal junction on this connection
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
int myCornerDetail
the level of corner detail in the loaded network
static Position readPosition(const SUMOSAXAttributes &attrs, const std::string &id, bool &ok)
read position from the given attributes, attribute errors to id
std::map< std::string, std::vector< Crossing > > myPedestrianCrossings
The pedestrian crossings found in the network.
A storage for options typed value containers)
Definition: OptionsCont.h:99
int priority
This edge&#39;s priority.
std::string id
This edge&#39;s id.
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
void myEndElement(int element)
Called when a closing tag occurs.
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge&#39;s lateral offset shal...
std::string fromNode
The node this edge starts at.
Represents a single node (junction) during network building.
Definition: NBNode.h:75
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
~NIImporter_SUMO()
Destructor.
void addRequest(const SUMOSAXAttributes &attrs)
Parses a reques and saves selected attributes in myCurrentJunction.
GeoConvHelper * myLocation
The coordinate transformation which was used to build the loaded network.
PositionVector shape
This lane&#39;s shape (needed to reconstruct edge shape for legacy networks)
NBTrafficLightLogicCont & myTLLCont
The node container to fill.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
void addProhibition(const SUMOSAXAttributes &attrs)
Parses a prohibition and saves it.
NBLoadedSUMOTLDef * myCurrentTL
The currently parsed traffic light.
bool myWalkingAreas
whether walkingareas must be built
std::set< std::string > myRailSignals
list of node id with rail signals (no NBTrafficLightDefinition exists)
int toLaneIdx
The index of the target lane.