SUMO - Simulation of Urban MObility

NBNode.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The representation of a single node
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef NBNode_h
00020 #define NBNode_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <vector>
00033 #include <deque>
00034 #include <utility>
00035 #include <string>
00036 #include <set>
00037 #include <utils/common/Named.h>
00038 #include <utils/geom/Bresenham.h>
00039 #include <utils/common/VectorHelper.h>
00040 #include <utils/geom/Position.h>
00041 #include <utils/geom/Line.h>
00042 #include <utils/geom/PositionVector.h>
00043 #include <utils/xml/SUMOXMLDefinitions.h>
00044 #include "NBEdge.h"
00045 #include "NBConnection.h"
00046 #include "NBConnectionDefs.h"
00047 #include "NBContHelper.h"
00048 
00049 
00050 // ===========================================================================
00051 // class declarations
00052 // ===========================================================================
00053 class NBRequest;
00054 class NBDistrict;
00055 class OptionsCont;
00056 class NBTrafficLightDefinition;
00057 class NBTypeCont;
00058 class NBTrafficLightLogicCont;
00059 class NBDistrictCont;
00060 class OutputDevice;
00061 
00062 
00063 // ===========================================================================
00064 // class definitions
00065 // ===========================================================================
00070 class NBNode : public Named {
00071     friend class NBNodeCont;
00072     friend class GNEJunction; // used for visualization (NETEDIT)
00073 
00074 public:
00086     class ApproachingDivider : public Bresenham::BresenhamCallBack {
00087     private:
00089         EdgeVector* myApproaching;
00090 
00092         NBEdge* myCurrentOutgoing;
00093 
00094     public:
00099         ApproachingDivider(EdgeVector* approaching,
00100                            NBEdge* currentOutgoing) throw();
00101 
00103         ~ApproachingDivider() throw();
00104 
00106         void execute(const unsigned int src, const unsigned int dest) throw();
00107 
00110         std::deque<int> *spread(const std::vector<int> &approachingLanes, int dest) const;
00111 
00112     };
00113 
00114 public:
00119     NBNode(const std::string& id, const Position& position) throw();
00120 
00121 
00127     NBNode(const std::string& id, const Position& position, SumoXMLNodeType type) throw();
00128 
00129 
00135     NBNode(const std::string& id, const Position& position, NBDistrict* district) throw();
00136 
00137 
00139     ~NBNode() throw();
00140 
00141 
00148     void reinit(const Position& position, SumoXMLNodeType type,
00149                 bool updateEdgeGeometries=false);
00150 
00151 
00154 
00158     const Position& getPosition() const throw() {
00159         return myPosition;
00160     }
00161 
00162 
00166     const EdgeVector& getIncomingEdges() const throw() {
00167         return myIncomingEdges;
00168     }
00169 
00170 
00174     const EdgeVector& getOutgoingEdges() const throw() {
00175         return myOutgoingEdges;
00176     }
00177 
00178 
00182     const EdgeVector& getEdges() const throw() {
00183         return myAllEdges;
00184     }
00185 
00186 
00191     SumoXMLNodeType getType() const throw() {
00192         return myType;
00193     }
00195 
00196 
00197 
00200 
00204     void addTrafficLight(NBTrafficLightDefinition* tlDef) throw();
00205 
00207     void removeTrafficLight(NBTrafficLightDefinition* tlDef) throw();
00208 
00211     void removeTrafficLights() throw();
00212 
00213 
00217     bool isTLControlled() const throw() {
00218         return myTrafficLights.size()!=0;
00219     }
00220 
00221 
00225     bool isJoinedTLSControlled() const throw();
00226 
00227 
00231     const std::set<NBTrafficLightDefinition*> &getControllingTLS() const throw() {
00232         return myTrafficLights;
00233     }
00235 
00236 
00237 
00240 
00250     unsigned int removeDummyEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc);
00252 
00253 
00254 
00257 
00262     void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
00264 
00265 
00266 
00268     void addIncomingEdge(NBEdge* edge);
00269 
00271     void addOutgoingEdge(NBEdge* edge);
00272 
00273 
00274 
00275 
00277     void computeLanes2Lanes();
00278 
00280     void computeLogic(const NBEdgeCont& ec, OptionsCont& oc);
00281 
00284     bool writeLogic(OutputDevice& into) const;
00285 
00287     void sortNodesEdges(bool leftHand);
00288 
00290     void computeType(const NBTypeCont& tc);
00291 
00294     void computePriorities();
00295 
00298     Position getEmptyDir() const;
00299 
00300 
00305     bool hasIncoming(const NBEdge* const e) const throw();
00306 
00307 
00312     bool hasOutgoing(const NBEdge* const e) const throw();
00313 
00314 
00315     NBEdge* getOppositeIncoming(NBEdge* e) const;
00316     void invalidateIncomingConnections();
00317     void invalidateOutgoingConnections();
00318 
00319     void removeDoubleEdges();
00320     NBEdge* getConnectionTo(NBNode* n) const;
00321 
00322 
00323     void addSortedLinkFoes(const NBConnection& mayDrive,
00324                            const NBConnection& mustStop);
00325 
00326     NBEdge* getPossiblySplittedIncoming(const std::string& edgeid);
00327     NBEdge* getPossiblySplittedOutgoing(const std::string& edgeid);
00328 
00331     void removeEdge(NBEdge* edge, bool removeFromConnections=true);
00332 
00342     bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const throw();
00343 
00344 
00351     bool mustBrake(const NBEdge* const from, const NBEdge* const to, int toLane) const throw();
00352 
00353 
00362     bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
00363                  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
00364                  bool regardNonSignalisedLowerPriority) const throw();
00365 
00366 
00374     bool foes(const NBEdge* const from1, const NBEdge* const to1,
00375               const NBEdge* const from2, const NBEdge* const to2) const throw();
00376 
00377 
00383     LinkDirection getDirection(const NBEdge* const incoming, const NBEdge* const outgoing) const throw();
00384 
00385     std::string stateCode(const NBEdge* incoming, NBEdge* outgoing, int fromLane, bool mayDefinitelyPass) const throw();
00386 
00387     void computeNodeShape(bool leftHand);
00388 
00389 
00390     const PositionVector& getShape() const;
00391 
00392     bool checkIsRemovable() const;
00393 
00394 
00395     std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const;
00396 
00397     SUMOReal getMaxEdgeWidth() const;
00398 
00399     friend class NBNodeShapeComputer;
00400 
00401     bool isNearDistrict() const;
00402     bool isDistrict() const;
00403 
00404     bool needsCont(NBEdge* fromE, NBEdge* toE, NBEdge* otherFromE, NBEdge* otherToE, const NBEdge::Connection& c) const;
00405 
00414     PositionVector computeInternalLaneShape(
00415         NBEdge* fromE, int fromL, NBEdge* toE, int toL, int numPoints=5) const;
00416 
00417 
00420     void replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff);
00421 
00424     void replaceIncoming(const EdgeVector& which, NBEdge* by);
00425 
00428     void replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff);
00429 
00432     void replaceOutgoing(const EdgeVector& which, NBEdge* by);
00433 
00434     void buildInnerEdges();
00435 
00436     const NBConnectionProhibits& getProhibitions() {
00437         return myBlockedConnections;
00438     }
00439 
00444     class nodes_by_id_sorter {
00445     public:
00447         explicit nodes_by_id_sorter() { }
00448 
00451         int operator()(NBNode* n1, NBNode* n2) const {
00452             return n1->getID()<n2->getID();
00453         }
00454 
00455     };
00456 
00457 private:
00458     bool isSimpleContinuation() const;
00459 
00461     void setPriorityJunctionPriorities();
00462 
00466     bool swapWhenReversed(bool leftHand,
00467                           const EdgeVector::iterator& i1,
00468                           const EdgeVector::iterator& i2);
00469 
00472     NBEdge* extractAndMarkFirst(EdgeVector& s);
00473 
00476     EdgeVector* getEdgesThatApproach(NBEdge* currentOutgoing);
00477 
00478 
00479 
00480 
00481     void replaceInConnectionProhibitions(NBEdge* which, NBEdge* by,
00482                                          unsigned int whichLaneOff, unsigned int byLaneOff);
00483 
00484 
00485     void remapRemoved(NBTrafficLightLogicCont& tc,
00486                       NBEdge* removed, const EdgeVector& incoming, const EdgeVector& outgoing);
00487 
00488 
00489 private:
00491     Position myPosition;
00492 
00494     EdgeVector myIncomingEdges;
00495 
00497     EdgeVector myOutgoingEdges;
00498 
00500     EdgeVector myAllEdges;
00501 
00503     SumoXMLNodeType myType;
00504 
00506     NBConnectionProhibits myBlockedConnections;
00507 
00509     NBDistrict* myDistrict;
00510 
00512     PositionVector myPoly;
00513 
00514     NBRequest* myRequest;
00515 
00516     std::set<NBTrafficLightDefinition*> myTrafficLights;
00517 
00518 private:
00520     NBNode(const NBNode& s);
00521 
00523     NBNode& operator=(const NBNode& s);
00524 
00525 
00526 };
00527 
00528 
00529 #endif
00530 
00531 /****************************************************************************/
00532 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines