SUMO - Simulation of Urban MObility
NBNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The representation of a single node
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <cassert>
37 #include <algorithm>
38 #include <vector>
39 #include <deque>
40 #include <set>
41 #include <cmath>
42 #include <iterator>
46 #include <utils/geom/GeomHelper.h>
47 #include <utils/geom/bezier.h>
49 #include <utils/common/StdDefs.h>
50 #include <utils/common/ToString.h>
53 #include <iomanip>
54 #include "NBNode.h"
55 #include "NBAlgorithms.h"
56 #include "NBNodeCont.h"
57 #include "NBNodeShapeComputer.h"
58 #include "NBEdgeCont.h"
59 #include "NBTypeCont.h"
60 #include "NBHelpers.h"
61 #include "NBDistrict.h"
62 #include "NBContHelper.h"
63 #include "NBRequest.h"
64 #include "NBOwnTLDef.h"
67 
68 #ifdef CHECK_MEMORY_LEAKS
69 #include <foreign/nvwa/debug_new.h>
70 #endif // CHECK_MEMORY_LEAKS
71 
72 // allow to extend a crossing across multiple edges
73 #define EXTEND_CROSSING_ANGLE_THRESHOLD 35.0 // degrees
74 // create intermediate walking areas if either of the following thresholds is exceeded
75 #define SPLIT_CROSSING_WIDTH_THRESHOLD 1.5 // meters
76 #define SPLIT_CROSSING_ANGLE_THRESHOLD 5 // degrees
77 
78 // minimum length for a weaving section at a combined on-off ramp
79 #define MIN_WEAVE_LENGTH 20.0
80 
81 #define DEBUGID "C"
82 
83 // ===========================================================================
84 // static members
85 // ===========================================================================
86 const int NBNode::FORWARD(1);
87 const int NBNode::BACKWARD(-1);
90 
91 // ===========================================================================
92 // method definitions
93 // ===========================================================================
94 /* -------------------------------------------------------------------------
95  * NBNode::ApproachingDivider-methods
96  * ----------------------------------------------------------------------- */
98  EdgeVector* approaching, NBEdge* currentOutgoing) :
99  myApproaching(approaching), myCurrentOutgoing(currentOutgoing) {
100  // check whether origin lanes have been given
101  assert(myApproaching != 0);
102  // collect lanes which are expliclity targeted
103  std::set<int> approachedLanes;
104  for (EdgeVector::iterator it = myApproaching->begin(); it != myApproaching->end(); ++it) {
105  const std::vector<NBEdge::Connection> conns = (*it)->getConnections();
106  for (std::vector<NBEdge::Connection>::const_iterator it_con = conns.begin(); it_con != conns.end(); ++it_con) {
107  if ((*it_con).toEdge == myCurrentOutgoing) {
108  approachedLanes.insert((*it_con).toLane);
109  }
110  }
111  }
112  // compute the indices of lanes that should be targeted (excluding pedestrian
113  // lanes that will be connected from walkingAreas and forbidden lanes)
114  // if the lane is targeted by an explicitly set connection we need
115  // to make it available anyway
116  for (int i = 0; i < (int)currentOutgoing->getNumLanes(); ++i) {
117  if ((currentOutgoing->getPermissions(i) == SVC_PEDESTRIAN
118  || isForbidden(currentOutgoing->getPermissions(i)))
119  && approachedLanes.count(i) == 0) {
120  continue;
121  }
122  myAvailableLanes.push_back((unsigned int)i);
123  }
124 }
125 
126 
128 
129 
130 void
131 NBNode::ApproachingDivider::execute(const unsigned int src, const unsigned int dest) {
132  assert(myApproaching->size() > src);
133  // get the origin edge
134  NBEdge* incomingEdge = (*myApproaching)[src];
135  if (incomingEdge->getStep() == NBEdge::LANES2LANES_DONE || incomingEdge->getStep() == NBEdge::LANES2LANES_USER) {
136  return;
137  }
138  std::vector<int> approachingLanes =
139  incomingEdge->getConnectionLanes(myCurrentOutgoing);
140  assert(approachingLanes.size() != 0);
141  std::deque<int>* approachedLanes = spread(approachingLanes, dest);
142  assert(approachedLanes->size() <= myAvailableLanes.size());
143  // set lanes
144  for (unsigned int i = 0; i < approachedLanes->size(); i++) {
145  assert(approachedLanes->size() > i);
146  assert(approachingLanes.size() > i);
147  unsigned int approached = myAvailableLanes[(*approachedLanes)[i]];
148  incomingEdge->setConnection((unsigned int) approachingLanes[i], myCurrentOutgoing,
149  approached, NBEdge::L2L_COMPUTED);
150  }
151  delete approachedLanes;
152 }
153 
154 
155 std::deque<int>*
156 NBNode::ApproachingDivider::spread(const std::vector<int>& approachingLanes,
157  int dest) const {
158  std::deque<int>* ret = new std::deque<int>();
159  unsigned int noLanes = (unsigned int) approachingLanes.size();
160  // when only one lane is approached, we check, whether the SUMOReal-value
161  // is assigned more to the left or right lane
162  if (noLanes == 1) {
163  ret->push_back(dest);
164  return ret;
165  }
166 
167  unsigned int noOutgoingLanes = (unsigned int)myAvailableLanes.size();
168  //
169  ret->push_back(dest);
170  unsigned int noSet = 1;
171  int roffset = 1;
172  int loffset = 1;
173  while (noSet < noLanes) {
174  // It may be possible, that there are not enough lanes the source
175  // lanes may be divided on
176  // In this case, they remain unset
177  // !!! this is only a hack. It is possible, that this yields in
178  // uncommon divisions
179  if (noOutgoingLanes == noSet) {
180  return ret;
181  }
182 
183  // as due to the conversion of SUMOReal->uint the numbers will be lower
184  // than they should be, we try to append to the left side first
185  //
186  // check whether the left boundary of the approached street has
187  // been overridden; if so, move all lanes to the right
188  if (dest + loffset >= static_cast<int>(noOutgoingLanes)) {
189  loffset -= 1;
190  roffset += 1;
191  for (unsigned int i = 0; i < ret->size(); i++) {
192  (*ret)[i] = (*ret)[i] - 1;
193  }
194  }
195  // append the next lane to the left of all edges
196  // increase the position (destination edge)
197  ret->push_back(dest + loffset);
198  noSet++;
199  loffset += 1;
200 
201  // as above
202  if (noOutgoingLanes == noSet) {
203  return ret;
204  }
205 
206  // now we try to append the next lane to the right side, when needed
207  if (noSet < noLanes) {
208  // check whether the right boundary of the approached street has
209  // been overridden; if so, move all lanes to the right
210  if (dest < roffset) {
211  loffset += 1;
212  roffset -= 1;
213  for (unsigned int i = 0; i < ret->size(); i++) {
214  (*ret)[i] = (*ret)[i] + 1;
215  }
216  }
217  ret->push_front(dest - roffset);
218  noSet++;
219  roffset += 1;
220  }
221  }
222  return ret;
223 }
224 
225 
226 /* -------------------------------------------------------------------------
227  * NBNode-methods
228  * ----------------------------------------------------------------------- */
229 NBNode::NBNode(const std::string& id, const Position& position,
230  SumoXMLNodeType type) :
231  Named(StringUtils::convertUmlaute(id)),
232  myPosition(position),
233  myType(type),
234  myDistrict(0),
235  myHaveCustomPoly(false),
236  myRequest(0),
237  myRadius(OptionsCont::getOptions().isDefault("default.junctions.radius") ? UNSPECIFIED_RADIUS : OptionsCont::getOptions().getFloat("default.junctions.radius")),
238  myKeepClear(OptionsCont::getOptions().getBool("default.junctions.keep-clear")),
239  myDiscardAllCrossings(false),
241 { }
242 
243 
244 NBNode::NBNode(const std::string& id, const Position& position, NBDistrict* district) :
245  Named(StringUtils::convertUmlaute(id)),
246  myPosition(position),
247  myType(district == 0 ? NODETYPE_UNKNOWN : NODETYPE_DISTRICT),
248  myDistrict(district),
249  myHaveCustomPoly(false),
250  myRequest(0),
251  myRadius(OptionsCont::getOptions().isDefault("default.junctions.radius") ? UNSPECIFIED_RADIUS : OptionsCont::getOptions().getFloat("default.junctions.radius")),
252  myKeepClear(OptionsCont::getOptions().getBool("default.junctions.keep-clear")),
253  myDiscardAllCrossings(false),
255 { }
256 
257 
259  delete myRequest;
260 }
261 
262 
263 void
265  bool updateEdgeGeometries) {
266  myPosition = position;
267  // patch type
268  myType = type;
269  if (!isTrafficLight(myType)) {
271  }
272  if (updateEdgeGeometries) {
273  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
274  PositionVector geom = (*i)->getGeometry();
275  geom[-1] = myPosition;
276  (*i)->setGeometry(geom);
277  }
278  for (EdgeVector::iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
279  PositionVector geom = (*i)->getGeometry();
280  geom[0] = myPosition;
281  (*i)->setGeometry(geom);
282  }
283  }
284 }
285 
286 
287 
288 // ----------- Applying offset
289 void
291  myPosition.add(xoff, yoff, 0);
292  myPoly.add(xoff, yoff, 0);
293 }
294 
295 
296 void
298  myPosition.mul(1, -1);
299  myPoly.mirrorX();
300  // mirror pre-computed geometty of crossings and walkingareas
301  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
302  (*it).shape.mirrorX();
303  }
304  for (std::vector<WalkingArea>::iterator it_wa = myWalkingAreas.begin(); it_wa != myWalkingAreas.end(); ++it_wa) {
305  (*it_wa).shape.mirrorX();
306  }
307 }
308 
309 
310 // ----------- Methods for dealing with assigned traffic lights
311 void
313  myTrafficLights.insert(tlDef);
314  // rail signals receive a temporary traffic light in order to set connection tl-linkIndex
317  }
318 }
319 
320 
321 void
323  tlDef->removeNode(this);
324  myTrafficLights.erase(tlDef);
325 }
326 
327 
328 void
330  std::set<NBTrafficLightDefinition*> trafficLights = myTrafficLights; // make a copy because we will modify the original
331  for (std::set<NBTrafficLightDefinition*>::const_iterator i = trafficLights.begin(); i != trafficLights.end(); ++i) {
332  removeTrafficLight(*i);
333  }
334 }
335 
336 
337 bool
339  if (!isTLControlled()) {
340  return false;
341  }
342  for (std::set<NBTrafficLightDefinition*>::const_iterator i = myTrafficLights.begin(); i != myTrafficLights.end(); ++i) {
343  if ((*i)->getID().find("joined") == 0) {
344  return true;
345  }
346  }
347  return false;
348 }
349 
350 
351 void
353  if (isTLControlled()) {
354  std::set<NBTrafficLightDefinition*> oldDefs(myTrafficLights);
355  for (std::set<NBTrafficLightDefinition*>::iterator it = oldDefs.begin(); it != oldDefs.end(); ++it) {
356  NBTrafficLightDefinition* orig = *it;
357  if (dynamic_cast<NBOwnTLDef*>(orig) == 0) {
358  NBTrafficLightDefinition* newDef = new NBOwnTLDef(orig->getID(), orig->getOffset(), orig->getType());
359  const std::vector<NBNode*>& nodes = orig->getNodes();
360  while (!nodes.empty()) {
361  newDef->addNode(nodes.front());
362  nodes.front()->removeTrafficLight(orig);
363  }
364  tlCont.removeFully(orig->getID());
365  tlCont.insert(newDef);
366  }
367  }
368  }
369 }
370 
371 
372 void
374  for (std::set<NBTrafficLightDefinition*>::iterator it = myTrafficLights.begin(); it != myTrafficLights.end(); ++it) {
375  (*it)->shiftTLConnectionLaneIndex(edge, offset);
376  }
377 }
378 
379 // ----------- Prunning the input
380 unsigned int
382  unsigned int ret = 0;
383  unsigned int pos = 0;
384  EdgeVector::const_iterator j = myIncomingEdges.begin();
385  while (j != myIncomingEdges.end()) {
386  // skip edges which are only incoming and not outgoing
387  if (find(myOutgoingEdges.begin(), myOutgoingEdges.end(), *j) == myOutgoingEdges.end()) {
388  ++j;
389  ++pos;
390  continue;
391  }
392  // an edge with both its origin and destination being the current
393  // node should be removed
394  NBEdge* dummy = *j;
395  WRITE_WARNING(" Removing self-looping edge '" + dummy->getID() + "'");
396  // get the list of incoming edges connected to the self-loop
397  EdgeVector incomingConnected;
398  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
399  if ((*i)->isConnectedTo(dummy) && *i != dummy) {
400  incomingConnected.push_back(*i);
401  }
402  }
403  // get the list of outgoing edges connected to the self-loop
404  EdgeVector outgoingConnected;
405  for (EdgeVector::const_iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
406  if (dummy->isConnectedTo(*i) && *i != dummy) {
407  outgoingConnected.push_back(*i);
408  }
409  }
410  // let the self-loop remap its connections
411  dummy->remapConnections(incomingConnected);
412  remapRemoved(tc, dummy, incomingConnected, outgoingConnected);
413  // delete the self-loop
414  ec.erase(dc, dummy);
415  j = myIncomingEdges.begin() + pos;
416  ++ret;
417  }
418  return ret;
419 }
420 
421 
422 // -----------
423 void
425  assert(edge != 0);
426  if (find(myIncomingEdges.begin(), myIncomingEdges.end(), edge) == myIncomingEdges.end()) {
427  myIncomingEdges.push_back(edge);
428  myAllEdges.push_back(edge);
429  }
430 }
431 
432 
433 void
435  assert(edge != 0);
436  if (find(myOutgoingEdges.begin(), myOutgoingEdges.end(), edge) == myOutgoingEdges.end()) {
437  myOutgoingEdges.push_back(edge);
438  myAllEdges.push_back(edge);
439  }
440 }
441 
442 
443 bool
445  // one in, one out->continuation
446  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
447  // both must have the same number of lanes
448  return (*(myIncomingEdges.begin()))->getNumLanes() == (*(myOutgoingEdges.begin()))->getNumLanes();
449  }
450  // two in and two out and both in reverse direction
451  if (myIncomingEdges.size() == 2 && myOutgoingEdges.size() == 2) {
452  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
453  NBEdge* in = *i;
454  EdgeVector::const_iterator opposite = find_if(myOutgoingEdges.begin(), myOutgoingEdges.end(), NBContHelper::opposite_finder(in));
455  // must have an opposite edge
456  if (opposite == myOutgoingEdges.end()) {
457  return false;
458  }
459  // both must have the same number of lanes
461  if (in->getNumLanes() != (*opposite)->getNumLanes()) {
462  return false;
463  }
464  }
465  return true;
466  }
467  // nope
468  return false;
469 }
470 
471 
474  const PositionVector& endShape,
475  int numPoints,
476  bool isTurnaround,
477  SUMOReal extrapolateBeg,
478  SUMOReal extrapolateEnd) const {
479 
480  const Position beg = begShape.back();
481  const Position end = endShape.front();
482  PositionVector ret;
483  PositionVector init;
484  bool noSpline = false;
485  if (beg.distanceTo(end) < POSITION_EPS || beg.distanceTo(begShape[-2]) < POSITION_EPS || end.distanceTo(endShape[1]) < POSITION_EPS) {
486  noSpline = true;
487  } else {
488  init.push_back(beg);
489  if (isTurnaround) {
490  // turnarounds:
491  // - end of incoming lane
492  // - position between incoming/outgoing end/begin shifted by the distance orthogonally
493  // - begin of outgoing lane
494  Position center = PositionVector::positionAtOffset(beg, end, beg.distanceTo(end) / (SUMOReal) 2.);
495  center.sub(beg.y() - end.y(), end.x() - beg.x());
496  init.push_back(center);
497  } else {
498  const SUMOReal angle = fabs(GeomHelper::angleDiff(begShape.angleAt2D(-2), endShape.angleAt2D(0)));
499  PositionVector endShapeBegLine(endShape[0], endShape[1]);
500  PositionVector begShapeEndLineRev(begShape[-1], begShape[-2]);
501  endShapeBegLine.extrapolate(100, true);
502  begShapeEndLineRev.extrapolate(100, true);
503  if (angle < M_PI / 4.) {
504  // very low angle: almost straight
505  const SUMOReal halfDistance = beg.distanceTo(end) / 2.;
506  if (halfDistance > 5) {
507  const SUMOReal endLength = begShape[-2].distanceTo(begShape[-1]);
508  const SUMOReal off1 = endLength + MIN2(extrapolateBeg, halfDistance);
509  init.push_back(PositionVector::positionAtOffset(begShapeEndLineRev[1], begShapeEndLineRev[0], off1));
510  const SUMOReal off2 = 100. - MIN2(extrapolateEnd, halfDistance);
511  init.push_back(PositionVector::positionAtOffset(endShapeBegLine[0], endShapeBegLine[1], off2));
512  } else {
513  noSpline = true;
514  }
515  } else {
516  // turning
517  // - end of incoming lane
518  // - intersection of the extrapolated lanes
519  // - begin of outgoing lane
520  // attention: if there is no intersection, use a straight line
521  init.push_back(endShapeBegLine.intersectionPosition2D(begShapeEndLineRev));
522  if (init[-1] == Position::INVALID) {
523  noSpline = true;
524  }
525  }
526  }
527  init.push_back(end);
528  }
529  //
530  if (noSpline) {
531  ret.push_back(beg);
532  ret.push_back(end);
533  } else {
534  SUMOReal* def = new SUMOReal[1 + (int)init.size() * 3];
535  for (int i = 0; i < (int)init.size(); ++i) {
536  // starts at index 1
537  def[i * 3 + 1] = init[i].x();
538  def[i * 3 + 2] = 0;
539  def[i * 3 + 3] = init[i].y();
540  }
541  SUMOReal* ret_buf = new SUMOReal[numPoints * 3 + 1];
542  bezier((int)init.size(), def, numPoints, ret_buf);
543  delete[] def;
544  Position prev;
545  for (int i = 0; i < (int)numPoints; i++) {
546  Position current(ret_buf[i * 3 + 1], ret_buf[i * 3 + 3], myPosition.z());
547  if (prev != current && !ISNAN(current.x()) && !ISNAN(current.y())) {
548  ret.push_back(current);
549  }
550  prev = current;
551  }
552  delete[] ret_buf;
553  }
554  return ret;
555 }
556 
557 
559 NBNode::computeInternalLaneShape(NBEdge* fromE, const NBEdge::Connection& con, int numPoints) const {
560  if (con.fromLane >= (int) fromE->getNumLanes()) {
561  throw ProcessError("Connection '" + fromE->getID() + "_" + toString(con.fromLane) + "->" + con.toEdge->getID() + "_" + toString(con.toLane) + "' starts at a non-existant lane.");
562  }
563  if (con.toLane >= (int) con.toEdge->getNumLanes()) {
564  throw ProcessError("Connection '" + fromE->getID() + "_" + toString(con.fromLane) + "->" + con.toEdge->getID() + "_" + toString(con.toLane) + "' targets a non-existant lane.");
565  }
566  PositionVector ret;
567  if (myCustomLaneShapes.size() > 0 && con.id != "") {
568  // this is the second pass (ids and shapes are already set
569  assert(con.shape.size() > 0);
570  CustomShapeMap::const_iterator it = myCustomLaneShapes.find(con.getInternalLaneID());
571  if (it != myCustomLaneShapes.end()) {
572  ret = it->second;
573  } else {
574  ret = con.shape;
575  }
576  it = myCustomLaneShapes.find(con.viaID + "_0");
577  if (it != myCustomLaneShapes.end()) {
578  ret.append(it->second);
579  } else {
580  ret.append(con.viaShape);
581  }
582  return ret;
583  }
584 
585  ret = computeSmoothShape(fromE->getLaneShape(con.fromLane), con.toEdge->getLaneShape(con.toLane),
586  numPoints, fromE->getTurnDestination() == con.toEdge,
587  (SUMOReal) 5. * (SUMOReal) fromE->getNumLanes(),
588  (SUMOReal) 5. * (SUMOReal) con.toEdge->getNumLanes());
589  const NBEdge::Lane& lane = fromE->getLaneStruct(con.fromLane);
590  if (lane.endOffset > 0) {
591  PositionVector beg = lane.shape.getSubpart(lane.shape.length() - lane.endOffset, lane.shape.length());;
592  beg.append(ret);
593  ret = beg;
594  }
595  return ret;
596 }
597 
598 
599 bool
600 NBNode::needsCont(const NBEdge* fromE, const NBEdge* otherFromE,
601  const NBEdge::Connection& c, const NBEdge::Connection& otherC) const {
602  const NBEdge* toE = c.toEdge;
603  const NBEdge* otherToE = otherC.toEdge;
604 
606  return false;
607  }
608  LinkDirection d1 = getDirection(fromE, toE);
609  const bool thisRight = (d1 == LINKDIR_RIGHT || d1 == LINKDIR_PARTRIGHT);
610  const bool rightTurnConflict = (thisRight &&
611  NBNode::rightTurnConflict(fromE, toE, c.fromLane, otherFromE, otherToE, otherC.fromLane));
612  if (thisRight && !rightTurnConflict) {
613  return false;
614  }
615  if (!(foes(otherFromE, otherToE, fromE, toE) || myRequest == 0 || rightTurnConflict)) {
616  // if they do not cross, no waiting place is needed
617  return false;
618  }
619  LinkDirection d2 = getDirection(otherFromE, otherToE);
620  if (d2 == LINKDIR_TURN) {
621  return false;
622  }
623  const bool thisLeft = (d1 == LINKDIR_LEFT || d1 == LINKDIR_TURN);
624  const bool otherLeft = (d2 == LINKDIR_LEFT || d2 == LINKDIR_TURN);
625  const bool bothLeft = thisLeft && otherLeft;
626  if (fromE == otherFromE && !thisRight) {
627  // ignore same edge links except for right-turns
628  return false;
629  }
630  if (thisRight && d2 != LINKDIR_STRAIGHT) {
631  return false;
632  }
633  if (c.tlID != "" && !bothLeft) {
634  assert(myTrafficLights.size() > 0);
635  return (c.contPos != NBEdge::UNSPECIFIED_CONTPOS) || (*myTrafficLights.begin())->needsCont(fromE, toE, otherFromE, otherToE);
636  }
637  if (fromE->getJunctionPriority(this) > 0 && otherFromE->getJunctionPriority(this) > 0) {
638  return mustBrake(fromE, toE, c.fromLane, c.toLane, false);
639  }
640  return false;
641 }
642 
643 
644 void
646  delete myRequest; // possibly recomputation step
647  myRequest = 0;
648  if (myIncomingEdges.size() == 0 || myOutgoingEdges.size() == 0) {
649  // no logic if nothing happens here
651  std::set<NBTrafficLightDefinition*> trafficLights = myTrafficLights; // make a copy because we will modify the original
653  for (std::set<NBTrafficLightDefinition*>::const_iterator i = trafficLights.begin(); i != trafficLights.end(); ++i) {
654  (*i)->setParticipantsInformation();
655  (*i)->setTLControllingInformation(ec);
656  }
657  return;
658  }
659  // check whether the node was set to be unregulated by the user
660  if (oc.getBool("keep-nodes-unregulated") || oc.isInStringVector("keep-nodes-unregulated.explicit", getID())
661  || (oc.getBool("keep-nodes-unregulated.district-nodes") && (isNearDistrict() || isDistrict()))) {
663  return;
664  }
665  // compute the logic if necessary or split the junction
667  // build the request
669  // check whether it is not too large
670  unsigned int numConnections = numNormalConnections();
671  if (numConnections >= SUMO_MAX_CONNECTIONS) {
672  // yep -> make it untcontrolled, warn
673  delete myRequest;
674  myRequest = 0;
677  } else {
679  }
680  WRITE_WARNING("Junction '" + getID() + "' is too complicated (" + toString(numConnections)
681  + " connections, max " + toString(SUMO_MAX_CONNECTIONS) + "); will be set to " + toString(myType));
682  } else if (numConnections == 0) {
683  delete myRequest;
684  myRequest = 0;
686  } else {
688  }
689  }
690 }
691 
692 
693 bool
694 NBNode::writeLogic(OutputDevice& into, const bool checkLaneFoes) const {
695  if (myRequest) {
696  myRequest->writeLogic(myID, into, checkLaneFoes);
697  return true;
698  }
699  return false;
700 }
701 
702 
703 void
704 NBNode::computeNodeShape(SUMOReal mismatchThreshold) {
705  if (myHaveCustomPoly) {
706  return;
707  }
708  if (myIncomingEdges.size() == 0 && myOutgoingEdges.size() == 0) {
709  // may be an intermediate step during network editing
710  myPoly.clear();
711  myPoly.push_back(myPosition);
712  return;
713  }
714  try {
715  NBNodeShapeComputer computer(*this);
716  myPoly = computer.compute();
717  if (myPoly.size() > 0) {
718  PositionVector tmp = myPoly;
719  tmp.push_back_noDoublePos(tmp[0]); // need closed shape
720  if (mismatchThreshold >= 0
721  && !tmp.around(myPosition)
722  && tmp.distance(myPosition) > mismatchThreshold) {
723  WRITE_WARNING("Shape for junction '" + myID + "' has distance " + toString(tmp.distance(myPosition)) + " to its given position");
724  }
725  }
726  } catch (InvalidArgument&) {
727  WRITE_WARNING("For junction '" + getID() + "': could not compute shape.");
728  // make sure our shape is not empty because our XML schema forbids empty attributes
729  myPoly.clear();
730  myPoly.push_back(myPosition);
731  }
732 }
733 
734 
735 void
737  // special case a):
738  // one in, one out, the outgoing has one lane more
739  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
740  NBEdge* in = myIncomingEdges[0];
741  NBEdge* out = myOutgoingEdges[0];
742  // check if it's not the turnaround
743  if (in->getTurnDestination() == out) {
744  // will be added later or not...
745  return;
746  }
747  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
748  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
749  if (in->getStep() <= NBEdge::LANES2EDGES
750  && in->getNumLanes() - inOffset == out->getNumLanes() - outOffset - 1
751  && in != out
752  && in->isConnectedTo(out)) {
753  for (int i = inOffset; i < (int) in->getNumLanes(); ++i) {
754  in->setConnection(i, out, i + 1, NBEdge::L2L_COMPUTED);
755  }
756  in->setConnection(inOffset, out, outOffset, NBEdge::L2L_COMPUTED);
757  return;
758  }
759  }
760  // special case b):
761  // two in, one out, the outgoing has the same number of lanes as the sum of the incoming
762  // --> highway on-ramp
763  if (myIncomingEdges.size() == 2 && myOutgoingEdges.size() == 1) {
764  NBEdge* out = myOutgoingEdges[0];
765  NBEdge* in1 = myIncomingEdges[0];
766  NBEdge* in2 = myIncomingEdges[1];
767  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
768  int in1Offset = MAX2(0, in1->getFirstNonPedestrianLaneIndex(FORWARD, true));
769  int in2Offset = MAX2(0, in2->getFirstNonPedestrianLaneIndex(FORWARD, true));
770  if (in1->getNumLanes() + in2->getNumLanes() - in1Offset - in2Offset == out->getNumLanes() - outOffset
771  && (in1->getStep() <= NBEdge::LANES2EDGES)
772  && (in2->getStep() <= NBEdge::LANES2EDGES)
773  && in1 != out
774  && in2 != out
775  && in1->isConnectedTo(out)
776  && in2->isConnectedTo(out)
777  && isLongEnough(out, MIN_WEAVE_LENGTH)) {
778  // for internal: check which one is the rightmost
779  SUMOReal a1 = in1->getAngleAtNode(this);
780  SUMOReal a2 = in2->getAngleAtNode(this);
783  if (ccw > cw) {
784  std::swap(in1, in2);
785  std::swap(in1Offset, in2Offset);
786  }
787  in1->addLane2LaneConnections(in1Offset, out, outOffset, in1->getNumLanes() - in1Offset, NBEdge::L2L_VALIDATED, true, true);
788  in2->addLane2LaneConnections(in2Offset, out, in1->getNumLanes() + outOffset - in1Offset, in2->getNumLanes() - in2Offset, NBEdge::L2L_VALIDATED, true, true);
789  return;
790  }
791  }
792  // special case c):
793  // one in, two out, the incoming has the same number of lanes as the sum of the outgoing
794  // --> highway off-ramp
795  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 2) {
796  NBEdge* in = myIncomingEdges[0];
797  NBEdge* out1 = myOutgoingEdges[0];
798  NBEdge* out2 = myOutgoingEdges[1];
799  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
800  int out1Offset = MAX2(0, out1->getFirstNonPedestrianLaneIndex(FORWARD, true));
801  int out2Offset = MAX2(0, out2->getFirstNonPedestrianLaneIndex(FORWARD, true));
802  if (in->getNumLanes() - inOffset == out2->getNumLanes() + out1->getNumLanes() - out1Offset - out2Offset
803  && (in->getStep() <= NBEdge::LANES2EDGES)
804  && in != out1
805  && in != out2
806  && in->isConnectedTo(out1)
807  && in->isConnectedTo(out2)) {
808  // for internal: check which one is the rightmost
809  if (NBContHelper::relative_outgoing_edge_sorter(in)(out2, out1)) {
810  std::swap(out1, out2);
811  std::swap(out1Offset, out2Offset);
812  }
813  in->addLane2LaneConnections(inOffset, out1, out1Offset, out1->getNumLanes() - out1Offset, NBEdge::L2L_VALIDATED, true, true);
814  in->addLane2LaneConnections(out1->getNumLanes() + inOffset - out1Offset, out2, out2Offset, out2->getNumLanes() - out2Offset, NBEdge::L2L_VALIDATED, false, true);
815  return;
816  }
817  }
818  // special case d):
819  // one in, one out, the outgoing has one lane less and node has type 'zipper'
820  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1 && myType == NODETYPE_ZIPPER) {
821  NBEdge* in = myIncomingEdges[0];
822  NBEdge* out = myOutgoingEdges[0];
823  // check if it's not the turnaround
824  if (in->getTurnDestination() == out) {
825  // will be added later or not...
826  return;
827  }
828  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
829  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
830  if (in->getStep() <= NBEdge::LANES2EDGES
831  && in->getNumLanes() - inOffset == out->getNumLanes() - outOffset + 1
832  && in != out
833  && in->isConnectedTo(out)) {
834  for (int i = inOffset; i < (int) in->getNumLanes(); ++i) {
835  in->setConnection(i, out, MIN2(outOffset + i, ((int)out->getNumLanes() - 1)), NBEdge::L2L_COMPUTED, true);
836  }
837  return;
838  }
839  }
840 
841  // go through this node's outgoing edges
842  // for every outgoing edge, compute the distribution of the node's
843  // incoming edges on this edge when approaching this edge
844  // the incoming edges' steps will then also be marked as LANE2LANE_RECHECK...
845  EdgeVector::reverse_iterator i;
846  for (i = myOutgoingEdges.rbegin(); i != myOutgoingEdges.rend(); i++) {
847  NBEdge* currentOutgoing = *i;
848  // get the information about edges that do approach this edge
849  EdgeVector* approaching = getEdgesThatApproach(currentOutgoing);
850  const unsigned int numApproaching = (unsigned int)approaching->size();
851  if (numApproaching != 0) {
852  ApproachingDivider divider(approaching, currentOutgoing);
853  Bresenham::compute(&divider, numApproaching, divider.numAvailableLanes());
854  }
855  delete approaching;
856 
857  // ensure that all modes have a connection if possible
858  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
859  NBEdge* incoming = *i;
860  if (incoming->getConnectionLanes(currentOutgoing).size() > 0) {
861  // no connections are needed for pedestrians during this step
862  // no satisfaction is possible if the outgoing edge disallows
863  SVCPermissions unsatisfied = incoming->getPermissions() & currentOutgoing->getPermissions() & ~SVC_PEDESTRIAN;
864  //std::cout << "initial unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
865  const std::vector<NBEdge::Connection>& elv = incoming->getConnections();
866  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
867  const NBEdge::Connection& c = *k;
868  if (c.toEdge == currentOutgoing) {
869  const SVCPermissions satisfied = (incoming->getPermissions(c.fromLane) & c.toEdge->getPermissions(c.toLane));
870  //std::cout << " from=" << c.fromLane << " to=" << c.toEdge->getID() << "_" << c.toLane << " satisfied=" << getVehicleClassNames(satisfied) << "\n";
871  unsatisfied &= ~satisfied;
872  }
873  }
874  if (unsatisfied != 0) {
875  //std::cout << " unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
876  int fromLane = 0;
877  while (unsatisfied != 0 && fromLane < (int)incoming->getNumLanes()) {
878  if ((incoming->getPermissions(fromLane) & unsatisfied) != 0) {
879  for (int toLane = 0; toLane < (int)currentOutgoing->getNumLanes(); ++toLane) {
880  const SVCPermissions satisfied = incoming->getPermissions(fromLane) & currentOutgoing->getPermissions(toLane) & unsatisfied;
881  if (satisfied != 0) {
882  incoming->setConnection((unsigned int)fromLane, currentOutgoing, toLane, NBEdge::L2L_COMPUTED);
883  //std::cout << " new connection from=" << fromLane << " to=" << currentOutgoing->getID() << "_" << toLane << " satisfies=" << getVehicleClassNames(satisfied) << "\n";
884  unsatisfied &= ~satisfied;
885  }
886  }
887  }
888  fromLane++;
889  }
890  //if (unsatisfied != 0) {
891  // std::cout << " still unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
892  //}
893  }
894  }
895  }
896  }
897 
898  // ... but we may have the case that there are no outgoing edges
899  // In this case, we have to mark the incoming edges as being in state
900  // LANE2LANE( not RECHECK) by hand
901  if (myOutgoingEdges.size() == 0) {
902  for (i = myIncomingEdges.rbegin(); i != myIncomingEdges.rend(); i++) {
903  (*i)->markAsInLane2LaneState();
904  }
905  }
906 
907  // DEBUG
908  //std::cout << "connections at " << getID() << "\n";
909  //for (i = myIncomingEdges.rbegin(); i != myIncomingEdges.rend(); i++) {
910  // const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
911  // for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
912  // std::cout << " " << (*i)->getID() << "_" << (*k).fromLane << " -> " << (*k).toEdge->getID() << "_" << (*k).toLane << "\n";
913  // }
914  //}
915 }
916 
917 bool
919  SUMOReal seen = out->getLoadedLength();
920  while (seen < minLength) {
921  // advance along trivial continuations
922  if (out->getToNode()->getOutgoingEdges().size() != 1
923  || out->getToNode()->getIncomingEdges().size() != 1) {
924  return false;
925  } else {
926  out = out->getToNode()->getOutgoingEdges()[0];
927  seen += out->getLoadedLength();
928  }
929  }
930  return true;
931 }
932 
933 EdgeVector*
935  // get the position of the node to get the approaching nodes of
936  EdgeVector::const_iterator i = find(myAllEdges.begin(),
937  myAllEdges.end(), currentOutgoing);
938  // get the first possible approaching edge
940  // go through the list of edges clockwise and add the edges
941  EdgeVector* approaching = new EdgeVector();
942  for (; *i != currentOutgoing;) {
943  // check only incoming edges
944  if ((*i)->getToNode() == this && (*i)->getTurnDestination() != currentOutgoing) {
945  std::vector<int> connLanes = (*i)->getConnectionLanes(currentOutgoing);
946  if (connLanes.size() != 0) {
947  approaching->push_back(*i);
948  }
949  }
951  }
952  return approaching;
953 }
954 
955 
956 void
957 NBNode::replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff) {
958  // replace the edge in the list of outgoing nodes
959  EdgeVector::iterator i = find(myOutgoingEdges.begin(), myOutgoingEdges.end(), which);
960  if (i != myOutgoingEdges.end()) {
961  (*i) = by;
962  i = find(myAllEdges.begin(), myAllEdges.end(), which);
963  (*i) = by;
964  }
965  // replace the edge in connections of incoming edges
966  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); ++i) {
967  (*i)->replaceInConnections(which, by, laneOff);
968  }
969  // replace within the connetion prohibition dependencies
970  replaceInConnectionProhibitions(which, by, 0, laneOff);
971 }
972 
973 
974 void
976  // replace edges
977  unsigned int laneOff = 0;
978  for (EdgeVector::const_iterator i = which.begin(); i != which.end(); i++) {
979  replaceOutgoing(*i, by, laneOff);
980  laneOff += (*i)->getNumLanes();
981  }
982  // removed SUMOReal occurences
984  // check whether this node belongs to a district and the edges
985  // must here be also remapped
986  if (myDistrict != 0) {
987  myDistrict->replaceOutgoing(which, by);
988  }
989 }
990 
991 
992 void
993 NBNode::replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff) {
994  // replace the edge in the list of incoming nodes
995  EdgeVector::iterator i = find(myIncomingEdges.begin(), myIncomingEdges.end(), which);
996  if (i != myIncomingEdges.end()) {
997  (*i) = by;
998  i = find(myAllEdges.begin(), myAllEdges.end(), which);
999  (*i) = by;
1000  }
1001  // replace within the connetion prohibition dependencies
1002  replaceInConnectionProhibitions(which, by, laneOff, 0);
1003 }
1004 
1005 
1006 void
1008  // replace edges
1009  unsigned int laneOff = 0;
1010  for (EdgeVector::const_iterator i = which.begin(); i != which.end(); i++) {
1011  replaceIncoming(*i, by, laneOff);
1012  laneOff += (*i)->getNumLanes();
1013  }
1014  // removed SUMOReal occurences
1016  // check whether this node belongs to a district and the edges
1017  // must here be also remapped
1018  if (myDistrict != 0) {
1019  myDistrict->replaceIncoming(which, by);
1020  }
1021 }
1022 
1023 
1024 
1025 void
1027  unsigned int whichLaneOff, unsigned int byLaneOff) {
1028  // replace in keys
1029  NBConnectionProhibits::iterator j = myBlockedConnections.begin();
1030  while (j != myBlockedConnections.end()) {
1031  bool changed = false;
1032  NBConnection c = (*j).first;
1033  if (c.replaceFrom(which, whichLaneOff, by, byLaneOff)) {
1034  changed = true;
1035  }
1036  if (c.replaceTo(which, whichLaneOff, by, byLaneOff)) {
1037  changed = true;
1038  }
1039  if (changed) {
1040  myBlockedConnections[c] = (*j).second;
1041  myBlockedConnections.erase(j);
1042  j = myBlockedConnections.begin();
1043  } else {
1044  j++;
1045  }
1046  }
1047  // replace in values
1048  for (j = myBlockedConnections.begin(); j != myBlockedConnections.end(); j++) {
1049  NBConnectionVector& prohibiting = (*j).second;
1050  for (NBConnectionVector::iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
1051  NBConnection& sprohibiting = *k;
1052  sprohibiting.replaceFrom(which, whichLaneOff, by, byLaneOff);
1053  sprohibiting.replaceTo(which, whichLaneOff, by, byLaneOff);
1054  }
1055  }
1056 }
1057 
1058 
1059 
1060 void
1062  unsigned int i, j;
1063  // check incoming
1064  for (i = 0; myIncomingEdges.size() > 0 && i < myIncomingEdges.size() - 1; i++) {
1065  j = i + 1;
1066  while (j < myIncomingEdges.size()) {
1067  if (myIncomingEdges[i] == myIncomingEdges[j]) {
1068  myIncomingEdges.erase(myIncomingEdges.begin() + j);
1069  } else {
1070  j++;
1071  }
1072  }
1073  }
1074  // check outgoing
1075  for (i = 0; myOutgoingEdges.size() > 0 && i < myOutgoingEdges.size() - 1; i++) {
1076  j = i + 1;
1077  while (j < myOutgoingEdges.size()) {
1078  if (myOutgoingEdges[i] == myOutgoingEdges[j]) {
1079  myOutgoingEdges.erase(myOutgoingEdges.begin() + j);
1080  } else {
1081  j++;
1082  }
1083  }
1084  }
1085  // check all
1086  for (i = 0; myAllEdges.size() > 0 && i < myAllEdges.size() - 1; i++) {
1087  j = i + 1;
1088  while (j < myAllEdges.size()) {
1089  if (myAllEdges[i] == myAllEdges[j]) {
1090  myAllEdges.erase(myAllEdges.begin() + j);
1091  } else {
1092  j++;
1093  }
1094  }
1095  }
1096 }
1097 
1098 
1099 bool
1100 NBNode::hasIncoming(const NBEdge* const e) const {
1101  return find(myIncomingEdges.begin(), myIncomingEdges.end(), e) != myIncomingEdges.end();
1102 }
1103 
1104 
1105 bool
1106 NBNode::hasOutgoing(const NBEdge* const e) const {
1107  return find(myOutgoingEdges.begin(), myOutgoingEdges.end(), e) != myOutgoingEdges.end();
1108 }
1109 
1110 
1111 NBEdge*
1113  EdgeVector edges = myIncomingEdges;
1114  if (find(edges.begin(), edges.end(), e) != edges.end()) {
1115  edges.erase(find(edges.begin(), edges.end(), e));
1116  }
1117  if (edges.size() == 0) {
1118  return 0;
1119  }
1120  if (e->getToNode() == this) {
1121  sort(edges.begin(), edges.end(), NBContHelper::edge_opposite_direction_sorter(e, this));
1122  } else {
1123  sort(edges.begin(), edges.end(), NBContHelper::edge_similar_direction_sorter(e));
1124  }
1125  return edges[0];
1126 }
1127 
1128 
1129 void
1131  const NBConnection& mustStop) {
1132  if (mayDrive.getFrom() == 0 ||
1133  mayDrive.getTo() == 0 ||
1134  mustStop.getFrom() == 0 ||
1135  mustStop.getTo() == 0) {
1136 
1137  WRITE_WARNING("Something went wrong during the building of a connection...");
1138  return; // !!! mark to recompute connections
1139  }
1140  NBConnectionVector conn = myBlockedConnections[mustStop];
1141  conn.push_back(mayDrive);
1142  myBlockedConnections[mustStop] = conn;
1143 }
1144 
1145 
1146 NBEdge*
1147 NBNode::getPossiblySplittedIncoming(const std::string& edgeid) {
1148  unsigned int size = (unsigned int) edgeid.length();
1149  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1150  std::string id = (*i)->getID();
1151  if (id.substr(0, size) == edgeid) {
1152  return *i;
1153  }
1154  }
1155  return 0;
1156 }
1157 
1158 
1159 NBEdge*
1160 NBNode::getPossiblySplittedOutgoing(const std::string& edgeid) {
1161  unsigned int size = (unsigned int) edgeid.length();
1162  for (EdgeVector::iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1163  std::string id = (*i)->getID();
1164  if (id.substr(0, size) == edgeid) {
1165  return *i;
1166  }
1167  }
1168  return 0;
1169 }
1170 
1171 
1172 void
1173 NBNode::removeEdge(NBEdge* edge, bool removeFromConnections) {
1174  EdgeVector::iterator i = find(myAllEdges.begin(), myAllEdges.end(), edge);
1175  if (i != myAllEdges.end()) {
1176  myAllEdges.erase(i);
1177  i = find(myOutgoingEdges.begin(), myOutgoingEdges.end(), edge);
1178  if (i != myOutgoingEdges.end()) {
1179  myOutgoingEdges.erase(i);
1180  } else {
1181  i = find(myIncomingEdges.begin(), myIncomingEdges.end(), edge);
1182  if (i != myIncomingEdges.end()) {
1183  myIncomingEdges.erase(i);
1184  } else {
1185  // edge must have been either incoming or outgoing
1186  assert(false);
1187  }
1188  }
1189  if (removeFromConnections) {
1190  for (i = myAllEdges.begin(); i != myAllEdges.end(); ++i) {
1191  (*i)->removeFromConnections(edge);
1192  }
1193  }
1194  }
1195 }
1196 
1197 
1198 Position
1200  Position pos(0, 0);
1201  EdgeVector::const_iterator i;
1202  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1203  NBNode* conn = (*i)->getFromNode();
1204  Position toAdd = conn->getPosition();
1205  toAdd.sub(myPosition);
1206  toAdd.mul((SUMOReal) 1.0 / sqrt(toAdd.x()*toAdd.x() + toAdd.y()*toAdd.y()));
1207  pos.add(toAdd);
1208  }
1209  for (i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1210  NBNode* conn = (*i)->getToNode();
1211  Position toAdd = conn->getPosition();
1212  toAdd.sub(myPosition);
1213  toAdd.mul((SUMOReal) 1.0 / sqrt(toAdd.x()*toAdd.x() + toAdd.y()*toAdd.y()));
1214  pos.add(toAdd);
1215  }
1216  pos.mul((SUMOReal) - 1.0 / (myIncomingEdges.size() + myOutgoingEdges.size()));
1217  if (pos.x() == 0 && pos.y() == 0) {
1218  pos = Position(1, 0);
1219  }
1220  pos.norm2d();
1221  return pos;
1222 }
1223 
1224 
1225 
1226 void
1228  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1229  (*i)->invalidateConnections();
1230  }
1231 }
1232 
1233 
1234 void
1236  for (EdgeVector::const_iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1237  (*i)->invalidateConnections();
1238  }
1239 }
1240 
1241 
1242 bool
1243 NBNode::mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const {
1244  // unregulated->does not need to brake
1245  if (myRequest == 0) {
1246  return false;
1247  }
1248  // vehicles which do not have a following lane must always decelerate to the end
1249  if (to == 0) {
1250  return true;
1251  }
1252  // check whether any other connection on this node prohibits this connection
1253  return myRequest->mustBrake(from, to, fromLane, toLane, includePedCrossings);
1254 }
1255 
1256 bool
1257 NBNode::mustBrakeForCrossing(const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing) const {
1258  return NBRequest::mustBrakeForCrossing(this, from, to, crossing);
1259 }
1260 
1261 
1262 bool
1263 NBNode::rightTurnConflict(const NBEdge* from, const NBEdge* to, int fromLane,
1264  const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorFromLane,
1265  bool lefthand) {
1266  if (from != prohibitorFrom) {
1267  return false;
1268  }
1269  if (from->isTurningDirectionAt(to)
1270  || prohibitorFrom->isTurningDirectionAt(prohibitorTo)) {
1271  // XXX should warn if there are any non-turning connections left of this
1272  return false;
1273  }
1274  // conflict if to is between prohibitorTo and from when going clockwise
1275  if (to->getStartAngle() == prohibitorTo->getStartAngle()) {
1276  // reduce rounding errors
1277  return false;
1278  }
1279  const LinkDirection d1 = from->getToNode()->getDirection(from, to);
1280  // must be a right turn to qualify as rightTurnConflict
1281  if (d1 == LINKDIR_STRAIGHT) {
1282  // no conflict for straight going connections
1283  // XXX actually this should check the main direction (which could also
1284  // be a turn)
1285  return false;
1286  } else {
1287  const LinkDirection d2 = prohibitorFrom->getToNode()->getDirection(prohibitorFrom, prohibitorTo);
1288  if (d1 == LINKDIR_LEFT || d1 == LINKDIR_PARTLEFT) {
1289  // check for leftTurnConflicht
1290  lefthand = !lefthand;
1291  if (d2 == LINKDIR_RIGHT || d1 == LINKDIR_PARTRIGHT) {
1292  // assume that the left-turning bicycle goes straight at first
1293  // and thus gets precedence over a right turning vehicle
1294  return false;
1295  }
1296  }
1297  if ((!lefthand && fromLane <= prohibitorFromLane) ||
1298  (lefthand && fromLane >= prohibitorFromLane)) {
1299  return false;
1300  }
1301  const SUMOReal toAngleAtNode = fmod(to->getStartAngle() + 180, (SUMOReal)360.0);
1302  const SUMOReal prohibitorToAngleAtNode = fmod(prohibitorTo->getStartAngle() + 180, (SUMOReal)360.0);
1303  return (lefthand != (GeomHelper::getCWAngleDiff(from->getEndAngle(), toAngleAtNode) <
1304  GeomHelper::getCWAngleDiff(from->getEndAngle(), prohibitorToAngleAtNode)));
1305  }
1306 }
1307 
1308 
1309 bool
1310 NBNode::isLeftMover(const NBEdge* const from, const NBEdge* const to) const {
1311  // when the junction has only one incoming edge, there are no
1312  // problems caused by left blockings
1313  if (myIncomingEdges.size() == 1 || myOutgoingEdges.size() == 1) {
1314  return false;
1315  }
1316  SUMOReal fromAngle = from->getAngleAtNode(this);
1317  SUMOReal toAngle = to->getAngleAtNode(this);
1318  SUMOReal cw = GeomHelper::getCWAngleDiff(fromAngle, toAngle);
1319  SUMOReal ccw = GeomHelper::getCCWAngleDiff(fromAngle, toAngle);
1320  std::vector<NBEdge*>::const_iterator i = std::find(myAllEdges.begin(), myAllEdges.end(), from);
1321  do {
1323  } while ((!hasOutgoing(*i) || from->isTurningDirectionAt(*i)) && *i != from);
1324  return cw < ccw && (*i) == to && myOutgoingEdges.size() > 2;
1325 }
1326 
1327 
1328 bool
1329 NBNode::forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
1330  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
1331  bool regardNonSignalisedLowerPriority) const {
1332  return myRequest != 0 && myRequest->forbids(possProhibitorFrom, possProhibitorTo,
1333  possProhibitedFrom, possProhibitedTo,
1334  regardNonSignalisedLowerPriority);
1335 }
1336 
1337 
1338 bool
1339 NBNode::foes(const NBEdge* const from1, const NBEdge* const to1,
1340  const NBEdge* const from2, const NBEdge* const to2) const {
1341  return myRequest != 0 && myRequest->foes(from1, to1, from2, to2);
1342 }
1343 
1344 
1345 void
1347  NBEdge* removed, const EdgeVector& incoming,
1348  const EdgeVector& outgoing) {
1349  assert(find(incoming.begin(), incoming.end(), removed) == incoming.end());
1350  bool changed = true;
1351  while (changed) {
1352  changed = false;
1353  NBConnectionProhibits blockedConnectionsTmp = myBlockedConnections;
1354  NBConnectionProhibits blockedConnectionsNew;
1355  // remap in connections
1356  for (NBConnectionProhibits::iterator i = blockedConnectionsTmp.begin(); i != blockedConnectionsTmp.end(); i++) {
1357  const NBConnection& blocker = (*i).first;
1358  const NBConnectionVector& blocked = (*i).second;
1359  // check the blocked connections first
1360  // check whether any of the blocked must be changed
1361  bool blockedChanged = false;
1362  NBConnectionVector newBlocked;
1363  NBConnectionVector::const_iterator j;
1364  for (j = blocked.begin(); j != blocked.end(); j++) {
1365  const NBConnection& sblocked = *j;
1366  if (sblocked.getFrom() == removed || sblocked.getTo() == removed) {
1367  blockedChanged = true;
1368  }
1369  }
1370  // adapt changes if so
1371  for (j = blocked.begin(); blockedChanged && j != blocked.end(); j++) {
1372  const NBConnection& sblocked = *j;
1373  if (sblocked.getFrom() == removed && sblocked.getTo() == removed) {
1374  /* for(EdgeVector::const_iterator k=incoming.begin(); k!=incoming.end(); k++) {
1375  !!! newBlocked.push_back(NBConnection(*k, *k));
1376  }*/
1377  } else if (sblocked.getFrom() == removed) {
1378  assert(sblocked.getTo() != removed);
1379  for (EdgeVector::const_iterator k = incoming.begin(); k != incoming.end(); k++) {
1380  newBlocked.push_back(NBConnection(*k, sblocked.getTo()));
1381  }
1382  } else if (sblocked.getTo() == removed) {
1383  assert(sblocked.getFrom() != removed);
1384  for (EdgeVector::const_iterator k = outgoing.begin(); k != outgoing.end(); k++) {
1385  newBlocked.push_back(NBConnection(sblocked.getFrom(), *k));
1386  }
1387  } else {
1388  newBlocked.push_back(NBConnection(sblocked.getFrom(), sblocked.getTo()));
1389  }
1390  }
1391  if (blockedChanged) {
1392  blockedConnectionsNew[blocker] = newBlocked;
1393  changed = true;
1394  }
1395  // if the blocked were kept
1396  else {
1397  if (blocker.getFrom() == removed && blocker.getTo() == removed) {
1398  changed = true;
1399  /* for(EdgeVector::const_iterator k=incoming.begin(); k!=incoming.end(); k++) {
1400  !!! blockedConnectionsNew[NBConnection(*k, *k)] = blocked;
1401  }*/
1402  } else if (blocker.getFrom() == removed) {
1403  assert(blocker.getTo() != removed);
1404  changed = true;
1405  for (EdgeVector::const_iterator k = incoming.begin(); k != incoming.end(); k++) {
1406  blockedConnectionsNew[NBConnection(*k, blocker.getTo())] = blocked;
1407  }
1408  } else if (blocker.getTo() == removed) {
1409  assert(blocker.getFrom() != removed);
1410  changed = true;
1411  for (EdgeVector::const_iterator k = outgoing.begin(); k != outgoing.end(); k++) {
1412  blockedConnectionsNew[NBConnection(blocker.getFrom(), *k)] = blocked;
1413  }
1414  } else {
1415  blockedConnectionsNew[blocker] = blocked;
1416  }
1417  }
1418  }
1419  myBlockedConnections = blockedConnectionsNew;
1420  }
1421  // remap in traffic lights
1422  tc.remapRemoved(removed, incoming, outgoing);
1423 }
1424 
1425 
1427 NBNode::getDirection(const NBEdge* const incoming, const NBEdge* const outgoing, bool leftHand) const {
1428  // ok, no connection at all -> dead end
1429  if (outgoing == 0) {
1430  return LINKDIR_NODIR;
1431  }
1432  // turning direction
1433  if (incoming->isTurningDirectionAt(outgoing)) {
1434  return leftHand ? LINKDIR_TURN_LEFTHAND : LINKDIR_TURN;
1435  }
1436  // get the angle between incoming/outgoing at the junction
1437  SUMOReal angle =
1438  NBHelpers::normRelAngle(incoming->getAngleAtNode(this), outgoing->getAngleAtNode(this));
1439  // ok, should be a straight connection
1440  if (abs((int) angle) + 1 < 45) {
1441  return LINKDIR_STRAIGHT;
1442  }
1443 
1444  // check for left and right, first
1445  if (angle > 0) {
1446  // check whether any other edge goes further to the right
1447  EdgeVector::const_iterator i =
1448  find(myAllEdges.begin(), myAllEdges.end(), outgoing);
1449  if (leftHand) {
1451  } else {
1453  }
1454  while ((*i) != incoming) {
1455  if ((*i)->getFromNode() == this && !incoming->isTurningDirectionAt(*i)) {
1456  //std::cout << incoming->getID() << " -> " << outgoing->getID() << " partRight because auf " << (*i)->getID() << "\n";
1457  return LINKDIR_PARTRIGHT;
1458  }
1459  if (leftHand) {
1461  } else {
1463  }
1464  }
1465  return LINKDIR_RIGHT;
1466  }
1467  // check whether any other edge goes further to the left
1468  EdgeVector::const_iterator i =
1469  find(myAllEdges.begin(), myAllEdges.end(), outgoing);
1470  if (leftHand) {
1472  } else {
1474  }
1475  while ((*i) != incoming) {
1476  if ((*i)->getFromNode() == this && !incoming->isTurningDirectionAt(*i)) {
1477  //std::cout << incoming->getID() << " -> " << outgoing->getID() << " partLeft because auf " << (*i)->getID() << "\n";
1478  return LINKDIR_PARTLEFT;
1479  }
1480  if (leftHand) {
1482  } else {
1484  }
1485  }
1486  return LINKDIR_LEFT;
1487 }
1488 
1489 
1490 LinkState
1491 NBNode::getLinkState(const NBEdge* incoming, NBEdge* outgoing, int fromlane, int toLane,
1492  bool mayDefinitelyPass, const std::string& tlID) const {
1493  if (tlID != "") {
1495  }
1496  if (outgoing == 0) { // always off
1498  }
1500  return LINKSTATE_EQUAL; // all the same
1501  }
1502  if (myType == NODETYPE_ALLWAY_STOP) {
1503  return LINKSTATE_ALLWAY_STOP; // all drive, first one to arrive may drive first
1504  }
1505  if (myType == NODETYPE_ZIPPER && mustBrake(incoming, outgoing, fromlane, toLane, false)) {
1506  return LINKSTATE_ZIPPER;
1507  }
1508  if ((!incoming->isInnerEdge() && mustBrake(incoming, outgoing, fromlane, toLane, true)) && !mayDefinitelyPass) {
1509  return myType == NODETYPE_PRIORITY_STOP ? LINKSTATE_STOP : LINKSTATE_MINOR; // minor road
1510  }
1511  // traffic lights are not regarded here
1512  return LINKSTATE_MAJOR;
1513 }
1514 
1515 
1516 bool
1518  // check whether this node is included in a traffic light or crossing
1519  if (myTrafficLights.size() != 0 || myCrossings.size() != 0) {
1520  return false;
1521  }
1522  EdgeVector::const_iterator i;
1523  // one in, one out -> just a geometry ...
1524  if (myOutgoingEdges.size() == 1 && myIncomingEdges.size() == 1) {
1525  // ... if types match ...
1526  if (!myIncomingEdges[0]->expandableBy(myOutgoingEdges[0])) {
1527  return false;
1528  }
1529  //
1530  return myIncomingEdges[0]->getTurnDestination(true) != myOutgoingEdges[0];
1531  }
1532  // two in, two out -> may be something else
1533  if (myOutgoingEdges.size() == 2 && myIncomingEdges.size() == 2) {
1534  // check whether the origin nodes of the incoming edges differ
1535  std::set<NBNode*> origSet;
1536  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1537  origSet.insert((*i)->getFromNode());
1538  }
1539  if (origSet.size() < 2) {
1540  return false;
1541  }
1542  // check whether this node is an intermediate node of
1543  // a two-directional street
1544  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1545  // each of the edges must have an opposite direction edge
1546  NBEdge* opposite = (*i)->getTurnDestination(true);
1547  if (opposite != 0) {
1548  // the other outgoing edges must be the continuation of the current
1549  NBEdge* continuation = opposite == myOutgoingEdges.front() ? myOutgoingEdges.back() : myOutgoingEdges.front();
1550  // check whether the types allow joining
1551  if (!(*i)->expandableBy(continuation)) {
1552  return false;
1553  }
1554  } else {
1555  // ok, at least one outgoing edge is not an opposite
1556  // of an incoming one
1557  return false;
1558  }
1559  }
1560  return true;
1561  }
1562  // ok, a real node
1563  return false;
1564 }
1565 
1566 
1567 std::vector<std::pair<NBEdge*, NBEdge*> >
1569  assert(checkIsRemovable());
1570  std::vector<std::pair<NBEdge*, NBEdge*> > ret;
1571  // one in, one out-case
1572  if (myOutgoingEdges.size() == 1 && myIncomingEdges.size() == 1) {
1573  ret.push_back(
1574  std::pair<NBEdge*, NBEdge*>(
1576  return ret;
1577  }
1578  // two in, two out-case
1579  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1580  // join with the edge that is not a turning direction
1581  NBEdge* opposite = (*i)->getTurnDestination(true);
1582  assert(opposite != 0);
1583  NBEdge* continuation = opposite == myOutgoingEdges.front() ? myOutgoingEdges.back() : myOutgoingEdges.front();
1584  ret.push_back(std::pair<NBEdge*, NBEdge*>(*i, continuation));
1585  }
1586  return ret;
1587 }
1588 
1589 
1590 const PositionVector&
1592  return myPoly;
1593 }
1594 
1595 
1596 void
1598  myPoly = shape;
1599  myHaveCustomPoly = (myPoly.size() > 1);
1600 }
1601 
1602 
1603 void
1604 NBNode::setCustomLaneShape(const std::string& laneID, const PositionVector& shape) {
1605  if (shape.size() > 1) {
1606  myCustomLaneShapes[laneID] = shape;
1607  } else {
1608  myCustomLaneShapes.erase(laneID);
1609  }
1610 }
1611 
1612 
1613 NBEdge*
1615  for (EdgeVector::const_iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1616  if ((*i)->getToNode() == n) {
1617  return (*i);
1618  }
1619  }
1620  return 0;
1621 }
1622 
1623 
1624 bool
1626  if (isDistrict()) {
1627  return false;
1628  }
1629  EdgeVector edges;
1630  copy(getIncomingEdges().begin(), getIncomingEdges().end(),
1631  back_inserter(edges));
1632  copy(getOutgoingEdges().begin(), getOutgoingEdges().end(),
1633  back_inserter(edges));
1634  for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
1635  NBEdge* t = *j;
1636  NBNode* other = 0;
1637  if (t->getToNode() == this) {
1638  other = t->getFromNode();
1639  } else {
1640  other = t->getToNode();
1641  }
1642  EdgeVector edges2;
1643  copy(other->getIncomingEdges().begin(), other->getIncomingEdges().end(), back_inserter(edges2));
1644  copy(other->getOutgoingEdges().begin(), other->getOutgoingEdges().end(), back_inserter(edges2));
1645  for (EdgeVector::const_iterator k = edges2.begin(); k != edges2.end(); ++k) {
1646  if ((*k)->getFromNode()->isDistrict() || (*k)->getToNode()->isDistrict()) {
1647  return true;
1648  }
1649  }
1650  }
1651  return false;
1652 }
1653 
1654 
1655 bool
1657  return myType == NODETYPE_DISTRICT;
1658 }
1659 
1660 
1661 int
1663  //gDebugFlag1 = getID() == DEBUGID;
1664  int numGuessed = 0;
1665  if (myCrossings.size() > 0 || myDiscardAllCrossings) {
1666  // user supplied crossings, do not guess
1667  return numGuessed;
1668  }
1669  if (gDebugFlag1) {
1670  std::cout << "guess crossings for " << getID() << "\n";
1671  }
1673  // check for pedestrial lanes going clockwise around the node
1674  std::vector<std::pair<NBEdge*, bool> > normalizedLanes;
1675  for (EdgeVector::const_iterator it = allEdges.begin(); it != allEdges.end(); ++it) {
1676  NBEdge* edge = *it;
1677  const std::vector<NBEdge::Lane>& lanes = edge->getLanes();
1678  if (edge->getFromNode() == this) {
1679  for (std::vector<NBEdge::Lane>::const_reverse_iterator it_l = lanes.rbegin(); it_l != lanes.rend(); ++it_l) {
1680  normalizedLanes.push_back(std::make_pair(edge, ((*it_l).permissions & SVC_PEDESTRIAN) != 0));
1681  }
1682  } else {
1683  for (std::vector<NBEdge::Lane>::const_iterator it_l = lanes.begin(); it_l != lanes.end(); ++it_l) {
1684  normalizedLanes.push_back(std::make_pair(edge, ((*it_l).permissions & SVC_PEDESTRIAN) != 0));
1685  }
1686  }
1687  }
1688  // do we even have a pedestrian lane?
1689  int firstSidewalk = -1;
1690  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
1691  if (normalizedLanes[i].second) {
1692  firstSidewalk = i;
1693  break;
1694  }
1695  }
1696  int hadCandidates = 0;
1697  std::vector<int> connectedCandidates; // number of crossings that were built for each connected candidate
1698  if (firstSidewalk != -1) {
1699  // rotate lanes to ensure that the first one allows pedestrians
1700  std::vector<std::pair<NBEdge*, bool> > tmp;
1701  copy(normalizedLanes.begin() + firstSidewalk, normalizedLanes.end(), std::back_inserter(tmp));
1702  copy(normalizedLanes.begin(), normalizedLanes.begin() + firstSidewalk, std::back_inserter(tmp));
1703  normalizedLanes = tmp;
1704  // find candidates
1705  EdgeVector candidates;
1706  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
1707  NBEdge* edge = normalizedLanes[i].first;
1708  const bool allowsPed = normalizedLanes[i].second;
1709  if (gDebugFlag1) {
1710  std::cout << " cands=" << toString(candidates) << " edge=" << edge->getID() << " allowsPed=" << allowsPed << "\n";
1711  }
1712  if (!allowsPed && (candidates.size() == 0 || candidates.back() != edge)) {
1713  candidates.push_back(edge);
1714  } else if (allowsPed) {
1715  if (candidates.size() > 0) {
1716  if (hadCandidates > 0 || forbidsPedestriansAfter(normalizedLanes, i)) {
1717  hadCandidates++;
1718  const int n = checkCrossing(candidates);
1719  numGuessed += n;
1720  if (n > 0) {
1721  connectedCandidates.push_back(n);
1722  }
1723  }
1724  candidates.clear();
1725  }
1726  }
1727  }
1728  if (hadCandidates > 0 && candidates.size() > 0) {
1729  // avoid wrapping around to the same sidewalk
1730  hadCandidates++;
1731  const int n = checkCrossing(candidates);
1732  numGuessed += n;
1733  if (n > 0) {
1734  connectedCandidates.push_back(n);
1735  }
1736  }
1737  }
1738  // Avoid duplicate crossing between the same pair of walkingareas
1739  if (gDebugFlag1) {
1740  std::cout << " hadCandidates=" << hadCandidates << " connectedCandidates=" << toString(connectedCandidates) << "\n";
1741  }
1742  if (hadCandidates == 2 && connectedCandidates.size() == 2) {
1743  // One or both of them might be split: remove the one with less splits
1744  if (connectedCandidates.back() <= connectedCandidates.front()) {
1745  numGuessed -= connectedCandidates.back();
1746  myCrossings.erase(myCrossings.end() - connectedCandidates.back(), myCrossings.end());
1747  } else {
1748  numGuessed -= connectedCandidates.front();
1749  myCrossings.erase(myCrossings.begin(), myCrossings.begin() + connectedCandidates.front());
1750  }
1751  }
1753  if (gDebugFlag1) {
1754  std::cout << "guessedCrossings:\n";
1755  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); it++) {
1756  std::cout << " edges=" << toString((*it).edges) << "\n";
1757  }
1758  }
1759  return numGuessed;
1760 }
1761 
1762 
1763 int
1765  if (gDebugFlag1) {
1766  std::cout << "checkCrossing candidates=" << toString(candidates) << "\n";
1767  }
1768  if (candidates.size() == 0) {
1769  if (gDebugFlag1) {
1770  std::cout << "no crossing added (numCandidates=" << candidates.size() << ")\n";
1771  }
1772  return 0;
1773  } else {
1774  // check whether the edges may be part of a common crossing due to having similar angle
1775  SUMOReal prevAngle = -100000; // dummy
1776  for (size_t i = 0; i < candidates.size(); ++i) {
1777  NBEdge* edge = candidates[i];
1778  SUMOReal angle = edge->getCrossingAngle(this);
1779  // edges should be sorted by angle but this only holds true approximately
1780  if (i > 0 && fabs(angle - prevAngle) > EXTEND_CROSSING_ANGLE_THRESHOLD) {
1781  if (gDebugFlag1) {
1782  std::cout << "no crossing added (found angle difference of " << fabs(angle - prevAngle) << " at i=" << i << "\n";
1783  }
1784  return 0;
1785  }
1786  if (!isTLControlled() && edge->getSpeed() > OptionsCont::getOptions().getFloat("crossings.guess.speed-threshold")) {
1787  if (gDebugFlag1) {
1788  std::cout << "no crossing added (uncontrolled, edge with speed=" << edge->getSpeed() << ")\n";
1789  }
1790  return 0;
1791  }
1792  prevAngle = angle;
1793  }
1794  if (candidates.size() == 1) {
1796  if (gDebugFlag1) {
1797  std::cout << "adding crossing: " << toString(candidates) << "\n";
1798  }
1799  return 1;
1800  } else {
1801  // check for intermediate walking areas
1802  SUMOReal prevAngle = -100000; // dummy
1803  for (EdgeVector::iterator it = candidates.begin(); it != candidates.end(); ++it) {
1804  SUMOReal angle = (*it)->getCrossingAngle(this);
1805  if (it != candidates.begin()) {
1806  NBEdge* prev = *(it - 1);
1807  NBEdge* curr = *it;
1808  Position prevPos, currPos;
1809  unsigned int laneI;
1810  // compute distance between candiate edges
1811  SUMOReal intermediateWidth = 0;
1812  if (prev->getToNode() == this) {
1813  laneI = prev->getNumLanes() - 1;
1814  prevPos = prev->getLanes()[laneI].shape[-1];
1815  } else {
1816  laneI = 0;
1817  prevPos = prev->getLanes()[laneI].shape[0];
1818  }
1819  intermediateWidth -= 0.5 * prev->getLaneWidth(laneI);
1820  if (curr->getFromNode() == this) {
1821  laneI = curr->getNumLanes() - 1;
1822  currPos = curr->getLanes()[laneI].shape[0];
1823  } else {
1824  laneI = 0;
1825  currPos = curr->getLanes()[laneI].shape[-1];
1826  }
1827  intermediateWidth -= 0.5 * curr->getLaneWidth(laneI);
1828  intermediateWidth += currPos.distanceTo2D(prevPos);
1829  if (gDebugFlag1) {
1830  std::cout
1831  << " prevAngle=" << prevAngle
1832  << " angle=" << angle
1833  << " intermediateWidth=" << intermediateWidth
1834  << "\n";
1835  }
1836  if (fabs(prevAngle - angle) > SPLIT_CROSSING_ANGLE_THRESHOLD
1837  || (intermediateWidth > SPLIT_CROSSING_WIDTH_THRESHOLD)) {
1838  return checkCrossing(EdgeVector(candidates.begin(), it))
1839  + checkCrossing(EdgeVector(it, candidates.end()));
1840  }
1841  }
1842  prevAngle = angle;
1843  }
1845  if (gDebugFlag1) {
1846  std::cout << "adding crossing: " << toString(candidates) << "\n";
1847  }
1848  return 1;
1849  }
1850  }
1851 }
1852 
1853 
1854 bool
1855 NBNode::forbidsPedestriansAfter(std::vector<std::pair<NBEdge*, bool> > normalizedLanes, int startIndex) {
1856  for (int i = startIndex; i < (int)normalizedLanes.size(); ++i) {
1857  if (!normalizedLanes[i].second) {
1858  return true;
1859  }
1860  }
1861  return false;
1862 }
1863 
1864 
1865 void
1867  buildCrossings();
1868  buildWalkingAreas(OptionsCont::getOptions().getInt("junctions.corner-detail"));
1869  // ensure that all crossings are properly connected
1870  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
1871  if ((*it).prevWalkingArea == "" || (*it).nextWalkingArea == "") {
1872  WRITE_WARNING("Discarding invalid crossing '" + (*it).id + "' at junction '" + getID() + "' with edges '" + toString((*it).edges) + "'.");
1873  for (std::vector<WalkingArea>::iterator it_wa = myWalkingAreas.begin(); it_wa != myWalkingAreas.end(); it_wa++) {
1874  if ((*it_wa).nextCrossing == (*it).id) {
1875  (*it_wa).nextCrossing = "";
1876  }
1877  }
1878  it = myCrossings.erase(it);
1879  } else {
1880  ++it;
1881  }
1882  }
1883 }
1884 
1885 
1886 void
1888  // build inner edges for vehicle movements across the junction
1889  unsigned int noInternalNoSplits = 0;
1890  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1891  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
1892  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
1893  if ((*k).toEdge == 0) {
1894  continue;
1895  }
1896  noInternalNoSplits++;
1897  }
1898  }
1899  unsigned int lno = 0;
1900  unsigned int splitNo = 0;
1901  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1902  (*i)->buildInnerEdges(*this, noInternalNoSplits, lno, splitNo);
1903  }
1904  // if there are custom lane shapes we need to built twice:
1905  // first to set the ids then to build intersections with the custom geometries
1906  if (myCustomLaneShapes.size() > 0) {
1907  unsigned int lno = 0;
1908  unsigned int splitNo = 0;
1909  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1910  (*i)->buildInnerEdges(*this, noInternalNoSplits, lno, splitNo);
1911  }
1912  }
1913 }
1914 
1915 
1916 unsigned int
1918  //gDebugFlag1 = getID() == DEBUGID;
1919  if (gDebugFlag1) {
1920  std::cout << "build crossings for " << getID() << ":\n";
1921  }
1922  if (myDiscardAllCrossings) {
1923  myCrossings.clear();
1924  }
1925  unsigned int index = 0;
1926  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
1927  (*it).id = ":" + getID() + "_c" + toString(index++);
1928  // reset fields, so repeated computation (Netedit) will sucessfully perform the checks
1929  // in buildWalkingAreas (split crossings) and buildInnerEdges (sanity check)
1930  (*it).nextWalkingArea = "";
1931  (*it).prevWalkingArea = "";
1932  EdgeVector& edges = (*it).edges;
1933  if (gDebugFlag1) {
1934  std::cout << " crossing=" << (*it).id << " edges=" << toString(edges);
1935  }
1936  // sorting the edges in the right way is imperative. We want to sort
1937  // them by getAngleAtNodeToCenter() but need to be extra carefull to avoid wrapping around 0 somewhere in between
1938  std::sort(edges.begin(), edges.end(), NBContHelper::edge_by_angle_to_nodeShapeCentroid_sorter(this));
1939  if (gDebugFlag1) {
1940  std::cout << " sortedEdges=" << toString(edges) << "\n";
1941  };
1942  // rotate the edges so that the largest relative angle difference comes at the end
1943  SUMOReal maxAngleDiff = 0;
1944  int maxAngleDiffIndex = 0; // index before maxDist
1945  for (int i = 0; i < (int) edges.size(); i++) {
1946  SUMOReal diff = NBHelpers::relAngle(edges[i]->getAngleAtNodeToCenter(this),
1947  edges[(i + 1) % edges.size()]->getAngleAtNodeToCenter(this));
1948  if (diff < 0) {
1949  diff += 360;
1950  }
1951  if (gDebugFlag1) {
1952  std::cout << " i=" << i << " a1=" << edges[i]->getAngleAtNodeToCenter(this) << " a2=" << edges[(i + 1) % edges.size()]->getAngleAtNodeToCenter(this) << " diff=" << diff << "\n";
1953  }
1954  if (diff > maxAngleDiff) {
1955  maxAngleDiff = diff;
1956  maxAngleDiffIndex = i;
1957  }
1958  }
1959  if (maxAngleDiff > 2 && maxAngleDiff < 360 - 2) {
1960  // if the angle differences is too small, we better not rotate
1961  std::rotate(edges.begin(), edges.begin() + (maxAngleDiffIndex + 1) % edges.size(), edges.end());
1962  if (gDebugFlag1) {
1963  std::cout << " rotatedEdges=" << toString(edges);
1964  }
1965  }
1966  // reverse to get them in CCW order (walking direction around the node)
1967  std::reverse(edges.begin(), edges.end());
1968  if (gDebugFlag1) {
1969  std::cout << " finalEdges=" << toString(edges) << "\n";
1970  }
1971  // compute shape
1972  (*it).shape.clear();
1973  const int begDir = (edges.front()->getFromNode() == this ? FORWARD : BACKWARD);
1974  const int endDir = (edges.back()->getToNode() == this ? FORWARD : BACKWARD);
1975  if (edges.front()->getFirstNonPedestrianLaneIndex(begDir) < 0
1976  || edges.back()->getFirstNonPedestrianLaneIndex(endDir) < 0) {
1977  // invalid crossing
1978  WRITE_WARNING("Discarding invalid crossing '" + (*it).id + "' at junction '" + getID() + "' with edges '" + toString((*it).edges) + "'.");
1979  it = myCrossings.erase(it);
1980  } else {
1981  NBEdge::Lane crossingBeg = edges.front()->getFirstNonPedestrianLane(begDir);
1982  NBEdge::Lane crossingEnd = edges.back()->getFirstNonPedestrianLane(endDir);
1983  crossingBeg.width = (crossingBeg.width == NBEdge::UNSPECIFIED_WIDTH ? SUMO_const_laneWidth : crossingBeg.width);
1984  crossingEnd.width = (crossingEnd.width == NBEdge::UNSPECIFIED_WIDTH ? SUMO_const_laneWidth : crossingEnd.width);
1985  crossingBeg.shape.move2side(begDir * crossingBeg.width / 2);
1986  crossingEnd.shape.move2side(endDir * crossingEnd.width / 2);
1987  crossingBeg.shape.extrapolate((*it).width / 2);
1988  crossingEnd.shape.extrapolate((*it).width / 2);
1989  (*it).shape.push_back(crossingBeg.shape[begDir == FORWARD ? 0 : -1]);
1990  (*it).shape.push_back(crossingEnd.shape[endDir == FORWARD ? -1 : 0]);
1991  ++it;
1992  }
1993  }
1994  return index;
1995 }
1996 
1997 
1998 void
1999 NBNode::buildWalkingAreas(int cornerDetail) {
2000  //gDebugFlag1 = getID() == DEBUGID;
2001  unsigned int index = 0;
2002  myWalkingAreas.clear();
2003  if (gDebugFlag1) {
2004  std::cout << "build walkingAreas for " << getID() << ":\n";
2005  }
2006  if (myAllEdges.size() == 0) {
2007  return;
2008  }
2010  // shapes are all pointing away from the intersection
2011  std::vector<std::pair<NBEdge*, NBEdge::Lane> > normalizedLanes;
2012  for (EdgeVector::const_iterator it = allEdges.begin(); it != allEdges.end(); ++it) {
2013  NBEdge* edge = *it;
2014  const std::vector<NBEdge::Lane>& lanes = edge->getLanes();
2015  if (edge->getFromNode() == this) {
2016  for (std::vector<NBEdge::Lane>::const_reverse_iterator it_l = lanes.rbegin(); it_l != lanes.rend(); ++it_l) {
2017  NBEdge::Lane l = *it_l;
2018  l.shape = l.shape.getSubpartByIndex(0, 2);
2020  normalizedLanes.push_back(std::make_pair(edge, l));
2021  }
2022  } else {
2023  for (std::vector<NBEdge::Lane>::const_iterator it_l = lanes.begin(); it_l != lanes.end(); ++it_l) {
2024  NBEdge::Lane l = *it_l;
2025  l.shape = l.shape.reverse();
2026  l.shape = l.shape.getSubpartByIndex(0, 2);
2028  normalizedLanes.push_back(std::make_pair(edge, l));
2029  }
2030  }
2031  }
2032  //if (gDebugFlag1) std::cout << " normalizedLanes=" << normalizedLanes.size() << "\n";
2033  // collect [start,count[ indices in normalizedLanes that belong to a walkingArea
2034  std::vector<std::pair<int, int> > waIndices;
2035  int start = -1;
2036  NBEdge* prevEdge = normalizedLanes.back().first;
2037  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
2038  NBEdge* edge = normalizedLanes[i].first;
2039  NBEdge::Lane& l = normalizedLanes[i].second;
2040  if (start == -1) {
2041  if ((l.permissions & SVC_PEDESTRIAN) != 0) {
2042  start = i;
2043  }
2044  } else {
2045  if ((l.permissions & SVC_PEDESTRIAN) == 0 || crossingBetween(edge, prevEdge)) {
2046  waIndices.push_back(std::make_pair(start, i - start));
2047  if ((l.permissions & SVC_PEDESTRIAN) != 0) {
2048  start = i;
2049  } else {
2050  start = -1;
2051  }
2052 
2053  }
2054  }
2055  if (gDebugFlag1) std::cout << " i=" << i << " edge=" << edge->getID() << " start=" << start << " ped=" << ((l.permissions & SVC_PEDESTRIAN) != 0)
2056  << " waI=" << waIndices.size() << " crossingBetween=" << crossingBetween(edge, prevEdge) << "\n";
2057  prevEdge = edge;
2058  }
2059  // deal with wrap-around issues
2060  if (start != - 1) {
2061  const int waNumLanes = (int)normalizedLanes.size() - start;
2062  if (waIndices.size() == 0) {
2063  waIndices.push_back(std::make_pair(start, waNumLanes));
2064  if (gDebugFlag1) {
2065  std::cout << " single wa, end at wrap-around\n";
2066  }
2067  } else {
2068  if (waIndices.front().first == 0) {
2069  NBEdge* edge = normalizedLanes.front().first;
2070  NBEdge* prevEdge = normalizedLanes.back().first;
2071  if (crossingBetween(edge, prevEdge)) {
2072  // do not wrap-around if there is a crossing in between
2073  waIndices.push_back(std::make_pair(start, waNumLanes));
2074  if (gDebugFlag1) {
2075  std::cout << " do not wrap around, turn-around in between\n";
2076  }
2077  } else {
2078  // first walkingArea wraps around
2079  waIndices.front().first = start;
2080  waIndices.front().second = waNumLanes + waIndices.front().second;
2081  if (gDebugFlag1) {
2082  std::cout << " wrapping around\n";
2083  }
2084  }
2085  } else {
2086  // last walkingArea ends at the wrap-around
2087  waIndices.push_back(std::make_pair(start, waNumLanes));
2088  if (gDebugFlag1) {
2089  std::cout << " end at wrap-around\n";
2090  }
2091  }
2092  }
2093  }
2094  if (gDebugFlag1) {
2095  std::cout << " normalizedLanes=" << normalizedLanes.size() << " waIndices:\n";
2096  for (int i = 0; i < (int)waIndices.size(); ++i) {
2097  std::cout << " " << waIndices[i].first << ", " << waIndices[i].second << "\n";
2098  }
2099  }
2100  // build walking areas connected to a sidewalk
2101  for (int i = 0; i < (int)waIndices.size(); ++i) {
2102  const bool buildExtensions = waIndices[i].second != (int)normalizedLanes.size();
2103  const int start = waIndices[i].first;
2104  const int prev = start > 0 ? start - 1 : (int)normalizedLanes.size() - 1;
2105  const int count = waIndices[i].second;
2106  const int end = (start + count) % normalizedLanes.size();
2107 
2108  WalkingArea wa(":" + getID() + "_w" + toString(index++), 1);
2109  if (gDebugFlag1) {
2110  std::cout << "build walkingArea " << wa.id << " start=" << start << " end=" << end << " count=" << count << " prev=" << prev << ":\n";
2111  }
2112  SUMOReal endCrossingWidth = 0;
2113  SUMOReal startCrossingWidth = 0;
2114  PositionVector endCrossingShape;
2115  PositionVector startCrossingShape;
2116  // check for connected crossings
2117  bool connectsCrossing = false;
2118  std::vector<Position> connectedPoints;
2119  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2120  if (gDebugFlag1) {
2121  std::cout << " crossing=" << (*it).id << " sortedEdges=" << toString((*it).edges) << "\n";
2122  }
2123  if ((*it).edges.back() == normalizedLanes[end].first
2124  && (normalizedLanes[end].second.permissions & SVC_PEDESTRIAN) == 0) {
2125  // crossing ends
2126  if ((*it).nextWalkingArea != "") {
2127  WRITE_WARNING("Invalid pedestrian topology at junction '" + getID()
2128  + "'; crossing '" + (*it).id
2129  + "' targets '" + (*it).nextWalkingArea
2130  + "' and '" + wa.id + "'.");
2131  }
2132  (*it).nextWalkingArea = wa.id;
2133  endCrossingWidth = (*it).width;
2134  endCrossingShape = (*it).shape;
2135  wa.width = MAX2(wa.width, endCrossingWidth);
2136  connectsCrossing = true;
2137  connectedPoints.push_back((*it).shape[-1]);
2138  if (gDebugFlag1) {
2139  std::cout << " crossing " << (*it).id << " ends\n";
2140  }
2141  }
2142  if ((*it).edges.front() == normalizedLanes[prev].first
2143  && (normalizedLanes[prev].second.permissions & SVC_PEDESTRIAN) == 0) {
2144  // crossing starts
2145  if ((*it).prevWalkingArea != "") {
2146  WRITE_WARNING("Invalid pedestrian topology at junction '" + getID()
2147  + "'; crossing '" + (*it).id
2148  + "' is targeted by '" + (*it).prevWalkingArea
2149  + "' and '" + wa.id + "'.");
2150  }
2151  (*it).prevWalkingArea = wa.id;
2152  wa.nextCrossing = (*it).id;
2153  startCrossingWidth = (*it).width;
2154  startCrossingShape = (*it).shape;
2155  wa.width = MAX2(wa.width, startCrossingWidth);
2156  connectsCrossing = true;
2157  connectedPoints.push_back((*it).shape[0]);
2158  if (gDebugFlag1) {
2159  std::cout << " crossing " << (*it).id << " starts\n";
2160  }
2161  }
2162  if (gDebugFlag1) std::cout << " check connections to crossing " << (*it).id
2163  << " cFront=" << (*it).edges.front()->getID() << " cBack=" << (*it).edges.back()->getID()
2164  << " wEnd=" << normalizedLanes[end].first->getID() << " wStart=" << normalizedLanes[start].first->getID()
2165  << " wStartPrev=" << normalizedLanes[prev].first->getID()
2166  << "\n";
2167  }
2168  if (count < 2 && !connectsCrossing) {
2169  // not relevant for walking
2170  continue;
2171  }
2172  // build shape and connections
2173  std::set<NBEdge*> connected;
2174  for (int j = 0; j < count; ++j) {
2175  const int nlI = (start + j) % normalizedLanes.size();
2176  NBEdge* edge = normalizedLanes[nlI].first;
2177  NBEdge::Lane l = normalizedLanes[nlI].second;
2178  wa.width = MAX2(wa.width, l.width);
2179  if (connected.count(edge) == 0) {
2180  if (edge->getFromNode() == this) {
2181  wa.nextSidewalks.push_back(edge->getID());
2182  connectedPoints.push_back(edge->getLaneShape(0)[0]);
2183  } else {
2184  wa.prevSidewalks.push_back(edge->getID());
2185  connectedPoints.push_back(edge->getLaneShape(0)[-1]);
2186  }
2187  connected.insert(edge);
2188  }
2189  l.shape.move2side(-l.width / 2);
2190  wa.shape.push_back(l.shape[0]);
2191  l.shape.move2side(l.width);
2192  wa.shape.push_back(l.shape[0]);
2193  }
2194  if (buildExtensions) {
2195  // extension at starting crossing
2196  if (startCrossingShape.size() > 0) {
2197  if (gDebugFlag1) {
2198  std::cout << " extension at startCrossing shape=" << startCrossingShape << "\n";
2199  }
2200  startCrossingShape.move2side(startCrossingWidth / 2);
2201  wa.shape.push_front_noDoublePos(startCrossingShape[0]); // right corner
2202  startCrossingShape.move2side(-startCrossingWidth);
2203  wa.shape.push_front_noDoublePos(startCrossingShape[0]); // left corner goes first
2204  }
2205  // extension at ending crossing
2206  if (endCrossingShape.size() > 0) {
2207  if (gDebugFlag1) {
2208  std::cout << " extension at endCrossing shape=" << endCrossingShape << "\n";
2209  }
2210  endCrossingShape.move2side(endCrossingWidth / 2);
2211  wa.shape.push_back_noDoublePos(endCrossingShape[-1]);
2212  endCrossingShape.move2side(-endCrossingWidth);
2213  wa.shape.push_back_noDoublePos(endCrossingShape[-1]);
2214  }
2215  }
2216  if (connected.size() == 2 && !connectsCrossing && wa.nextSidewalks.size() == 1 && wa.prevSidewalks.size() == 1) {
2217  // do not build a walkingArea since a normal connection exists
2218  NBEdge* e1 = *connected.begin();
2219  NBEdge* e2 = *(++connected.begin());
2220  if (e1->hasConnectionTo(e2, 0, 0) || e2->hasConnectionTo(e1, 0, 0)) {
2221  continue;
2222  }
2223  }
2224  // build smooth inner curve (optional)
2225  if (cornerDetail > 0) {
2226  int smoothEnd = end;
2227  int smoothPrev = prev;
2228  // extend to green verge
2229  if (endCrossingWidth > 0 && normalizedLanes[smoothEnd].second.permissions == 0) {
2230  smoothEnd = (smoothEnd + 1) % normalizedLanes.size();
2231  }
2232  if (startCrossingWidth > 0 && normalizedLanes[smoothPrev].second.permissions == 0) {
2233  if (smoothPrev == 0) {
2234  smoothPrev = (int)normalizedLanes.size() - 1;
2235  } else {
2236  smoothPrev--;
2237  }
2238  }
2239  PositionVector begShape = normalizedLanes[smoothEnd].second.shape;
2240  begShape = begShape.reverse();
2241  //begShape.extrapolate(endCrossingWidth);
2242  begShape.move2side(normalizedLanes[smoothEnd].second.width / 2);
2243  PositionVector endShape = normalizedLanes[smoothPrev].second.shape;
2244  endShape.move2side(normalizedLanes[smoothPrev].second.width / 2);
2245  //endShape.extrapolate(startCrossingWidth);
2246  PositionVector curve = computeSmoothShape(begShape, endShape, cornerDetail + 2, false, 25, 25);
2247  if (gDebugFlag1) std::cout
2248  << " end=" << smoothEnd << " prev=" << smoothPrev
2249  << " endCrossingWidth=" << endCrossingWidth << " startCrossingWidth=" << startCrossingWidth
2250  << " begShape=" << begShape << " endShape=" << endShape << " smooth curve=" << curve << "\n";
2251  if (curve.size() > 2) {
2252  curve.erase(curve.begin());
2253  curve.pop_back();
2254  if (endCrossingWidth > 0) {
2255  wa.shape.pop_back();
2256  }
2257  if (startCrossingWidth > 0) {
2258  wa.shape.erase(wa.shape.begin());
2259  }
2260  wa.shape.append(curve, 0);
2261  }
2262  }
2263  // determine length (average of all possible connections)
2264  SUMOReal lengthSum = 0;
2265  int combinations = 0;
2266  for (std::vector<Position>::const_iterator it1 = connectedPoints.begin(); it1 != connectedPoints.end(); ++it1) {
2267  for (std::vector<Position>::const_iterator it2 = connectedPoints.begin(); it2 != connectedPoints.end(); ++it2) {
2268  const Position& p1 = *it1;
2269  const Position& p2 = *it2;
2270  if (p1 != p2) {
2271  lengthSum += p1.distanceTo2D(p2);
2272  combinations += 1;
2273  }
2274  }
2275  }
2276  if (gDebugFlag1) {
2277  std::cout << " combinations=" << combinations << " connectedPoints=" << connectedPoints << "\n";
2278  }
2279  wa.length = POSITION_EPS;
2280  if (combinations > 0) {
2281  wa.length = MAX2(POSITION_EPS, lengthSum / combinations);
2282  }
2283  myWalkingAreas.push_back(wa);
2284  }
2285  // build walkingAreas between split crossings
2286  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2287  Crossing& prev = *it;
2288  Crossing& next = (it != myCrossings.begin() ? * (it - 1) : * (myCrossings.end() - 1));
2289  if (gDebugFlag1) {
2290  std::cout << " checkIntermediate: prev=" << prev.id << " next=" << next.id << " prev.nextWA=" << prev.nextWalkingArea << "\n";
2291  }
2292  if (prev.nextWalkingArea == "") {
2293  if (next.prevWalkingArea != "") {
2294  WRITE_WARNING("Invalid pedestrian topology: crossing '" + prev.id + "' has no target.");
2295  continue;
2296  }
2297  WalkingArea wa(":" + getID() + "_w" + toString(index++), prev.width);
2298  prev.nextWalkingArea = wa.id;
2299  wa.nextCrossing = next.id;
2300  next.prevWalkingArea = wa.id;
2301  // back of previous crossing
2302  PositionVector tmp = prev.shape;
2303  tmp.move2side(-prev.width / 2);
2304  wa.shape.push_back(tmp[-1]);
2305  tmp.move2side(prev.width);
2306  wa.shape.push_back(tmp[-1]);
2307  // front of next crossing
2308  tmp = next.shape;
2309  tmp.move2side(prev.width / 2);
2310  wa.shape.push_back(tmp[0]);
2311  tmp.move2side(-prev.width);
2312  wa.shape.push_back(tmp[0]);
2313  // length (special case)
2314  wa.length = MAX2(POSITION_EPS, prev.shape.back().distanceTo2D(next.shape.front()));
2315  myWalkingAreas.push_back(wa);
2316  if (gDebugFlag1) {
2317  std::cout << " build wa=" << wa.id << "\n";
2318  }
2319  }
2320  }
2321 }
2322 
2323 
2324 bool
2325 NBNode::crossingBetween(const NBEdge* e1, const NBEdge* e2) const {
2326  if (e1 == e2) {
2327  return false;
2328  }
2329  for (std::vector<Crossing>::const_iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2330  const EdgeVector& edges = (*it).edges;
2331  EdgeVector::const_iterator it1 = find(edges.begin(), edges.end(), e1);
2332  EdgeVector::const_iterator it2 = find(edges.begin(), edges.end(), e2);
2333  if (it1 != edges.end() && it2 != edges.end()) {
2334  return true;
2335  }
2336  }
2337  return false;
2338 }
2339 
2340 
2341 EdgeVector
2342 NBNode::edgesBetween(const NBEdge* e1, const NBEdge* e2) const {
2343  EdgeVector result;
2344  EdgeVector::const_iterator it = find(myAllEdges.begin(), myAllEdges.end(), e1);
2345  assert(it != myAllEdges.end());
2347  EdgeVector::const_iterator it_end = find(myAllEdges.begin(), myAllEdges.end(), e2);
2348  assert(it_end != myAllEdges.end());
2349  while (it != it_end) {
2350  result.push_back(*it);
2352  }
2353  return result;
2354 }
2355 
2356 
2357 bool
2359  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
2360  return true;
2361  }
2362  if (myIncomingEdges.size() == 2 && myOutgoingEdges.size() == 2) {
2363  // check whether the incoming and outgoing edges are pairwise (near) parallel and
2364  // thus the only cross-connections could be turn-arounds
2365  NBEdge* out0 = myOutgoingEdges[0];
2366  NBEdge* out1 = myOutgoingEdges[1];
2367  for (EdgeVector::const_iterator it = myIncomingEdges.begin(); it != myIncomingEdges.end(); ++it) {
2368  NBEdge* inEdge = *it;
2369  SUMOReal angle0 = fabs(NBHelpers::relAngle(inEdge->getAngleAtNode(this), out0->getAngleAtNode(this)));
2370  SUMOReal angle1 = fabs(NBHelpers::relAngle(inEdge->getAngleAtNode(this), out1->getAngleAtNode(this)));
2371  if (MAX2(angle0, angle1) <= 160) {
2372  // neither of the outgoing edges is parallel to inEdge
2373  return false;
2374  }
2375  }
2376  return true;
2377  }
2378  return false;
2379 }
2380 
2381 
2382 void
2386  }
2387 }
2388 
2389 
2390 void
2391 NBNode::addCrossing(EdgeVector edges, SUMOReal width, bool priority, bool fromSumoNet) {
2392  myCrossings.push_back(Crossing(this, edges, width, priority));
2393  if (fromSumoNet) {
2395  }
2396 }
2397 
2398 
2399 void
2401  EdgeSet edgeSet(edges.begin(), edges.end());
2402  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
2403  EdgeSet edgeSet2((*it).edges.begin(), (*it).edges.end());
2404  if (edgeSet == edgeSet2) {
2405  it = myCrossings.erase(it);
2406  } else {
2407  ++it;
2408  }
2409  }
2410 }
2411 
2412 
2413 const NBNode::Crossing&
2414 NBNode::getCrossing(const std::string& id) const {
2415  for (std::vector<Crossing>::const_iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2416  if ((*it).id == id) {
2417  return *it;
2418  }
2419  }
2420  throw ProcessError("Request for unknown crossing '" + id + "'");
2421 }
2422 
2423 
2424 void
2425 NBNode::setCrossingTLIndices(unsigned int startIndex) {
2426  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2427  (*it).tlLinkNo = startIndex++;
2428  }
2429 }
2430 
2431 
2432 int
2434  return myRequest->getSizes().second;
2435 }
2436 
2437 Position
2439  /* Conceptually, the center point would be identical with myPosition.
2440  * However, if the shape is influenced by custom geometry endpoints of the adjoining edges,
2441  * myPosition may fall outside the shape. In this case it is better to use
2442  * the center of the shape
2443  **/
2444  PositionVector tmp = myPoly;
2445  tmp.closePolygon();
2446  //std::cout << getID() << " around=" << tmp.around(myPosition) << " dist=" << tmp.distance(myPosition) << "\n";
2447  if (tmp.size() < 3 || tmp.around(myPosition) || tmp.distance(myPosition) < POSITION_EPS) {
2448  return myPosition;
2449  } else {
2450  return myPoly.getPolygonCenter();
2451  }
2452 }
2453 
2454 
2455 EdgeVector
2457  EdgeVector result = myAllEdges;
2458  if (gDebugFlag1) {
2459  std::cout << " angles:\n";
2460  for (EdgeVector::const_iterator it = result.begin(); it != result.end(); ++it) {
2461  std::cout << " edge=" << (*it)->getID() << " edgeAngle=" << (*it)->getAngleAtNode(this) << " angleToShape=" << (*it)->getAngleAtNodeToCenter(this) << "\n";
2462  }
2463  std::cout << " allEdges before: " << toString(result) << "\n";
2464  }
2465  sort(result.begin(), result.end(), NBContHelper::edge_by_angle_to_nodeShapeCentroid_sorter(this));
2466  // let the first edge in myAllEdges remain the first
2467  if (gDebugFlag1) {
2468  std::cout << " allEdges sorted: " << toString(result) << "\n";
2469  }
2470  rotate(result.begin(), std::find(result.begin(), result.end(), *myAllEdges.begin()), result.end());
2471  if (gDebugFlag1) {
2472  std::cout << " allEdges rotated: " << toString(result) << "\n";
2473  }
2474  return result;
2475 }
2476 
2477 
2478 std::string
2479 NBNode::getNodeIDFromInternalLane(const std::string id) {
2480  // this relies on the fact that internal ids always have the form
2481  // :<nodeID>_<part1>_<part2>
2482  // i.e. :C_3_0, :C_c1_0 :C_w0_0
2483  assert(id[0] == ':');
2484  size_t sep_index = id.rfind('_');
2485  if (sep_index == std::string::npos) {
2486  WRITE_ERROR("Invalid lane id '" + id + "' (missing '_').");
2487  return "";
2488  }
2489  sep_index = id.substr(0, sep_index).rfind('_');
2490  if (sep_index == std::string::npos) {
2491  WRITE_ERROR("Invalid lane id '" + id + "' (missing '_').");
2492  return "";
2493  }
2494  return id.substr(1, sep_index - 1);
2495 }
2496 
2497 
2498 void
2500  // simple case: edges with LANESPREAD_CENTER and a (possible) turndirection at the same node
2501  for (EdgeVector::iterator it = myIncomingEdges.begin(); it != myIncomingEdges.end(); it++) {
2502  NBEdge* edge = *it;
2503  NBEdge* turnDest = edge->getTurnDestination(true);
2504  if (turnDest != 0) {
2505  edge->shiftPositionAtNode(this, turnDest);
2506  turnDest->shiftPositionAtNode(this, edge);
2507  }
2508  }
2509  // @todo: edges in the same direction with sharp angles starting/ending at the same position
2510 }
2511 
2512 
2513 bool
2515  return type == NODETYPE_TRAFFIC_LIGHT
2518 }
2519 
2520 
2521 bool
2522 NBNode::rightOnRedConflict(int index, int foeIndex) const {
2524  for (std::set<NBTrafficLightDefinition*>::const_iterator i = myTrafficLights.begin(); i != myTrafficLights.end(); ++i) {
2525  if ((*i)->rightOnRedConflict(index, foeIndex)) {
2526  return true;
2527  }
2528  }
2529  }
2530  return false;
2531 }
2532 /****************************************************************************/
2533 
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:102
std::string id
Definition: NBEdge.h:181
void sub(SUMOReal dx, SUMOReal dy)
Substracts the given position from this one.
Definition: Position.h:139
The link is a partial left direction.
const PositionVector & getLaneShape(unsigned int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:532
void replaceIncoming(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of incoming by the second Connections are remap...
Definition: NBNode.cpp:993
bool hasConnectionTo(NBEdge *destEdge, unsigned int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
Definition: NBEdge.cpp:806
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges.
Definition: NBNode.h:240
void replaceOutgoing(const EdgeVector &which, NBEdge *const by)
Replaces outgoing edges from the vector (source) by the given edge.
Definition: NBDistrict.cpp:145
Position getEmptyDir() const
Returns something like the most unused direction Should only be used to add source or sink nodes...
Definition: NBNode.cpp:1199
static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle clockwise.
Definition: GeomHelper.cpp:162
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:148
int toLane
The lane the connections yields in.
Definition: NBEdge.h:166
void setRoundabout()
update the type of this node as a roundabout
Definition: NBNode.cpp:2383
std::vector< Crossing > myCrossings
Vector of crossings.
Definition: NBNode.h:751
Position getCenter() const
Returns a position that is guaranteed to lie within the node shape.
Definition: NBNode.cpp:2438
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
SUMOReal width
This lane&#39;s width.
Definition: NBNode.h:143
ApproachingDivider(EdgeVector *approaching, NBEdge *currentOutgoing)
Constructor.
Definition: NBNode.cpp:97
static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle counter-clockwise.
Definition: GeomHelper.cpp:152
SUMOReal distance(const Position &p, bool perpendicular=false) const
PositionVector shape
The lane&#39;s shape.
Definition: NBEdge.h:128
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:49
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
is a pedestrian
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
std::string viaID
Definition: NBEdge.h:186
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:164
#define EXTEND_CROSSING_ANGLE_THRESHOLD
Definition: NBNode.cpp:73
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
Definition: NBAlgorithms.h:120
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset)
patches loaded signal plans by modifying lane indices
Definition: NBNode.cpp:373
std::string id
the (edge)-id of this crossing
Definition: NBNode.h:145
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:119
void norm2d()
Definition: Position.h:158
bool isDistrict() const
Definition: NBNode.cpp:1656
PositionVector myPoly
the (outer) shape of the junction
Definition: NBNode.h:766
NBEdge * getOppositeIncoming(NBEdge *e) const
Definition: NBNode.cpp:1112
void execute(const unsigned int src, const unsigned int dest)
Definition: NBNode.cpp:131
SUMOReal myRadius
the turning radius (for all corners) at this node in m.
Definition: NBNode.h:776
SumoXMLNodeType myType
The type of the junction.
Definition: NBNode.h:757
#define M_PI
Definition: angles.h:37
A container for traffic light definitions and built programs.
SUMOReal length
This lane&#39;s width.
Definition: NBNode.h:171
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:264
SUMOReal width
This lane&#39;s width.
Definition: NBNode.h:169
static SUMOReal normRelAngle(SUMOReal angle1, SUMOReal angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:69
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:304
~NBNode()
Destructor.
Definition: NBNode.cpp:258
Some static methods for string processing.
Definition: StringUtils.h:45
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:441
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:500
int myCrossingsLoadedFromSumoNet
number of crossings loaded from a sumo net
Definition: NBNode.h:787
This class computes shapes of junctions.
This is an uncontrolled, minor link, has to stop.
const Crossing & getCrossing(const std::string &id) const
return the crossing with the given id
Definition: NBNode.cpp:2414
void removeEdge(NBEdge *edge, bool removeFromConnections=true)
Removes edge from this node and optionally removes connections as well.
Definition: NBNode.cpp:1173
SUMOReal getEndAngle() const
Returns the angle at the end of the edge The angle is computed in computeAngle()
Definition: NBEdge.h:387
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition: NBNode.cpp:424
int SVCPermissions
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Definition: NBEdge.h:70
Class to sort edges by their angle in relation to the given edge.
Definition: NBContHelper.h:148
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
The link is a 180 degree turn.
int numNormalConnections() const
return the number of lane-to-lane connections at this junction (excluding crossings) ...
Definition: NBNode.cpp:2433
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition: NBNode.cpp:1106
A container for districts.
The base class for traffic light logic definitions.
EdgeVector edgesBetween(const NBEdge *e1, const NBEdge *e2) const
return all edges that lie clockwise between the given edges
Definition: NBNode.cpp:2342
bool addLane2LaneConnections(unsigned int fromLane, NBEdge *dest, unsigned int toLane, unsigned int no, Lane2LaneInfoType type, bool invalidatePrevious=false, bool mayDefinitelyPass=false)
Builds no connections starting at the given lanes.
Definition: NBEdge.cpp:699
bool isJoinedTLSControlled() const
Returns whether this node is controlled by a tls that spans over more than one node.
Definition: NBNode.cpp:338
void buildBitfieldLogic()
Definition: NBRequest.cpp:156
void removeDoubleEdges()
Definition: NBNode.cpp:1061
T MAX2(T a, T b)
Definition: StdDefs.h:79
SUMOReal getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:447
#define SUMO_MAX_CONNECTIONS
the maximum number of connections across an intersection
Definition: StdDefs.h:42
PositionVector shape
The lane&#39;s shape.
Definition: NBNode.h:141
#define SPLIT_CROSSING_ANGLE_THRESHOLD
Definition: NBNode.cpp:76
PositionVector getSubpartByIndex(int beginIndex, int count) const
void buildWalkingAreas(int cornerDetail)
Definition: NBNode.cpp:1999
bool isInnerEdge() const
Returns whether this edge was marked as being within an intersection.
Definition: NBEdge.h:874
This is an uncontrolled, right-before-left link.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permission is a forbidden edge.
void remapConnections(const EdgeVector &incoming)
Remaps the connection in a way that allows the removal of it.
Definition: NBEdge.cpp:900
std::string id
the (edge)-id of this walkingArea
Definition: NBNode.h:167
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
EdgeVector getEdgesSortedByAngleAtNodeCenter() const
returns the list of all edges sorted clockwise by getAngleAtNodeToCenter
Definition: NBNode.cpp:2456
bool checkIsRemovable() const
Definition: NBNode.cpp:1517
static const SUMOReal UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:207
void mirrorX()
mirror coordinates along the x-axis
Definition: NBNode.cpp:297
bool around(const Position &p, SUMOReal offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point ...
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
Definition: NBNode.cpp:322
void setCustomShape(const PositionVector &shape)
set the junction shape
Definition: NBNode.cpp:1597
The link is controlled by a tls which is off, not blinking, may pass.
static SUMOReal angleDiff(const SUMOReal angle1, const SUMOReal angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:178
NBConnectionProhibits myBlockedConnections
Definition: NBNode.h:760
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
Definition: NBRequest.cpp:325
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition: NBNode.cpp:1100
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
This is an uncontrolled, all-way stop link.
void addOutgoingEdge(NBEdge *edge)
adds an outgoing edge
Definition: NBNode.cpp:434
NBEdge * getFrom() const
returns the from-edge (start of the connection)
unsigned int numAvailableLanes() const
Definition: NBNode.h:116
#define abs(a)
Definition: polyfonts.c:67
This is an uncontrolled, zipper-merge link.
The link is a (hard) left direction.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The connection was computed and validated.
Definition: NBEdge.h:115
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
Definition: NBNode.cpp:1263
PositionVector reverse() const
#define MIN_WEAVE_LENGTH
Definition: NBNode.cpp:79
NBRequest * myRequest
Definition: NBNode.h:771
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
CustomShapeMap myCustomLaneShapes
Definition: NBNode.h:781
The link is a straight direction.
SUMOTime getOffset()
Returns the offset.
PositionVector shape
Definition: NBEdge.h:182
NBDistrict * myDistrict
The district the node is the centre of.
Definition: NBNode.h:763
A class representing a single district.
Definition: NBDistrict.h:72
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges.
Definition: NBNode.h:248
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn&#39;t set.
Definition: NBEdge.h:413
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:122
static bool mustBrakeForCrossing(const NBNode *node, const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing)
Returns the information whether the described flow must brake for the given crossing.
Definition: NBRequest.cpp:749
const std::string & getID() const
Returns the id.
Definition: Named.h:65
EdgeVector myAllEdges
Vector of incoming and outgoing edges.
Definition: NBNode.h:748
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:132
bool needsCont(const NBEdge *fromE, const NBEdge *otherFromE, const NBEdge::Connection &c, const NBEdge::Connection &otherC) const
whether an internal junction should be built at from and respect other
Definition: NBNode.cpp:600
void computeLanes2Lanes()
computes the connections of lanes to edges
Definition: NBNode.cpp:736
void invalidateIncomingConnections()
Definition: NBNode.cpp:1227
bool isConnectedTo(NBEdge *e)
Returns the information whethe a connection to the given edge has been added (or computed) ...
Definition: NBEdge.cpp:812
void push_front_noDoublePos(const Position &p)
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:2400
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:228
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
std::set< NBEdge * > EdgeSet
Definition: NBCont.h:51
Lanes to lanes - relationships are loaded; no recheck is necessary/wished.
Definition: NBEdge.h:102
std::string prevWalkingArea
the lane-id of the previous walkingArea
Definition: NBNode.h:147
NBEdge * getPossiblySplittedIncoming(const std::string &edgeid)
Definition: NBNode.cpp:1147
bool isSimpleContinuation() const
Definition: NBNode.cpp:444
int checkCrossing(EdgeVector candidates)
Definition: NBNode.cpp:1764
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition: NBNode.h:183
std::vector< unsigned int > myAvailableLanes
The available lanes to which connections shall be built.
Definition: NBNode.h:104
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
void mirrorX()
mirror coordinates along the x-axis
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:168
std::string getInternalLaneID() const
Definition: NBEdge.cpp:79
This is an uncontrolled, minor link, has to brake.
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:162
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
bool mustBrakeForCrossing(const NBEdge *const from, const NBEdge *const to, const Crossing &crossing) const
Returns the information whether the described flow must brake for the given crossing.
Definition: NBNode.cpp:1257
A list of positions.
bool mustBrake(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:765
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
void buildCrossingsAndWalkingAreas()
Definition: NBNode.cpp:1866
unsigned int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:345
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:2358
void invalidateOutgoingConnections()
Definition: NBNode.cpp:1235
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
EdgeBuildingStep getStep() const
The building step of this edge.
Definition: NBEdge.h:439
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:1834
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
Definition: NBNode.cpp:329
SUMOReal contPos
custom position for internal junction on this connection
Definition: NBEdge.h:176
EdgeVector * getEdgesThatApproach(NBEdge *currentOutgoing)
Definition: NBNode.cpp:934
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
std::set< NBTrafficLightDefinition * > myTrafficLights
Definition: NBNode.h:773
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition: NBEdge.cpp:2404
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
void setCustomLaneShape(const std::string &laneID, const PositionVector &shape)
sets a custom shape for an internal lane
Definition: NBNode.cpp:1604
T MIN2(T a, T b)
Definition: StdDefs.h:73
void bezier(int npts, SUMOReal b[], int cpts, SUMOReal p[])
Definition: bezier.cpp:99
PositionVector computeSmoothShape(const PositionVector &begShape, const PositionVector &endShape, int numPoints, bool isTurnaround, SUMOReal extrapolateBeg, SUMOReal extrapolateEnd) const
Compute a smooth curve between the given geometries.
Definition: NBNode.cpp:473
std::string nextCrossing
the lane-id of the next crossing
Definition: NBNode.h:175
void setCrossingTLIndices(unsigned int startIndex)
set tl indices of this nodes crossing starting at the given index
Definition: NBNode.cpp:2425
The link is a (hard) right direction.
#define POSITION_EPS
Definition: config.h:188
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1491
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
Definition: NBNode.cpp:2522
bool myDiscardAllCrossings
whether to discard all pedestrian crossings
Definition: NBNode.h:784
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream&#39;s direction.
Definition: NBNode.cpp:1427
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
PositionVector compute()
Computes the shape of the assigned junction.
const PositionVector & getShape() const
retrieve the junction shape
Definition: NBNode.cpp:1591
T ISNAN(T a)
Definition: StdDefs.h:114
The link is a partial right direction.
static void compute(BresenhamCallBack *callBack, const unsigned int val1, const unsigned int val2)
Definition: Bresenham.cpp:45
NBEdge * getConnectionTo(NBNode *n) const
Definition: NBNode.cpp:1614
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector myIncomingEdges
Vector of incoming edges.
Definition: NBNode.h:742
bool isLeftMover(const NBEdge *const from, const NBEdge *const to) const
Computes whether the given connection is a left mover across the junction.
Definition: NBNode.cpp:1310
Base class for objects which have an id.
Definition: Named.h:45
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
Definition: NBNode.cpp:1568
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1261
void avoidOverlap()
fix overlap
Definition: NBNode.cpp:2499
NBEdge * getPossiblySplittedOutgoing(const std::string &edgeid)
Definition: NBNode.cpp:1160
unsigned int removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes edges which are both incoming and outgoing into this node.
Definition: NBNode.cpp:381
EdgeVector myOutgoingEdges
Vector of outgoing edges.
Definition: NBNode.h:745
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:2362
SUMOReal getCrossingAngle(NBNode *node)
return the angle for computing pedestrian crossings at the given node
Definition: NBEdge.cpp:2421
NBEdge * myCurrentOutgoing
The approached current edge.
Definition: NBNode.h:101
static const int BACKWARD
Definition: NBNode.h:184
std::string myID
The name of the object.
Definition: Named.h:133
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:369
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:312
bool isNearDistrict() const
Definition: NBNode.cpp:1625
PositionVector computeInternalLaneShape(NBEdge *fromE, const NBEdge::Connection &con, int numPoints) const
Compute the shape for an internal lane.
Definition: NBNode.cpp:559
bool myHaveCustomPoly
whether this nodes shape was set by the user
Definition: NBNode.h:769
std::vector< int > getConnectionLanes(NBEdge *currentOutgoing) const
Returns the list of lanes that may be used to reach the given edge.
Definition: NBEdge.cpp:874
void addCrossing(EdgeVector edges, SUMOReal width, bool priority, bool fromSumoNet=false)
add a pedestrian crossing to this node
Definition: NBNode.cpp:2391
Position myPosition
The position the node lies at.
Definition: NBNode.h:739
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
void replaceOutgoing(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of outgoing by the second Connections are remap...
Definition: NBNode.cpp:957
PositionVector viaShape
Definition: NBEdge.h:188
SUMOReal angleAt2D(int pos) const
~ApproachingDivider()
Destructor.
Definition: NBNode.cpp:127
std::vector< WalkingArea > myWalkingAreas
Vector of walking areas.
Definition: NBNode.h:754
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
unsigned int buildCrossings()
Definition: NBNode.cpp:1917
bool mustBrake(const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool includePedCrossings) const
Returns the information whether the described flow must let any other flow pass.
Definition: NBNode.cpp:1243
bool myKeepClear
whether the junction area must be kept clear
Definition: NBNode.h:779
void replaceInConnectionProhibitions(NBEdge *which, NBEdge *by, unsigned int whichLaneOff, unsigned int byLaneOff)
Definition: NBNode.cpp:1026
The link is controlled by a tls which is off and blinks, has to brake.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
void buildInnerEdges()
build internal lanes, pedestrian crossings and walking areas
Definition: NBNode.cpp:1887
A definition of a pedestrian walking area.
Definition: NBNode.h:160
EdgeVector * myApproaching
The list of edges that approach the current edge.
Definition: NBNode.h:98
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
A storage for options typed value containers)
Definition: OptionsCont.h:108
static const SUMOReal DEFAULT_CROSSING_WIDTH
default width of pedetrian crossings
Definition: NBNode.h:186
Position intersectionPosition2D(const Position &p1, const Position &p2, const SUMOReal withinDist=0.) const
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
Definition: NBEdgeCont.cpp:380
void replaceInConnections(NBEdge *which, NBEdge *by, unsigned int laneOff)
Definition: NBEdge.cpp:955
This is an uncontrolled, major link, may pass.
void mul(SUMOReal val)
Multiplies both positions with the given value.
Definition: Position.h:99
std::deque< int > * spread(const std::vector< int > &approachingLanes, int dest) const
Definition: NBNode.cpp:156
NBEdge * getTo() const
returns the to-edge (end of the connection)
The connection was computed.
Definition: NBEdge.h:111
bool crossingBetween(const NBEdge *e1, const NBEdge *e2) const
return true if the given edges are connected by a crossing
Definition: NBNode.cpp:2325
Represents a single node (junction) during network building.
Definition: NBNode.h:74
bool removeFully(const std::string id)
Removes a logic definition (and all programs) from the dictionary.
Lane & getLaneStruct(unsigned int lane)
Definition: NBEdge.h:1065
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBRequest.cpp:422
Lanes to lanes - relationships are computed; no recheck is necessary/wished.
Definition: NBEdge.h:100
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
The link is a 180 degree turn (left-hand network)
int guessCrossings()
guess pedestrian crossings and return how many were guessed
Definition: NBNode.cpp:1662
A definition of a pedestrian crossing.
Definition: NBNode.h:132
void move2side(SUMOReal amount)
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
Definition: NBNode.cpp:1130
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:214
Computes lane-2-lane connections.
Definition: NBNode.h:95
static const SUMOReal UNSPECIFIED_RADIUS
unspecified lane width
Definition: NBNode.h:189
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
Definition: NBNode.cpp:694
static SUMOReal relAngle(SUMOReal angle1, SUMOReal angle2)
Definition: NBHelpers.cpp:56
void push_back_noDoublePos(const Position &p)
#define SPLIT_CROSSING_WIDTH_THRESHOLD
Definition: NBNode.cpp:75
void computeLogic(const NBEdgeCont &ec, OptionsCont &oc)
computes the node&#39;s type, logic and traffic light
Definition: NBNode.cpp:645
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:429
SUMOReal getStartAngle() const
Returns the angle at the start of the edge The angle is computed in computeAngle() ...
Definition: NBEdge.h:378
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBNode.cpp:1339
void invalidateTLS(NBTrafficLightLogicCont &tlCont)
causes the traffic light to be computed anew
Definition: NBNode.cpp:352
std::string nextWalkingArea
the lane-id of the next walkingArea
Definition: NBNode.h:149
void closePolygon()
ensures that the last position equals the first
Lanes to edges - relationships are computed/loaded.
Definition: NBEdge.h:96
NBNode(const std::string &id, const Position &position, SumoXMLNodeType type)
Constructor.
Definition: NBNode.cpp:229
void setConnection(unsigned int lane, NBEdge *destEdge, unsigned int destLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, SUMOReal contPos=UNSPECIFIED_CONTPOS)
Adds a connection to a certain lane of a certain edge.
Definition: NBEdge.cpp:716
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:761
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition: NBEdge.cpp:2126
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
std::vector< std::string > prevSidewalks
the lane-id of the previous sidewalk lane or ""
Definition: NBNode.h:179
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:2514
void shiftPositionAtNode(NBNode *node, NBEdge *opposite)
shift geometry at the given node to avoid overlap
Definition: NBEdge.cpp:2504
std::vector< std::string > nextSidewalks
the lane-id of the next sidewalk lane or ""
Definition: NBNode.h:177
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
void reshiftPosition(SUMOReal xoff, SUMOReal yoff)
Applies an offset to the node.
Definition: NBNode.cpp:290
void computeNodeShape(SUMOReal mismatchThreshold)
Compute the junction shape for this node.
Definition: NBNode.cpp:704
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
SUMOReal width
This lane&#39;s width.
Definition: NBEdge.h:138
void extrapolate(const SUMOReal val, const bool onlyFirst=false)
void remapRemoved(NBTrafficLightLogicCont &tc, NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Definition: NBNode.cpp:1346
std::pair< unsigned int, unsigned int > getSizes() const
returns the number of the junction&#39;s lanes and the number of the junction&#39;s links in respect...
Definition: NBRequest.cpp:403
PositionVector shape
The polygonal shape.
Definition: NBNode.h:173
static const Position INVALID
Definition: Position.h:261
void replaceIncoming(const EdgeVector &which, NBEdge *const by)
Replaces incoming edges from the vector (sinks) by the given edge.
Definition: NBDistrict.cpp:113
SUMOReal getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1281
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBNode.cpp:1329
The link has no direction (is a dead end link)
bool forbidsPedestriansAfter(std::vector< std::pair< NBEdge *, bool > > normalizedLanes, int startIndex)
return whether there is a non-sidewalk lane after the given index;
Definition: NBNode.cpp:1855
static bool isLongEnough(NBEdge *out, SUMOReal minLength)
Definition: NBNode.cpp:918
static std::string getNodeIDFromInternalLane(const std::string id)
returns the node id for internal lanes, crossings and walkingareas
Definition: NBNode.cpp:2479
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:361