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-2016 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  for (std::set<NBTrafficLightDefinition*>::const_iterator it = myTrafficLights.begin(); it != myTrafficLights.end(); ++it) {
636  if ((*it)->needsCont(fromE, toE, otherFromE, otherToE)) {
637  return true;
638  }
639  }
640  return false;
641  }
642  if (fromE->getJunctionPriority(this) > 0 && otherFromE->getJunctionPriority(this) > 0) {
643  return mustBrake(fromE, toE, c.fromLane, c.toLane, false);
644  }
645  return false;
646 }
647 
648 
649 void
651  delete myRequest; // possibly recomputation step
652  myRequest = 0;
653  if (myIncomingEdges.size() == 0 || myOutgoingEdges.size() == 0) {
654  // no logic if nothing happens here
656  std::set<NBTrafficLightDefinition*> trafficLights = myTrafficLights; // make a copy because we will modify the original
658  for (std::set<NBTrafficLightDefinition*>::const_iterator i = trafficLights.begin(); i != trafficLights.end(); ++i) {
659  (*i)->setParticipantsInformation();
660  (*i)->setTLControllingInformation();
661  }
662  return;
663  }
664  // check whether the node was set to be unregulated by the user
665  if (oc.getBool("keep-nodes-unregulated") || oc.isInStringVector("keep-nodes-unregulated.explicit", getID())
666  || (oc.getBool("keep-nodes-unregulated.district-nodes") && (isNearDistrict() || isDistrict()))) {
668  return;
669  }
670  // compute the logic if necessary or split the junction
672  // build the request
674  // check whether it is not too large
675  unsigned int numConnections = numNormalConnections();
676  if (numConnections >= SUMO_MAX_CONNECTIONS) {
677  // yep -> make it untcontrolled, warn
678  delete myRequest;
679  myRequest = 0;
682  } else {
684  }
685  WRITE_WARNING("Junction '" + getID() + "' is too complicated (" + toString(numConnections)
686  + " connections, max " + toString(SUMO_MAX_CONNECTIONS) + "); will be set to " + toString(myType));
687  } else if (numConnections == 0) {
688  delete myRequest;
689  myRequest = 0;
691  } else {
693  }
694  }
695 }
696 
697 
698 bool
699 NBNode::writeLogic(OutputDevice& into, const bool checkLaneFoes) const {
700  if (myRequest) {
701  myRequest->writeLogic(myID, into, checkLaneFoes);
702  return true;
703  }
704  return false;
705 }
706 
707 
708 void
709 NBNode::computeNodeShape(SUMOReal mismatchThreshold) {
710  if (myHaveCustomPoly) {
711  return;
712  }
713  if (myIncomingEdges.size() == 0 && myOutgoingEdges.size() == 0) {
714  // may be an intermediate step during network editing
715  myPoly.clear();
716  myPoly.push_back(myPosition);
717  return;
718  }
719  try {
720  NBNodeShapeComputer computer(*this);
721  myPoly = computer.compute();
722  if (myPoly.size() > 0) {
723  PositionVector tmp = myPoly;
724  tmp.push_back_noDoublePos(tmp[0]); // need closed shape
725  if (mismatchThreshold >= 0
726  && !tmp.around(myPosition)
727  && tmp.distance(myPosition) > mismatchThreshold) {
728  WRITE_WARNING("Shape for junction '" + myID + "' has distance " + toString(tmp.distance(myPosition)) + " to its given position");
729  }
730  }
731  } catch (InvalidArgument&) {
732  WRITE_WARNING("For junction '" + getID() + "': could not compute shape.");
733  // make sure our shape is not empty because our XML schema forbids empty attributes
734  myPoly.clear();
735  myPoly.push_back(myPosition);
736  }
737 }
738 
739 
740 void
742  // special case a):
743  // one in, one out, the outgoing has one lane more
744  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
745  NBEdge* in = myIncomingEdges[0];
746  NBEdge* out = myOutgoingEdges[0];
747  // check if it's not the turnaround
748  if (in->getTurnDestination() == out) {
749  // will be added later or not...
750  return;
751  }
752  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
753  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
754  if (in->getStep() <= NBEdge::LANES2EDGES
755  && in->getNumLanes() - inOffset == out->getNumLanes() - outOffset - 1
756  && in != out
757  && in->isConnectedTo(out)) {
758  for (int i = inOffset; i < (int) in->getNumLanes(); ++i) {
759  in->setConnection(i, out, i - inOffset + outOffset + 1, NBEdge::L2L_COMPUTED);
760  }
761  in->setConnection(inOffset, out, outOffset, NBEdge::L2L_COMPUTED);
762  return;
763  }
764  }
765  // special case b):
766  // two in, one out, the outgoing has the same number of lanes as the sum of the incoming
767  // --> highway on-ramp
768  if (myIncomingEdges.size() == 2 && myOutgoingEdges.size() == 1) {
769  NBEdge* out = myOutgoingEdges[0];
770  NBEdge* in1 = myIncomingEdges[0];
771  NBEdge* in2 = myIncomingEdges[1];
772  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
773  int in1Offset = MAX2(0, in1->getFirstNonPedestrianLaneIndex(FORWARD, true));
774  int in2Offset = MAX2(0, in2->getFirstNonPedestrianLaneIndex(FORWARD, true));
775  if (in1->getNumLanes() + in2->getNumLanes() - in1Offset - in2Offset == out->getNumLanes() - outOffset
776  && (in1->getStep() <= NBEdge::LANES2EDGES)
777  && (in2->getStep() <= NBEdge::LANES2EDGES)
778  && in1 != out
779  && in2 != out
780  && in1->isConnectedTo(out)
781  && in2->isConnectedTo(out)
782  && isLongEnough(out, MIN_WEAVE_LENGTH)) {
783  // for internal: check which one is the rightmost
784  SUMOReal a1 = in1->getAngleAtNode(this);
785  SUMOReal a2 = in2->getAngleAtNode(this);
788  if (ccw > cw) {
789  std::swap(in1, in2);
790  std::swap(in1Offset, in2Offset);
791  }
792  in1->addLane2LaneConnections(in1Offset, out, outOffset, in1->getNumLanes() - in1Offset, NBEdge::L2L_VALIDATED, true, true);
793  in2->addLane2LaneConnections(in2Offset, out, in1->getNumLanes() + outOffset - in1Offset, in2->getNumLanes() - in2Offset, NBEdge::L2L_VALIDATED, true, true);
794  return;
795  }
796  }
797  // special case c):
798  // one in, two out, the incoming has the same number of lanes as the sum of the outgoing
799  // --> highway off-ramp
800  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 2) {
801  NBEdge* in = myIncomingEdges[0];
802  NBEdge* out1 = myOutgoingEdges[0];
803  NBEdge* out2 = myOutgoingEdges[1];
804  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
805  int out1Offset = MAX2(0, out1->getFirstNonPedestrianLaneIndex(FORWARD, true));
806  int out2Offset = MAX2(0, out2->getFirstNonPedestrianLaneIndex(FORWARD, true));
807  if (in->getNumLanes() - inOffset == out2->getNumLanes() + out1->getNumLanes() - out1Offset - out2Offset
808  && (in->getStep() <= NBEdge::LANES2EDGES)
809  && in != out1
810  && in != out2
811  && in->isConnectedTo(out1)
812  && in->isConnectedTo(out2)) {
813  // for internal: check which one is the rightmost
814  if (NBContHelper::relative_outgoing_edge_sorter(in)(out2, out1)) {
815  std::swap(out1, out2);
816  std::swap(out1Offset, out2Offset);
817  }
818  in->addLane2LaneConnections(inOffset, out1, out1Offset, out1->getNumLanes() - out1Offset, NBEdge::L2L_VALIDATED, true, true);
819  in->addLane2LaneConnections(out1->getNumLanes() + inOffset - out1Offset, out2, out2Offset, out2->getNumLanes() - out2Offset, NBEdge::L2L_VALIDATED, false, true);
820  return;
821  }
822  }
823  // special case d):
824  // one in, one out, the outgoing has one lane less and node has type 'zipper'
825  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1 && myType == NODETYPE_ZIPPER) {
826  NBEdge* in = myIncomingEdges[0];
827  NBEdge* out = myOutgoingEdges[0];
828  // check if it's not the turnaround
829  if (in->getTurnDestination() == out) {
830  // will be added later or not...
831  return;
832  }
833  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
834  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
835  if (in->getStep() <= NBEdge::LANES2EDGES
836  && in->getNumLanes() - inOffset == out->getNumLanes() - outOffset + 1
837  && in != out
838  && in->isConnectedTo(out)) {
839  for (int i = inOffset; i < (int) in->getNumLanes(); ++i) {
840  in->setConnection(i, out, MIN2(outOffset + i, ((int)out->getNumLanes() - 1)), NBEdge::L2L_COMPUTED, true);
841  }
842  return;
843  }
844  }
845  // special case f):
846  // one in, one out, same number of lanes
847  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
848  NBEdge* in = myIncomingEdges[0];
849  NBEdge* out = myOutgoingEdges[0];
850  // check if it's not the turnaround
851  if (in->getTurnDestination() == out) {
852  // will be added later or not...
853  return;
854  }
855  const int inOffset = MAX2(0, in->getFirstNonPedestrianLaneIndex(FORWARD, true));
856  const int outOffset = MAX2(0, out->getFirstNonPedestrianLaneIndex(FORWARD, true));
857  if (in->getStep() <= NBEdge::LANES2EDGES
858  && in->getNumLanes() - inOffset == out->getNumLanes() - outOffset
859  && in != out
860  && in->isConnectedTo(out)) {
861  for (int i = inOffset; i < (int) in->getNumLanes(); ++i) {
862  in->setConnection(i, out, i - inOffset + outOffset, NBEdge::L2L_COMPUTED);
863  }
864  //std::cout << " special case f at node=" << getID() << " inOffset=" << inOffset << " outOffset=" << outOffset << "\n";
865  return;
866  }
867  }
868 
869  // go through this node's outgoing edges
870  // for every outgoing edge, compute the distribution of the node's
871  // incoming edges on this edge when approaching this edge
872  // the incoming edges' steps will then also be marked as LANE2LANE_RECHECK...
873  EdgeVector::reverse_iterator i;
874  for (i = myOutgoingEdges.rbegin(); i != myOutgoingEdges.rend(); i++) {
875  NBEdge* currentOutgoing = *i;
876  // get the information about edges that do approach this edge
877  EdgeVector* approaching = getEdgesThatApproach(currentOutgoing);
878  const unsigned int numApproaching = (unsigned int)approaching->size();
879  if (numApproaching != 0) {
880  ApproachingDivider divider(approaching, currentOutgoing);
881  Bresenham::compute(&divider, numApproaching, divider.numAvailableLanes());
882  }
883  delete approaching;
884 
885  // ensure that all modes have a connection if possible
886  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
887  NBEdge* incoming = *i;
888  if (incoming->getConnectionLanes(currentOutgoing).size() > 0 && incoming->getStep() <= NBEdge::LANES2LANES_DONE) {
889  // no connections are needed for pedestrians during this step
890  // no satisfaction is possible if the outgoing edge disallows
891  SVCPermissions unsatisfied = incoming->getPermissions() & currentOutgoing->getPermissions() & ~SVC_PEDESTRIAN;
892  //std::cout << "initial unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
893  const std::vector<NBEdge::Connection>& elv = incoming->getConnections();
894  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
895  const NBEdge::Connection& c = *k;
896  if (c.toEdge == currentOutgoing) {
897  const SVCPermissions satisfied = (incoming->getPermissions(c.fromLane) & c.toEdge->getPermissions(c.toLane));
898  //std::cout << " from=" << c.fromLane << " to=" << c.toEdge->getID() << "_" << c.toLane << " satisfied=" << getVehicleClassNames(satisfied) << "\n";
899  unsatisfied &= ~satisfied;
900  }
901  }
902  if (unsatisfied != 0) {
903  //std::cout << " unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
904  int fromLane = 0;
905  while (unsatisfied != 0 && fromLane < (int)incoming->getNumLanes()) {
906  if ((incoming->getPermissions(fromLane) & unsatisfied) != 0) {
907  for (int toLane = 0; toLane < (int)currentOutgoing->getNumLanes(); ++toLane) {
908  const SVCPermissions satisfied = incoming->getPermissions(fromLane) & currentOutgoing->getPermissions(toLane) & unsatisfied;
909  if (satisfied != 0) {
910  incoming->setConnection((unsigned int)fromLane, currentOutgoing, toLane, NBEdge::L2L_COMPUTED);
911  //std::cout << " new connection from=" << fromLane << " to=" << currentOutgoing->getID() << "_" << toLane << " satisfies=" << getVehicleClassNames(satisfied) << "\n";
912  unsatisfied &= ~satisfied;
913  }
914  }
915  }
916  fromLane++;
917  }
918  //if (unsatisfied != 0) {
919  // std::cout << " still unsatisfied modes from edge=" << incoming->getID() << " toEdge=" << currentOutgoing->getID() << " deadModes=" << getVehicleClassNames(unsatisfied) << "\n";
920  //}
921  }
922  }
923  }
924  }
925  // special case e): rail_crossing
926  // there should only be straight connections here
928  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
929  const std::vector<NBEdge::Connection> cons = (*i)->getConnections();
930  for (std::vector<NBEdge::Connection>::const_iterator k = cons.begin(); k != cons.end(); ++k) {
931  if (getDirection(*i, (*k).toEdge) != LINKDIR_STRAIGHT) {
932  (*i)->removeFromConnections((*k).toEdge);
933  }
934  }
935  }
936  }
937 
938  // ... but we may have the case that there are no outgoing edges
939  // In this case, we have to mark the incoming edges as being in state
940  // LANE2LANE( not RECHECK) by hand
941  if (myOutgoingEdges.size() == 0) {
942  for (i = myIncomingEdges.rbegin(); i != myIncomingEdges.rend(); i++) {
943  (*i)->markAsInLane2LaneState();
944  }
945  }
946 
947  // DEBUG
948  //std::cout << "connections at " << getID() << "\n";
949  //for (i = myIncomingEdges.rbegin(); i != myIncomingEdges.rend(); i++) {
950  // const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
951  // for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
952  // std::cout << " " << (*i)->getID() << "_" << (*k).fromLane << " -> " << (*k).toEdge->getID() << "_" << (*k).toLane << "\n";
953  // }
954  //}
955 }
956 
957 bool
959  SUMOReal seen = out->getLoadedLength();
960  while (seen < minLength) {
961  // advance along trivial continuations
962  if (out->getToNode()->getOutgoingEdges().size() != 1
963  || out->getToNode()->getIncomingEdges().size() != 1) {
964  return false;
965  } else {
966  out = out->getToNode()->getOutgoingEdges()[0];
967  seen += out->getLoadedLength();
968  }
969  }
970  return true;
971 }
972 
973 EdgeVector*
975  // get the position of the node to get the approaching nodes of
976  EdgeVector::const_iterator i = find(myAllEdges.begin(),
977  myAllEdges.end(), currentOutgoing);
978  // get the first possible approaching edge
980  // go through the list of edges clockwise and add the edges
981  EdgeVector* approaching = new EdgeVector();
982  for (; *i != currentOutgoing;) {
983  // check only incoming edges
984  if ((*i)->getToNode() == this && (*i)->getTurnDestination() != currentOutgoing) {
985  std::vector<int> connLanes = (*i)->getConnectionLanes(currentOutgoing);
986  if (connLanes.size() != 0) {
987  approaching->push_back(*i);
988  }
989  }
991  }
992  return approaching;
993 }
994 
995 
996 void
997 NBNode::replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff) {
998  // replace the edge in the list of outgoing nodes
999  EdgeVector::iterator i = find(myOutgoingEdges.begin(), myOutgoingEdges.end(), which);
1000  if (i != myOutgoingEdges.end()) {
1001  (*i) = by;
1002  i = find(myAllEdges.begin(), myAllEdges.end(), which);
1003  (*i) = by;
1004  }
1005  // replace the edge in connections of incoming edges
1006  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); ++i) {
1007  (*i)->replaceInConnections(which, by, laneOff);
1008  }
1009  // replace within the connetion prohibition dependencies
1010  replaceInConnectionProhibitions(which, by, 0, laneOff);
1011 }
1012 
1013 
1014 void
1016  // replace edges
1017  unsigned int laneOff = 0;
1018  for (EdgeVector::const_iterator i = which.begin(); i != which.end(); i++) {
1019  replaceOutgoing(*i, by, laneOff);
1020  laneOff += (*i)->getNumLanes();
1021  }
1022  // removed SUMOReal occurences
1024  // check whether this node belongs to a district and the edges
1025  // must here be also remapped
1026  if (myDistrict != 0) {
1027  myDistrict->replaceOutgoing(which, by);
1028  }
1029 }
1030 
1031 
1032 void
1033 NBNode::replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff) {
1034  // replace the edge in the list of incoming nodes
1035  EdgeVector::iterator i = find(myIncomingEdges.begin(), myIncomingEdges.end(), which);
1036  if (i != myIncomingEdges.end()) {
1037  (*i) = by;
1038  i = find(myAllEdges.begin(), myAllEdges.end(), which);
1039  (*i) = by;
1040  }
1041  // replace within the connetion prohibition dependencies
1042  replaceInConnectionProhibitions(which, by, laneOff, 0);
1043 }
1044 
1045 
1046 void
1048  // replace edges
1049  unsigned int laneOff = 0;
1050  for (EdgeVector::const_iterator i = which.begin(); i != which.end(); i++) {
1051  replaceIncoming(*i, by, laneOff);
1052  laneOff += (*i)->getNumLanes();
1053  }
1054  // removed SUMOReal occurences
1056  // check whether this node belongs to a district and the edges
1057  // must here be also remapped
1058  if (myDistrict != 0) {
1059  myDistrict->replaceIncoming(which, by);
1060  }
1061 }
1062 
1063 
1064 
1065 void
1067  unsigned int whichLaneOff, unsigned int byLaneOff) {
1068  // replace in keys
1069  NBConnectionProhibits::iterator j = myBlockedConnections.begin();
1070  while (j != myBlockedConnections.end()) {
1071  bool changed = false;
1072  NBConnection c = (*j).first;
1073  if (c.replaceFrom(which, whichLaneOff, by, byLaneOff)) {
1074  changed = true;
1075  }
1076  if (c.replaceTo(which, whichLaneOff, by, byLaneOff)) {
1077  changed = true;
1078  }
1079  if (changed) {
1080  myBlockedConnections[c] = (*j).second;
1081  myBlockedConnections.erase(j);
1082  j = myBlockedConnections.begin();
1083  } else {
1084  j++;
1085  }
1086  }
1087  // replace in values
1088  for (j = myBlockedConnections.begin(); j != myBlockedConnections.end(); j++) {
1089  NBConnectionVector& prohibiting = (*j).second;
1090  for (NBConnectionVector::iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
1091  NBConnection& sprohibiting = *k;
1092  sprohibiting.replaceFrom(which, whichLaneOff, by, byLaneOff);
1093  sprohibiting.replaceTo(which, whichLaneOff, by, byLaneOff);
1094  }
1095  }
1096 }
1097 
1098 
1099 
1100 void
1102  unsigned int i, j;
1103  // check incoming
1104  for (i = 0; myIncomingEdges.size() > 0 && i < myIncomingEdges.size() - 1; i++) {
1105  j = i + 1;
1106  while (j < myIncomingEdges.size()) {
1107  if (myIncomingEdges[i] == myIncomingEdges[j]) {
1108  myIncomingEdges.erase(myIncomingEdges.begin() + j);
1109  } else {
1110  j++;
1111  }
1112  }
1113  }
1114  // check outgoing
1115  for (i = 0; myOutgoingEdges.size() > 0 && i < myOutgoingEdges.size() - 1; i++) {
1116  j = i + 1;
1117  while (j < myOutgoingEdges.size()) {
1118  if (myOutgoingEdges[i] == myOutgoingEdges[j]) {
1119  myOutgoingEdges.erase(myOutgoingEdges.begin() + j);
1120  } else {
1121  j++;
1122  }
1123  }
1124  }
1125  // check all
1126  for (i = 0; myAllEdges.size() > 0 && i < myAllEdges.size() - 1; i++) {
1127  j = i + 1;
1128  while (j < myAllEdges.size()) {
1129  if (myAllEdges[i] == myAllEdges[j]) {
1130  myAllEdges.erase(myAllEdges.begin() + j);
1131  } else {
1132  j++;
1133  }
1134  }
1135  }
1136 }
1137 
1138 
1139 bool
1140 NBNode::hasIncoming(const NBEdge* const e) const {
1141  return find(myIncomingEdges.begin(), myIncomingEdges.end(), e) != myIncomingEdges.end();
1142 }
1143 
1144 
1145 bool
1146 NBNode::hasOutgoing(const NBEdge* const e) const {
1147  return find(myOutgoingEdges.begin(), myOutgoingEdges.end(), e) != myOutgoingEdges.end();
1148 }
1149 
1150 
1151 NBEdge*
1153  EdgeVector edges = myIncomingEdges;
1154  if (find(edges.begin(), edges.end(), e) != edges.end()) {
1155  edges.erase(find(edges.begin(), edges.end(), e));
1156  }
1157  if (edges.size() == 0) {
1158  return 0;
1159  }
1160  if (e->getToNode() == this) {
1161  sort(edges.begin(), edges.end(), NBContHelper::edge_opposite_direction_sorter(e, this));
1162  } else {
1163  sort(edges.begin(), edges.end(), NBContHelper::edge_similar_direction_sorter(e));
1164  }
1165  return edges[0];
1166 }
1167 
1168 
1169 void
1171  const NBConnection& mustStop) {
1172  if (mayDrive.getFrom() == 0 ||
1173  mayDrive.getTo() == 0 ||
1174  mustStop.getFrom() == 0 ||
1175  mustStop.getTo() == 0) {
1176 
1177  WRITE_WARNING("Something went wrong during the building of a connection...");
1178  return; // !!! mark to recompute connections
1179  }
1180  NBConnectionVector conn = myBlockedConnections[mustStop];
1181  conn.push_back(mayDrive);
1182  myBlockedConnections[mustStop] = conn;
1183 }
1184 
1185 
1186 NBEdge*
1187 NBNode::getPossiblySplittedIncoming(const std::string& edgeid) {
1188  unsigned int size = (unsigned int) edgeid.length();
1189  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1190  std::string id = (*i)->getID();
1191  if (id.substr(0, size) == edgeid) {
1192  return *i;
1193  }
1194  }
1195  return 0;
1196 }
1197 
1198 
1199 NBEdge*
1200 NBNode::getPossiblySplittedOutgoing(const std::string& edgeid) {
1201  unsigned int size = (unsigned int) edgeid.length();
1202  for (EdgeVector::iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1203  std::string id = (*i)->getID();
1204  if (id.substr(0, size) == edgeid) {
1205  return *i;
1206  }
1207  }
1208  return 0;
1209 }
1210 
1211 
1212 void
1213 NBNode::removeEdge(NBEdge* edge, bool removeFromConnections) {
1214  EdgeVector::iterator i = find(myAllEdges.begin(), myAllEdges.end(), edge);
1215  if (i != myAllEdges.end()) {
1216  myAllEdges.erase(i);
1217  i = find(myOutgoingEdges.begin(), myOutgoingEdges.end(), edge);
1218  if (i != myOutgoingEdges.end()) {
1219  myOutgoingEdges.erase(i);
1220  } else {
1221  i = find(myIncomingEdges.begin(), myIncomingEdges.end(), edge);
1222  if (i != myIncomingEdges.end()) {
1223  myIncomingEdges.erase(i);
1224  } else {
1225  // edge must have been either incoming or outgoing
1226  assert(false);
1227  }
1228  }
1229  if (removeFromConnections) {
1230  for (i = myAllEdges.begin(); i != myAllEdges.end(); ++i) {
1231  (*i)->removeFromConnections(edge);
1232  }
1233  }
1234  // invalidate controlled connections for loaded traffic light plans
1235  for (std::set<NBTrafficLightDefinition*>::iterator i = myTrafficLights.begin(); i != myTrafficLights.end(); ++i) {
1236  (*i)->replaceRemoved(edge, -1, 0, -1);
1237  }
1238  }
1239 }
1240 
1241 
1242 Position
1244  Position pos(0, 0);
1245  EdgeVector::const_iterator i;
1246  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1247  NBNode* conn = (*i)->getFromNode();
1248  Position toAdd = conn->getPosition();
1249  toAdd.sub(myPosition);
1250  toAdd.mul((SUMOReal) 1.0 / sqrt(toAdd.x()*toAdd.x() + toAdd.y()*toAdd.y()));
1251  pos.add(toAdd);
1252  }
1253  for (i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1254  NBNode* conn = (*i)->getToNode();
1255  Position toAdd = conn->getPosition();
1256  toAdd.sub(myPosition);
1257  toAdd.mul((SUMOReal) 1.0 / sqrt(toAdd.x()*toAdd.x() + toAdd.y()*toAdd.y()));
1258  pos.add(toAdd);
1259  }
1260  pos.mul((SUMOReal) - 1.0 / (myIncomingEdges.size() + myOutgoingEdges.size()));
1261  if (pos.x() == 0 && pos.y() == 0) {
1262  pos = Position(1, 0);
1263  }
1264  pos.norm2d();
1265  return pos;
1266 }
1267 
1268 
1269 
1270 void
1272  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1273  (*i)->invalidateConnections();
1274  }
1275 }
1276 
1277 
1278 void
1280  for (EdgeVector::const_iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1281  (*i)->invalidateConnections();
1282  }
1283 }
1284 
1285 
1286 bool
1287 NBNode::mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const {
1288  // unregulated->does not need to brake
1289  if (myRequest == 0) {
1290  return false;
1291  }
1292  // vehicles which do not have a following lane must always decelerate to the end
1293  if (to == 0) {
1294  return true;
1295  }
1296  // check whether any other connection on this node prohibits this connection
1297  return myRequest->mustBrake(from, to, fromLane, toLane, includePedCrossings);
1298 }
1299 
1300 bool
1301 NBNode::mustBrakeForCrossing(const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing) const {
1302  return NBRequest::mustBrakeForCrossing(this, from, to, crossing);
1303 }
1304 
1305 
1306 bool
1307 NBNode::rightTurnConflict(const NBEdge* from, const NBEdge* to, int fromLane,
1308  const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorFromLane,
1309  bool lefthand) {
1310  if (from != prohibitorFrom) {
1311  return false;
1312  }
1313  if (from->isTurningDirectionAt(to)
1314  || prohibitorFrom->isTurningDirectionAt(prohibitorTo)) {
1315  // XXX should warn if there are any non-turning connections left of this
1316  return false;
1317  }
1318  // conflict if to is between prohibitorTo and from when going clockwise
1319  if (to->getStartAngle() == prohibitorTo->getStartAngle()) {
1320  // reduce rounding errors
1321  return false;
1322  }
1323  const LinkDirection d1 = from->getToNode()->getDirection(from, to);
1324  // must be a right turn to qualify as rightTurnConflict
1325  if (d1 == LINKDIR_STRAIGHT) {
1326  // no conflict for straight going connections
1327  // XXX actually this should check the main direction (which could also
1328  // be a turn)
1329  return false;
1330  } else {
1331  const LinkDirection d2 = prohibitorFrom->getToNode()->getDirection(prohibitorFrom, prohibitorTo);
1332  if (d1 == LINKDIR_LEFT || d1 == LINKDIR_PARTLEFT) {
1333  // check for leftTurnConflicht
1334  lefthand = !lefthand;
1335  if (d2 == LINKDIR_RIGHT || d1 == LINKDIR_PARTRIGHT) {
1336  // assume that the left-turning bicycle goes straight at first
1337  // and thus gets precedence over a right turning vehicle
1338  return false;
1339  }
1340  }
1341  if ((!lefthand && fromLane <= prohibitorFromLane) ||
1342  (lefthand && fromLane >= prohibitorFromLane)) {
1343  return false;
1344  }
1345  const SUMOReal toAngleAtNode = fmod(to->getStartAngle() + 180, (SUMOReal)360.0);
1346  const SUMOReal prohibitorToAngleAtNode = fmod(prohibitorTo->getStartAngle() + 180, (SUMOReal)360.0);
1347  return (lefthand != (GeomHelper::getCWAngleDiff(from->getEndAngle(), toAngleAtNode) <
1348  GeomHelper::getCWAngleDiff(from->getEndAngle(), prohibitorToAngleAtNode)));
1349  }
1350 }
1351 
1352 
1353 bool
1354 NBNode::isLeftMover(const NBEdge* const from, const NBEdge* const to) const {
1355  // when the junction has only one incoming edge, there are no
1356  // problems caused by left blockings
1357  if (myIncomingEdges.size() == 1 || myOutgoingEdges.size() == 1) {
1358  return false;
1359  }
1360  SUMOReal fromAngle = from->getAngleAtNode(this);
1361  SUMOReal toAngle = to->getAngleAtNode(this);
1362  SUMOReal cw = GeomHelper::getCWAngleDiff(fromAngle, toAngle);
1363  SUMOReal ccw = GeomHelper::getCCWAngleDiff(fromAngle, toAngle);
1364  std::vector<NBEdge*>::const_iterator i = std::find(myAllEdges.begin(), myAllEdges.end(), from);
1365  do {
1367  } while ((!hasOutgoing(*i) || from->isTurningDirectionAt(*i)) && *i != from);
1368  return cw < ccw && (*i) == to && myOutgoingEdges.size() > 2;
1369 }
1370 
1371 
1372 bool
1373 NBNode::forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
1374  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
1375  bool regardNonSignalisedLowerPriority) const {
1376  return myRequest != 0 && myRequest->forbids(possProhibitorFrom, possProhibitorTo,
1377  possProhibitedFrom, possProhibitedTo,
1378  regardNonSignalisedLowerPriority);
1379 }
1380 
1381 
1382 bool
1383 NBNode::foes(const NBEdge* const from1, const NBEdge* const to1,
1384  const NBEdge* const from2, const NBEdge* const to2) const {
1385  return myRequest != 0 && myRequest->foes(from1, to1, from2, to2);
1386 }
1387 
1388 
1389 void
1391  NBEdge* removed, const EdgeVector& incoming,
1392  const EdgeVector& outgoing) {
1393  assert(find(incoming.begin(), incoming.end(), removed) == incoming.end());
1394  bool changed = true;
1395  while (changed) {
1396  changed = false;
1397  NBConnectionProhibits blockedConnectionsTmp = myBlockedConnections;
1398  NBConnectionProhibits blockedConnectionsNew;
1399  // remap in connections
1400  for (NBConnectionProhibits::iterator i = blockedConnectionsTmp.begin(); i != blockedConnectionsTmp.end(); i++) {
1401  const NBConnection& blocker = (*i).first;
1402  const NBConnectionVector& blocked = (*i).second;
1403  // check the blocked connections first
1404  // check whether any of the blocked must be changed
1405  bool blockedChanged = false;
1406  NBConnectionVector newBlocked;
1407  NBConnectionVector::const_iterator j;
1408  for (j = blocked.begin(); j != blocked.end(); j++) {
1409  const NBConnection& sblocked = *j;
1410  if (sblocked.getFrom() == removed || sblocked.getTo() == removed) {
1411  blockedChanged = true;
1412  }
1413  }
1414  // adapt changes if so
1415  for (j = blocked.begin(); blockedChanged && j != blocked.end(); j++) {
1416  const NBConnection& sblocked = *j;
1417  if (sblocked.getFrom() == removed && sblocked.getTo() == removed) {
1418  /* for(EdgeVector::const_iterator k=incoming.begin(); k!=incoming.end(); k++) {
1419  !!! newBlocked.push_back(NBConnection(*k, *k));
1420  }*/
1421  } else if (sblocked.getFrom() == removed) {
1422  assert(sblocked.getTo() != removed);
1423  for (EdgeVector::const_iterator k = incoming.begin(); k != incoming.end(); k++) {
1424  newBlocked.push_back(NBConnection(*k, sblocked.getTo()));
1425  }
1426  } else if (sblocked.getTo() == removed) {
1427  assert(sblocked.getFrom() != removed);
1428  for (EdgeVector::const_iterator k = outgoing.begin(); k != outgoing.end(); k++) {
1429  newBlocked.push_back(NBConnection(sblocked.getFrom(), *k));
1430  }
1431  } else {
1432  newBlocked.push_back(NBConnection(sblocked.getFrom(), sblocked.getTo()));
1433  }
1434  }
1435  if (blockedChanged) {
1436  blockedConnectionsNew[blocker] = newBlocked;
1437  changed = true;
1438  }
1439  // if the blocked were kept
1440  else {
1441  if (blocker.getFrom() == removed && blocker.getTo() == removed) {
1442  changed = true;
1443  /* for(EdgeVector::const_iterator k=incoming.begin(); k!=incoming.end(); k++) {
1444  !!! blockedConnectionsNew[NBConnection(*k, *k)] = blocked;
1445  }*/
1446  } else if (blocker.getFrom() == removed) {
1447  assert(blocker.getTo() != removed);
1448  changed = true;
1449  for (EdgeVector::const_iterator k = incoming.begin(); k != incoming.end(); k++) {
1450  blockedConnectionsNew[NBConnection(*k, blocker.getTo())] = blocked;
1451  }
1452  } else if (blocker.getTo() == removed) {
1453  assert(blocker.getFrom() != removed);
1454  changed = true;
1455  for (EdgeVector::const_iterator k = outgoing.begin(); k != outgoing.end(); k++) {
1456  blockedConnectionsNew[NBConnection(blocker.getFrom(), *k)] = blocked;
1457  }
1458  } else {
1459  blockedConnectionsNew[blocker] = blocked;
1460  }
1461  }
1462  }
1463  myBlockedConnections = blockedConnectionsNew;
1464  }
1465  // remap in traffic lights
1466  tc.remapRemoved(removed, incoming, outgoing);
1467 }
1468 
1469 
1471 NBNode::getDirection(const NBEdge* const incoming, const NBEdge* const outgoing, bool leftHand) const {
1472  // ok, no connection at all -> dead end
1473  if (outgoing == 0) {
1474  return LINKDIR_NODIR;
1475  }
1476  // turning direction
1477  if (incoming->isTurningDirectionAt(outgoing)) {
1478  return leftHand ? LINKDIR_TURN_LEFTHAND : LINKDIR_TURN;
1479  }
1480  // get the angle between incoming/outgoing at the junction
1481  SUMOReal angle =
1482  NBHelpers::normRelAngle(incoming->getAngleAtNode(this), outgoing->getAngleAtNode(this));
1483  // ok, should be a straight connection
1484  if (abs((int) angle) + 1 < 45) {
1485  return LINKDIR_STRAIGHT;
1486  }
1487 
1488  // check for left and right, first
1489  if (angle > 0) {
1490  // check whether any other edge goes further to the right
1491  EdgeVector::const_iterator i =
1492  find(myAllEdges.begin(), myAllEdges.end(), outgoing);
1493  if (leftHand) {
1495  } else {
1497  }
1498  while ((*i) != incoming) {
1499  if ((*i)->getFromNode() == this && !incoming->isTurningDirectionAt(*i)) {
1500  //std::cout << incoming->getID() << " -> " << outgoing->getID() << " partRight because auf " << (*i)->getID() << "\n";
1501  return LINKDIR_PARTRIGHT;
1502  }
1503  if (leftHand) {
1505  } else {
1507  }
1508  }
1509  return LINKDIR_RIGHT;
1510  }
1511  // check whether any other edge goes further to the left
1512  EdgeVector::const_iterator i =
1513  find(myAllEdges.begin(), myAllEdges.end(), outgoing);
1514  if (leftHand) {
1516  } else {
1518  }
1519  while ((*i) != incoming) {
1520  if ((*i)->getFromNode() == this && !incoming->isTurningDirectionAt(*i)) {
1521  //std::cout << incoming->getID() << " -> " << outgoing->getID() << " partLeft because auf " << (*i)->getID() << "\n";
1522  return LINKDIR_PARTLEFT;
1523  }
1524  if (leftHand) {
1526  } else {
1528  }
1529  }
1530  return LINKDIR_LEFT;
1531 }
1532 
1533 
1534 LinkState
1535 NBNode::getLinkState(const NBEdge* incoming, NBEdge* outgoing, int fromlane, int toLane,
1536  bool mayDefinitelyPass, const std::string& tlID) const {
1537  if (myType == NODETYPE_RAIL_CROSSING && isRailway(incoming->getPermissions())) {
1538  return LINKSTATE_MAJOR; // the trains must run on time
1539  }
1540  if (tlID != "") {
1542  }
1543  if (outgoing == 0) { // always off
1545  }
1547  return LINKSTATE_EQUAL; // all the same
1548  }
1549  if (myType == NODETYPE_ALLWAY_STOP) {
1550  return LINKSTATE_ALLWAY_STOP; // all drive, first one to arrive may drive first
1551  }
1552  if (myType == NODETYPE_ZIPPER && mustBrake(incoming, outgoing, fromlane, toLane, false)) {
1553  return LINKSTATE_ZIPPER;
1554  }
1555  if ((!incoming->isInnerEdge() && mustBrake(incoming, outgoing, fromlane, toLane, true)) && !mayDefinitelyPass) {
1556  return myType == NODETYPE_PRIORITY_STOP ? LINKSTATE_STOP : LINKSTATE_MINOR; // minor road
1557  }
1558  // traffic lights are not regarded here
1559  return LINKSTATE_MAJOR;
1560 }
1561 
1562 
1563 bool
1565  // check whether this node is included in a traffic light or crossing
1566  if (myTrafficLights.size() != 0 || myCrossings.size() != 0) {
1567  return false;
1568  }
1569  EdgeVector::const_iterator i;
1570  // one in, one out -> just a geometry ...
1571  if (myOutgoingEdges.size() == 1 && myIncomingEdges.size() == 1) {
1572  // ... if types match ...
1573  if (!myIncomingEdges[0]->expandableBy(myOutgoingEdges[0])) {
1574  return false;
1575  }
1576  //
1577  return myIncomingEdges[0]->getTurnDestination(true) != myOutgoingEdges[0];
1578  }
1579  // two in, two out -> may be something else
1580  if (myOutgoingEdges.size() == 2 && myIncomingEdges.size() == 2) {
1581  // check whether the origin nodes of the incoming edges differ
1582  std::set<NBNode*> origSet;
1583  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1584  origSet.insert((*i)->getFromNode());
1585  }
1586  if (origSet.size() < 2) {
1587  return false;
1588  }
1589  // check whether this node is an intermediate node of
1590  // a two-directional street
1591  for (i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1592  // each of the edges must have an opposite direction edge
1593  NBEdge* opposite = (*i)->getTurnDestination(true);
1594  if (opposite != 0) {
1595  // the other outgoing edges must be the continuation of the current
1596  NBEdge* continuation = opposite == myOutgoingEdges.front() ? myOutgoingEdges.back() : myOutgoingEdges.front();
1597  // check whether the types allow joining
1598  if (!(*i)->expandableBy(continuation)) {
1599  return false;
1600  }
1601  } else {
1602  // ok, at least one outgoing edge is not an opposite
1603  // of an incoming one
1604  return false;
1605  }
1606  }
1607  return true;
1608  }
1609  // ok, a real node
1610  return false;
1611 }
1612 
1613 
1614 std::vector<std::pair<NBEdge*, NBEdge*> >
1616  assert(checkIsRemovable());
1617  std::vector<std::pair<NBEdge*, NBEdge*> > ret;
1618  // one in, one out-case
1619  if (myOutgoingEdges.size() == 1 && myIncomingEdges.size() == 1) {
1620  ret.push_back(
1621  std::pair<NBEdge*, NBEdge*>(
1623  return ret;
1624  }
1625  // two in, two out-case
1626  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1627  // join with the edge that is not a turning direction
1628  NBEdge* opposite = (*i)->getTurnDestination(true);
1629  assert(opposite != 0);
1630  NBEdge* continuation = opposite == myOutgoingEdges.front() ? myOutgoingEdges.back() : myOutgoingEdges.front();
1631  ret.push_back(std::pair<NBEdge*, NBEdge*>(*i, continuation));
1632  }
1633  return ret;
1634 }
1635 
1636 
1637 const PositionVector&
1639  return myPoly;
1640 }
1641 
1642 
1643 void
1645  myPoly = shape;
1646  myHaveCustomPoly = (myPoly.size() > 1);
1647 }
1648 
1649 
1650 void
1651 NBNode::setCustomLaneShape(const std::string& laneID, const PositionVector& shape) {
1652  if (shape.size() > 1) {
1653  myCustomLaneShapes[laneID] = shape;
1654  } else {
1655  myCustomLaneShapes.erase(laneID);
1656  }
1657 }
1658 
1659 
1660 NBEdge*
1662  for (EdgeVector::const_iterator i = myOutgoingEdges.begin(); i != myOutgoingEdges.end(); i++) {
1663  if ((*i)->getToNode() == n) {
1664  return (*i);
1665  }
1666  }
1667  return 0;
1668 }
1669 
1670 
1671 bool
1673  if (isDistrict()) {
1674  return false;
1675  }
1676  EdgeVector edges;
1677  copy(getIncomingEdges().begin(), getIncomingEdges().end(),
1678  back_inserter(edges));
1679  copy(getOutgoingEdges().begin(), getOutgoingEdges().end(),
1680  back_inserter(edges));
1681  for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
1682  NBEdge* t = *j;
1683  NBNode* other = 0;
1684  if (t->getToNode() == this) {
1685  other = t->getFromNode();
1686  } else {
1687  other = t->getToNode();
1688  }
1689  EdgeVector edges2;
1690  copy(other->getIncomingEdges().begin(), other->getIncomingEdges().end(), back_inserter(edges2));
1691  copy(other->getOutgoingEdges().begin(), other->getOutgoingEdges().end(), back_inserter(edges2));
1692  for (EdgeVector::const_iterator k = edges2.begin(); k != edges2.end(); ++k) {
1693  if ((*k)->getFromNode()->isDistrict() || (*k)->getToNode()->isDistrict()) {
1694  return true;
1695  }
1696  }
1697  }
1698  return false;
1699 }
1700 
1701 
1702 bool
1704  return myType == NODETYPE_DISTRICT;
1705 }
1706 
1707 
1708 int
1710  //gDebugFlag1 = getID() == DEBUGID;
1711  int numGuessed = 0;
1712  if (myCrossings.size() > 0 || myDiscardAllCrossings) {
1713  // user supplied crossings, do not guess
1714  return numGuessed;
1715  }
1716  if (gDebugFlag1) {
1717  std::cout << "guess crossings for " << getID() << "\n";
1718  }
1720  // check for pedestrial lanes going clockwise around the node
1721  std::vector<std::pair<NBEdge*, bool> > normalizedLanes;
1722  for (EdgeVector::const_iterator it = allEdges.begin(); it != allEdges.end(); ++it) {
1723  NBEdge* edge = *it;
1724  const std::vector<NBEdge::Lane>& lanes = edge->getLanes();
1725  if (edge->getFromNode() == this) {
1726  for (std::vector<NBEdge::Lane>::const_reverse_iterator it_l = lanes.rbegin(); it_l != lanes.rend(); ++it_l) {
1727  normalizedLanes.push_back(std::make_pair(edge, ((*it_l).permissions & SVC_PEDESTRIAN) != 0));
1728  }
1729  } else {
1730  for (std::vector<NBEdge::Lane>::const_iterator it_l = lanes.begin(); it_l != lanes.end(); ++it_l) {
1731  normalizedLanes.push_back(std::make_pair(edge, ((*it_l).permissions & SVC_PEDESTRIAN) != 0));
1732  }
1733  }
1734  }
1735  // do we even have a pedestrian lane?
1736  int firstSidewalk = -1;
1737  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
1738  if (normalizedLanes[i].second) {
1739  firstSidewalk = i;
1740  break;
1741  }
1742  }
1743  int hadCandidates = 0;
1744  std::vector<int> connectedCandidates; // number of crossings that were built for each connected candidate
1745  if (firstSidewalk != -1) {
1746  // rotate lanes to ensure that the first one allows pedestrians
1747  std::vector<std::pair<NBEdge*, bool> > tmp;
1748  copy(normalizedLanes.begin() + firstSidewalk, normalizedLanes.end(), std::back_inserter(tmp));
1749  copy(normalizedLanes.begin(), normalizedLanes.begin() + firstSidewalk, std::back_inserter(tmp));
1750  normalizedLanes = tmp;
1751  // find candidates
1752  EdgeVector candidates;
1753  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
1754  NBEdge* edge = normalizedLanes[i].first;
1755  const bool allowsPed = normalizedLanes[i].second;
1756  if (gDebugFlag1) {
1757  std::cout << " cands=" << toString(candidates) << " edge=" << edge->getID() << " allowsPed=" << allowsPed << "\n";
1758  }
1759  if (!allowsPed && (candidates.size() == 0 || candidates.back() != edge)) {
1760  candidates.push_back(edge);
1761  } else if (allowsPed) {
1762  if (candidates.size() > 0) {
1763  if (hadCandidates > 0 || forbidsPedestriansAfter(normalizedLanes, i)) {
1764  hadCandidates++;
1765  const int n = checkCrossing(candidates);
1766  numGuessed += n;
1767  if (n > 0) {
1768  connectedCandidates.push_back(n);
1769  }
1770  }
1771  candidates.clear();
1772  }
1773  }
1774  }
1775  if (hadCandidates > 0 && candidates.size() > 0) {
1776  // avoid wrapping around to the same sidewalk
1777  hadCandidates++;
1778  const int n = checkCrossing(candidates);
1779  numGuessed += n;
1780  if (n > 0) {
1781  connectedCandidates.push_back(n);
1782  }
1783  }
1784  }
1785  // Avoid duplicate crossing between the same pair of walkingareas
1786  if (gDebugFlag1) {
1787  std::cout << " hadCandidates=" << hadCandidates << " connectedCandidates=" << toString(connectedCandidates) << "\n";
1788  }
1789  if (hadCandidates == 2 && connectedCandidates.size() == 2) {
1790  // One or both of them might be split: remove the one with less splits
1791  if (connectedCandidates.back() <= connectedCandidates.front()) {
1792  numGuessed -= connectedCandidates.back();
1793  myCrossings.erase(myCrossings.end() - connectedCandidates.back(), myCrossings.end());
1794  } else {
1795  numGuessed -= connectedCandidates.front();
1796  myCrossings.erase(myCrossings.begin(), myCrossings.begin() + connectedCandidates.front());
1797  }
1798  }
1800  if (gDebugFlag1) {
1801  std::cout << "guessedCrossings:\n";
1802  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); it++) {
1803  std::cout << " edges=" << toString((*it).edges) << "\n";
1804  }
1805  }
1806  return numGuessed;
1807 }
1808 
1809 
1810 int
1812  if (gDebugFlag1) {
1813  std::cout << "checkCrossing candidates=" << toString(candidates) << "\n";
1814  }
1815  if (candidates.size() == 0) {
1816  if (gDebugFlag1) {
1817  std::cout << "no crossing added (numCandidates=" << candidates.size() << ")\n";
1818  }
1819  return 0;
1820  } else {
1821  // check whether the edges may be part of a common crossing due to having similar angle
1822  SUMOReal prevAngle = -100000; // dummy
1823  for (size_t i = 0; i < candidates.size(); ++i) {
1824  NBEdge* edge = candidates[i];
1825  SUMOReal angle = edge->getCrossingAngle(this);
1826  // edges should be sorted by angle but this only holds true approximately
1827  if (i > 0 && fabs(angle - prevAngle) > EXTEND_CROSSING_ANGLE_THRESHOLD) {
1828  if (gDebugFlag1) {
1829  std::cout << "no crossing added (found angle difference of " << fabs(angle - prevAngle) << " at i=" << i << "\n";
1830  }
1831  return 0;
1832  }
1833  if (!isTLControlled() && edge->getSpeed() > OptionsCont::getOptions().getFloat("crossings.guess.speed-threshold")) {
1834  if (gDebugFlag1) {
1835  std::cout << "no crossing added (uncontrolled, edge with speed > " << edge->getSpeed() << ")\n";
1836  }
1837  return 0;
1838  }
1839  prevAngle = angle;
1840  }
1841  if (candidates.size() == 1) {
1843  if (gDebugFlag1) {
1844  std::cout << "adding crossing: " << toString(candidates) << "\n";
1845  }
1846  return 1;
1847  } else {
1848  // check for intermediate walking areas
1849  SUMOReal prevAngle = -100000; // dummy
1850  for (EdgeVector::iterator it = candidates.begin(); it != candidates.end(); ++it) {
1851  SUMOReal angle = (*it)->getCrossingAngle(this);
1852  if (it != candidates.begin()) {
1853  NBEdge* prev = *(it - 1);
1854  NBEdge* curr = *it;
1855  Position prevPos, currPos;
1856  unsigned int laneI;
1857  // compute distance between candiate edges
1858  SUMOReal intermediateWidth = 0;
1859  if (prev->getToNode() == this) {
1860  laneI = prev->getNumLanes() - 1;
1861  prevPos = prev->getLanes()[laneI].shape[-1];
1862  } else {
1863  laneI = 0;
1864  prevPos = prev->getLanes()[laneI].shape[0];
1865  }
1866  intermediateWidth -= 0.5 * prev->getLaneWidth(laneI);
1867  if (curr->getFromNode() == this) {
1868  laneI = curr->getNumLanes() - 1;
1869  currPos = curr->getLanes()[laneI].shape[0];
1870  } else {
1871  laneI = 0;
1872  currPos = curr->getLanes()[laneI].shape[-1];
1873  }
1874  intermediateWidth -= 0.5 * curr->getLaneWidth(laneI);
1875  intermediateWidth += currPos.distanceTo2D(prevPos);
1876  if (gDebugFlag1) {
1877  std::cout
1878  << " prevAngle=" << prevAngle
1879  << " angle=" << angle
1880  << " intermediateWidth=" << intermediateWidth
1881  << "\n";
1882  }
1883  if (fabs(prevAngle - angle) > SPLIT_CROSSING_ANGLE_THRESHOLD
1884  || (intermediateWidth > SPLIT_CROSSING_WIDTH_THRESHOLD)) {
1885  return checkCrossing(EdgeVector(candidates.begin(), it))
1886  + checkCrossing(EdgeVector(it, candidates.end()));
1887  }
1888  }
1889  prevAngle = angle;
1890  }
1892  if (gDebugFlag1) {
1893  std::cout << "adding crossing: " << toString(candidates) << "\n";
1894  }
1895  return 1;
1896  }
1897  }
1898 }
1899 
1900 
1901 bool
1902 NBNode::forbidsPedestriansAfter(std::vector<std::pair<NBEdge*, bool> > normalizedLanes, int startIndex) {
1903  for (int i = startIndex; i < (int)normalizedLanes.size(); ++i) {
1904  if (!normalizedLanes[i].second) {
1905  return true;
1906  }
1907  }
1908  return false;
1909 }
1910 
1911 
1912 void
1914  buildCrossings();
1915  buildWalkingAreas(OptionsCont::getOptions().getInt("junctions.corner-detail"));
1916  // ensure that all crossings are properly connected
1917  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
1918  if ((*it).prevWalkingArea == "" || (*it).nextWalkingArea == "") {
1919  WRITE_WARNING("Discarding invalid crossing '" + (*it).id + "' at junction '" + getID() + "' with edges '" + toString((*it).edges) + "'.");
1920  for (std::vector<WalkingArea>::iterator it_wa = myWalkingAreas.begin(); it_wa != myWalkingAreas.end(); it_wa++) {
1921  if ((*it_wa).nextCrossing == (*it).id) {
1922  (*it_wa).nextCrossing = "";
1923  }
1924  }
1925  it = myCrossings.erase(it);
1926  } else {
1927  ++it;
1928  }
1929  }
1930 }
1931 
1932 
1933 void
1935  // build inner edges for vehicle movements across the junction
1936  unsigned int noInternalNoSplits = 0;
1937  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1938  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
1939  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
1940  if ((*k).toEdge == 0) {
1941  continue;
1942  }
1943  noInternalNoSplits++;
1944  }
1945  }
1946  unsigned int lno = 0;
1947  unsigned int splitNo = 0;
1948  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1949  (*i)->buildInnerEdges(*this, noInternalNoSplits, lno, splitNo);
1950  }
1951  // if there are custom lane shapes we need to built twice:
1952  // first to set the ids then to build intersections with the custom geometries
1953  if (myCustomLaneShapes.size() > 0) {
1954  unsigned int lno = 0;
1955  unsigned int splitNo = 0;
1956  for (EdgeVector::const_iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
1957  (*i)->buildInnerEdges(*this, noInternalNoSplits, lno, splitNo);
1958  }
1959  }
1960 }
1961 
1962 
1963 unsigned int
1965  //gDebugFlag1 = getID() == DEBUGID;
1966  if (gDebugFlag1) {
1967  std::cout << "build crossings for " << getID() << ":\n";
1968  }
1969  if (myDiscardAllCrossings) {
1970  myCrossings.clear();
1971  }
1972  unsigned int index = 0;
1973  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
1974  (*it).id = ":" + getID() + "_c" + toString(index++);
1975  // reset fields, so repeated computation (Netedit) will sucessfully perform the checks
1976  // in buildWalkingAreas (split crossings) and buildInnerEdges (sanity check)
1977  (*it).nextWalkingArea = "";
1978  (*it).prevWalkingArea = "";
1979  EdgeVector& edges = (*it).edges;
1980  if (gDebugFlag1) {
1981  std::cout << " crossing=" << (*it).id << " edges=" << toString(edges);
1982  }
1983  // sorting the edges in the right way is imperative. We want to sort
1984  // them by getAngleAtNodeToCenter() but need to be extra carefull to avoid wrapping around 0 somewhere in between
1985  std::sort(edges.begin(), edges.end(), NBContHelper::edge_by_angle_to_nodeShapeCentroid_sorter(this));
1986  if (gDebugFlag1) {
1987  std::cout << " sortedEdges=" << toString(edges) << "\n";
1988  };
1989  // rotate the edges so that the largest relative angle difference comes at the end
1990  SUMOReal maxAngleDiff = 0;
1991  int maxAngleDiffIndex = 0; // index before maxDist
1992  for (int i = 0; i < (int) edges.size(); i++) {
1993  SUMOReal diff = NBHelpers::relAngle(edges[i]->getAngleAtNodeToCenter(this),
1994  edges[(i + 1) % edges.size()]->getAngleAtNodeToCenter(this));
1995  if (diff < 0) {
1996  diff += 360;
1997  }
1998  if (gDebugFlag1) {
1999  std::cout << " i=" << i << " a1=" << edges[i]->getAngleAtNodeToCenter(this) << " a2=" << edges[(i + 1) % edges.size()]->getAngleAtNodeToCenter(this) << " diff=" << diff << "\n";
2000  }
2001  if (diff > maxAngleDiff) {
2002  maxAngleDiff = diff;
2003  maxAngleDiffIndex = i;
2004  }
2005  }
2006  if (maxAngleDiff > 2 && maxAngleDiff < 360 - 2) {
2007  // if the angle differences is too small, we better not rotate
2008  std::rotate(edges.begin(), edges.begin() + (maxAngleDiffIndex + 1) % edges.size(), edges.end());
2009  if (gDebugFlag1) {
2010  std::cout << " rotatedEdges=" << toString(edges);
2011  }
2012  }
2013  // reverse to get them in CCW order (walking direction around the node)
2014  std::reverse(edges.begin(), edges.end());
2015  if (gDebugFlag1) {
2016  std::cout << " finalEdges=" << toString(edges) << "\n";
2017  }
2018  // compute shape
2019  (*it).shape.clear();
2020  const int begDir = (edges.front()->getFromNode() == this ? FORWARD : BACKWARD);
2021  const int endDir = (edges.back()->getToNode() == this ? FORWARD : BACKWARD);
2022  if (edges.front()->getFirstNonPedestrianLaneIndex(begDir) < 0
2023  || edges.back()->getFirstNonPedestrianLaneIndex(endDir) < 0) {
2024  // invalid crossing
2025  WRITE_WARNING("Discarding invalid crossing '" + (*it).id + "' at junction '" + getID() + "' with edges '" + toString((*it).edges) + "'.");
2026  it = myCrossings.erase(it);
2027  } else {
2028  NBEdge::Lane crossingBeg = edges.front()->getFirstNonPedestrianLane(begDir);
2029  NBEdge::Lane crossingEnd = edges.back()->getFirstNonPedestrianLane(endDir);
2030  crossingBeg.width = (crossingBeg.width == NBEdge::UNSPECIFIED_WIDTH ? SUMO_const_laneWidth : crossingBeg.width);
2031  crossingEnd.width = (crossingEnd.width == NBEdge::UNSPECIFIED_WIDTH ? SUMO_const_laneWidth : crossingEnd.width);
2032  crossingBeg.shape.move2side(begDir * crossingBeg.width / 2);
2033  crossingEnd.shape.move2side(endDir * crossingEnd.width / 2);
2034  crossingBeg.shape.extrapolate((*it).width / 2);
2035  crossingEnd.shape.extrapolate((*it).width / 2);
2036  (*it).shape.push_back(crossingBeg.shape[begDir == FORWARD ? 0 : -1]);
2037  (*it).shape.push_back(crossingEnd.shape[endDir == FORWARD ? -1 : 0]);
2038  ++it;
2039  }
2040  }
2041  return index;
2042 }
2043 
2044 
2045 void
2046 NBNode::buildWalkingAreas(int cornerDetail) {
2047  //gDebugFlag1 = getID() == DEBUGID;
2048  unsigned int index = 0;
2049  myWalkingAreas.clear();
2050  if (gDebugFlag1) {
2051  std::cout << "build walkingAreas for " << getID() << ":\n";
2052  }
2053  if (myAllEdges.size() == 0) {
2054  return;
2055  }
2057  // shapes are all pointing away from the intersection
2058  std::vector<std::pair<NBEdge*, NBEdge::Lane> > normalizedLanes;
2059  for (EdgeVector::const_iterator it = allEdges.begin(); it != allEdges.end(); ++it) {
2060  NBEdge* edge = *it;
2061  const std::vector<NBEdge::Lane>& lanes = edge->getLanes();
2062  if (edge->getFromNode() == this) {
2063  for (std::vector<NBEdge::Lane>::const_reverse_iterator it_l = lanes.rbegin(); it_l != lanes.rend(); ++it_l) {
2064  NBEdge::Lane l = *it_l;
2065  l.shape = l.shape.getSubpartByIndex(0, 2);
2067  normalizedLanes.push_back(std::make_pair(edge, l));
2068  }
2069  } else {
2070  for (std::vector<NBEdge::Lane>::const_iterator it_l = lanes.begin(); it_l != lanes.end(); ++it_l) {
2071  NBEdge::Lane l = *it_l;
2072  l.shape = l.shape.reverse();
2073  l.shape = l.shape.getSubpartByIndex(0, 2);
2075  normalizedLanes.push_back(std::make_pair(edge, l));
2076  }
2077  }
2078  }
2079  //if (gDebugFlag1) std::cout << " normalizedLanes=" << normalizedLanes.size() << "\n";
2080  // collect [start,count[ indices in normalizedLanes that belong to a walkingArea
2081  std::vector<std::pair<int, int> > waIndices;
2082  int start = -1;
2083  NBEdge* prevEdge = normalizedLanes.back().first;
2084  for (int i = 0; i < (int)normalizedLanes.size(); ++i) {
2085  NBEdge* edge = normalizedLanes[i].first;
2086  NBEdge::Lane& l = normalizedLanes[i].second;
2087  if (start == -1) {
2088  if ((l.permissions & SVC_PEDESTRIAN) != 0) {
2089  start = i;
2090  }
2091  } else {
2092  if ((l.permissions & SVC_PEDESTRIAN) == 0 || crossingBetween(edge, prevEdge)) {
2093  waIndices.push_back(std::make_pair(start, i - start));
2094  if ((l.permissions & SVC_PEDESTRIAN) != 0) {
2095  start = i;
2096  } else {
2097  start = -1;
2098  }
2099 
2100  }
2101  }
2102  if (gDebugFlag1) std::cout << " i=" << i << " edge=" << edge->getID() << " start=" << start << " ped=" << ((l.permissions & SVC_PEDESTRIAN) != 0)
2103  << " waI=" << waIndices.size() << " crossingBetween=" << crossingBetween(edge, prevEdge) << "\n";
2104  prevEdge = edge;
2105  }
2106  // deal with wrap-around issues
2107  if (start != - 1) {
2108  const int waNumLanes = (int)normalizedLanes.size() - start;
2109  if (waIndices.size() == 0) {
2110  waIndices.push_back(std::make_pair(start, waNumLanes));
2111  if (gDebugFlag1) {
2112  std::cout << " single wa, end at wrap-around\n";
2113  }
2114  } else {
2115  if (waIndices.front().first == 0) {
2116  NBEdge* edge = normalizedLanes.front().first;
2117  NBEdge* prevEdge = normalizedLanes.back().first;
2118  if (crossingBetween(edge, prevEdge)) {
2119  // do not wrap-around if there is a crossing in between
2120  waIndices.push_back(std::make_pair(start, waNumLanes));
2121  if (gDebugFlag1) {
2122  std::cout << " do not wrap around, turn-around in between\n";
2123  }
2124  } else {
2125  // first walkingArea wraps around
2126  waIndices.front().first = start;
2127  waIndices.front().second = waNumLanes + waIndices.front().second;
2128  if (gDebugFlag1) {
2129  std::cout << " wrapping around\n";
2130  }
2131  }
2132  } else {
2133  // last walkingArea ends at the wrap-around
2134  waIndices.push_back(std::make_pair(start, waNumLanes));
2135  if (gDebugFlag1) {
2136  std::cout << " end at wrap-around\n";
2137  }
2138  }
2139  }
2140  }
2141  if (gDebugFlag1) {
2142  std::cout << " normalizedLanes=" << normalizedLanes.size() << " waIndices:\n";
2143  for (int i = 0; i < (int)waIndices.size(); ++i) {
2144  std::cout << " " << waIndices[i].first << ", " << waIndices[i].second << "\n";
2145  }
2146  }
2147  // build walking areas connected to a sidewalk
2148  for (int i = 0; i < (int)waIndices.size(); ++i) {
2149  const bool buildExtensions = waIndices[i].second != (int)normalizedLanes.size();
2150  const int start = waIndices[i].first;
2151  const int prev = start > 0 ? start - 1 : (int)normalizedLanes.size() - 1;
2152  const int count = waIndices[i].second;
2153  const int end = (start + count) % normalizedLanes.size();
2154 
2155  WalkingArea wa(":" + getID() + "_w" + toString(index++), 1);
2156  if (gDebugFlag1) {
2157  std::cout << "build walkingArea " << wa.id << " start=" << start << " end=" << end << " count=" << count << " prev=" << prev << ":\n";
2158  }
2159  SUMOReal endCrossingWidth = 0;
2160  SUMOReal startCrossingWidth = 0;
2161  PositionVector endCrossingShape;
2162  PositionVector startCrossingShape;
2163  // check for connected crossings
2164  bool connectsCrossing = false;
2165  std::vector<Position> connectedPoints;
2166  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2167  if (gDebugFlag1) {
2168  std::cout << " crossing=" << (*it).id << " sortedEdges=" << toString((*it).edges) << "\n";
2169  }
2170  if ((*it).edges.back() == normalizedLanes[end].first
2171  && (normalizedLanes[end].second.permissions & SVC_PEDESTRIAN) == 0) {
2172  // crossing ends
2173  if ((*it).nextWalkingArea != "") {
2174  WRITE_WARNING("Invalid pedestrian topology at junction '" + getID()
2175  + "'; crossing '" + (*it).id
2176  + "' targets '" + (*it).nextWalkingArea
2177  + "' and '" + wa.id + "'.");
2178  }
2179  (*it).nextWalkingArea = wa.id;
2180  endCrossingWidth = (*it).width;
2181  endCrossingShape = (*it).shape;
2182  wa.width = MAX2(wa.width, endCrossingWidth);
2183  connectsCrossing = true;
2184  connectedPoints.push_back((*it).shape[-1]);
2185  if (gDebugFlag1) {
2186  std::cout << " crossing " << (*it).id << " ends\n";
2187  }
2188  }
2189  if ((*it).edges.front() == normalizedLanes[prev].first
2190  && (normalizedLanes[prev].second.permissions & SVC_PEDESTRIAN) == 0) {
2191  // crossing starts
2192  if ((*it).prevWalkingArea != "") {
2193  WRITE_WARNING("Invalid pedestrian topology at junction '" + getID()
2194  + "'; crossing '" + (*it).id
2195  + "' is targeted by '" + (*it).prevWalkingArea
2196  + "' and '" + wa.id + "'.");
2197  }
2198  (*it).prevWalkingArea = wa.id;
2199  wa.nextCrossing = (*it).id;
2200  startCrossingWidth = (*it).width;
2201  startCrossingShape = (*it).shape;
2202  wa.width = MAX2(wa.width, startCrossingWidth);
2203  connectsCrossing = true;
2204  connectedPoints.push_back((*it).shape[0]);
2205  if (gDebugFlag1) {
2206  std::cout << " crossing " << (*it).id << " starts\n";
2207  }
2208  }
2209  if (gDebugFlag1) std::cout << " check connections to crossing " << (*it).id
2210  << " cFront=" << (*it).edges.front()->getID() << " cBack=" << (*it).edges.back()->getID()
2211  << " wEnd=" << normalizedLanes[end].first->getID() << " wStart=" << normalizedLanes[start].first->getID()
2212  << " wStartPrev=" << normalizedLanes[prev].first->getID()
2213  << "\n";
2214  }
2215  if (count < 2 && !connectsCrossing) {
2216  // not relevant for walking
2217  if (gDebugFlag1) {
2218  std::cout << " not relevant for walking: count=" << count << " connectsCrossing=" << connectsCrossing << "\n";
2219  }
2220  continue;
2221  }
2222  // build shape and connections
2223  std::set<NBEdge*> connected;
2224  for (int j = 0; j < count; ++j) {
2225  const int nlI = (start + j) % normalizedLanes.size();
2226  NBEdge* edge = normalizedLanes[nlI].first;
2227  NBEdge::Lane l = normalizedLanes[nlI].second;
2228  wa.width = MAX2(wa.width, l.width);
2229  if (connected.count(edge) == 0) {
2230  if (edge->getFromNode() == this) {
2231  wa.nextSidewalks.push_back(edge->getID());
2232  connectedPoints.push_back(edge->getLaneShape(0)[0]);
2233  } else {
2234  wa.prevSidewalks.push_back(edge->getID());
2235  connectedPoints.push_back(edge->getLaneShape(0)[-1]);
2236  }
2237  connected.insert(edge);
2238  }
2239  l.shape.move2side(-l.width / 2);
2240  wa.shape.push_back(l.shape[0]);
2241  l.shape.move2side(l.width);
2242  wa.shape.push_back(l.shape[0]);
2243  }
2244  if (buildExtensions) {
2245  // extension at starting crossing
2246  if (startCrossingShape.size() > 0) {
2247  if (gDebugFlag1) {
2248  std::cout << " extension at startCrossing shape=" << startCrossingShape << "\n";
2249  }
2250  startCrossingShape.move2side(startCrossingWidth / 2);
2251  wa.shape.push_front_noDoublePos(startCrossingShape[0]); // right corner
2252  startCrossingShape.move2side(-startCrossingWidth);
2253  wa.shape.push_front_noDoublePos(startCrossingShape[0]); // left corner goes first
2254  }
2255  // extension at ending crossing
2256  if (endCrossingShape.size() > 0) {
2257  if (gDebugFlag1) {
2258  std::cout << " extension at endCrossing shape=" << endCrossingShape << "\n";
2259  }
2260  endCrossingShape.move2side(endCrossingWidth / 2);
2261  wa.shape.push_back_noDoublePos(endCrossingShape[-1]);
2262  endCrossingShape.move2side(-endCrossingWidth);
2263  wa.shape.push_back_noDoublePos(endCrossingShape[-1]);
2264  }
2265  }
2266  if (connected.size() == 2 && !connectsCrossing && wa.nextSidewalks.size() == 1 && wa.prevSidewalks.size() == 1
2267  && normalizedLanes.size() == 2) {
2268  // do not build a walkingArea since a normal connection exists
2269  NBEdge* e1 = *connected.begin();
2270  NBEdge* e2 = *(++connected.begin());
2271  if (e1->hasConnectionTo(e2, 0, 0) || e2->hasConnectionTo(e1, 0, 0)) {
2272  if (gDebugFlag1) {
2273  std::cout << " not building a walkingarea since normal connections exist\n";
2274  }
2275  continue;
2276  }
2277  }
2278  // build smooth inner curve (optional)
2279  if (cornerDetail > 0) {
2280  int smoothEnd = end;
2281  int smoothPrev = prev;
2282  // extend to green verge
2283  if (endCrossingWidth > 0 && normalizedLanes[smoothEnd].second.permissions == 0) {
2284  smoothEnd = (smoothEnd + 1) % normalizedLanes.size();
2285  }
2286  if (startCrossingWidth > 0 && normalizedLanes[smoothPrev].second.permissions == 0) {
2287  if (smoothPrev == 0) {
2288  smoothPrev = (int)normalizedLanes.size() - 1;
2289  } else {
2290  smoothPrev--;
2291  }
2292  }
2293  PositionVector begShape = normalizedLanes[smoothEnd].second.shape;
2294  begShape = begShape.reverse();
2295  //begShape.extrapolate(endCrossingWidth);
2296  begShape.move2side(normalizedLanes[smoothEnd].second.width / 2);
2297  PositionVector endShape = normalizedLanes[smoothPrev].second.shape;
2298  endShape.move2side(normalizedLanes[smoothPrev].second.width / 2);
2299  //endShape.extrapolate(startCrossingWidth);
2300  PositionVector curve = computeSmoothShape(begShape, endShape, cornerDetail + 2, false, 25, 25);
2301  if (gDebugFlag1) std::cout
2302  << " end=" << smoothEnd << " prev=" << smoothPrev
2303  << " endCrossingWidth=" << endCrossingWidth << " startCrossingWidth=" << startCrossingWidth
2304  << " begShape=" << begShape << " endShape=" << endShape << " smooth curve=" << curve << "\n";
2305  if (curve.size() > 2) {
2306  curve.erase(curve.begin());
2307  curve.pop_back();
2308  if (endCrossingWidth > 0) {
2309  wa.shape.pop_back();
2310  }
2311  if (startCrossingWidth > 0) {
2312  wa.shape.erase(wa.shape.begin());
2313  }
2314  wa.shape.append(curve, 0);
2315  }
2316  }
2317  // determine length (average of all possible connections)
2318  SUMOReal lengthSum = 0;
2319  int combinations = 0;
2320  for (std::vector<Position>::const_iterator it1 = connectedPoints.begin(); it1 != connectedPoints.end(); ++it1) {
2321  for (std::vector<Position>::const_iterator it2 = connectedPoints.begin(); it2 != connectedPoints.end(); ++it2) {
2322  const Position& p1 = *it1;
2323  const Position& p2 = *it2;
2324  if (p1 != p2) {
2325  lengthSum += p1.distanceTo2D(p2);
2326  combinations += 1;
2327  }
2328  }
2329  }
2330  if (gDebugFlag1) {
2331  std::cout << " combinations=" << combinations << " connectedPoints=" << connectedPoints << "\n";
2332  }
2333  wa.length = POSITION_EPS;
2334  if (combinations > 0) {
2335  wa.length = MAX2(POSITION_EPS, lengthSum / combinations);
2336  }
2337  myWalkingAreas.push_back(wa);
2338  }
2339  // build walkingAreas between split crossings
2340  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2341  Crossing& prev = *it;
2342  Crossing& next = (it != myCrossings.begin() ? * (it - 1) : * (myCrossings.end() - 1));
2343  if (gDebugFlag1) {
2344  std::cout << " checkIntermediate: prev=" << prev.id << " next=" << next.id << " prev.nextWA=" << prev.nextWalkingArea << "\n";
2345  }
2346  if (prev.nextWalkingArea == "") {
2347  if (next.prevWalkingArea != "") {
2348  WRITE_WARNING("Invalid pedestrian topology: crossing '" + prev.id + "' has no target.");
2349  continue;
2350  }
2351  WalkingArea wa(":" + getID() + "_w" + toString(index++), prev.width);
2352  prev.nextWalkingArea = wa.id;
2353  wa.nextCrossing = next.id;
2354  next.prevWalkingArea = wa.id;
2355  // back of previous crossing
2356  PositionVector tmp = prev.shape;
2357  tmp.move2side(-prev.width / 2);
2358  wa.shape.push_back(tmp[-1]);
2359  tmp.move2side(prev.width);
2360  wa.shape.push_back(tmp[-1]);
2361  // front of next crossing
2362  tmp = next.shape;
2363  tmp.move2side(prev.width / 2);
2364  wa.shape.push_back(tmp[0]);
2365  tmp.move2side(-prev.width);
2366  wa.shape.push_back(tmp[0]);
2367  // length (special case)
2368  wa.length = MAX2(POSITION_EPS, prev.shape.back().distanceTo2D(next.shape.front()));
2369  myWalkingAreas.push_back(wa);
2370  if (gDebugFlag1) {
2371  std::cout << " build wa=" << wa.id << "\n";
2372  }
2373  }
2374  }
2375 }
2376 
2377 
2378 bool
2379 NBNode::crossingBetween(const NBEdge* e1, const NBEdge* e2) const {
2380  if (e1 == e2) {
2381  return false;
2382  }
2383  for (std::vector<Crossing>::const_iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2384  const EdgeVector& edges = (*it).edges;
2385  EdgeVector::const_iterator it1 = find(edges.begin(), edges.end(), e1);
2386  EdgeVector::const_iterator it2 = find(edges.begin(), edges.end(), e2);
2387  if (it1 != edges.end() && it2 != edges.end()) {
2388  return true;
2389  }
2390  }
2391  return false;
2392 }
2393 
2394 
2395 EdgeVector
2396 NBNode::edgesBetween(const NBEdge* e1, const NBEdge* e2) const {
2397  EdgeVector result;
2398  EdgeVector::const_iterator it = find(myAllEdges.begin(), myAllEdges.end(), e1);
2399  assert(it != myAllEdges.end());
2401  EdgeVector::const_iterator it_end = find(myAllEdges.begin(), myAllEdges.end(), e2);
2402  assert(it_end != myAllEdges.end());
2403  while (it != it_end) {
2404  result.push_back(*it);
2406  }
2407  return result;
2408 }
2409 
2410 
2411 bool
2413  if (myIncomingEdges.size() == 1 && myOutgoingEdges.size() == 1) {
2414  return true;
2415  }
2416  if (myIncomingEdges.size() == 2 && myOutgoingEdges.size() == 2) {
2417  // check whether the incoming and outgoing edges are pairwise (near) parallel and
2418  // thus the only cross-connections could be turn-arounds
2419  NBEdge* out0 = myOutgoingEdges[0];
2420  NBEdge* out1 = myOutgoingEdges[1];
2421  for (EdgeVector::const_iterator it = myIncomingEdges.begin(); it != myIncomingEdges.end(); ++it) {
2422  NBEdge* inEdge = *it;
2423  SUMOReal angle0 = fabs(NBHelpers::relAngle(inEdge->getAngleAtNode(this), out0->getAngleAtNode(this)));
2424  SUMOReal angle1 = fabs(NBHelpers::relAngle(inEdge->getAngleAtNode(this), out1->getAngleAtNode(this)));
2425  if (MAX2(angle0, angle1) <= 160) {
2426  // neither of the outgoing edges is parallel to inEdge
2427  return false;
2428  }
2429  }
2430  return true;
2431  }
2432  return false;
2433 }
2434 
2435 
2436 void
2440  }
2441 }
2442 
2443 
2444 void
2445 NBNode::addCrossing(EdgeVector edges, SUMOReal width, bool priority, bool fromSumoNet) {
2446  myCrossings.push_back(Crossing(this, edges, width, priority));
2447  if (fromSumoNet) {
2449  }
2450 }
2451 
2452 
2453 void
2455  EdgeSet edgeSet(edges.begin(), edges.end());
2456  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end();) {
2457  EdgeSet edgeSet2((*it).edges.begin(), (*it).edges.end());
2458  if (edgeSet == edgeSet2) {
2459  it = myCrossings.erase(it);
2460  } else {
2461  ++it;
2462  }
2463  }
2464 }
2465 
2466 
2467 const NBNode::Crossing&
2468 NBNode::getCrossing(const std::string& id) const {
2469  for (std::vector<Crossing>::const_iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2470  if ((*it).id == id) {
2471  return *it;
2472  }
2473  }
2474  throw ProcessError("Request for unknown crossing '" + id + "'");
2475 }
2476 
2477 
2478 void
2479 NBNode::setCrossingTLIndices(unsigned int startIndex) {
2480  for (std::vector<Crossing>::iterator it = myCrossings.begin(); it != myCrossings.end(); ++it) {
2481  (*it).tlLinkNo = startIndex++;
2482  }
2483 }
2484 
2485 
2486 int
2488  return myRequest->getSizes().second;
2489 }
2490 
2491 Position
2493  /* Conceptually, the center point would be identical with myPosition.
2494  * However, if the shape is influenced by custom geometry endpoints of the adjoining edges,
2495  * myPosition may fall outside the shape. In this case it is better to use
2496  * the center of the shape
2497  **/
2498  PositionVector tmp = myPoly;
2499  tmp.closePolygon();
2500  //std::cout << getID() << " around=" << tmp.around(myPosition) << " dist=" << tmp.distance(myPosition) << "\n";
2501  if (tmp.size() < 3 || tmp.around(myPosition) || tmp.distance(myPosition) < POSITION_EPS) {
2502  return myPosition;
2503  } else {
2504  return myPoly.getPolygonCenter();
2505  }
2506 }
2507 
2508 
2509 EdgeVector
2511  EdgeVector result = myAllEdges;
2512  if (gDebugFlag1) {
2513  std::cout << " angles:\n";
2514  for (EdgeVector::const_iterator it = result.begin(); it != result.end(); ++it) {
2515  std::cout << " edge=" << (*it)->getID() << " edgeAngle=" << (*it)->getAngleAtNode(this) << " angleToShape=" << (*it)->getAngleAtNodeToCenter(this) << "\n";
2516  }
2517  std::cout << " allEdges before: " << toString(result) << "\n";
2518  }
2519  sort(result.begin(), result.end(), NBContHelper::edge_by_angle_to_nodeShapeCentroid_sorter(this));
2520  // let the first edge in myAllEdges remain the first
2521  if (gDebugFlag1) {
2522  std::cout << " allEdges sorted: " << toString(result) << "\n";
2523  }
2524  rotate(result.begin(), std::find(result.begin(), result.end(), *myAllEdges.begin()), result.end());
2525  if (gDebugFlag1) {
2526  std::cout << " allEdges rotated: " << toString(result) << "\n";
2527  }
2528  return result;
2529 }
2530 
2531 
2532 std::string
2533 NBNode::getNodeIDFromInternalLane(const std::string id) {
2534  // this relies on the fact that internal ids always have the form
2535  // :<nodeID>_<part1>_<part2>
2536  // i.e. :C_3_0, :C_c1_0 :C_w0_0
2537  assert(id[0] == ':');
2538  size_t sep_index = id.rfind('_');
2539  if (sep_index == std::string::npos) {
2540  WRITE_ERROR("Invalid lane id '" + id + "' (missing '_').");
2541  return "";
2542  }
2543  sep_index = id.substr(0, sep_index).rfind('_');
2544  if (sep_index == std::string::npos) {
2545  WRITE_ERROR("Invalid lane id '" + id + "' (missing '_').");
2546  return "";
2547  }
2548  return id.substr(1, sep_index - 1);
2549 }
2550 
2551 
2552 void
2554  // simple case: edges with LANESPREAD_CENTER and a (possible) turndirection at the same node
2555  for (EdgeVector::iterator it = myIncomingEdges.begin(); it != myIncomingEdges.end(); it++) {
2556  NBEdge* edge = *it;
2557  NBEdge* turnDest = edge->getTurnDestination(true);
2558  if (turnDest != 0) {
2559  edge->shiftPositionAtNode(this, turnDest);
2560  turnDest->shiftPositionAtNode(this, edge);
2561  }
2562  }
2563  // @todo: edges in the same direction with sharp angles starting/ending at the same position
2564 }
2565 
2566 
2567 bool
2569  return type == NODETYPE_TRAFFIC_LIGHT
2572 }
2573 
2574 
2575 bool
2576 NBNode::rightOnRedConflict(int index, int foeIndex) const {
2578  for (std::set<NBTrafficLightDefinition*>::const_iterator i = myTrafficLights.begin(); i != myTrafficLights.end(); ++i) {
2579  if ((*i)->rightOnRedConflict(index, foeIndex)) {
2580  return true;
2581  }
2582  }
2583  }
2584  return false;
2585 }
2586 /****************************************************************************/
2587 
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:91
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:541
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:1033
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:812
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:1243
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:2437
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:2492
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:1703
PositionVector myPoly
the (outer) shape of the junction
Definition: NBNode.h:766
NBEdge * getOppositeIncoming(NBEdge *e) const
Definition: NBNode.cpp:1152
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:502
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:2468
void removeEdge(NBEdge *edge, bool removeFromConnections=true)
Removes edge from this node and optionally removes connections as well.
Definition: NBNode.cpp:1213
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:2487
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition: NBNode.cpp:1146
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:2396
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:707
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:1101
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOReal getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:449
#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:2046
bool isInnerEdge() const
Returns whether this edge was marked as being within an intersection.
Definition: NBEdge.h:876
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:906
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:2510
bool checkIsRemovable() const
Definition: NBNode.cpp:1564
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 ...
bool 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:724
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
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:1644
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:1140
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:1307
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:741
void invalidateIncomingConnections()
Definition: NBNode.cpp:1271
bool isConnectedTo(NBEdge *e)
Returns the information whethe a connection to the given edge has been added (or computed) ...
Definition: NBEdge.cpp:818
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:2454
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:1187
bool isSimpleContinuation() const
Definition: NBNode.cpp:444
int checkCrossing(EdgeVector candidates)
Definition: NBNode.cpp:1811
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:1301
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:1913
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:2412
void invalidateOutgoingConnections()
Definition: NBNode.cpp:1279
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:441
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:1867
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
Definition: NBNode.cpp:329
EdgeVector * getEdgesThatApproach(NBEdge *currentOutgoing)
Definition: NBNode.cpp:974
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:2435
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:1651
T MIN2(T a, T b)
Definition: StdDefs.h:69
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:2479
The link is a (hard) right direction.
#define POSITION_EPS
Definition: config.h:187
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1535
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:2576
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:1471
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
PositionVector compute()
Computes the shape of the assigned junction.
const PositionVector & getShape() const
retrieve the junction shape
Definition: NBNode.cpp:1638
T ISNAN(T a)
Definition: StdDefs.h:110
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:1661
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:1354
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:1615
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1267
void avoidOverlap()
fix overlap
Definition: NBNode.cpp:2553
NBEdge * getPossiblySplittedOutgoing(const std::string &edgeid)
Definition: NBNode.cpp:1200
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:206
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:2393
SUMOReal getCrossingAngle(NBNode *node)
return the angle for computing pedestrian crossings at the given node
Definition: NBEdge.cpp:2452
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:1672
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:880
void addCrossing(EdgeVector edges, SUMOReal width, bool priority, bool fromSumoNet=false)
add a pedestrian crossing to this node
Definition: NBNode.cpp:2445
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:997
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:1964
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:1287
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:1066
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:1934
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:961
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:2379
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:1067
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:1709
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:1170
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
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:699
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:650
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:431
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:1383
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
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:763
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition: NBEdge.cpp:2157
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:2568
void shiftPositionAtNode(NBNode *node, NBEdge *opposite)
shift geometry at the given node to avoid overlap
Definition: NBEdge.cpp:2535
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:709
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:1390
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:1287
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:1373
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:1902
static bool isLongEnough(NBEdge *out, SUMOReal minLength)
Definition: NBNode.cpp:958
static std::string getNodeIDFromInternalLane(const std::string id)
returns the node id for internal lanes, crossings and walkingareas
Definition: NBNode.cpp:2533
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:361