|
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 00078 public: 00090 class ApproachingDivider : public Bresenham::BresenhamCallBack { 00091 private: 00093 EdgeVector* myApproaching; 00094 00096 NBEdge* myCurrentOutgoing; 00097 00098 public: 00103 ApproachingDivider(EdgeVector* approaching, 00104 NBEdge* currentOutgoing) ; 00105 00107 ~ApproachingDivider() ; 00108 00110 void execute(const unsigned int src, const unsigned int dest) ; 00111 00114 std::deque<int> *spread(const std::vector<int> &approachingLanes, int dest) const; 00115 00116 }; 00117 00118 public: 00123 NBNode(const std::string& id, const Position& position) ; 00124 00125 00131 NBNode(const std::string& id, const Position& position, SumoXMLNodeType type) ; 00132 00133 00139 NBNode(const std::string& id, const Position& position, NBDistrict* district) ; 00140 00141 00143 ~NBNode() ; 00144 00145 00152 void reinit(const Position& position, SumoXMLNodeType type, 00153 bool updateEdgeGeometries = false); 00154 00155 00158 00162 const Position& getPosition() const { 00163 return myPosition; 00164 } 00165 00166 00170 const EdgeVector& getIncomingEdges() const { 00171 return myIncomingEdges; 00172 } 00173 00174 00178 const EdgeVector& getOutgoingEdges() const { 00179 return myOutgoingEdges; 00180 } 00181 00182 00186 const EdgeVector& getEdges() const { 00187 return myAllEdges; 00188 } 00189 00190 00195 SumoXMLNodeType getType() const { 00196 return myType; 00197 } 00199 00200 00201 00204 00208 void addTrafficLight(NBTrafficLightDefinition* tlDef) ; 00209 00211 void removeTrafficLight(NBTrafficLightDefinition* tlDef) ; 00212 00215 void removeTrafficLights() ; 00216 00217 00221 bool isTLControlled() const { 00222 return myTrafficLights.size() != 0; 00223 } 00224 00225 00229 bool isJoinedTLSControlled() const ; 00230 00231 00235 const std::set<NBTrafficLightDefinition*> &getControllingTLS() const { 00236 return myTrafficLights; 00237 } 00239 00240 00241 00244 00254 unsigned int removeSelfLoops(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc); 00256 00257 00258 00261 00266 void reshiftPosition(SUMOReal xoff, SUMOReal yoff); 00268 00269 00270 00272 void addIncomingEdge(NBEdge* edge); 00273 00275 void addOutgoingEdge(NBEdge* edge); 00276 00277 00278 00279 00281 void computeLanes2Lanes(); 00282 00284 void computeLogic(const NBEdgeCont& ec, OptionsCont& oc); 00285 00288 bool writeLogic(OutputDevice& into) const; 00289 00291 void sortNodesEdges(bool leftHand); 00292 00294 void computeType(const NBTypeCont& tc); 00295 00298 void computePriorities(); 00299 00302 Position getEmptyDir() const; 00303 00304 00309 bool hasIncoming(const NBEdge* const e) const ; 00310 00311 00316 bool hasOutgoing(const NBEdge* const e) const ; 00317 00318 00319 NBEdge* getOppositeIncoming(NBEdge* e) const; 00320 void invalidateIncomingConnections(); 00321 void invalidateOutgoingConnections(); 00322 00323 void removeDoubleEdges(); 00324 NBEdge* getConnectionTo(NBNode* n) const; 00325 00326 00327 void addSortedLinkFoes(const NBConnection& mayDrive, 00328 const NBConnection& mustStop); 00329 00330 NBEdge* getPossiblySplittedIncoming(const std::string& edgeid); 00331 NBEdge* getPossiblySplittedOutgoing(const std::string& edgeid); 00332 00335 void removeEdge(NBEdge* edge, bool removeFromConnections = true); 00336 00346 bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const ; 00347 00348 00355 bool mustBrake(const NBEdge* const from, const NBEdge* const to, int toLane) const ; 00356 00357 00366 bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00367 const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00368 bool regardNonSignalisedLowerPriority) const ; 00369 00370 00378 bool foes(const NBEdge* const from1, const NBEdge* const to1, 00379 const NBEdge* const from2, const NBEdge* const to2) const ; 00380 00381 00387 LinkDirection getDirection(const NBEdge* const incoming, const NBEdge* const outgoing) const ; 00388 00389 std::string stateCode(const NBEdge* incoming, NBEdge* outgoing, int fromLane, bool mayDefinitelyPass) const ; 00390 00391 void computeNodeShape(bool leftHand); 00392 00393 00394 const PositionVector& getShape() const; 00395 00396 bool checkIsRemovable() const; 00397 00398 00399 std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const; 00400 00401 SUMOReal getMaxEdgeWidth() const; 00402 00403 friend class NBNodeShapeComputer; 00404 00405 bool isNearDistrict() const; 00406 bool isDistrict() const; 00407 00408 bool needsCont(NBEdge* fromE, NBEdge* toE, NBEdge* otherFromE, NBEdge* otherToE, const NBEdge::Connection& c) const; 00409 00418 PositionVector computeInternalLaneShape( 00419 NBEdge* fromE, int fromL, NBEdge* toE, int toL, int numPoints = 5) const; 00420 00421 00424 void replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff); 00425 00428 void replaceIncoming(const EdgeVector& which, NBEdge* by); 00429 00432 void replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff); 00433 00436 void replaceOutgoing(const EdgeVector& which, NBEdge* by); 00437 00438 void buildInnerEdges(); 00439 00440 const NBConnectionProhibits& getProhibitions() { 00441 return myBlockedConnections; 00442 } 00443 00448 class nodes_by_id_sorter { 00449 public: 00451 explicit nodes_by_id_sorter() { } 00452 00455 int operator()(NBNode* n1, NBNode* n2) const { 00456 return n1->getID() < n2->getID(); 00457 } 00458 00459 }; 00460 00461 private: 00462 bool isSimpleContinuation() const; 00463 00465 void setPriorityJunctionPriorities(); 00466 00470 bool swapWhenReversed(bool leftHand, 00471 const EdgeVector::iterator& i1, 00472 const EdgeVector::iterator& i2); 00473 00476 NBEdge* extractAndMarkFirst(EdgeVector& s); 00477 00480 EdgeVector* getEdgesThatApproach(NBEdge* currentOutgoing); 00481 00482 00483 00484 00485 void replaceInConnectionProhibitions(NBEdge* which, NBEdge* by, 00486 unsigned int whichLaneOff, unsigned int byLaneOff); 00487 00488 00489 void remapRemoved(NBTrafficLightLogicCont& tc, 00490 NBEdge* removed, const EdgeVector& incoming, const EdgeVector& outgoing); 00491 00492 00493 private: 00495 Position myPosition; 00496 00498 EdgeVector myIncomingEdges; 00499 00501 EdgeVector myOutgoingEdges; 00502 00504 EdgeVector myAllEdges; 00505 00507 SumoXMLNodeType myType; 00508 00510 NBConnectionProhibits myBlockedConnections; 00511 00513 NBDistrict* myDistrict; 00514 00516 PositionVector myPoly; 00517 00518 NBRequest* myRequest; 00519 00520 std::set<NBTrafficLightDefinition*> myTrafficLights; 00521 00522 private: 00524 NBNode(const NBNode& s); 00525 00527 NBNode& operator=(const NBNode& s); 00528 00529 00530 }; 00531 00532 00533 #endif 00534 00535 /****************************************************************************/ 00536