00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NBNode_h
00020 #define NBNode_h
00021
00022
00023
00024
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/common/VectorHelper.h>
00039 #include <utils/geom/Position2D.h>
00040 #include <utils/geom/Line2D.h>
00041 #include <utils/geom/Position2DVector.h>
00042 #include "NBEdge.h"
00043 #include "NBJunctionLogicCont.h"
00044 #include "NBConnection.h"
00045 #include "NBConnectionDefs.h"
00046 #include "NBContHelper.h"
00047 #include "NBMMLDirections.h"
00048 #include <utils/geom/Bresenham.h>
00049
00050
00051
00052
00053
00054 class NBRequest;
00055 class NBDistrict;
00056 class OptionsCont;
00057 class NBTrafficLightDefinition;
00058 class NBTypeCont;
00059 class NBTrafficLightLogicCont;
00060 class NBDistrictCont;
00061 class OutputDevice;
00062
00063
00064
00065
00066
00071 class NBNode {
00072 public:
00084 class ApproachingDivider : public Bresenham::BresenhamCallBack {
00085 private:
00087 std::vector<NBEdge*> *myApproaching;
00088
00090 NBEdge *myCurrentOutgoing;
00091
00092 public:
00097 ApproachingDivider(std::vector<NBEdge*> *approaching,
00098 NBEdge *currentOutgoing) throw();
00099
00101 ~ApproachingDivider() throw();
00102
00104 void execute(SUMOReal src, SUMOReal dest) throw();
00105
00108 std::deque<int> *spread(const std::vector<int> &approachingLanes,
00109 SUMOReal dest) const;
00110
00111 };
00112
00113
00117 enum BasicNodeType {
00119 NODETYPE_UNKNOWN,
00121 NODETYPE_TRAFFIC_LIGHT,
00123 NODETYPE_PRIORITY_JUNCTION,
00125 NODETYPE_RIGHT_BEFORE_LEFT,
00127 NODETYPE_DISTRICT,
00129 NODETYPE_NOJUNCTION,
00131 NODETYPE_DEAD_END
00132 };
00133
00134
00135 public:
00140 NBNode(const std::string &id, const Position2D &position) throw();
00141
00142
00148 NBNode(const std::string &id, const Position2D &position, BasicNodeType type) throw();
00149
00150
00156 NBNode(const std::string &id, const Position2D &position, NBDistrict *district) throw();
00157
00158
00160 ~NBNode() throw();
00161
00162
00167 void reinit(const Position2D &position, BasicNodeType type) throw();
00168
00169
00172
00176 const std::string &getID() const throw() {
00177 return myID;
00178 }
00179
00180
00184 const Position2D &getPosition() const throw() {
00185 return myPosition;
00186 }
00187
00188
00192 const EdgeVector &getIncomingEdges() const throw() {
00193 return *myIncomingEdges;
00194 }
00195
00196
00200 const EdgeVector &getOutgoingEdges() const throw() {
00201 return *myOutgoingEdges;
00202 }
00203
00204
00208 const EdgeVector &getEdges() const throw() {
00209 return myAllEdges;
00210 }
00211
00212
00217 BasicNodeType getType() const throw() {
00218 return myType;
00219 }
00221
00222
00223
00226
00230 void addTrafficLight(NBTrafficLightDefinition *tld) throw();
00231
00232
00235 void removeTrafficLights() throw();
00236
00237
00241 bool isTLControlled() const throw() {
00242 return myTrafficLights.size()!=0;
00243 }
00244
00245
00249 bool isJoinedTLSControlled() const throw();
00250
00251
00255 const std::set<NBTrafficLightDefinition*> &getControllingTLS() const throw() {
00256 return myTrafficLights;
00257 }
00259
00260
00261
00263 void addIncomingEdge(NBEdge *edge);
00264
00266 void addOutgoingEdge(NBEdge *edge);
00267
00268 void writeXMLInternalLinks(OutputDevice &into);
00269 void writeXMLInternalSuccInfos(OutputDevice &into);
00270 void writeXMLInternalNodes(OutputDevice &into);
00271
00272
00273
00275 void writeXML(OutputDevice &into);
00276
00278 void computeLanes2Lanes();
00279
00281 void computeLogic(const NBEdgeCont &ec, NBJunctionLogicCont &jc,
00282 OptionsCont &oc);
00283
00285 void sortNodesEdges(bool leftHand, const NBTypeCont &tc);
00286
00289 Position2D getEmptyDir() const;
00290
00291
00296 bool hasIncoming(const NBEdge * const e) const throw();
00297
00298
00303 bool hasOutgoing(const NBEdge * const e) const throw();
00304
00305
00306 NBEdge *getOppositeIncoming(NBEdge *e) const;
00307 void invalidateIncomingConnections();
00308 void invalidateOutgoingConnections();
00309
00310 void removeDoubleEdges();
00311 NBEdge *getConnectionTo(NBNode *n) const;
00312
00313
00314 void addSortedLinkFoes(const NBConnection &mayDrive,
00315 const NBConnection &mustStop);
00316
00317 NBEdge *getPossiblySplittedIncoming(const std::string &edgeid);
00318 NBEdge *getPossiblySplittedOutgoing(const std::string &edgeid);
00319
00320 unsigned int eraseDummies(NBDistrictCont &dc, NBEdgeCont &ec,
00321 NBTrafficLightLogicCont &tc);
00322
00323 void removeOutgoing(NBEdge *edge);
00324 void removeIncoming(NBEdge *edge);
00325
00335 bool isLeftMover(const NBEdge * const from, const NBEdge * const to) const throw();
00336
00337
00344 bool mustBrake(const NBEdge * const from, const NBEdge * const to, int toLane) const throw();
00345
00346
00355 bool forbids(const NBEdge * const possProhibitorFrom, const NBEdge * const possProhibitorTo,
00356 const NBEdge * const possProhibitedFrom, const NBEdge * const possProhibitedTo,
00357 bool regardNonSignalisedLowerPriority) const throw();
00358
00359
00367 bool foes(const NBEdge * const from1, const NBEdge * const to1,
00368 const NBEdge * const from2, const NBEdge * const to2) const throw();
00369
00370
00376 NBMMLDirection getMMLDirection(const NBEdge * const incoming, const NBEdge * const outgoing) const throw();
00377
00378 char stateCode(NBEdge *incoming, NBEdge *outgoing, int fromLane, bool mayDefinitelyPass) const throw();
00379
00380 void computeNodeShape(bool leftHand);
00381
00382 friend class NBNodeCont;
00383
00384
00385 const Position2DVector &getShape() const;
00386
00387 unsigned int countInternalLanes(bool includeSplits);
00388
00389 std::string getInternalLaneID(NBEdge *from, unsigned int fromlane,
00390 NBEdge *to, unsigned int tolane) const;
00391
00392
00393 bool checkIsRemovable() const;
00394
00395
00396 std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const;
00397
00398 SUMOReal getMaxEdgeWidth() const;
00399
00400 friend class NBNodeShapeComputer;
00401
00402 bool isNearDistrict() const;
00403 bool isDistrict() const;
00404
00405
00406 std::pair<SUMOReal, std::vector<unsigned int> > getCrossingPosition(NBEdge *fromE, unsigned int fromL,
00407 NBEdge *toE, unsigned int toL);
00408 std::string getCrossingNames_dividedBySpace(NBEdge *fromE, unsigned int fromL,
00409 NBEdge *toE, unsigned int toL);
00410 std::string getCrossingSourcesNames_dividedBySpace(NBEdge *fromE, unsigned int fromL,
00411 NBEdge *toE, unsigned int toL);
00412
00415 void replaceIncoming(NBEdge *which, NBEdge *by, unsigned int laneOff);
00416
00419 void replaceIncoming(const EdgeVector &which, NBEdge *by);
00420
00423 void replaceOutgoing(NBEdge *which, NBEdge *by, unsigned int laneOff);
00424
00427 void replaceOutgoing(const EdgeVector &which, NBEdge *by);
00428
00429
00434 class nodes_by_id_sorter {
00435 public:
00437 explicit nodes_by_id_sorter() { }
00438
00441 int operator()(NBNode *n1, NBNode *n2) const {
00442 return n1->getID()<n2->getID();
00443 }
00444
00445 };
00446
00447 private:
00449 void buildBitfieldLogic();
00450
00453 void sortSmall();
00454
00455
00456 BasicNodeType computeType(const NBTypeCont &tc) const;
00457 bool isSimpleContinuation() const;
00458
00460 void setPriorities();
00461
00463 void setPriorityJunctionPriorities();
00464
00468 bool swapWhenReversed(bool leftHand,
00469 const std::vector<NBEdge*>::iterator &i1,
00470 const std::vector<NBEdge*>::iterator &i2);
00471
00474 NBEdge* extractAndMarkFirst(std::vector<NBEdge*> &s);
00475
00478 std::vector<NBEdge*> *getEdgesThatApproach(NBEdge *currentOutgoing);
00479
00481 void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
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 Position2DVector computeInternalLaneShape(NBEdge *fromE,
00493 int fromL, NBEdge *toE, int toL);
00494
00495 void writeinternal(EdgeVector *myIncomingEdges, OutputDevice &into, const std::string &id);
00496
00497 private:
00499 std::string myID;
00500
00502 Position2D myPosition;
00503
00505 std::vector<NBEdge*> *myIncomingEdges;
00506
00508 std::vector<NBEdge*> *myOutgoingEdges;
00509
00511 std::vector<NBEdge*> myAllEdges;
00512
00514 BasicNodeType myType;
00515
00517 NBConnectionProhibits myBlockedConnections;
00518
00520 NBDistrict *myDistrict;
00521
00523 Position2DVector myPoly;
00524
00525 NBRequest *myRequest;
00526
00527 std::set<NBTrafficLightDefinition*> myTrafficLights;
00528
00529 private:
00531 NBNode(const NBNode &s);
00532
00534 NBNode &operator=(const NBNode &s);
00535
00536
00537 };
00538
00539
00540 #endif
00541
00542
00543