SUMO - Simulation of Urban MObility
NBNetBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // Instance responsible for building networks
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
15 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <fstream>
38 #include "NBNetBuilder.h"
39 #include "NBNodeCont.h"
40 #include "NBEdgeCont.h"
42 #include "NBDistrictCont.h"
43 #include "NBDistrict.h"
44 #include "NBRequest.h"
45 #include "NBTypeCont.h"
51 #include <utils/common/SysUtils.h>
52 #include <utils/common/ToString.h>
54 #include "NBAlgorithms.h"
55 #include "NBAlgorithms_Ramps.h"
56 #include "NBHeightMapper.h"
57 
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
63  myEdgeCont(myTypeCont),
64  myHaveLoadedNetworkWithoutInternalEdges(false),
65  myNetworkHaveCrossings(false) {
66 }
67 
68 
70 
71 
72 void
74  // apply options to type control
75  myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.lanewidth"), oc.getFloat("default.speed"),
76  oc.getInt("default.priority"), parseVehicleClasses("", oc.getString("default.disallow")));
77  // apply options to edge control
79  // apply options to traffic light logics control
81 }
82 
83 
84 void
85 NBNetBuilder::compute(OptionsCont& oc, const std::set<std::string>& explicitTurnarounds, bool mayAddOrRemove) {
87 
88  const bool lefthand = oc.getBool("lefthand");
89  if (lefthand) {
90  mirrorX();
91  }
92 
93  // MODIFYING THE SETS OF NODES AND EDGES
94 
95  // Removes edges that are connecting the same node
96  long before = SysUtils::getCurrentMillis();
97  PROGRESS_BEGIN_MESSAGE("Removing self-loops");
99  PROGRESS_TIME_MESSAGE(before);
100  if (mayAddOrRemove && oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
101  before = SysUtils::getCurrentMillis();
102  PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
104  PROGRESS_TIME_MESSAGE(before);
105  }
106  if (mayAddOrRemove && oc.exists("keep-edges.components") && oc.getInt("keep-edges.components") > 0) {
107  before = SysUtils::getCurrentMillis();
108  PROGRESS_BEGIN_MESSAGE("Finding largest components");
109  myNodeCont.removeComponents(myDistrictCont, myEdgeCont, oc.getInt("keep-edges.components"));
110  PROGRESS_TIME_MESSAGE(before);
111  }
112  if (mayAddOrRemove && oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
113  if (oc.isSet("keep-edges.explicit") || oc.isSet("keep-edges.input-file")) {
114  before = SysUtils::getCurrentMillis();
115  PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
117  PROGRESS_TIME_MESSAGE(before);
118  }
119  }
120  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
121  // preliminary geometry computations to determine the length of edges
122  // This depends on turning directions and sorting of edge list
123  // in case junctions are joined geometry computations have to be repeated
124  // preliminary roundabout computations to avoid damaging roundabouts via junctions.join or ramps.guess
130  if (oc.getBool("roundabouts.guess")) {
132  }
133  const std::set<EdgeSet>& roundabouts = myEdgeCont.getRoundabouts();
134  for (std::set<EdgeSet>::const_iterator it_round = roundabouts.begin();
135  it_round != roundabouts.end(); ++it_round) {
136  std::vector<std::string> nodeIDs;
137  for (EdgeSet::const_iterator it_edge = it_round->begin(); it_edge != it_round->end(); ++it_edge) {
138  nodeIDs.push_back((*it_edge)->getToNode()->getID());
139  }
140  myNodeCont.addJoinExclusion(nodeIDs);
141  }
142  }
143  // join junctions (may create new "geometry"-nodes so it needs to come before removing these
144  if (mayAddOrRemove && oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
145  myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
146  }
148  if (mayAddOrRemove && oc.getBool("junctions.join")) {
149  before = SysUtils::getCurrentMillis();
150  PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
151  numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont);
152  PROGRESS_TIME_MESSAGE(before);
153  }
154  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
155  // reset geometry to avoid influencing subsequent steps (ramps.guess)
157  }
158  if (numJoined > 0) {
159  // bit of a misnomer since we're already done
160  WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
161  }
162  //
163  if (mayAddOrRemove) {
164  int no = 0;
165  const bool removeGeometryNodes = oc.exists("geometry.remove") && oc.getBool("geometry.remove");
166  before = SysUtils::getCurrentMillis();
167  PROGRESS_BEGIN_MESSAGE("Removing empty nodes" + std::string(removeGeometryNodes ? " and geometry nodes" : ""));
168  // removeUnwishedNodes needs turnDirections. @todo: try to call this less often
171  PROGRESS_TIME_MESSAGE(before);
172  WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
173  }
174 
175  // MOVE TO ORIGIN
176  // compute new boundary after network modifications have taken place
177  Boundary boundary;
178  for (std::map<std::string, NBNode*>::const_iterator it = myNodeCont.begin(); it != myNodeCont.end(); ++it) {
179  boundary.add(it->second->getPosition());
180  }
181  for (std::map<std::string, NBEdge*>::const_iterator it = myEdgeCont.begin(); it != myEdgeCont.end(); ++it) {
182  boundary.add(it->second->getGeometry().getBoxBoundary());
183  }
184  geoConvHelper.setConvBoundary(boundary);
185 
186  if (!oc.getBool("offset.disable-normalization") && oc.isDefault("offset.x") && oc.isDefault("offset.y")) {
187  moveToOrigin(geoConvHelper, lefthand);
188  }
189  geoConvHelper.computeFinal(lefthand); // information needed for location element fixed at this point
190 
191  if (oc.exists("geometry.min-dist") && !oc.isDefault("geometry.min-dist")) {
192  before = SysUtils::getCurrentMillis();
193  PROGRESS_BEGIN_MESSAGE("Reducing geometries");
194  myEdgeCont.reduceGeometries(oc.getFloat("geometry.min-dist"));
195  PROGRESS_TIME_MESSAGE(before);
196  }
197  // @note: removing geometry can create similar edges so joinSimilarEdges must come afterwards
198  // @note: likewise splitting can destroy similarities so joinSimilarEdges must come before
199  if (mayAddOrRemove && oc.getBool("edges.join")) {
200  before = SysUtils::getCurrentMillis();
201  PROGRESS_BEGIN_MESSAGE("Joining similar edges");
203  PROGRESS_TIME_MESSAGE(before);
204  }
205  if (oc.getBool("opposites.guess")) {
206  PROGRESS_BEGIN_MESSAGE("guessing opposite direction edges");
209  }
210  //
211  if (mayAddOrRemove && oc.exists("geometry.split") && oc.getBool("geometry.split")) {
212  before = SysUtils::getCurrentMillis();
213  PROGRESS_BEGIN_MESSAGE("Splitting geometry edges");
215  PROGRESS_TIME_MESSAGE(before);
216  }
217  // turning direction
218  before = SysUtils::getCurrentMillis();
219  PROGRESS_BEGIN_MESSAGE("Computing turning directions");
221  PROGRESS_TIME_MESSAGE(before);
222  // correct edge geometries to avoid overlap
224  // guess ramps
225  if (mayAddOrRemove) {
226  if ((oc.exists("ramps.guess") && oc.getBool("ramps.guess")) || (oc.exists("ramps.set") && oc.isSet("ramps.set"))) {
227  before = SysUtils::getCurrentMillis();
228  PROGRESS_BEGIN_MESSAGE("Guessing and setting on-/off-ramps");
231  PROGRESS_TIME_MESSAGE(before);
232  }
233  }
234  // guess sidewalks
235  if (mayAddOrRemove && ((oc.getBool("sidewalks.guess") || oc.getBool("sidewalks.guess.from-permissions")))) {
236  const int sidewalks = myEdgeCont.guessSidewalks(oc.getFloat("default.sidewalk-width"),
237  oc.getFloat("sidewalks.guess.min-speed"),
238  oc.getFloat("sidewalks.guess.max-speed"),
239  oc.getBool("sidewalks.guess.from-permissions"));
240  WRITE_MESSAGE("Guessed " + toString(sidewalks) + " sidewalks.");
241  }
242 
243  // check whether any not previously setable connections may be set now
245 
246  // remap ids if wished
247  int numChangedEdges = myEdgeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
248  int numChangedNodes = myNodeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
249  if (numChangedEdges + numChangedNodes > 0) {
250  WRITE_MESSAGE("Remapped " + toString(numChangedEdges) + " edge IDs and " + toString(numChangedNodes) + " node IDs.");
251  }
252 
253  //
254  if (oc.exists("geometry.max-angle")) {
256  DEG2RAD(oc.getFloat("geometry.max-angle")),
257  oc.getFloat("geometry.min-radius"),
258  oc.getBool("geometry.min-radius.fix"));
259  }
260 
261  // GEOMETRY COMPUTATION
262  //
263  before = SysUtils::getCurrentMillis();
264  PROGRESS_BEGIN_MESSAGE("Sorting nodes' edges");
266  PROGRESS_TIME_MESSAGE(before);
268  //
269  before = SysUtils::getCurrentMillis();
270  PROGRESS_BEGIN_MESSAGE("Computing node shapes");
271  if (oc.exists("geometry.junction-mismatch-threshold")) {
272  myNodeCont.computeNodeShapes(oc.getFloat("geometry.junction-mismatch-threshold"));
273  } else {
275  }
276  PROGRESS_TIME_MESSAGE(before);
277  //
278  before = SysUtils::getCurrentMillis();
279  PROGRESS_BEGIN_MESSAGE("Computing edge shapes");
281  PROGRESS_TIME_MESSAGE(before);
282  // resort edges based on the node and edge shapes
285 
286  // APPLY SPEED MODIFICATIONS
287  if (oc.exists("speed.offset")) {
288  const double speedOffset = oc.getFloat("speed.offset");
289  const double speedFactor = oc.getFloat("speed.factor");
290  if (speedOffset != 0 || speedFactor != 1) {
291  const double speedMin = oc.getFloat("speed.minimum");
292  before = SysUtils::getCurrentMillis();
293  PROGRESS_BEGIN_MESSAGE("Applying speed modifications");
294  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
295  (*i).second->setSpeed(-1, MAX2((*i).second->getSpeed() * speedFactor + speedOffset, speedMin));
296  }
297  PROGRESS_TIME_MESSAGE(before);
298  }
299  }
300 
301  // CONNECTIONS COMPUTATION
302  //
303  before = SysUtils::getCurrentMillis();
304  PROGRESS_BEGIN_MESSAGE("Computing node types");
306  PROGRESS_TIME_MESSAGE(before);
307  //
308  myNetworkHaveCrossings = oc.getBool("walkingareas");
309  if (mayAddOrRemove && oc.getBool("crossings.guess")) {
310  myNetworkHaveCrossings = true;
311  int crossings = 0;
312  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
313  crossings += (*i).second->guessCrossings();
314  }
315  WRITE_MESSAGE("Guessed " + toString(crossings) + " pedestrian crossings.");
316  }
317  if (!myNetworkHaveCrossings) {
318  // recheck whether we had crossings in the input
319  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
320  if (i->second->getCrossingsIncludingInvalid().size() > 0) {
321  myNetworkHaveCrossings = true;
322  break;
323  }
324  }
325  }
326 
327  if (oc.isDefault("no-internal-links") && !myNetworkHaveCrossings && myHaveLoadedNetworkWithoutInternalEdges) {
328  oc.set("no-internal-links", "true");
329  } else if (!mayAddOrRemove && myNetworkHaveCrossings) {
330  // crossings added via netedit
331  oc.resetWritable();
332  oc.set("no-internal-links", "false");
333  }
334 
335  //
336  before = SysUtils::getCurrentMillis();
337  PROGRESS_BEGIN_MESSAGE("Computing priorities");
339  PROGRESS_TIME_MESSAGE(before);
340  //
341  before = SysUtils::getCurrentMillis();
342  PROGRESS_BEGIN_MESSAGE("Computing approached edges");
343  myEdgeCont.computeEdge2Edges(oc.getBool("no-left-connections"));
344  PROGRESS_TIME_MESSAGE(before);
345  //
346  if (mayAddOrRemove && oc.getBool("roundabouts.guess")) {
347  before = SysUtils::getCurrentMillis();
348  PROGRESS_BEGIN_MESSAGE("Guessing and setting roundabouts");
349  const int numGuessed = myEdgeCont.guessRoundabouts();
350  if (numGuessed > 0) {
351  WRITE_MESSAGE(" Guessed " + toString(numGuessed) + " roundabout(s).");
352  }
353  PROGRESS_TIME_MESSAGE(before);
354  }
356  //
357  before = SysUtils::getCurrentMillis();
358  PROGRESS_BEGIN_MESSAGE("Computing approaching lanes");
360  PROGRESS_TIME_MESSAGE(before);
361  //
362  before = SysUtils::getCurrentMillis();
363  PROGRESS_BEGIN_MESSAGE("Dividing of lanes on approached lanes");
366  PROGRESS_TIME_MESSAGE(before);
367  //
368  before = SysUtils::getCurrentMillis();
369  PROGRESS_BEGIN_MESSAGE("Processing turnarounds");
370  if (!oc.getBool("no-turnarounds")) {
371  myEdgeCont.appendTurnarounds(oc.getBool("no-turnarounds.tls"));
372  } else {
373  myEdgeCont.appendTurnarounds(explicitTurnarounds, oc.getBool("no-turnarounds.tls"));
374  }
375  PROGRESS_TIME_MESSAGE(before);
376  //
377  before = SysUtils::getCurrentMillis();
378  PROGRESS_BEGIN_MESSAGE("Rechecking of lane endings");
380  PROGRESS_TIME_MESSAGE(before);
381 
382  if (myNetworkHaveCrossings && !oc.getBool("no-internal-links")) {
383  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
384  i->second->buildCrossingsAndWalkingAreas();
385  }
386  } else if (oc.getBool("no-internal-links")) {
387  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
388  i->second->discardAllCrossings(false);
389  }
390  }
391 
392  // GUESS TLS POSITIONS
393  before = SysUtils::getCurrentMillis();
394  PROGRESS_BEGIN_MESSAGE("Assigning nodes to traffic lights");
395  if (oc.isSet("tls.set")) {
396  std::vector<std::string> tlControlledNodes = oc.getStringVector("tls.set");
398  for (std::vector<std::string>::const_iterator i = tlControlledNodes.begin(); i != tlControlledNodes.end(); ++i) {
399  NBNode* node = myNodeCont.retrieve(*i);
400  if (node == 0) {
401  WRITE_WARNING("Building a tl-logic for junction '" + *i + "' is not possible." + "\n The junction '" + *i + "' is not known.");
402  } else {
404  }
405  }
406  }
408  PROGRESS_TIME_MESSAGE(before);
409  //
410  if (oc.getBool("tls.join")) {
411  before = SysUtils::getCurrentMillis();
412  PROGRESS_BEGIN_MESSAGE("Joining traffic light nodes");
413  myNodeCont.joinTLS(myTLLCont, oc.getFloat("tls.join-dist"));
414  PROGRESS_TIME_MESSAGE(before);
415  }
416 
417 
418  // COMPUTING RIGHT-OF-WAY AND TRAFFIC LIGHT PROGRAMS
419  //
420  before = SysUtils::getCurrentMillis();
421  PROGRESS_BEGIN_MESSAGE("Computing traffic light control information");
423  PROGRESS_TIME_MESSAGE(before);
424  //
425  before = SysUtils::getCurrentMillis();
426  PROGRESS_BEGIN_MESSAGE("Computing node logics");
428  PROGRESS_TIME_MESSAGE(before);
429  //
430  before = SysUtils::getCurrentMillis();
431  PROGRESS_BEGIN_MESSAGE("Computing traffic light logics");
432  std::pair<int, int> numbers = myTLLCont.computeLogics(oc);
433  PROGRESS_TIME_MESSAGE(before);
434  std::string progCount = "";
435  if (numbers.first != numbers.second) {
436  progCount = "(" + toString(numbers.second) + " programs) ";
437  }
438  WRITE_MESSAGE(" " + toString(numbers.first) + " traffic light(s) " + progCount + "computed.");
439  //
440  if (oc.isSet("street-sign-output")) {
441  before = SysUtils::getCurrentMillis();
442  PROGRESS_BEGIN_MESSAGE("Generating street signs");
444  PROGRESS_TIME_MESSAGE(before);
445  }
446 
447  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
448  (*i).second->sortOutgoingConnectionsByIndex();
449  }
450  // FINISHING INNER EDGES
451  if (!oc.getBool("no-internal-links")) {
452  before = SysUtils::getCurrentMillis();
453  PROGRESS_BEGIN_MESSAGE("Building inner edges");
454  // walking areas shall only be built if crossings are wished as well
455  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
456  (*i).second->buildInnerEdges();
457  }
458  PROGRESS_TIME_MESSAGE(before);
459  }
460  // PATCH NODE SHAPES
461  if (oc.getFloat("junctions.scurve-stretch") > 0) {
462  // @note: nodes have collected correction hints in buildInnerEdges()
463  before = SysUtils::getCurrentMillis();
464  PROGRESS_BEGIN_MESSAGE("stretching junctions to smooth geometries");
468  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
469  (*i).second->buildInnerEdges();
470  }
471  PROGRESS_TIME_MESSAGE(before);
472  }
473  if (lefthand) {
474  mirrorX();
475  };
476 
477  if (oc.exists("geometry.check-overlap") && oc.getFloat("geometry.check-overlap") > 0) {
478  before = SysUtils::getCurrentMillis();
479  PROGRESS_BEGIN_MESSAGE("Checking overlapping edges");
480  myEdgeCont.checkOverlap(oc.getFloat("geometry.check-overlap"), oc.getFloat("geometry.check-overlap.vertical-threshold"));
481  PROGRESS_TIME_MESSAGE(before);
482  }
483  if (oc.exists("geometry.max-grade") && oc.getFloat("geometry.max-grade") > 0 && geoConvHelper.getConvBoundary().getZRange() > 0) {
484  before = SysUtils::getCurrentMillis();
485  PROGRESS_BEGIN_MESSAGE("Checking edge grade");
486  // user input is in %
487  myEdgeCont.checkGrade(oc.getFloat("geometry.max-grade") / 100);
488  PROGRESS_TIME_MESSAGE(before);
489  }
490  if (oc.exists("ptstop-output") && oc.isSet("ptstop-output")) {
491  before = SysUtils::getCurrentMillis();
492  PROGRESS_BEGIN_MESSAGE("Processing public transport stops");
494  PROGRESS_TIME_MESSAGE(before);
495  }
496 
497  if (oc.exists("ptline-output") && oc.isSet("ptline-output")) {
498  before = SysUtils::getCurrentMillis();
499  PROGRESS_BEGIN_MESSAGE("Revising public transport stops based on pt lines");
501  PROGRESS_TIME_MESSAGE(before);
502  }
503 
504  // report
505  WRITE_MESSAGE("-----------------------------------------------------");
506  WRITE_MESSAGE("Summary:");
508  WRITE_MESSAGE(" Network boundaries:");
509  WRITE_MESSAGE(" Original boundary : " + toString(geoConvHelper.getOrigBoundary()));
510  WRITE_MESSAGE(" Applied offset : " + toString(geoConvHelper.getOffsetBase()));
511  WRITE_MESSAGE(" Converted boundary : " + toString(geoConvHelper.getConvBoundary()));
512  WRITE_MESSAGE("-----------------------------------------------------");
514  // report on very large networks
515  if (MAX2(geoConvHelper.getConvBoundary().xmax(), geoConvHelper.getConvBoundary().ymax()) > 1000000 ||
516  MIN2(geoConvHelper.getConvBoundary().xmin(), geoConvHelper.getConvBoundary().ymin()) < -1000000) {
517  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");
518  }
519 }
520 
521 
522 /*
523 void
524 NBNetBuilder::computeSingleNode(NBNode* node, OptionsCont& oc, const std::set<std::string>& explicitTurnarounds, bool mayAddOrRemove) {
525  // for a single node do the following:
526  // sortEdges
527  // computeLaneShapes
528  // computeNodeShapes
529  // computeEdgeShapes
530 }
531 */
532 
533 
534 void
535 NBNetBuilder::moveToOrigin(GeoConvHelper& geoConvHelper, bool lefthand) {
536  long before = SysUtils::getCurrentMillis();
537  PROGRESS_BEGIN_MESSAGE("Moving network to origin");
538  Boundary boundary = geoConvHelper.getConvBoundary();
539  const double x = -boundary.xmin();
540  const double y = -(lefthand ? boundary.ymax() : boundary.ymin());
541  //if (lefthand) {
542  // y = boundary.ymax();
543  //}
544  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
545  (*i).second->reshiftPosition(x, y);
546  }
547  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
548  (*i).second->reshiftPosition(x, y);
549  }
550  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
551  (*i).second->reshiftPosition(x, y);
552  }
553  for (std::map<std::string, NBPTStop*>::const_iterator i = myPTStopCont.begin(); i != myPTStopCont.end(); ++i) {
554  (*i).second->reshiftPostion(x, y);
555  }
556  geoConvHelper.moveConvertedBy(x, y);
557  PROGRESS_TIME_MESSAGE(before);
558 }
559 
560 
561 void
563  // mirror the network along the X-axis
564  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
565  (*i).second->mirrorX();
566  }
567  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
568  (*i).second->mirrorX();
569  }
570  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
571  (*i).second->mirrorX();
572  }
573 }
574 
575 
576 bool
577 NBNetBuilder::transformCoordinate(Position& from, bool includeInBoundary, GeoConvHelper* from_srs) {
578  Position orig(from);
579  bool ok = GeoConvHelper::getProcessing().x2cartesian(from, includeInBoundary);
580  if (ok) {
581  const NBHeightMapper& hm = NBHeightMapper::get();
582  if (hm.ready()) {
583  if (from_srs != 0 && from_srs->usingGeoProjection()) {
584  from_srs->cartesian2geo(orig);
585  }
586  double z = hm.getZ(orig);
587  from = Position(from.x(), from.y(), z);
588  }
589  }
590  return ok;
591 }
592 
593 
594 bool
595 NBNetBuilder::transformCoordinates(PositionVector& from, bool includeInBoundary, GeoConvHelper* from_srs) {
596  const double maxLength = OptionsCont::getOptions().getFloat("geometry.max-segment-length");
597  if (maxLength > 0 && from.size() > 1) {
598  // transformation to cartesian coordinates must happen before we can check segment length
599  PositionVector copy = from;
600  for (int i = 0; i < (int) from.size(); i++) {
601  transformCoordinate(copy[i], false);
602  }
603  // check lengths and insert new points where needed (in the original
604  // coordinate system)
605  int inserted = 0;
606  for (int i = 0; i < (int)copy.size() - 1; i++) {
607  Position start = from[i + inserted];
608  Position end = from[i + inserted + 1];
609  double length = copy[i].distanceTo(copy[i + 1]);
610  const Position step = (end - start) * (maxLength / length);
611  int steps = 0;
612  while (length > maxLength) {
613  length -= maxLength;
614  steps++;
615  from.insert(from.begin() + i + inserted + 1, start + (step * steps));
616  inserted++;
617  }
618  }
619  // now perform the transformation again so that height mapping can be
620  // performed for the new points
621  }
622  bool ok = true;
623  for (int i = 0; i < (int) from.size(); i++) {
624  ok = ok && transformCoordinate(from[i], includeInBoundary, from_srs);
625  }
626  return ok;
627 }
628 
629 /****************************************************************************/
NBNetBuilder()
Constructor.
NBTypeCont myTypeCont
The used container for street types.
Definition: NBNetBuilder.h:240
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:132
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:177
NBPTStopCont myPTStopCont
The used container for pt stops.
Definition: NBNetBuilder.h:252
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) ...
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:165
void sortOutgoingLanesConnections()
Sorts all lanes of all edges within the container by their direction.
Definition: NBEdgeCont.cpp:608
void markRoundabouts()
mark edge priorities and prohibit turn-arounds for all roundabout edges
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
void setConvBoundary(const Boundary &boundary)
sets the converted boundary
void checkOverlap(double threshold, double zThreshold) const
check whether edges overlap
void resetWritable()
Resets all options to be writeable.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
void reduceGeometries(const double minDist)
Definition: NBEdgeCont.cpp:581
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:497
bool ready() const
returns whether the NBHeightMapper has data
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:367
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
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:222
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.
Definition: NBEdgeCont.cpp:933
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:144
~NBNetBuilder()
Destructor.
double x() const
Returns the x-position.
Definition: Position.h:63
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:98
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void guessOpposites()
Sets opposite lane information for geometrically close edges.
Definition: NBEdgeCont.cpp:791
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:531
std::map< std::string, NBPTStop * >::const_iterator begin() const
Returns the pointer to the begin of the stored pt stops.
Definition: NBPTStopCont.h:54
T MAX2(T a, T b)
Definition: StdDefs.h:74
void generateStreetSigns()
assigns street signs to edges based on toNode types
void recheckPostProcessConnections()
Try to set any stored connections.
Definition: NBEdgeCont.cpp:856
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.
Definition: NBNodeCont.cpp:890
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:437
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:624
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:48
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
void checkGeometries(const double maxAngle, const double minRadius, bool fix)
Definition: NBEdgeCont.cpp:589
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
void process(NBEdgeCont &cont)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static void reportWarnings()
reports warnings if any occured
Definition: NBRequest.cpp:774
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:204
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:60
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
void removeUnwishedEdges(NBDistrictCont &dc)
Removes unwished edges (not in keep-edges)
Definition: NBEdgeCont.cpp:553
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void setDefaults(int defaultNumLanes, double defaultLaneWidth, double defaultSpeed, int defaultPriority, SVCPermissions defaultPermissions)
Sets the default values.
Definition: NBTypeCont.cpp:47
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
std::map< std::string, NBDistrict * >::const_iterator end() const
Returns the pointer to the end of the stored districts.
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:78
NBEdgeCont myEdgeCont
The used container for edges.
Definition: NBNetBuilder.h:243
double y() const
Returns the y-position.
Definition: Position.h:68
bool myNetworkHaveCrossings
flag to indicate that network has crossings
Definition: NBNetBuilder.h:261
std::map< std::string, NBPTStop * >::const_iterator end() const
Returns the pointer to the end of the stored pt stops.
Definition: NBPTStopCont.h:62
void computeEdge2Edges(bool noLeftMovers)
Computes for each edge the approached edges.
Definition: NBEdgeCont.cpp:616
void computeLaneShapes()
Computes the shapes of all lanes of all edges stored in the container.
Definition: NBEdgeCont.cpp:696
NBTrafficLightLogicCont myTLLCont
The used container for traffic light logics.
Definition: NBNetBuilder.h:246
T MIN2(T a, T b)
Definition: StdDefs.h:68
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
void splitGeometry(NBNodeCont &nc)
Splits edges into multiple if they have a complex geometry.
Definition: NBEdgeCont.cpp:570
const Position getOffsetBase() const
Returns the network base.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:555
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:119
#define DEG2RAD(x)
Definition: GeomHelper.h:45
const Boundary & getConvBoundary() const
Returns the converted boundary.
void process(NBEdgeCont &cont)
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
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 appendTurnarounds(bool noTLSControlled)
Appends turnarounds to all edges stored in the container.
Definition: NBEdgeCont.cpp:672
int remapIDs(bool numericaIDs, bool reservedIDs)
remap node IDs accoring to options –numerical-ids and –reserved-ids
static void computeNodeTypes(NBNodeCont &nc)
Computes node types.
void moveToOrigin(GeoConvHelper &geoConvHelper, bool lefthand)
shift network so its lower left corner is at 0,0
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:126
A storage for options typed value containers)
Definition: OptionsCont.h:99
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:138
void computeEdgeShapes()
Computes the shapes of all edges stored in the container.
Definition: NBEdgeCont.cpp:688
Represents a single node (junction) during network building.
Definition: NBNode.h:75
T get(const std::string &str) const
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:249
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
const Boundary & getOrigBoundary() const
Returns the original boundary.
void checkGrade(double threshold) const
check whether edges are to steep
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:106
void recheckLanes()
Rechecks whether all lanes have a successor for each of the stored edges.
Definition: NBEdgeCont.cpp:632
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:46
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:86
bool myHaveLoadedNetworkWithoutInternalEdges
whether a .net.xml without internal edges was loaded
Definition: NBNetBuilder.h:258
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
int remapIDs(bool numericaIDs, bool reservedIDs)
remap node IDs accoring to options –numerical-ids and –reserved-ids
NBNodeCont myNodeCont
The used container for nodes.
Definition: NBNetBuilder.h:237
void setTLControllingInformation(const NBEdgeCont &ec, const NBNodeCont &nc)
Informs the edges about being controlled by a tls.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:114
std::pair< int, int > computeLogics(OptionsCont &oc)
Computes the traffic light logics using the stored definitions and stores the results.
double getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition: Boundary.cpp:174
Set z-values for all network positions based on data from a height map.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
NBPTLineCont myPTLineCont
The used container for pt stops.
Definition: NBNetBuilder.h:255
TrafficLightType
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
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:310