SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // The representation of a single node 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef NBNode_h 00024 #define NBNode_h 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include <vector> 00037 #include <deque> 00038 #include <utility> 00039 #include <string> 00040 #include <set> 00041 #include <utils/common/Named.h> 00042 #include <utils/geom/Bresenham.h> 00043 #include <utils/common/VectorHelper.h> 00044 #include <utils/geom/Position.h> 00045 #include <utils/geom/Line.h> 00046 #include <utils/geom/PositionVector.h> 00047 #include <utils/xml/SUMOXMLDefinitions.h> 00048 #include "NBEdge.h" 00049 #include "NBConnection.h" 00050 #include "NBConnectionDefs.h" 00051 #include "NBContHelper.h" 00052 00053 00054 // =========================================================================== 00055 // class declarations 00056 // =========================================================================== 00057 class NBRequest; 00058 class NBDistrict; 00059 class OptionsCont; 00060 class NBTrafficLightDefinition; 00061 class NBTypeCont; 00062 class NBTrafficLightLogicCont; 00063 class NBDistrictCont; 00064 class OutputDevice; 00065 00066 00067 // =========================================================================== 00068 // class definitions 00069 // =========================================================================== 00074 class NBNode : public Named { 00075 friend class NBNodeCont; 00076 friend class GNEJunction; // < used for visualization (NETEDIT) 00077 friend class NBNodesEdgesSorter; // < sorts the edges 00078 friend class NBNodeTypeComputer; // < computes type 00079 friend class NBEdgePriorityComputer; // < computes priorities of edges per intersection 00080 00081 public: 00093 class ApproachingDivider : public Bresenham::BresenhamCallBack { 00094 private: 00096 EdgeVector* myApproaching; 00097 00099 NBEdge* myCurrentOutgoing; 00100 00101 public: 00106 ApproachingDivider(EdgeVector* approaching, 00107 NBEdge* currentOutgoing) ; 00108 00110 ~ApproachingDivider() ; 00111 00113 void execute(const unsigned int src, const unsigned int dest) ; 00114 00117 std::deque<int> *spread(const std::vector<int> &approachingLanes, int dest) const; 00118 00119 }; 00120 00121 public: 00126 NBNode(const std::string& id, const Position& position) ; 00127 00128 00134 NBNode(const std::string& id, const Position& position, SumoXMLNodeType type) ; 00135 00136 00142 NBNode(const std::string& id, const Position& position, NBDistrict* district) ; 00143 00144 00146 ~NBNode() ; 00147 00148 00155 void reinit(const Position& position, SumoXMLNodeType type, 00156 bool updateEdgeGeometries = false); 00157 00158 00161 00165 const Position& getPosition() const { 00166 return myPosition; 00167 } 00168 00169 00173 const EdgeVector& getIncomingEdges() const { 00174 return myIncomingEdges; 00175 } 00176 00177 00181 const EdgeVector& getOutgoingEdges() const { 00182 return myOutgoingEdges; 00183 } 00184 00185 00189 const EdgeVector& getEdges() const { 00190 return myAllEdges; 00191 } 00192 00193 00198 SumoXMLNodeType getType() const { 00199 return myType; 00200 } 00202 00203 00204 00207 00211 void addTrafficLight(NBTrafficLightDefinition* tlDef) ; 00212 00214 void removeTrafficLight(NBTrafficLightDefinition* tlDef) ; 00215 00218 void removeTrafficLights() ; 00219 00220 00224 bool isTLControlled() const { 00225 return myTrafficLights.size() != 0; 00226 } 00227 00228 00232 bool isJoinedTLSControlled() const ; 00233 00234 00238 const std::set<NBTrafficLightDefinition*> &getControllingTLS() const { 00239 return myTrafficLights; 00240 } 00242 00243 00244 00247 00257 unsigned int removeSelfLoops(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc); 00259 00260 00261 00264 00269 void reshiftPosition(SUMOReal xoff, SUMOReal yoff); 00271 00272 00273 00275 void addIncomingEdge(NBEdge* edge); 00276 00278 void addOutgoingEdge(NBEdge* edge); 00279 00280 00281 00282 00284 void computeLanes2Lanes(); 00285 00287 void computeLogic(const NBEdgeCont& ec, OptionsCont& oc); 00288 00291 bool writeLogic(OutputDevice& into) const; 00292 00295 Position getEmptyDir() const; 00296 00297 00302 bool hasIncoming(const NBEdge* const e) const ; 00303 00304 00309 bool hasOutgoing(const NBEdge* const e) const ; 00310 00311 00312 NBEdge* getOppositeIncoming(NBEdge* e) const; 00313 void invalidateIncomingConnections(); 00314 void invalidateOutgoingConnections(); 00315 00316 void removeDoubleEdges(); 00317 NBEdge* getConnectionTo(NBNode* n) const; 00318 00319 00320 void addSortedLinkFoes(const NBConnection& mayDrive, 00321 const NBConnection& mustStop); 00322 00323 NBEdge* getPossiblySplittedIncoming(const std::string& edgeid); 00324 NBEdge* getPossiblySplittedOutgoing(const std::string& edgeid); 00325 00328 void removeEdge(NBEdge* edge, bool removeFromConnections = true); 00329 00339 bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const ; 00340 00341 00348 bool mustBrake(const NBEdge* const from, const NBEdge* const to, int toLane) const ; 00349 00350 00359 bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00360 const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00361 bool regardNonSignalisedLowerPriority) const ; 00362 00363 00371 bool foes(const NBEdge* const from1, const NBEdge* const to1, 00372 const NBEdge* const from2, const NBEdge* const to2) const ; 00373 00374 00380 LinkDirection getDirection(const NBEdge* const incoming, const NBEdge* const outgoing) const ; 00381 00382 std::string stateCode(const NBEdge* incoming, NBEdge* outgoing, int fromLane, bool mayDefinitelyPass) const ; 00383 00384 void computeNodeShape(bool leftHand); 00385 00386 00387 const PositionVector& getShape() const; 00388 00389 bool checkIsRemovable() const; 00390 00391 00392 std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const; 00393 00394 SUMOReal getMaxEdgeWidth() const; 00395 00396 friend class NBNodeShapeComputer; 00397 00398 bool isNearDistrict() const; 00399 bool isDistrict() const; 00400 00401 bool needsCont(NBEdge* fromE, NBEdge* toE, NBEdge* otherFromE, NBEdge* otherToE, const NBEdge::Connection& c) const; 00402 00411 PositionVector computeInternalLaneShape( 00412 NBEdge* fromE, int fromL, NBEdge* toE, int toL, int numPoints = 5) const; 00413 00414 00417 void replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff); 00418 00421 void replaceIncoming(const EdgeVector& which, NBEdge* by); 00422 00425 void replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff); 00426 00429 void replaceOutgoing(const EdgeVector& which, NBEdge* by); 00430 00431 void buildInnerEdges(); 00432 00433 const NBConnectionProhibits& getProhibitions() { 00434 return myBlockedConnections; 00435 } 00436 00441 class nodes_by_id_sorter { 00442 public: 00444 explicit nodes_by_id_sorter() { } 00445 00448 int operator()(NBNode* n1, NBNode* n2) const { 00449 return n1->getID() < n2->getID(); 00450 } 00451 00452 }; 00453 00454 private: 00455 bool isSimpleContinuation() const; 00456 00458 void setPriorityJunctionPriorities(); 00459 00462 EdgeVector* getEdgesThatApproach(NBEdge* currentOutgoing); 00463 00464 00465 00466 00467 void replaceInConnectionProhibitions(NBEdge* which, NBEdge* by, 00468 unsigned int whichLaneOff, unsigned int byLaneOff); 00469 00470 00471 void remapRemoved(NBTrafficLightLogicCont& tc, 00472 NBEdge* removed, const EdgeVector& incoming, const EdgeVector& outgoing); 00473 00474 00475 private: 00477 Position myPosition; 00478 00480 EdgeVector myIncomingEdges; 00481 00483 EdgeVector myOutgoingEdges; 00484 00486 EdgeVector myAllEdges; 00487 00489 SumoXMLNodeType myType; 00490 00492 NBConnectionProhibits myBlockedConnections; 00493 00495 NBDistrict* myDistrict; 00496 00498 PositionVector myPoly; 00499 00500 NBRequest* myRequest; 00501 00502 std::set<NBTrafficLightDefinition*> myTrafficLights; 00503 00504 private: 00506 NBNode(const NBNode& s); 00507 00509 NBNode& operator=(const NBNode& s); 00510 00511 00512 }; 00513 00514 00515 #endif 00516 00517 /****************************************************************************/ 00518