Eclipse SUMO - Simulation of Urban MObility
NBNodeShapeComputer.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// This class computes shapes of junctions
21/****************************************************************************/
22#include <config.h>
23
24#include <algorithm>
25#include <iterator>
34#include "NBNode.h"
35#include "NBNodeShapeComputer.h"
36
37//#define DEBUG_NODE_SHAPE
38//#define DEBUG_SMOOTH_CORNERS
39//#define DEBUG_RADIUS
40#define DEBUGCOND (myNode.getID() == "C")
41
42
43#define EXT 100.0
44#define EXT2 10.0
45
46// foot and bicycle paths as well as pure service roads should not get large junctions
47// railways also do have have junctions with sharp turns so can be excluded
50
51// ===========================================================================
52// method definitions
53// ===========================================================================
55 myNode(node),
56 myRadius(node.getRadius()) {
57}
58
59
61
62
65#ifdef DEBUG_NODE_SHAPE
66 if (DEBUGCOND) {
67 // annotate edges edges to make their ordering visible
68 int i = 0;
69 for (NBEdge* e : myNode.getEdges()) {
70 e->setStreetName(toString(i));
71 i++;
72 }
73 }
74#endif
75 // check whether the node is a dead end node or a node where only turning is possible
76 // in this case, we will use "computeNodeShapeSmall"
77 if (myNode.getEdges().size() == 1) {
78 return computeNodeShapeSmall();
79 }
80 if (myNode.getEdges().size() == 2 && myNode.getIncomingEdges().size() == 1) {
81 if (myNode.getIncomingEdges()[0]->isTurningDirectionAt(myNode.getOutgoingEdges()[0])) {
82 return computeNodeShapeSmall();
83 }
84 }
85 const bool geometryLike = myNode.isSimpleContinuation(true, true);
86 const PositionVector& ret = computeNodeShapeDefault(geometryLike);
87 // fail fall-back: use "computeNodeShapeSmall"
88 if (ret.size() < 3) {
89 return computeNodeShapeSmall();
90 }
91 return ret;
92}
93
94
95void
97 assert(l1[0].distanceTo2D(l1[1]) >= EXT);
98 assert(l2[0].distanceTo2D(l2[1]) >= EXT);
100 tmp.push_back(PositionVector::positionAtOffset2D(l1[0], l1[1], EXT));
101 tmp.push_back(l1[1]);
102 tmp[1].sub(tmp[0]);
103 tmp[1].set(-tmp[1].y(), tmp[1].x());
104 tmp[1].add(tmp[0]);
105 tmp.extrapolate2D(EXT);
106 if (l2.intersects(tmp[0], tmp[1])) {
107 const double offset = l2.intersectsAtLengths2D(tmp)[0];
108 if (l2.length2D() - offset > POSITION_EPS) {
109 PositionVector tl2 = l2.getSubpart2D(offset, l2.length2D());
110 tl2.extrapolate2D(EXT);
111 l2.erase(l2.begin(), l2.begin() + (l2.size() - tl2.size()));
112 l2[0] = tl2[0];
113 }
114 }
115}
116
117
118const PositionVector
120 // if we have less than two edges, we can not compute the node's shape this way
121 if (myNode.getEdges().size() < 2) {
122 return PositionVector();
123 }
124 // magic values
126 const double defaultRadius = getDefaultRadius(oc);
127 const bool useDefaultRadius = myNode.getRadius() == NBNode::UNSPECIFIED_RADIUS || myNode.getRadius() == defaultRadius;
128 myRadius = (useDefaultRadius ? defaultRadius : myNode.getRadius());
129 double smallRadius = useDefaultRadius ? oc.getFloat("junctions.small-radius") : myRadius;
130 const int cornerDetail = oc.getInt("junctions.corner-detail");
131 const double sCurveStretch = oc.getFloat("junctions.scurve-stretch");
132 const bool rectangularCut = oc.getBool("rectangular-lane-cut");
133 const bool openDriveOutput = oc.isSet("opendrive-output");
134
135 // Extend geometries to move the stop line forward.
136 // In OpenDrive the junction starts whenever the geometry changes. Stop
137 // line information is not given or ambiguous (sign positions at most)
138 // In SUMO, stop lines are where the junction starts. This is computed
139 // heuristically from intersecting the junctions roads geometries.
140 const double advanceStopLine = oc.exists("opendrive-files") && oc.isSet("opendrive-files") ? oc.getFloat("opendrive.advance-stopline") : 0;
141
142
143#ifdef DEBUG_NODE_SHAPE
144 if (DEBUGCOND) {
145 std::cout << "\ncomputeNodeShapeDefault node " << myNode.getID() << " simple=" << simpleContinuation << " useDefaultRadius=" << useDefaultRadius << " radius=" << myRadius << "\n";
146 }
147#endif
148
149 // initialise
150 EdgeVector::const_iterator i;
151 // edges located in the value-vector have the same direction as the key edge
152 std::map<NBEdge*, std::set<NBEdge*> > same;
153 // the counter-clockwise boundary of the edge regarding possible same-direction edges
154 GeomsMap geomsCCW;
155 // the clockwise boundary of the edge regarding possible same-direction edges
156 GeomsMap geomsCW;
157 EdgeVector usedEdges = myNode.getEdges();
158 computeEdgeBoundaries(usedEdges, geomsCCW, geomsCW);
159
160 // check which edges are parallel
161 joinSameDirectionEdges(usedEdges, same);
162 // compute unique direction list
163 EdgeVector newAll = computeUniqueDirectionList(usedEdges, same, geomsCCW, geomsCW);
164 // if we have only two "directions", let's not compute the geometry using this method
165 if (newAll.size() < 2) {
166 return PositionVector();
167 }
168
169 // All geoms are outgoing from myNode.
170 // for every direction in newAll we compute the offset at which the
171 // intersection ends and the edge starts. This value is saved in 'distances'
172 // If the geometries need to be extended to get an intersection, this is
173 // recorded in 'myExtended'
174 std::map<NBEdge*, double> distances;
175 std::map<NBEdge*, bool> myExtended;
176
177 for (i = newAll.begin(); i != newAll.end(); ++i) {
178 EdgeVector::const_iterator cwi = i;
179 EdgeVector::const_iterator ccwi = i;
180 double ccad;
181 double cad;
182 initNeighbors(newAll, i, geomsCW, geomsCCW, cwi, ccwi, cad, ccad);
183 assert(geomsCCW.find(*i) != geomsCCW.end());
184 assert(geomsCW.find(*ccwi) != geomsCW.end());
185 assert(geomsCW.find(*cwi) != geomsCW.end());
186
187 // there are only 2 directions and they are almost parallel
188 if (*cwi == *ccwi &&
189 (
190 // no change in lane numbers, even low angles still give a good intersection
191 (simpleContinuation && fabs(ccad - cad) < (double) 0.1)
192 // lane numbers change, a direct intersection could be far away from the node position
193 // so we use a larger threshold
194 || (!simpleContinuation && fabs(ccad - cad) < DEG2RAD(22.5)))
195 ) {
196 // compute the mean position between both edges ends ...
197 Position p;
198 if (myExtended.find(*ccwi) != myExtended.end()) {
199 p = geomsCCW[*ccwi][0];
200 p.add(geomsCW[*ccwi][0]);
201 p.mul(0.5);
202#ifdef DEBUG_NODE_SHAPE
203 if (DEBUGCOND) {
204 std::cout << " extended: p=" << p << " angle=" << (ccad - cad) << "\n";
205 }
206#endif
207 } else {
208 p = geomsCCW[*ccwi][0];
209 p.add(geomsCW[*ccwi][0]);
210 p.add(geomsCCW[*i][0]);
211 p.add(geomsCW[*i][0]);
212 p.mul(0.25);
213#ifdef DEBUG_NODE_SHAPE
214 if (DEBUGCOND) {
215 std::cout << " unextended: p=" << p << " angle=" << (ccad - cad) << "\n";
216 }
217#endif
218 }
219 // ... compute the distance to this point ...
220 double dist = MAX2(
221 geomsCCW[*i].nearest_offset_to_point2D(p),
222 geomsCW[*i].nearest_offset_to_point2D(p));
223 if (dist < 0) {
224 if (isRailway((*i)->getPermissions())) {
225 // better not mess up bidi geometries
226 return PositionVector();
227 }
228 // ok, we have the problem that even the extrapolated geometry
229 // does not reach the point
230 // in this case, the geometry has to be extenden... too bad ...
231 // ... let's append the mean position to the geometry
232 PositionVector g = (*i)->getGeometry();
233 if (myNode.hasIncoming(*i)) {
235 } else {
237 }
238 (*i)->setGeometry(g);
239 // and rebuild previous information
240 geomsCCW[*i] = (*i)->getCCWBoundaryLine(myNode);
241 geomsCCW[*i].extrapolate(EXT);
242 geomsCW[*i] = (*i)->getCWBoundaryLine(myNode);
243 geomsCW[*i].extrapolate(EXT);
244 // the distance is now = zero (the point we have appended)
245 distances[*i] = EXT;
246 myExtended[*i] = true;
247#ifdef DEBUG_NODE_SHAPE
248 if (DEBUGCOND) {
249 std::cout << " extending (dist=" << dist << ")\n";
250 }
251#endif
252 } else {
253 if (!simpleContinuation) {
254 dist += myRadius;
255 } else {
256 // if the angles change, junction should have some size to avoid degenerate shape
257 double radius2 = fabs(ccad - cad) * (*i)->getNumLanes();
258 if (radius2 > NUMERICAL_EPS || openDriveOutput) {
259 radius2 = MAX2(0.15, radius2);
260 }
261 if (myNode.getCrossings().size() > 0) {
262 double width = myNode.getCrossings()[0]->customWidth;
263 if (width == NBEdge::UNSPECIFIED_WIDTH) {
264 width = OptionsCont::getOptions().getFloat("default.crossing-width");
265 }
266 radius2 = MAX2(radius2, width / 2);
267 }
268 dist += radius2;
269#ifdef DEBUG_NODE_SHAPE
270 if (DEBUGCOND) {
271 std::cout << " using radius=" << radius2 << " ccad=" << ccad << " cad=" << cad << "\n";
272 }
273#endif
274 }
275 distances[*i] = dist;
276 }
277
278 } else {
279 // the angles are different enough to compute the intersection of
280 // the outer boundaries directly (or there are more than 2 directions). The "nearer" neighbor causes the furthest distance
281 const bool ccwCloser = ccad < cad;
282 const bool cwLargeTurn = needsLargeTurn(*i, *cwi, same);
283 const bool ccwLargeTurn = needsLargeTurn(*i, *ccwi, same);
284 const bool neighLargeTurn = ccwCloser ? ccwLargeTurn : cwLargeTurn;
285 const bool neigh2LargeTurn = ccwCloser ? cwLargeTurn : ccwLargeTurn;
286 // the border facing the closer neighbor
287 const PositionVector& currGeom = ccwCloser ? geomsCCW[*i] : geomsCW[*i];
288 // the border facing the far neighbor
289 const PositionVector& currGeom2 = ccwCloser ? geomsCW[*i] : geomsCCW[*i];
290 // the border of the closer neighbor
291 const PositionVector& neighGeom = ccwCloser ? geomsCW[*ccwi] : geomsCCW[*cwi];
292 // the border of the far neighbor
293 const PositionVector& neighGeom2 = ccwCloser ? geomsCCW[*cwi] : geomsCW[*ccwi];
294#ifdef DEBUG_NODE_SHAPE
295 if (DEBUGCOND) {
296 std::cout << " i=" << (*i)->getID() << " neigh=" << (*ccwi)->getID() << " neigh2=" << (*cwi)->getID() << "\n";
297 std::cout << " ccwCloser=" << ccwCloser
298 << "\n currGeom=" << currGeom << " neighGeom=" << neighGeom
299 << "\n currGeom2=" << currGeom2 << " neighGeom2=" << neighGeom2
300 << "\n";
301 }
302#endif
303 if (!simpleContinuation) {
304 if (currGeom.intersects(neighGeom)) {
305 distances[*i] = (neighLargeTurn ? myRadius : smallRadius) + closestIntersection(currGeom, neighGeom, EXT);
306#ifdef DEBUG_NODE_SHAPE
307 if (DEBUGCOND) {
308 std::cout << " neigh intersects dist=" << distances[*i] << " currGeom=" << currGeom << " neighGeom=" << neighGeom << "\n";
309 }
310#endif
311 if (*cwi != *ccwi && currGeom2.intersects(neighGeom2)) {
312 // also use the second intersection point
313 // but prevent very large node shapes
314 const double farAngleDist = ccwCloser ? cad : ccad;
315 double a1 = distances[*i];
316 double a2 = (neigh2LargeTurn ? myRadius : smallRadius) + closestIntersection(currGeom2, neighGeom2, EXT);
317#ifdef DEBUG_NODE_SHAPE
318 if (DEBUGCOND) {
319 std::cout << " neigh2 also intersects a1=" << a1 << " a2=" << a2 << " ccad=" << RAD2DEG(ccad) << " cad=" << RAD2DEG(cad) << " dist[cwi]=" << distances[*cwi] << " dist[ccwi]=" << distances[*ccwi] << " farAngleDist=" << RAD2DEG(farAngleDist) << " currGeom2=" << currGeom2 << " neighGeom2=" << neighGeom2 << "\n";
320 }
321#endif
322 //if (RAD2DEG(farAngleDist) < 175) {
323 // distances[*i] = MAX2(a1, MIN2(a2, a1 + 180 - RAD2DEG(farAngleDist)));
324 //}
325 if (a2 <= EXT) {
326 distances[*i] = MAX2(a1, a2);
327 } else if (ccad > DEG2RAD(90. + 45.) && cad > DEG2RAD(90. + 45.)) {
328 // do nothing.
329 } else if (farAngleDist < DEG2RAD(135) || (fabs(RAD2DEG(farAngleDist) - 180) > 1 && fabs(a2 - a1) < 10)) {
330 distances[*i] = MAX2(a1, a2);
331 }
332#ifdef DEBUG_NODE_SHAPE
333 if (DEBUGCOND) {
334 std::cout << " a1=" << a1 << " a2=" << a2 << " dist=" << distances[*i] << "\n";
335 }
336#endif
337 }
338 } else {
339 if (*cwi != *ccwi && currGeom2.intersects(neighGeom2)) {
340 distances[*i] = (neigh2LargeTurn ? myRadius : smallRadius) + currGeom2.intersectsAtLengths2D(neighGeom2)[0];
341#ifdef DEBUG_NODE_SHAPE
342 if (DEBUGCOND) {
343 std::cout << " neigh2 intersects dist=" << distances[*i] << " currGeom2=" << currGeom2 << " neighGeom2=" << neighGeom2 << "\n";
344 }
345#endif
346 } else {
347 distances[*i] = EXT + myRadius;
348#ifdef DEBUG_NODE_SHAPE
349 if (DEBUGCOND) {
350 std::cout << " no intersects dist=" << distances[*i] << " currGeom=" << currGeom << " neighGeom=" << neighGeom << " currGeom2=" << currGeom2 << " neighGeom2=" << neighGeom2 << "\n";
351 }
352#endif
353 }
354 }
355 } else {
356 if (currGeom.intersects(neighGeom)) {
357 distances[*i] = currGeom.intersectsAtLengths2D(neighGeom)[0];
358 } else {
359 distances[*i] = (double) EXT;
360 }
361 }
362 }
363 if (useDefaultRadius && sCurveStretch > 0) {
364 double sCurveWidth = myNode.getDisplacementError();
365 if (sCurveWidth > 0) {
366 const double sCurveRadius = myRadius + sCurveWidth / SUMO_const_laneWidth * sCurveStretch * pow((*i)->getSpeed(), 2 + sCurveStretch) / 1000;
367 const double stretch = EXT + sCurveRadius - distances[*i];
368 if (stretch > 0) {
369 distances[*i] += stretch;
370 // fixate extended geometry for repeated computation
371 const double shorten = distances[*i] - EXT;
372 (*i)->shortenGeometryAtNode(&myNode, shorten);
373 for (std::set<NBEdge*>::iterator k = same[*i].begin(); k != same[*i].end(); ++k) {
374 (*k)->shortenGeometryAtNode(&myNode, shorten);
375 }
376#ifdef DEBUG_NODE_SHAPE
377 if (DEBUGCOND) {
378 std::cout << " stretching junction: sCurveWidth=" << sCurveWidth << " sCurveRadius=" << sCurveRadius << " stretch=" << stretch << " dist=" << distances[*i] << "\n";
379 }
380#endif
381 }
382 }
383 }
384 }
385
386 for (NBEdge* const edge : newAll) {
387 if (distances.find(edge) == distances.end()) {
388 assert(false);
389 distances[edge] = EXT;
390 }
391 }
392 // because of lane spread right the crossing point may be identical to the junction center and thus the distance is exactly EXT
393 const double off = EXT - NUMERICAL_EPS;
394 // prevent inverted node shapes
395 // (may happen with near-parallel edges)
396 const double minDistSum = 2 * (EXT + myRadius);
397 for (NBEdge* const edge : newAll) {
398 if (distances[edge] < off && edge->hasDefaultGeometryEndpointAtNode(&myNode)) {
399 for (EdgeVector::const_iterator j = newAll.begin(); j != newAll.end(); ++j) {
400 if (distances[*j] > off && (*j)->hasDefaultGeometryEndpointAtNode(&myNode) && distances[edge] + distances[*j] < minDistSum) {
401 const double angleDiff = fabs(NBHelpers::relAngle(edge->getAngleAtNode(&myNode), (*j)->getAngleAtNode(&myNode)));
402 if (angleDiff > 160 || angleDiff < 20) {
403#ifdef DEBUG_NODE_SHAPE
404 if (DEBUGCOND) {
405 std::cout << " increasing dist for i=" << edge->getID() << " because of j=" << (*j)->getID() << " jDist=" << distances[*j]
406 << " oldI=" << distances[edge] << " newI=" << minDistSum - distances[*j]
407 << " angleDiff=" << angleDiff
408 << " geomI=" << edge->getGeometry() << " geomJ=" << (*j)->getGeometry() << "\n";
409 }
410#endif
411 distances[edge] = minDistSum - distances[*j];
412 }
413 }
414 }
415 }
416 }
417
418
419 // build
420 PositionVector ret;
421 for (i = newAll.begin(); i != newAll.end(); ++i) {
422 const PositionVector& ccwBound = geomsCCW[*i];
423 const PositionVector& cwBound = geomsCW[*i];
424 //double offset = MIN3(distances[*i], cwBound.length2D() - POSITION_EPS, ccwBound.length2D() - POSITION_EPS);
425 double offset = distances[*i];
426 if (!(*i)->hasDefaultGeometryEndpointAtNode(&myNode)) {
427 // for non geometry-endpoints, only shorten but never extend the geometry
428 if (advanceStopLine > 0 && offset < EXT) {
429#ifdef DEBUG_NODE_SHAPE
430 std::cout << " i=" << (*i)->getID() << " offset=" << offset << " advanceStopLine=" << advanceStopLine << "\n";
431#endif
432 // fixate extended geometry for repeated computation
433 (*i)->extendGeometryAtNode(&myNode, advanceStopLine);
434 for (std::set<NBEdge*>::iterator k = same[*i].begin(); k != same[*i].end(); ++k) {
435 (*k)->extendGeometryAtNode(&myNode, advanceStopLine);
436 }
437 }
438 offset = MAX2(EXT - advanceStopLine, offset);
439 }
440 if (offset == -1) {
441 WRITE_WARNINGF(TL("Fixing offset for edge '%' at node '%."), (*i)->getID(), myNode.getID());
442 offset = (double) - .1;
443 }
444 Position p = ccwBound.positionAtOffset2D(offset);
445 p.setz(myNode.getPosition().z());
446 if (i != newAll.begin()) {
447 ret.append(getSmoothCorner(geomsCW[*(i - 1)], ccwBound, ret[-1], p, cornerDetail));
448 }
450 //
451 Position p2 = cwBound.positionAtOffset2D(offset);
452 p2.setz(myNode.getPosition().z());
453 ret.push_back_noDoublePos(p2);
454#ifdef DEBUG_NODE_SHAPE
455 if (DEBUGCOND) {
456 std::cout << " build stopLine for i=" << (*i)->getID() << " offset=" << offset << " dist=" << distances[*i] << " cwLength=" << cwBound.length2D() << " ccwLength=" << ccwBound.length2D() << " p=" << p << " p2=" << p2 << " ccwBound=" << ccwBound << " cwBound=" << cwBound << "\n";
457 }
458#endif
459 (*i)->setNodeBorder(&myNode, p, p2, rectangularCut);
460 for (std::set<NBEdge*>::iterator k = same[*i].begin(); k != same[*i].end(); ++k) {
461 (*k)->setNodeBorder(&myNode, p, p2, rectangularCut);
462 }
463 }
464 // final curve segment
465 ret.append(getSmoothCorner(geomsCW[*(newAll.end() - 1)], geomsCCW[*newAll.begin()], ret[-1], ret[0], cornerDetail));
466#ifdef DEBUG_NODE_SHAPE
467 if (DEBUGCOND) {
468 std::cout << " final shape=" << ret << "\n";
469 }
470#endif
471 return ret;
472}
473
474
475double
477 std::vector<double> intersections = geom1.intersectsAtLengths2D(geom2);
478 double result = intersections[0];
479 for (std::vector<double>::iterator it = intersections.begin() + 1; it != intersections.end(); ++it) {
480 if (fabs(*it - offset) < fabs(result - offset)) {
481 result = *it;
482 }
483 }
484 return result;
485}
486
487bool
489 std::map<NBEdge*, std::set<NBEdge*> >& same) const {
490 const SVCPermissions p1 = e1->getPermissions();
491 const SVCPermissions p2 = e2->getPermissions();
492 if ((p1 & p2 & SVC_LARGE_TURN) != 0) {
493 // note: would could also check whether there is actually a connection
494 // between those edges
495 return true;
496 }
497 // maybe edges in the same direction need a large turn
498 for (NBEdge* e2s : same[e2]) {
499 if ((p1 & e2s->getPermissions() & SVC_LARGE_TURN) != 0
500 && (e1->getToNode() == e2s->getFromNode() || e2s->getToNode() == e1->getFromNode())) {
501 return true;
502 }
503 for (NBEdge* e1s : same[e1]) {
504 if ((e2s->getPermissions() & e1s->getPermissions() & SVC_LARGE_TURN) != 0
505 && (e2s->getToNode() == e1s->getFromNode() || e1s->getToNode() == e2s->getFromNode())) {
506 return true;
507 }
508 }
509 }
510 for (NBEdge* e1s : same[e1]) {
511 if ((p2 & e1s->getPermissions() & SVC_LARGE_TURN) != 0
512 && (e2->getToNode() == e1s->getFromNode() || e1s->getToNode() == e2->getFromNode())) {
513 return true;
514 }
515 }
516 //std::cout << " e1=" << e1->getID() << " e2=" << e2->getID() << " sameE1=" << toString(same[e1]) << " sameE2=" << toString(same[e2]) << "\n";
517 return false;
518}
519
522 const Position& begPoint, const Position& endPoint, int cornerDetail) {
523 PositionVector ret;
524 if (cornerDetail > 0) {
525 PositionVector begShape2 = begShape.reverse().getSubpart2D(EXT2, begShape.length());
526 const double begSplit = begShape2.nearest_offset_to_point2D(begPoint, false);
527#ifdef DEBUG_SMOOTH_CORNERS
528 if (DEBUGCOND) {
529 std::cout << " begLength=" << begShape2.length2D() << " begSplit=" << begSplit << "\n";
530 }
531#endif
532 if (begSplit > POSITION_EPS && begSplit < begShape2.length2D() - POSITION_EPS) {
533 begShape2 = begShape2.splitAt(begSplit, true).first;
534 } else {
535 return ret;
536 }
537 PositionVector endShape2 = endShape.getSubpart(0, endShape.length() - EXT2);
538 const double endSplit = endShape2.nearest_offset_to_point2D(endPoint, false);
539#ifdef DEBUG_SMOOTH_CORNERS
540 if (DEBUGCOND) {
541 std::cout << " endLength=" << endShape2.length2D() << " endSplit=" << endSplit << "\n";
542 }
543#endif
544 if (endSplit > POSITION_EPS && endSplit < endShape2.length2D() - POSITION_EPS) {
545 endShape2 = endShape2.splitAt(endSplit, true).second;
546 } else {
547 return ret;
548 }
549 // flatten z to junction z level
550 begShape2 = begShape2.interpolateZ(myNode.getPosition().z(), myNode.getPosition().z());
551 endShape2 = endShape2.interpolateZ(myNode.getPosition().z(), myNode.getPosition().z());
552#ifdef DEBUG_SMOOTH_CORNERS
553 if (DEBUGCOND) {
554 std::cout << "getSmoothCorner begPoint=" << begPoint << " endPoint=" << endPoint
555 << " begShape=" << begShape << " endShape=" << endShape
556 << " begShape2=" << begShape2 << " endShape2=" << endShape2
557 << "\n";
558 }
559#endif
560 if (begShape2.size() < 2 || endShape2.size() < 2) {
561 return ret;
562 }
563 const double angle = GeomHelper::angleDiff(begShape2.angleAt2D(-2), endShape2.angleAt2D(0));
564 NBNode* recordError = nullptr;
565#ifdef DEBUG_SMOOTH_CORNERS
566 if (DEBUGCOND) {
567 std::cout << " angle=" << RAD2DEG(angle) << "\n";
568 }
569 recordError = const_cast<NBNode*>(&myNode);
570#endif
571 // fill highly acute corners
572 //if (fabs(angle) > DEG2RAD(135)) {
573 // return ret;
574 //}
575 PositionVector curve = myNode.computeSmoothShape(begShape2, endShape2, cornerDetail + 2, false, 25, 25, recordError, NBNode::AVOID_WIDE_LEFT_TURN);
576 //PositionVector curve = myNode.computeSmoothShape(begShape2, endShape2, cornerDetail + 2, false, 25, 25, recordError, 0);
577 const double curvature = curve.length2D() / MAX2(NUMERICAL_EPS, begPoint.distanceTo2D(endPoint));
578#ifdef DEBUG_SMOOTH_CORNERS
579 if (DEBUGCOND) {
580 std::cout << " curve=" << curve << " curveLength=" << curve.length2D() << " dist=" << begPoint.distanceTo2D(endPoint) << " curvature=" << curvature << "\n";
581 }
582#endif
583 if (curvature > 2 && angle > DEG2RAD(85)) {
584 // simplify dubious inside corner shape
585 return ret;
586 }
587 if (curve.size() > 2) {
588 curve.erase(curve.begin());
589 curve.pop_back();
590 ret = curve;
591 }
592 }
593 return ret;
594}
595
596void
598 GeomsMap& geomsCCW,
599 GeomsMap& geomsCW) {
600 // compute boundary lines and extend it by EXT m
601 for (NBEdge* const edge : edges) {
602 // store current edge's boundary as current ccw/cw boundary
603 try {
604 geomsCCW[edge] = edge->getCCWBoundaryLine(myNode);
605 } catch (InvalidArgument& e) {
606 WRITE_WARNING("While computing intersection geometry at junction '" + myNode.getID() + "': " + std::string(e.what()));
607 geomsCCW[edge] = edge->getGeometry();
608 }
609 try {
610 geomsCW[edge] = edge->getCWBoundaryLine(myNode);
611 } catch (InvalidArgument& e) {
612 WRITE_WARNING("While computing intersection geometry at junction '" + myNode.getID() + "': " + std::string(e.what()));
613 geomsCW[edge] = edge->getGeometry();
614 }
615 // ensure the boundary is valid
616 if (geomsCCW[edge].length2D() < NUMERICAL_EPS) {
617 geomsCCW[edge] = edge->getGeometry();
618 }
619 if (geomsCW[edge].length2D() < NUMERICAL_EPS) {
620 geomsCW[edge] = edge->getGeometry();
621 }
622 // cut off all parts beyond EXT to avoid issues with curved-back roads
623 geomsCCW[edge] = geomsCCW[edge].getSubpart2D(0, MAX2(EXT, edge->getTotalWidth()));
624 geomsCW[edge] = geomsCW[edge].getSubpart2D(0, MAX2(EXT, edge->getTotalWidth()));
625 // extend the boundary by extrapolating it by EXT m towards the junction
626 geomsCCW[edge].extrapolate2D(EXT, true);
627 geomsCW[edge].extrapolate2D(EXT, true);
628 // ensure minimum length by extending it away from the junction
629 geomsCCW[edge].extrapolate(EXT2, false, true);
630 geomsCW[edge].extrapolate(EXT2, false, true);
631 }
632}
633
634void
635NBNodeShapeComputer::joinSameDirectionEdges(const EdgeVector& edges, std::map<NBEdge*, std::set<NBEdge*> >& same) {
636 // compute same (edges where an intersection doesn't work well
637 // (always check an edge and its cw neighbor)
638 const double angleChangeLookahead = 35; // distance to look ahead for a misleading angle
639 const bool isXodr = OptionsCont::getOptions().exists("opendrive-files") && OptionsCont::getOptions().isSet("opendrive-files");
640 EdgeSet foundOpposite;
641 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); i++) {
642 EdgeVector::const_iterator j;
643 if (i == edges.end() - 1) {
644 j = edges.begin();
645 } else {
646 j = i + 1;
647 }
648 const bool incoming = (*i)->getToNode() == &myNode;
649 const bool incoming2 = (*j)->getToNode() == &myNode;
650 const bool differentDirs = (incoming != incoming2);
651 const bool sameGeom = (*i)->getGeometry() == (differentDirs ? (*j)->getGeometry().reverse() : (*j)->getGeometry());
652 const PositionVector g1 = incoming ? (*i)->getCCWBoundaryLine(myNode) : (*i)->getCWBoundaryLine(myNode);
653 const PositionVector g2 = incoming ? (*j)->getCCWBoundaryLine(myNode) : (*j)->getCWBoundaryLine(myNode);
654 const double angle1further = (g1.size() > 2 && g1[0].distanceTo2D(g1[1]) < angleChangeLookahead ?
655 g1.angleAt2D(1) : g1.angleAt2D(0));
656 const double angle2further = (g2.size() > 2 && g2[0].distanceTo2D(g2[1]) < angleChangeLookahead ?
657 g2.angleAt2D(1) : g2.angleAt2D(0));
658 const double angleDiff = GeomHelper::angleDiff(g1.angleAt2D(0), g2.angleAt2D(0));
659 const double angleDiffFurther = GeomHelper::angleDiff(angle1further, angle2further);
660 const bool ambiguousGeometry = ((angleDiff > 0 && angleDiffFurther < 0) || (angleDiff < 0 && angleDiffFurther > 0));
661 //if (ambiguousGeometry) {
662 // @todo: this warning would be helpful in many cases. However, if angle and angleFurther jump between 179 and -179 it is misleading
663 // WRITE_WARNINGF(TL("Ambiguous angles at junction '%' for edges '%' and '%'."), myNode.getID(), (*i)->getID(), (*j)->getID());
664 //}
665#ifdef DEBUG_NODE_SHAPE
666 if (DEBUGCOND) {
667 std::cout << " checkSameDirection " << (*i)->getID() << " " << (*j)->getID()
668 << " diffDirs=" << differentDirs
669 << " isOpposite=" << (differentDirs && foundOpposite.count(*i) == 0)
670 << " angleDiff=" << angleDiff
671 << " ambiguousGeometry=" << ambiguousGeometry
672 << " badInsersection=" << badIntersection(*i, *j, EXT)
673 << "\n";
674
675 }
676#endif
677 if (sameGeom || fabs(angleDiff) < DEG2RAD(20)) {
678 const bool isOpposite = differentDirs && foundOpposite.count(*i) == 0;
679 if (isOpposite) {
680 foundOpposite.insert(*i);
681 foundOpposite.insert(*j);
682 }
683 if (isOpposite || ambiguousGeometry || (!isXodr && badIntersection(*i, *j, EXT))) {
684 // maintain equivalence relation for all members of the equivalence class
685 for (std::set<NBEdge*>::iterator k = same[*i].begin(); k != same[*i].end(); ++k) {
686 if (*j != *k) {
687 same[*k].insert(*j);
688 same[*j].insert(*k);
689 }
690 }
691 for (std::set<NBEdge*>::iterator k = same[*j].begin(); k != same[*j].end(); ++k) {
692 if (*i != *k) {
693 same[*k].insert(*i);
694 same[*i].insert(*k);
695 }
696 }
697 same[*i].insert(*j);
698 same[*j].insert(*i);
699#ifdef DEBUG_NODE_SHAPE
700 if (DEBUGCOND) {
701 std::cout << " joinedSameDirectionEdges " << (*i)->getID() << " " << (*j)->getID() << " isOpposite=" << isOpposite << " ambiguousGeometry=" << ambiguousGeometry << "\n";
702 }
703#endif
704 }
705 }
706 }
707}
708
709
710bool
711NBNodeShapeComputer::badIntersection(const NBEdge* e1, const NBEdge* e2, double distance) {
712 // check whether the two edges are on top of each other. In that case they should be joined
713 // also, if they never touch along their common length
714 const double commonLength = MIN3(distance, e1->getGeometry().length(), e2->getGeometry().length());
715 PositionVector geom1 = e1->getGeometry();
716 PositionVector geom2 = e2->getGeometry();
717 // shift to make geom the centerline of the edge regardless of spreadtype
719 geom1.move2side(e1->getTotalWidth() / 2);
720 }
722 geom2.move2side(e2->getTotalWidth() / 2);
723 }
724 // always let geometry start at myNode
725 if (e1->getToNode() == &myNode) {
726 geom1 = geom1.reverse();
727 }
728 if (e2->getToNode() == &myNode) {
729 geom2 = geom2.reverse();
730 }
731 geom1 = geom1.getSubpart2D(0, commonLength);
732 geom2 = geom2.getSubpart2D(0, commonLength);
733 double endAngleDiff = 0;
734 if (geom1.size() >= 2 && geom2.size() >= 2) {
735 endAngleDiff = fabs(RAD2DEG(GeomHelper::angleDiff(
736 geom1.angleAt2D((int)geom1.size() - 2),
737 geom2.angleAt2D((int)geom2.size() - 2))));
738 }
739 const double minDistanceThreshold = (e1->getTotalWidth() + e2->getTotalWidth()) / 2 + POSITION_EPS;
740 std::vector<double> distances = geom1.distances(geom2, true);
741 const double minDist = VectorHelper<double>::minValue(distances);
742 const double maxDist = VectorHelper<double>::maxValue(distances);
743 const bool curvingTowards = geom1[0].distanceTo2D(geom2[0]) > minDistanceThreshold && minDist < minDistanceThreshold;
744 const bool onTop = (maxDist - POSITION_EPS < minDistanceThreshold) && endAngleDiff < 30;
745 geom1.extrapolate2D(EXT);
746 geom2.extrapolate2D(EXT);
747 Position intersect = geom1.intersectionPosition2D(geom2);
748 const bool intersects = intersect != Position::INVALID && geom1.distance2D(intersect) < POSITION_EPS;
749#ifdef DEBUG_NODE_SHAPE
750 if (DEBUGCOND) {
751 std::cout << " badIntersect: onTop=" << onTop << " curveTo=" << curvingTowards << " intersects=" << intersects
752 << " endAngleDiff=" << endAngleDiff
753 << " geom1=" << geom1 << " geom2=" << geom2
754 << " distances=" << toString(distances) << " minDist=" << minDist << " maxDist=" << maxDist << " thresh=" << minDistanceThreshold
755 << " intersectPos=" << intersect
756 << "\n";
757 }
758#endif
759 return onTop || curvingTowards || !intersects;
760}
761
762
765 const EdgeVector& all,
766 std::map<NBEdge*, std::set<NBEdge*> >& same,
767 GeomsMap& geomsCCW,
768 GeomsMap& geomsCW) {
769 // store relationships
770 EdgeVector newAll = all;
771 for (NBEdge* e1 : all) {
772 // determine which of the edges marks the outer boundary
773 auto e2NewAll = std::find(newAll.begin(), newAll.end(), e1);
774#ifdef DEBUG_NODE_SHAPE
775 if (DEBUGCOND) std::cout << "computeUniqueDirectionList e1=" << e1->getID()
776 << " deleted=" << (e2NewAll == newAll.end())
777 << " same=" << joinNamedToStringSorting(same[e1], ',') << "\n";
778#endif
779 if (e2NewAll == newAll.end()) {
780 continue;
781 }
782 auto e1It = std::find(all.begin(), all.end(), e1);
783 auto bestCCW = e1It;
784 auto bestCW = e1It;
785 bool changed = true;
786 while (changed) {
787 changed = false;
788 for (NBEdge* e2 : same[e1]) {
789#ifdef DEBUG_NODE_SHAPE
790 if (DEBUGCOND) {
791 std::cout << " e2=" << e2->getID() << "\n";
792 }
793#endif
794 auto e2It = std::find(all.begin(), all.end(), e2);
795 if (e2It + 1 == bestCCW || (e2It == (all.end() - 1) && bestCCW == all.begin())) {
796 bestCCW = e2It;
797 changed = true;
798#ifdef DEBUG_NODE_SHAPE
799 if (DEBUGCOND) {
800 std::cout << " bestCCW=" << e2->getID() << "\n";
801 }
802#endif
803 } else if (bestCW + 1 == e2It || (bestCW == (all.end() - 1) && e2It == all.begin())) {
804 bestCW = e2It;
805 changed = true;
806#ifdef DEBUG_NODE_SHAPE
807 if (DEBUGCOND) {
808 std::cout << " bestCW=" << e2->getID() << "\n";
809 }
810#endif
811 }
812 }
813 }
814 if (bestCW != e1It) {
815 geomsCW[e1] = geomsCW[*bestCW];
816 computeSameEnd(geomsCW[e1], geomsCCW[e1]);
817 }
818 if (bestCCW != e1It) {
819 geomsCCW[e1] = geomsCCW[*bestCCW];
820 computeSameEnd(geomsCW[e1], geomsCCW[e1]);
821 }
822 // clean up
823 for (NBEdge* e2 : same[e1]) {
824 auto e2NewAllIt = std::find(newAll.begin(), newAll.end(), e2);
825 if (e2NewAllIt != newAll.end()) {
826 newAll.erase(e2NewAllIt);
827 }
828 }
829 }
830#ifdef DEBUG_NODE_SHAPE
831 if (DEBUGCOND) {
832 std::cout << " newAll:\n";
833 for (NBEdge* e : newAll) {
834 std::cout << " " << e->getID() << " geomCCW=" << geomsCCW[e] << " geomsCW=" << geomsCW[e] << "\n";
835 }
836 }
837#endif
838 return newAll;
839}
840
841
842void
843NBNodeShapeComputer::initNeighbors(const EdgeVector& edges, const EdgeVector::const_iterator& current,
844 GeomsMap& geomsCW,
845 GeomsMap& geomsCCW,
846 EdgeVector::const_iterator& cwi,
847 EdgeVector::const_iterator& ccwi,
848 double& cad,
849 double& ccad) {
850 const double twoPI = (double)(2 * M_PI);
851 cwi = current;
852 cwi++;
853 if (cwi == edges.end()) {
854 std::advance(cwi, -((int)edges.size())); // set to edges.begin();
855 }
856 ccwi = current;
857 if (ccwi == edges.begin()) {
858 std::advance(ccwi, edges.size() - 1); // set to edges.end() - 1;
859 } else {
860 ccwi--;
861 }
862
863 const double angleCurCCW = geomsCCW[*current].angleAt2D(0);
864 const double angleCurCW = geomsCW[*current].angleAt2D(0);
865 const double angleCCW = geomsCW[*ccwi].angleAt2D(0);
866 const double angleCW = geomsCCW[*cwi].angleAt2D(0);
867 ccad = angleCCW - angleCurCCW;
868 while (ccad < 0.) {
869 ccad += twoPI;
870 }
871 cad = angleCurCW - angleCW;
872 while (cad < 0.) {
873 cad += twoPI;
874 }
875}
876
877
878
879const PositionVector
881#ifdef DEBUG_NODE_SHAPE
882 if (DEBUGCOND) {
883 std::cout << "computeNodeShapeSmall node=" << myNode.getID() << "\n";
884 }
885#endif
886 PositionVector ret;
887 for (NBEdge* e : myNode.getEdges()) {
888 // compute crossing with normal
889 PositionVector edgebound1 = e->getCCWBoundaryLine(myNode).getSubpartByIndex(0, 2);
890 PositionVector edgebound2 = e->getCWBoundaryLine(myNode).getSubpartByIndex(0, 2);
891 Position delta = edgebound1[1] - edgebound1[0];
892 delta.set(-delta.y(), delta.x()); // rotate 90 degrees
894 cross.extrapolate2D(500);
895 edgebound1.extrapolate2D(500);
896 edgebound2.extrapolate2D(500);
897 if (cross.intersects(edgebound1)) {
898 Position np = cross.intersectionPosition2D(edgebound1);
899 np.set(np.x(), np.y(), myNode.getPosition().z());
900 ret.push_back_noDoublePos(np);
901 }
902 if (cross.intersects(edgebound2)) {
903 Position np = cross.intersectionPosition2D(edgebound2);
904 np.set(np.x(), np.y(), myNode.getPosition().z());
905 ret.push_back_noDoublePos(np);
906 }
907 e->resetNodeBorder(&myNode);
908 }
909 return ret;
910}
911
912
913double
915 // look for incoming/outgoing edge pairs that do not go straight and allow wide vehicles
916 // (connection information is not available yet)
917 // @TODO compute the radius for each pair of neighboring edge intersections in computeNodeShapeDefault rather than use the maximum
918 const double radius = oc.getFloat("default.junctions.radius");
919 const double smallRadius = oc.getFloat("junctions.small-radius");
920 double maxRightAngle = 0; // rad
921 double extraWidthRight = 0; // m
922 double maxLeftAngle = 0; // rad
923 double extraWidthLeft = 0; // m
924 int laneDelta = 0;
925 int totalWideLanesIn = 0;
926 for (NBEdge* in : myNode.getIncomingEdges()) {
927 int wideLanesIn = 0;
928 for (int i = 0; i < in->getNumLanes(); i++) {
929 if ((in->getPermissions(i) & SVC_LARGE_TURN) != 0) {
930 wideLanesIn++;
931 }
932 }
933 totalWideLanesIn += wideLanesIn;
934 for (NBEdge* out : myNode.getOutgoingEdges()) {
935 if ((in->getPermissions() & out->getPermissions() & SVC_LARGE_TURN) != 0) {
936 if (myNode.getDirection(in, out) == LinkDirection::TURN) {
937 continue;
938 };
939 const double angle = GeomHelper::angleDiff(
940 in->getGeometry().angleAt2D(-2),
941 out->getGeometry().angleAt2D(0));
942 if (angle < 0) {
943 if (maxRightAngle < -angle) {
944 maxRightAngle = -angle;
945 extraWidthRight = MAX2(getExtraWidth(in, SVC_LARGE_TURN), getExtraWidth(out, SVC_LARGE_TURN));
946 }
947 } else {
948 if (maxLeftAngle < angle) {
949 maxLeftAngle = angle;
950 // all edges clockwise between in and out count as extra width
951 extraWidthLeft = 0;
952 EdgeVector::const_iterator pIn = std::find(myNode.getEdges().begin(), myNode.getEdges().end(), in);
954 while (*pIn != out) {
955 extraWidthLeft += (*pIn)->getTotalWidth();
956#ifdef DEBUG_RADIUS
957 if (DEBUGCOND) {
958 std::cout << " in=" << in->getID() << " out=" << out->getID() << " extra=" << (*pIn)->getID() << " extraWidthLeft=" << extraWidthLeft << "\n";
959 }
960#endif
962 }
963 }
964 }
965 int wideLanesOut = 0;
966 for (int i = 0; i < out->getNumLanes(); i++) {
967 if ((out->getPermissions(i) & SVC_LARGE_TURN) != 0) {
968 wideLanesOut++;
969 }
970 }
971#ifdef DEBUG_RADIUS
972 if (DEBUGCOND) {
973 std::cout << " in=" << in->getID() << " out=" << out->getID() << " wideLanesIn=" << wideLanesIn << " wideLanesOut=" << wideLanesOut << "\n";
974 }
975#endif
976 laneDelta = MAX2(laneDelta, abs(wideLanesOut - wideLanesIn));
977 }
978 }
979 }
980 // special case: on/off-ramp
981 if (myNode.getOutgoingEdges().size() == 1 || myNode.getIncomingEdges().size() == 1) {
982 int totalWideLanesOut = 0;
983 for (NBEdge* out : myNode.getOutgoingEdges()) {
984 for (int i = 0; i < out->getNumLanes(); i++) {
985 if ((out->getPermissions(i) & SVC_LARGE_TURN) != 0) {
986 totalWideLanesOut++;
987 }
988 }
989 }
990 if (totalWideLanesIn == totalWideLanesOut) {
991 // use total laneDelta instead of individual edge lane delta
992 laneDelta = 0;
993 }
994 }
995 // changing the number of wide-vehicle lanes on a straight segment requires a larger junction to allow for smooth driving
996 // otherwise we can reduce the radius according to the angle
997 double result = radius;
998 // left turns are assumed to cross additional edges and thus du not determine the required radius in most cases
999 double maxTurnAngle = maxRightAngle;
1000 double extraWidth = extraWidthRight;
1001 if (maxRightAngle < DEG2RAD(5)) {
1002 maxTurnAngle = maxLeftAngle;
1003 extraWidth = extraWidthLeft;
1004 }
1005 const double minRadius = maxTurnAngle >= DEG2RAD(30) ? MIN2(smallRadius, radius) : smallRadius;
1006 if (laneDelta == 0 || maxTurnAngle >= DEG2RAD(30) || myNode.isConstantWidthTransition()) {
1007 // subtract radius gained from extra lanes
1008 // do not increase radius for turns that are sharper than a right angle
1009 result = radius * tan(0.5 * MIN2(0.5 * M_PI, maxTurnAngle)) - extraWidth;
1010 }
1011 result = MAX2(minRadius, result);
1012#ifdef DEBUG_RADIUS
1013 if (DEBUGCOND) {
1014 std::cout << "getDefaultRadius n=" << myNode.getID()
1015 << " r=" << radius << " sr=" << smallRadius
1016 << " mr=" << minRadius
1017 << " laneDelta=" << laneDelta
1018 << " rightA=" << RAD2DEG(maxRightAngle)
1019 << " leftA=" << RAD2DEG(maxLeftAngle)
1020 << " maxA=" << RAD2DEG(maxTurnAngle)
1021 << " extraWidth=" << extraWidth
1022 << " result=" << result << "\n";
1023 }
1024#endif
1025 return result;
1026}
1027
1028
1029double
1031 double result = 0;
1032 int lane = 0;
1033 while (lane < e->getNumLanes() && e->getPermissions(lane) == 0) {
1034 // ignore forbidden lanes out the outside
1035 lane++;
1036 }
1037 while (lane < e->getNumLanes() && (e->getPermissions(lane) & exclude) == 0) {
1038 result += e->getLaneWidth(lane);
1039 lane++;
1040 }
1041 return result;
1042}
1043
1044
1045/****************************************************************************/
#define DEG2RAD(x)
Definition: GeomHelper.h:35
#define RAD2DEG(x)
Definition: GeomHelper.h:36
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:268
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:267
#define TL(string)
Definition: MsgHandler.h:284
std::set< NBEdge * > EdgeSet
container for unique edges
Definition: NBCont.h:50
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:42
#define EXT
#define DEBUGCOND
void computeSameEnd(PositionVector &l1, PositionVector &l2)
#define EXT2
const SVCPermissions SVCAll
all VClasses are allowed
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_DELIVERY
vehicle is a small delivery vehicle
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ TURN
The link is a 180 degree turn.
const double SUMO_const_laneWidth
Definition: StdDefs.h:48
T MIN3(T a, T b, T c)
Definition: StdDefs.h:89
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
std::string joinNamedToStringSorting(const std::set< T * > &ns, const T_BETWEEN &between)
Definition: ToString.h:307
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:179
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
The representation of a single edge during network building.
Definition: NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4215
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:632
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:536
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:771
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition: NBEdge.cpp:946
double getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition: NBEdge.cpp:4053
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:529
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:341
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
Definition: NBHelpers.cpp:45
Represents a single node (junction) during network building.
Definition: NBNode.h:66
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:2306
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition: NBNode.cpp:1813
double getDisplacementError() const
compute the displacement error during s-curve computation
Definition: NBNode.h:638
bool isSimpleContinuation(bool checkLaneNumbers=true, bool checkWidth=false) const
check if node is a simple continuation
Definition: NBNode.cpp:504
static const double UNSPECIFIED_RADIUS
unspecified lane width
Definition: NBNode.h:218
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition: NBNode.h:266
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition: NBNode.h:271
PositionVector computeSmoothShape(const PositionVector &begShape, const PositionVector &endShape, int numPoints, bool isTurnaround, double extrapolateBeg, double extrapolateEnd, NBNode *recordError=0, int shapeFlag=0) const
Compute a smooth curve between the given geometries.
Definition: NBNode.cpp:539
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.cpp:2896
bool isConstantWidthTransition() const
detects whether a given junction splits or merges lanes while keeping constant road width
Definition: NBNode.cpp:843
static const int AVOID_WIDE_LEFT_TURN
Definition: NBNode.h:222
const Position & getPosition() const
Definition: NBNode.h:258
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition: NBNode.h:276
double getRadius() const
Returns the turning radius of this node.
Definition: NBNode.h:288
PositionVector getSmoothCorner(PositionVector begShape, PositionVector endShape, const Position &begPoint, const Position &endPoint, int cornerDetail)
Compute smoothed corner shape.
double closestIntersection(const PositionVector &geom1, const PositionVector &geom2, double offset)
return the intersection point closest to the given offset
const PositionVector computeNodeShapeSmall()
Computes the node geometry using normals.
double myRadius
the computed node radius
EdgeVector computeUniqueDirectionList(const EdgeVector &all, std::map< NBEdge *, std::set< NBEdge * > > &same, GeomsMap &geomsCCW, GeomsMap &geomsCW)
Joins edges.
void computeEdgeBoundaries(const EdgeVector &edges, GeomsMap &geomsCCW, GeomsMap &geomsCW)
compute clockwise/counter-clockwise edge boundaries
std::map< NBEdge *, PositionVector > GeomsMap
NBNodeShapeComputer(const NBNode &node)
Constructor.
const PositionVector compute()
Computes the shape of the assigned junction.
~NBNodeShapeComputer()
Destructor.
bool badIntersection(const NBEdge *e1, const NBEdge *e2, double distance)
const PositionVector computeNodeShapeDefault(bool simpleContinuation)
Computes the node geometry Edges with the same direction are grouped. Then the node geometry is built...
const NBNode & myNode
The node to compute the geometry for.
void joinSameDirectionEdges(const EdgeVector &edges, std::map< NBEdge *, std::set< NBEdge * > > &same)
Joins edges and computes ccw/cw boundaries.
double getDefaultRadius(const OptionsCont &oc)
determine the default radius appropriate for the current junction
static void initNeighbors(const EdgeVector &edges, const EdgeVector::const_iterator &current, GeomsMap &geomsCW, GeomsMap &geomsCCW, EdgeVector::const_iterator &cwi, EdgeVector::const_iterator &ccwi, double &cad, double &ccad)
Initialize neighbors and angles.
bool needsLargeTurn(NBEdge *e1, NBEdge *e2, std::map< NBEdge *, std::set< NBEdge * > > &same) const
whether the given edges (along with those in the same direction) requires a large turning radius
static const SVCPermissions SVC_LARGE_TURN
static double getExtraWidth(const NBEdge *e, SVCPermissions exclude)
compute with of rightmost lanes that exlude the given permissions
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void set(double x, double y)
set positions x and y
Definition: Position.h:85
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:300
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:254
double x() const
Returns the x-position.
Definition: Position.h:55
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:125
void setz(double z)
set position z
Definition: Position.h:80
void mul(double val)
Multiplies both positions with the given value.
Definition: Position.h:105
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
double length() const
Returns the length.
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
void push_front_noDoublePos(const Position &p)
insert in front a non double position
void add(double xoff, double yoff, double zoff)
std::vector< double > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
double 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)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
std::vector< double > distances(const PositionVector &s, bool perpendicular=false) const
distances of all my points to s and all of s points to myself
std::pair< PositionVector, PositionVector > splitAt(double where, bool use2D=false) const
Returns the two lists made when this list vector is splitted at the given point.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
PositionVector interpolateZ(double zStart, double zEnd) const
returned vector that varies z smoothly over its length
double angleAt2D(int pos) const
get angle in certain position of position vector
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
void push_back_noDoublePos(const Position &p)
insert in back a non double position
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
PositionVector reverse() const
reverse position vector
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
void sub(const Position &offset)
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static T maxValue(const std::vector< T > &v)
Definition: VectorHelper.h:87
static T minValue(const std::vector< T > &v)
Definition: VectorHelper.h:97
#define M_PI
Definition: odrSpiral.cpp:45