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