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