SUMO - Simulation of Urban MObility
NBNetBuilder.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // Instance responsible for building networks
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <fstream>
31 #include "NBNetBuilder.h"
32 #include "NBNodeCont.h"
33 #include "NBEdgeCont.h"
35 #include "NBDistrictCont.h"
36 #include "NBDistrict.h"
37 #include "NBRequest.h"
38 #include "NBTypeCont.h"
44 #include <utils/common/SysUtils.h>
45 #include <utils/common/ToString.h>
47 #include "NBAlgorithms.h"
48 #include "NBAlgorithms_Ramps.h"
49 #include "NBAlgorithms_Railway.h"
50 #include "NBHeightMapper.h"
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  myEdgeCont(myTypeCont),
58  myNetworkHaveCrossings(false) {
59 }
60 
61 
63 
64 
65 void
67  // apply options to type control
68  myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.lanewidth"), oc.getFloat("default.speed"),
69  oc.getInt("default.priority"), parseVehicleClasses("", oc.getString("default.disallow")));
70  // apply options to edge control
72  // apply options to traffic light logics control
74 }
75 
76 
77 void
78 NBNetBuilder::compute(OptionsCont& oc, const std::set<std::string>& explicitTurnarounds, bool mayAddOrRemove) {
80 
81  const bool lefthand = oc.getBool("lefthand");
82  if (lefthand) {
83  mirrorX();
84  }
85 
86  // MODIFYING THE SETS OF NODES AND EDGES
87 
88  long before = SysUtils::getCurrentMillis();
89 
90 
91  // Removes edges that are connecting the same node
92  PROGRESS_BEGIN_MESSAGE("Removing self-loops");
94  PROGRESS_TIME_MESSAGE(before);
95  if (mayAddOrRemove && oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
96  before = SysUtils::getCurrentMillis();
97  PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
99  PROGRESS_TIME_MESSAGE(before);
100  }
101  if (mayAddOrRemove && oc.exists("keep-edges.components") && oc.getInt("keep-edges.components") > 0) {
102  before = SysUtils::getCurrentMillis();
103  PROGRESS_BEGIN_MESSAGE("Finding largest components");
104  myNodeCont.removeComponents(myDistrictCont, myEdgeCont, oc.getInt("keep-edges.components"));
105  PROGRESS_TIME_MESSAGE(before);
106  }
107  if (mayAddOrRemove && oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
108  if (oc.isSet("keep-edges.explicit") || oc.isSet("keep-edges.input-file")) {
109  before = SysUtils::getCurrentMillis();
110  PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
112  PROGRESS_TIME_MESSAGE(before);
113  }
114  }
115  // Processing pt stops and lines
116  if (oc.exists("ptstop-output") && oc.isSet("ptstop-output")) {
117  before = SysUtils::getCurrentMillis();
118  PROGRESS_BEGIN_MESSAGE("Processing public transport stops");
119  if (!(oc.exists("ptline-output") && oc.isSet("ptline-output"))) {
121  }
123  PROGRESS_TIME_MESSAGE(before);
124  }
125 
126  if (oc.exists("ptline-output") && oc.isSet("ptline-output")) {
127  before = SysUtils::getCurrentMillis();
128  PROGRESS_BEGIN_MESSAGE("Revising public transport stops based on pt lines");
130  PROGRESS_TIME_MESSAGE(before);
131  }
132 
133  if (oc.exists("ptline-output") && oc.isSet("ptline-output") && oc.exists("ptline-clean-up") && oc.getBool("ptline-clean-up")) {
134  before = SysUtils::getCurrentMillis();
135  PROGRESS_BEGIN_MESSAGE("Cleaning up public transport stops that are not served by any line");
137  PROGRESS_TIME_MESSAGE(before);
138  }
139 
140  if (oc.exists("ptstop-output") && oc.isSet("ptstop-output")) {
141  before = SysUtils::getCurrentMillis();
142  PROGRESS_BEGIN_MESSAGE("Align pt stop id signs with corresponding edge id signs");
144  PROGRESS_TIME_MESSAGE(before);
145  }
146 
147  // analyse and fix railway topology
148  if (oc.exists("railway.topology.all-bidi") && oc.getBool("railway.topology.all-bidi")) {
151  } else if (oc.exists("railway.topology.repair") && oc.getBool("railway.topology.repair")) {
154  }
155  if (oc.exists("railway.topology.output") && oc.isSet("railway.topology.output")) {
156  NBTurningDirectionsComputer::computeTurnDirections(myNodeCont, false); // recompute after new edges were added
158  }
159 
160  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
161  // preliminary geometry computations to determine the length of edges
162  // This depends on turning directions and sorting of edge list
163  // in case junctions are joined geometry computations have to be repeated
164  // preliminary roundabout computations to avoid damaging roundabouts via junctions.join or ramps.guess
170  if (oc.getBool("roundabouts.guess")) {
172  }
173  const std::set<EdgeSet>& roundabouts = myEdgeCont.getRoundabouts();
174  for (std::set<EdgeSet>::const_iterator it_round = roundabouts.begin();
175  it_round != roundabouts.end(); ++it_round) {
176  std::vector<std::string> nodeIDs;
177  for (EdgeSet::const_iterator it_edge = it_round->begin(); it_edge != it_round->end(); ++it_edge) {
178  nodeIDs.push_back((*it_edge)->getToNode()->getID());
179  }
180  myNodeCont.addJoinExclusion(nodeIDs);
181  }
183  }
184  // join junctions (may create new "geometry"-nodes so it needs to come before removing these
185  if (mayAddOrRemove && oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
186  myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
187  }
189  if (mayAddOrRemove && oc.getBool("junctions.join")) {
190  before = SysUtils::getCurrentMillis();
191  PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
192  numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont, myPTStopCont);
193  PROGRESS_TIME_MESSAGE(before);
194  }
195  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
196  // reset geometry to avoid influencing subsequent steps (ramps.guess)
198  }
199  if (numJoined > 0) {
200  // bit of a misnomer since we're already done
201  WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
202  }
203  //
204  if (mayAddOrRemove) {
205  int no = 0;
206  const bool removeGeometryNodes = oc.exists("geometry.remove") && oc.getBool("geometry.remove");
207  before = SysUtils::getCurrentMillis();
208  PROGRESS_BEGIN_MESSAGE("Removing empty nodes" + std::string(removeGeometryNodes ? " and geometry nodes" : ""));
209  // removeUnwishedNodes needs turnDirections. @todo: try to call this less often
212  PROGRESS_TIME_MESSAGE(before);
213  WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
214  }
215 
216  // MOVE TO ORIGIN
217  // compute new boundary after network modifications have taken place
218  Boundary boundary;
219  for (std::map<std::string, NBNode*>::const_iterator it = myNodeCont.begin(); it != myNodeCont.end(); ++it) {
220  boundary.add(it->second->getPosition());
221  }
222  for (std::map<std::string, NBEdge*>::const_iterator it = myEdgeCont.begin(); it != myEdgeCont.end(); ++it) {
223  boundary.add(it->second->getGeometry().getBoxBoundary());
224  }
225  geoConvHelper.setConvBoundary(boundary);
226 
227  if (!oc.getBool("offset.disable-normalization") && oc.isDefault("offset.x") && oc.isDefault("offset.y")) {
228  moveToOrigin(geoConvHelper, lefthand);
229  }
230  geoConvHelper.computeFinal(lefthand); // information needed for location element fixed at this point
231 
232  if (oc.exists("geometry.min-dist") && !oc.isDefault("geometry.min-dist")) {
233  before = SysUtils::getCurrentMillis();
234  PROGRESS_BEGIN_MESSAGE("Reducing geometries");
235  myEdgeCont.reduceGeometries(oc.getFloat("geometry.min-dist"));
236  PROGRESS_TIME_MESSAGE(before);
237  }
238  // @note: removing geometry can create similar edges so joinSimilarEdges must come afterwards
239  // @note: likewise splitting can destroy similarities so joinSimilarEdges must come before
240  if (mayAddOrRemove && oc.getBool("edges.join")) {
241  before = SysUtils::getCurrentMillis();
242  PROGRESS_BEGIN_MESSAGE("Joining similar edges");
244  PROGRESS_TIME_MESSAGE(before);
245  }
246  if (oc.getBool("opposites.guess")) {
247  PROGRESS_BEGIN_MESSAGE("guessing opposite direction edges");
250  }
251  //
252  if (mayAddOrRemove && oc.exists("geometry.split") && oc.getBool("geometry.split")) {
253  before = SysUtils::getCurrentMillis();
254  PROGRESS_BEGIN_MESSAGE("Splitting geometry edges");
256  PROGRESS_TIME_MESSAGE(before);
257  }
258  // turning direction
259  before = SysUtils::getCurrentMillis();
260  PROGRESS_BEGIN_MESSAGE("Computing turning directions");
262  PROGRESS_TIME_MESSAGE(before);
263  // correct edge geometries to avoid overlap
264  if (oc.exists("geometry.avoid-overlap") && oc.getBool("geometry.avoid-overlap")) {
266  }
267 
268  // GUESS TLS POSITIONS
269  before = SysUtils::getCurrentMillis();
270  PROGRESS_BEGIN_MESSAGE("Assigning nodes to traffic lights");
271  if (oc.isSet("tls.set")) {
272  std::vector<std::string> tlControlledNodes = oc.getStringVector("tls.set");
274  for (std::vector<std::string>::const_iterator i = tlControlledNodes.begin(); i != tlControlledNodes.end(); ++i) {
275  NBNode* node = myNodeCont.retrieve(*i);
276  if (node == nullptr) {
277  WRITE_WARNING("Building a tl-logic for junction '" + *i + "' is not possible." + "\n The junction '" + *i + "' is not known.");
278  } else {
280  }
281  }
282  }
284  PROGRESS_TIME_MESSAGE(before);
285 
286  // guess ramps (after guessing tls because ramps should not be build at traffic lights)
287  if (mayAddOrRemove) {
288  const bool modifyRamps = (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))
289  || (oc.exists("ramps.set") && oc.isSet("ramps.set"));
290  if (modifyRamps
291  || (oc.exists("ramps.guess-acceleration-lanes") && oc.getBool("ramps.guess-acceleration-lanes"))) {
292  before = SysUtils::getCurrentMillis();
293  if (modifyRamps) {
294  PROGRESS_BEGIN_MESSAGE("Guessing and setting on-/off-ramps");
295  }
298  if (modifyRamps) {
299  PROGRESS_TIME_MESSAGE(before);
300  }
301  }
302  }
303  // guess sidewalks
304  if (mayAddOrRemove && ((oc.getBool("sidewalks.guess") || oc.getBool("sidewalks.guess.from-permissions")))) {
305  const int sidewalks = myEdgeCont.guessSidewalks(oc.getFloat("default.sidewalk-width"),
306  oc.getFloat("sidewalks.guess.min-speed"),
307  oc.getFloat("sidewalks.guess.max-speed"),
308  oc.getBool("sidewalks.guess.from-permissions"));
309  WRITE_MESSAGE("Guessed " + toString(sidewalks) + " sidewalks.");
310  }
311 
312  // check whether any not previously setable connections may be set now
314 
315  // remap ids if wished
316  int numChangedEdges = myEdgeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"), oc.getString("prefix"), myPTStopCont);
317  int numChangedNodes = myNodeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"), oc.getString("prefix"));
318  if (numChangedEdges + numChangedNodes > 0) {
319  WRITE_MESSAGE("Remapped " + toString(numChangedEdges) + " edge IDs and " + toString(numChangedNodes) + " node IDs.");
320  }
321 
322  //
323  if (oc.exists("geometry.max-angle")) {
325  DEG2RAD(oc.getFloat("geometry.max-angle")),
326  oc.getFloat("geometry.min-radius"),
327  oc.getBool("geometry.min-radius.fix"));
328  }
329 
330  // GEOMETRY COMPUTATION
331  //
332  before = SysUtils::getCurrentMillis();
333  PROGRESS_BEGIN_MESSAGE("Sorting nodes' edges");
335  PROGRESS_TIME_MESSAGE(before);
337  //
338  before = SysUtils::getCurrentMillis();
339  PROGRESS_BEGIN_MESSAGE("Computing node shapes");
340  if (oc.exists("geometry.junction-mismatch-threshold")) {
341  myNodeCont.computeNodeShapes(oc.getFloat("geometry.junction-mismatch-threshold"));
342  } else {
344  }
345  PROGRESS_TIME_MESSAGE(before);
346  //
347  before = SysUtils::getCurrentMillis();
348  PROGRESS_BEGIN_MESSAGE("Computing edge shapes");
349  myEdgeCont.computeEdgeShapes(oc.getBool("geometry.max-grade.fix") ? oc.getFloat("geometry.max-grade") / 100 : -1);
350  PROGRESS_TIME_MESSAGE(before);
351  // resort edges based on the node and edge shapes
354 
355  // APPLY SPEED MODIFICATIONS
356  if (oc.exists("speed.offset")) {
357  const double speedOffset = oc.getFloat("speed.offset");
358  const double speedFactor = oc.getFloat("speed.factor");
359  const double speedMin = oc.getFloat("speed.minimum");
360  if (speedOffset != 0 || speedFactor != 1 || speedMin > 0) {
361  before = SysUtils::getCurrentMillis();
362  PROGRESS_BEGIN_MESSAGE("Applying speed modifications");
363  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
364  (*i).second->setSpeed(-1, MAX2((*i).second->getSpeed() * speedFactor + speedOffset, speedMin));
365  }
366  PROGRESS_TIME_MESSAGE(before);
367  }
368  }
369 
370  // CONNECTIONS COMPUTATION
371  //
372  before = SysUtils::getCurrentMillis();
373  PROGRESS_BEGIN_MESSAGE("Computing node types");
375  PROGRESS_TIME_MESSAGE(before);
376  //
377  myNetworkHaveCrossings = oc.getBool("walkingareas");
378  if (mayAddOrRemove && oc.getBool("crossings.guess")) {
379  myNetworkHaveCrossings = true;
380  int crossings = 0;
381  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
382  crossings += (*i).second->guessCrossings();
383  }
384  WRITE_MESSAGE("Guessed " + toString(crossings) + " pedestrian crossings.");
385  }
386  if (!myNetworkHaveCrossings) {
387  // recheck whether we had crossings in the input
388  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
389  if (i->second->getCrossingsIncludingInvalid().size() > 0) {
390  myNetworkHaveCrossings = true;
391  break;
392  }
393  }
394  }
395 
396  if (!mayAddOrRemove && myNetworkHaveCrossings) {
397  // crossings added via netedit
398  oc.resetWritable();
399  oc.set("no-internal-links", "false");
400  }
401 
402  //
403  before = SysUtils::getCurrentMillis();
404  PROGRESS_BEGIN_MESSAGE("Computing priorities");
406  PROGRESS_TIME_MESSAGE(before);
407  //
408  before = SysUtils::getCurrentMillis();
409  PROGRESS_BEGIN_MESSAGE("Computing approached edges");
410  myEdgeCont.computeEdge2Edges(oc.getBool("no-left-connections"));
411  PROGRESS_TIME_MESSAGE(before);
412  //
413  if (oc.getBool("roundabouts.guess")) {
414  before = SysUtils::getCurrentMillis();
415  PROGRESS_BEGIN_MESSAGE("Guessing and setting roundabouts");
416  const int numGuessed = myEdgeCont.guessRoundabouts();
417  if (numGuessed > 0) {
418  WRITE_MESSAGE(" Guessed " + toString(numGuessed) + " roundabout(s).");
419  }
420  PROGRESS_TIME_MESSAGE(before);
421  }
423  //
424  before = SysUtils::getCurrentMillis();
425  PROGRESS_BEGIN_MESSAGE("Computing approaching lanes");
427  PROGRESS_TIME_MESSAGE(before);
428  //
429  before = SysUtils::getCurrentMillis();
430  PROGRESS_BEGIN_MESSAGE("Dividing of lanes on approached lanes");
433  PROGRESS_TIME_MESSAGE(before);
434  //
435  before = SysUtils::getCurrentMillis();
436  PROGRESS_BEGIN_MESSAGE("Processing turnarounds");
437  if (!oc.getBool("no-turnarounds")) {
438  myEdgeCont.appendTurnarounds(oc.getBool("no-turnarounds.tls"), oc.getBool("no-turnarounds.except-deadend"));
439  } else {
440  myEdgeCont.appendTurnarounds(explicitTurnarounds, oc.getBool("no-turnarounds.tls"));
441  }
442  if (oc.exists("railway.topology.repair") && oc.getBool("railway.topology.repair")
443  && myPTStopCont.getStops().size() > 0) {
444  // allow direction reversal at all bidi-edges with stops
446  }
447  PROGRESS_TIME_MESSAGE(before);
448  //
449  before = SysUtils::getCurrentMillis();
450  PROGRESS_BEGIN_MESSAGE("Rechecking of lane endings");
452  PROGRESS_TIME_MESSAGE(before);
453 
454  if (myNetworkHaveCrossings && !oc.getBool("no-internal-links")) {
455  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
456  i->second->buildCrossingsAndWalkingAreas();
457  }
458  } else {
459  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
460  // needed by netedit if the last crossings was deleted from the network
461  // and walkingareas have been invalidated since the last call to compute()
462  i->second->discardWalkingareas();
463  }
464  if (oc.getBool("no-internal-links")) {
465  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
466  i->second->discardAllCrossings(false);
467  }
468  }
469  }
470  // join traffic lights (after building connections)
471  if (oc.getBool("tls.join")) {
472  before = SysUtils::getCurrentMillis();
473  PROGRESS_BEGIN_MESSAGE("Joining traffic light nodes");
474  myNodeCont.joinTLS(myTLLCont, oc.getFloat("tls.join-dist"));
475  PROGRESS_TIME_MESSAGE(before);
476  }
477 
478  // COMPUTING RIGHT-OF-WAY AND TRAFFIC LIGHT PROGRAMS
479  //
480  before = SysUtils::getCurrentMillis();
481  PROGRESS_BEGIN_MESSAGE("Computing traffic light control information");
483  PROGRESS_TIME_MESSAGE(before);
484  //
485  before = SysUtils::getCurrentMillis();
486  PROGRESS_BEGIN_MESSAGE("Computing node logics");
488  PROGRESS_TIME_MESSAGE(before);
489  //
490  before = SysUtils::getCurrentMillis();
491  PROGRESS_BEGIN_MESSAGE("Computing traffic light logics");
492  std::pair<int, int> numbers = myTLLCont.computeLogics(oc);
493  PROGRESS_TIME_MESSAGE(before);
494  std::string progCount = "";
495  if (numbers.first != numbers.second) {
496  progCount = "(" + toString(numbers.second) + " programs) ";
497  }
498  WRITE_MESSAGE(" " + toString(numbers.first) + " traffic light(s) " + progCount + "computed.");
499  //
500  if (oc.isSet("street-sign-output")) {
501  before = SysUtils::getCurrentMillis();
502  PROGRESS_BEGIN_MESSAGE("Generating street signs");
504  PROGRESS_TIME_MESSAGE(before);
505  }
506 
507  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
508  (*i).second->sortOutgoingConnectionsByIndex();
509  }
510  // FINISHING INNER EDGES
511  if (!oc.getBool("no-internal-links")) {
512  before = SysUtils::getCurrentMillis();
513  PROGRESS_BEGIN_MESSAGE("Building inner edges");
514  // walking areas shall only be built if crossings are wished as well
515  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
516  (*i).second->buildInnerEdges();
517  }
518  PROGRESS_TIME_MESSAGE(before);
519  }
520  // PATCH NODE SHAPES
521  if (oc.getFloat("junctions.scurve-stretch") > 0) {
522  // @note: nodes have collected correction hints in buildInnerEdges()
523  before = SysUtils::getCurrentMillis();
524  PROGRESS_BEGIN_MESSAGE("stretching junctions to smooth geometries");
528  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
529  (*i).second->buildInnerEdges();
530  }
531  PROGRESS_TIME_MESSAGE(before);
532  }
533  // compute lane-to-lane node logics (require traffic lights and inner edges to be done)
535 
536  if (lefthand) {
537  mirrorX();
538  };
539 
540  if (oc.exists("geometry.check-overlap") && oc.getFloat("geometry.check-overlap") > 0) {
541  before = SysUtils::getCurrentMillis();
542  PROGRESS_BEGIN_MESSAGE("Checking overlapping edges");
543  myEdgeCont.checkOverlap(oc.getFloat("geometry.check-overlap"), oc.getFloat("geometry.check-overlap.vertical-threshold"));
544  PROGRESS_TIME_MESSAGE(before);
545  }
546  if (geoConvHelper.getConvBoundary().getZRange() > 0 && oc.getFloat("geometry.max-grade") > 0) {
547  before = SysUtils::getCurrentMillis();
548  PROGRESS_BEGIN_MESSAGE("Checking edge grade");
549  // user input is in %
550  myEdgeCont.checkGrade(oc.getFloat("geometry.max-grade") / 100);
551  PROGRESS_TIME_MESSAGE(before);
552  }
553 
554  //find accesses for pt rail stops and add bidi-stops
555  if (oc.exists("ptstop-output") && oc.isSet("ptstop-output")) {
556  before = SysUtils::getCurrentMillis();
557  const int numBidiStops = myPTStopCont.generateBidiStops(myEdgeCont);
558  PROGRESS_BEGIN_MESSAGE("Find accesses for pt rail stops");
559  double maxRadius = oc.getFloat("railway.access-distance");
560  double accessFactor = oc.getFloat("railway.access-factor");
561  int maxCount = oc.getInt("railway.max-accesses");
562  myPTStopCont.findAccessEdgesForRailStops(myEdgeCont, maxRadius, maxCount, accessFactor);
563  PROGRESS_TIME_MESSAGE(before);
564  if (numBidiStops > 0) {
565  if (oc.exists("ptline-output") && oc.isSet("ptline-output")) {
567  }
568  }
569  }
570 
571  // report
572  WRITE_MESSAGE("-----------------------------------------------------");
573  WRITE_MESSAGE("Summary:");
575  WRITE_MESSAGE(" Network boundaries:");
576  WRITE_MESSAGE(" Original boundary : " + toString(geoConvHelper.getOrigBoundary()));
577  WRITE_MESSAGE(" Applied offset : " + toString(geoConvHelper.getOffsetBase()));
578  WRITE_MESSAGE(" Converted boundary : " + toString(geoConvHelper.getConvBoundary()));
579  WRITE_MESSAGE("-----------------------------------------------------");
581  // report on very large networks
582  if (MAX2(geoConvHelper.getConvBoundary().xmax(), geoConvHelper.getConvBoundary().ymax()) > 1000000 ||
583  MIN2(geoConvHelper.getConvBoundary().xmin(), geoConvHelper.getConvBoundary().ymin()) < -1000000) {
584  WRITE_WARNING("Network contains very large coordinates and will probably flicker in the GUI. Check for outlying nodes and make sure the network is shifted to the coordinate origin");
585  }
586 }
587 
588 
589 /*
590 void
591 NBNetBuilder::computeSingleNode(NBNode* node, OptionsCont& oc, const std::set<std::string>& explicitTurnarounds, bool mayAddOrRemove) {
592  // for a single node do the following:
593  // sortEdges
594  // computeLaneShapes
595  // computeNodeShapes
596  // computeEdgeShapes
597 }
598 */
599 
600 
601 void
602 NBNetBuilder::moveToOrigin(GeoConvHelper& geoConvHelper, bool lefthand) {
603  long before = SysUtils::getCurrentMillis();
604  PROGRESS_BEGIN_MESSAGE("Moving network to origin");
605  Boundary boundary = geoConvHelper.getConvBoundary();
606  const double x = -boundary.xmin();
607  const double y = -(lefthand ? boundary.ymax() : boundary.ymin());
608  //if (lefthand) {
609  // y = boundary.ymax();
610  //}
611  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
612  (*i).second->reshiftPosition(x, y);
613  }
614  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
615  (*i).second->reshiftPosition(x, y);
616  }
617  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
618  (*i).second->reshiftPosition(x, y);
619  }
620  for (std::map<std::string, NBPTStop*>::const_iterator i = myPTStopCont.begin(); i != myPTStopCont.end(); ++i) {
621  (*i).second->reshiftPosition(x, y);
622  }
623  geoConvHelper.moveConvertedBy(x, y);
624  PROGRESS_TIME_MESSAGE(before);
625 }
626 
627 
628 void
630  // mirror the network along the X-axis
631  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
632  (*i).second->mirrorX();
633  }
634  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
635  (*i).second->mirrorX();
636  }
637  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
638  (*i).second->mirrorX();
639  }
640 }
641 
642 
643 bool
644 NBNetBuilder::transformCoordinate(Position& from, bool includeInBoundary, GeoConvHelper* from_srs) {
645  Position orig(from);
646  bool ok = true;
648  && GeoConvHelper::getLoaded().usingGeoProjection()
649  && from_srs != nullptr
650  && from_srs->usingGeoProjection()
651  && *from_srs != GeoConvHelper::getLoaded()) {
652  from_srs->cartesian2geo(from);
653  ok &= GeoConvHelper::getLoaded().x2cartesian(from, false);
654  }
655  ok &= GeoConvHelper::getProcessing().x2cartesian(from, includeInBoundary);
656  if (ok) {
657  const NBHeightMapper& hm = NBHeightMapper::get();
658  if (hm.ready()) {
659  if (from_srs != nullptr && from_srs->usingGeoProjection()) {
660  from_srs->cartesian2geo(orig);
661  }
662  double z = hm.getZ(orig);
663  from = Position(from.x(), from.y(), z);
664  }
665  }
666  return ok;
667 }
668 
669 
670 bool
671 NBNetBuilder::transformCoordinates(PositionVector& from, bool includeInBoundary, GeoConvHelper* from_srs) {
672  const double maxLength = OptionsCont::getOptions().getFloat("geometry.max-segment-length");
673  if (maxLength > 0 && from.size() > 1) {
674  // transformation to cartesian coordinates must happen before we can check segment length
675  PositionVector copy = from;
676  for (int i = 0; i < (int) from.size(); i++) {
677  transformCoordinate(copy[i], false);
678  }
679  // check lengths and insert new points where needed (in the original
680  // coordinate system)
681  int inserted = 0;
682  for (int i = 0; i < (int)copy.size() - 1; i++) {
683  Position start = from[i + inserted];
684  Position end = from[i + inserted + 1];
685  double length = copy[i].distanceTo(copy[i + 1]);
686  const Position step = (end - start) * (maxLength / length);
687  int steps = 0;
688  while (length > maxLength) {
689  length -= maxLength;
690  steps++;
691  from.insert(from.begin() + i + inserted + 1, start + (step * steps));
692  inserted++;
693  }
694  }
695  // now perform the transformation again so that height mapping can be
696  // performed for the new points
697  }
698  bool ok = true;
699  for (int i = 0; i < (int) from.size(); i++) {
700  ok = ok && transformCoordinate(from[i], includeInBoundary, from_srs);
701  }
702  return ok;
703 }
704 
705 
706 bool
708  // see GNELoadThread::fillOptions
709  return OptionsCont::getOptions().exists("new");
710 }
711 
712 
713 /****************************************************************************/
NBNetBuilder()
Constructor.
NBTypeCont myTypeCont
The used container for street types.
Definition: NBNetBuilder.h:236
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:179
NBPTStopCont myPTStopCont
The used container for pt stops.
Definition: NBNetBuilder.h:248
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
void removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes self-loop edges (edges where the source and the destination node are the same) ...
Definition: NBNodeCont.cpp:167
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
void sortOutgoingLanesConnections()
Sorts all lanes of all edges within the container by their direction.
Definition: NBEdgeCont.cpp:757
void markRoundabouts()
mark edge priorities and prohibit turn-arounds for all roundabout edges
void setConvBoundary(const Boundary &boundary)
sets the converted boundary
void alignIdSigns()
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static void validateRailCrossings(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Checks rail_crossing for validity.
void resetWritable()
Resets all options to be writeable.
int generateBidiStops(NBEdgeCont &cont)
duplicate stops for superposed rail edges and return the number of generated stops ...
void computeLogics2(const NBEdgeCont &ec, OptionsCont &oc)
compute right-of-way logic for all lane-to-lane connections
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:116
void appendTurnarounds(bool noTLSControlled, bool onlyDeadends)
Appends turnarounds to all edges stored in the container.
Definition: NBEdgeCont.cpp:821
void reduceGeometries(const double minDist)
Definition: NBEdgeCont.cpp:730
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:565
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:370
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:121
void mirrorX()
mirror the network along the X-axis
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
Definition: NBNodeCont.cpp:224
void joinTLS(NBTrafficLightLogicCont &tlc, double maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
int guessRoundabouts()
Determines which edges belong to roundabouts and increases their priority.
static void repairTopology(NBNetBuilder &nb)
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
~NBNetBuilder()
Destructor.
void postprocess(std::set< std::string > &usedStops)
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
double y() const
Returns the y-position.
Definition: Position.h:62
std::map< std::string, NBDistrict * >::const_iterator end() const
Returns the pointer to the end of the stored districts.
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
void guessOpposites()
Sets opposite lane information for geometrically close edges.
Definition: NBEdgeCont.cpp:961
double x() const
Returns the x-position.
Definition: Position.h:57
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
Definition: GeoConvHelper.h:89
void findAccessEdgesForRailStops(NBEdgeCont &cont, double maxRadius, int maxCount, double accessFactor)
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:599
T MAX2(T a, T b)
Definition: StdDefs.h:76
const Boundary & getOrigBoundary() const
Returns the original boundary.
void generateStreetSigns()
assigns street signs to edges based on toNode types
void recheckPostProcessConnections()
Try to set any stored connections.
static bool transformCoordinates(PositionVector &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:193
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:444
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
static void sortNodesEdges(NBNodeCont &nc, bool useNodeShape=false)
Sorts a node&#39;s edges clockwise regarding driving direction.
void computeLanes2Edges()
Computes for each edge which lanes approach the next edges.
Definition: NBEdgeCont.cpp:773
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void checkGeometries(const double maxAngle, const double minRadius, bool fix)
Definition: NBEdgeCont.cpp:738
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void fixBidiStops(const NBEdgeCont &ec)
select the correct stop on superposed rail edges
void checkOverlap(double threshold, double zThreshold) const
check whether edges overlap
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
void localizePTStops(NBEdgeCont &cont)
void checkGrade(double threshold) const
check whether edges are to steep
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
void process(NBEdgeCont &cont)
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1002
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:245
static void analyzeTopology(NBNetBuilder &nb)
Computes highway on-/off-ramps (if wished)
std::set< std::string > & getServedPTStops()
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:623
void assignLanes(NBEdgeCont &cont)
std::map< std::string, NBPTStop * >::const_iterator begin() const
Returns the pointer to the begin of the stored pt stops.
Definition: NBPTStopCont.h:51
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:185
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:53
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void removeUnwishedEdges(NBDistrictCont &dc)
Removes unwished edges (not in keep-edges)
Definition: NBEdgeCont.cpp:702
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void setDefaults(int defaultNumLanes, double defaultLaneWidth, double defaultSpeed, int defaultPriority, SVCPermissions defaultPermissions)
Sets the default values.
Definition: NBTypeCont.cpp:40
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
A list of positions.
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Definition: NBEdgeCont.cpp:72
NBEdgeCont myEdgeCont
The used container for edges.
Definition: NBNetBuilder.h:239
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool myNetworkHaveCrossings
flag to indicate that network has crossings
Definition: NBNetBuilder.h:256
void computeEdge2Edges(bool noLeftMovers)
Computes for each edge the approached edges.
Definition: NBEdgeCont.cpp:765
void computeLaneShapes()
Computes the shapes of all lanes of all edges stored in the container.
Definition: NBEdgeCont.cpp:866
NBTrafficLightLogicCont myTLLCont
The used container for traffic light logics.
Definition: NBNetBuilder.h:242
bool exists(const std::string &name) const
Returns the information whether the named option is known.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
T MIN2(T a, T b)
Definition: StdDefs.h:70
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:243
void splitGeometry(NBNodeCont &nc)
Splits edges into multiple if they have a complex geometry.
Definition: NBEdgeCont.cpp:719
static void makeAllBidi(NBNetBuilder &nb)
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
#define DEG2RAD(x)
Definition: GeomHelper.h:38
std::map< std::string, NBPTStop * >::const_iterator end() const
Returns the pointer to the end of the stored pt stops.
Definition: NBPTStopCont.h:58
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix)
remap node IDs accoring to options –numerical-ids and –reserved-ids
const std::map< std::string, NBPTStop * > & getStops() const
Definition: NBPTStopCont.h:62
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
int guessSidewalks(double width, double minSpeed, double maxSpeed, bool fromPermissions)
add sidwalks to edges within the given limits or permissions and return the number of edges affected ...
static void computeRamps(NBNetBuilder &nb, OptionsCont &oc)
Computes highway on-/off-ramps (if wished)
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
void moveToOrigin(GeoConvHelper &geoConvHelper, bool lefthand)
shift network so its lower left corner is at 0,0
static int getNumLoaded()
Definition: GeoConvHelper.h:93
static bool runningNetedit()
whether netbuilding takes place in the context of NETEDIT
A storage for options typed value containers)
Definition: OptionsCont.h:92
const Position getOffsetBase() const
Returns the network base.
void appendRailwayTurnarounds(const NBPTStopCont &sc)
Appends turnarounds to all bidiRail edges with stops.
Definition: NBEdgeCont.cpp:837
Represents a single node (junction) during network building.
Definition: NBNode.h:68
static void computeTurnDirections(NBNodeCont &nc, bool warn=true)
Computes turnaround destinations for all edges (if exist)
NBDistrictCont myDistrictCont
The used container for districts.
Definition: NBNetBuilder.h:245
void computeEdgeShapes(double smoothElevationThreshold=-1)
Computes the shapes of all edges stored in the container.
Definition: NBEdgeCont.cpp:858
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
void recheckLanes()
Rechecks whether all lanes have a successor for each of the stored edges.
Definition: NBEdgeCont.cpp:781
static void computeNodeTypes(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Computes node types.
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:39
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:244
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
NBParkingCont myParkingCont
Definition: NBNetBuilder.h:253
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
double getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition: Boundary.cpp:167
NBNodeCont myNodeCont
The used container for nodes.
Definition: NBNetBuilder.h:233
void setTLControllingInformation(const NBEdgeCont &ec, const NBNodeCont &nc)
Informs the edges about being controlled by a tls.
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix, NBPTStopCont &sc)
remap node IDs accoring to options –numerical-ids and –reserved-ids
std::pair< int, int > computeLogics(OptionsCont &oc)
Computes the traffic light logics using the stored definitions and stores the results.
bool ready() const
returns whether the NBHeightMapper has data
Set z-values for all network positions based on data from a height map.
NBPTLineCont myPTLineCont
The used container for pt stops.
Definition: NBNetBuilder.h:251
TrafficLightType
void removeComponents(NBDistrictCont &dc, NBEdgeCont &ec, const int numKeep)
Checks the network for weak connectivity and removes all but the largest components. The connectivity check is done regardless of edge direction and vclass.
Definition: NBNodeCont.cpp:312