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 "NBDistribution.h"
45 #include "NBRequest.h"
46 #include "NBTypeCont.h"
52 #include <utils/common/SysUtils.h>
53 #include <utils/common/ToString.h>
55 #include "NBAlgorithms.h"
56 #include "NBAlgorithms_Ramps.h"
57 #include "NBHeightMapper.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
68  myEdgeCont(myTypeCont),
69  myHaveLoadedNetworkWithoutInternalEdges(false),
70  myNetworkHaveCrossings(false) {
71 }
72 
73 
75 
76 
77 void
79  // apply options to type control
80  myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.lanewidth"), oc.getFloat("default.speed"),
81  oc.getInt("default.priority"), parseVehicleClasses("", oc.getString("default.disallow")));
82  // apply options to edge control
84  // apply options to traffic light logics control
86 }
87 
88 
89 void
91  const std::set<std::string>& explicitTurnarounds,
92  bool mayAddOrRemove) {
94 
95 
96  const bool lefthand = oc.getBool("lefthand");
97  if (lefthand) {
98  mirrorX();
99  };
100 
101  // MODIFYING THE SETS OF NODES AND EDGES
102 
103  // Removes edges that are connecting the same node
104  long before = SysUtils::getCurrentMillis();
105  PROGRESS_BEGIN_MESSAGE("Removing self-loops");
107  PROGRESS_TIME_MESSAGE(before);
108  //
109  if (oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
110  before = SysUtils::getCurrentMillis();
111  PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
113  PROGRESS_TIME_MESSAGE(before);
114  }
115  //
116  if (oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
117  if (oc.isSet("keep-edges.explicit") || oc.isSet("keep-edges.input-file")) {
118  before = SysUtils::getCurrentMillis();
119  PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
121  PROGRESS_TIME_MESSAGE(before);
122  }
123  }
124  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
125  // preliminary geometry computations to determine the length of edges
126  // This depends on turning directions and sorting of edge list
127  // in case junctions are joined geometry computations have to be repeated
128  // preliminary roundabout computations to avoid damaging roundabouts via junctions.join or ramps.guess
134  if (oc.getBool("roundabouts.guess")) {
136  }
137  const std::set<EdgeSet>& roundabouts = myEdgeCont.getRoundabouts();
138  for (std::set<EdgeSet>::const_iterator it_round = roundabouts.begin();
139  it_round != roundabouts.end(); ++it_round) {
140  std::vector<std::string> nodeIDs;
141  for (EdgeSet::const_iterator it_edge = it_round->begin(); it_edge != it_round->end(); ++it_edge) {
142  nodeIDs.push_back((*it_edge)->getToNode()->getID());
143  }
144  myNodeCont.addJoinExclusion(nodeIDs);
145  }
146  }
147  // join junctions (may create new "geometry"-nodes so it needs to come before removing these
148  if (oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
149  myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
150  }
152  if (oc.getBool("junctions.join")) {
153  before = SysUtils::getCurrentMillis();
154  PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
155  numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont);
156  PROGRESS_TIME_MESSAGE(before);
157  }
158  if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
159  // reset geometry to avoid influencing subsequent steps (ramps.guess)
161  }
162  if (numJoined > 0) {
163  // bit of a misnomer since we're already done
164  WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
165  }
166  //
167  if (mayAddOrRemove) {
168  int no = 0;
169  const bool removeGeometryNodes = oc.exists("geometry.remove") && oc.getBool("geometry.remove");
170  before = SysUtils::getCurrentMillis();
171  PROGRESS_BEGIN_MESSAGE("Removing empty nodes" + std::string(removeGeometryNodes ? " and geometry nodes" : ""));
172  // removeUnwishedNodes needs turnDirections. @todo: try to call this less often
175  PROGRESS_TIME_MESSAGE(before);
176  WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
177  }
178 
179  // MOVE TO ORIGIN
180  // compute new boundary after network modifications have taken place
181  Boundary boundary;
182  for (std::map<std::string, NBNode*>::const_iterator it = myNodeCont.begin(); it != myNodeCont.end(); ++it) {
183  boundary.add(it->second->getPosition());
184  }
185  for (std::map<std::string, NBEdge*>::const_iterator it = myEdgeCont.begin(); it != myEdgeCont.end(); ++it) {
186  boundary.add(it->second->getGeometry().getBoxBoundary());
187  }
188  geoConvHelper.setConvBoundary(boundary);
189 
190  if (!oc.getBool("offset.disable-normalization") && oc.isDefault("offset.x") && oc.isDefault("offset.y")) {
191  moveToOrigin(geoConvHelper, lefthand);
192  }
193  geoConvHelper.computeFinal(lefthand); // information needed for location element fixed at this point
194 
195  if (oc.exists("geometry.min-dist") && !oc.isDefault("geometry.min-dist")) {
196  before = SysUtils::getCurrentMillis();
197  PROGRESS_BEGIN_MESSAGE("Reducing geometries");
198  myEdgeCont.reduceGeometries(oc.getFloat("geometry.min-dist"));
199  PROGRESS_TIME_MESSAGE(before);
200  }
201  // @note: removing geometry can create similar edges so joinSimilarEdges must come afterwards
202  // @note: likewise splitting can destroy similarities so joinSimilarEdges must come before
203  if (mayAddOrRemove && oc.getBool("edges.join")) {
204  before = SysUtils::getCurrentMillis();
205  PROGRESS_BEGIN_MESSAGE("Joining similar edges");
207  PROGRESS_TIME_MESSAGE(before);
208  }
209  if (oc.getBool("opposites.guess")) {
210  PROGRESS_BEGIN_MESSAGE("guessing opposite direction edges");
213  }
214  //
215  if (mayAddOrRemove && oc.exists("geometry.split") && oc.getBool("geometry.split")) {
216  before = SysUtils::getCurrentMillis();
217  PROGRESS_BEGIN_MESSAGE("Splitting geometry edges");
219  PROGRESS_TIME_MESSAGE(before);
220  }
221  // turning direction
222  before = SysUtils::getCurrentMillis();
223  PROGRESS_BEGIN_MESSAGE("Computing turning directions");
225  PROGRESS_TIME_MESSAGE(before);
226  // correct edge geometries to avoid overlap
228  // guess ramps
229  if (mayAddOrRemove) {
230  if ((oc.exists("ramps.guess") && oc.getBool("ramps.guess")) || (oc.exists("ramps.set") && oc.isSet("ramps.set"))) {
231  before = SysUtils::getCurrentMillis();
232  PROGRESS_BEGIN_MESSAGE("Guessing and setting on-/off-ramps");
235  PROGRESS_TIME_MESSAGE(before);
236  }
237  }
238  // guess sidewalks
239  if (oc.getBool("sidewalks.guess") || oc.getBool("sidewalks.guess.from-permissions")) {
240  const int sidewalks = myEdgeCont.guessSidewalks(oc.getFloat("default.sidewalk-width"),
241  oc.getFloat("sidewalks.guess.min-speed"),
242  oc.getFloat("sidewalks.guess.max-speed"),
243  oc.getBool("sidewalks.guess.from-permissions"));
244  WRITE_MESSAGE("Guessed " + toString(sidewalks) + " sidewalks.");
245  }
246 
247  // check whether any not previously setable connections may be set now
249 
250  // remap ids if wished
251  int numChangedEdges = myEdgeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
252  int numChangedNodes = myNodeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
253  if (numChangedEdges + numChangedNodes > 0) {
254  WRITE_MESSAGE("Remapped " + toString(numChangedEdges) + " edge IDs and " + toString(numChangedNodes) + " node IDs.");
255  }
256 
257  //
258  if (oc.exists("geometry.max-angle")) {
260  DEG2RAD(oc.getFloat("geometry.max-angle")),
261  oc.getFloat("geometry.min-radius"),
262  oc.getBool("geometry.min-radius.fix"));
263  }
264 
265  // GEOMETRY COMPUTATION
266  //
267  before = SysUtils::getCurrentMillis();
268  PROGRESS_BEGIN_MESSAGE("Sorting nodes' edges");
270  PROGRESS_TIME_MESSAGE(before);
272  //
273  // PABLO PARTE IMPORTANTE
274  before = SysUtils::getCurrentMillis();
275  PROGRESS_BEGIN_MESSAGE("Computing node shapes");
276  if (oc.exists("geometry.junction-mismatch-threshold")) {
277  myNodeCont.computeNodeShapes(oc.getFloat("geometry.junction-mismatch-threshold"));
278  } else {
280  }
281  PROGRESS_TIME_MESSAGE(before);
282  //
283  before = SysUtils::getCurrentMillis();
284  PROGRESS_BEGIN_MESSAGE("Computing edge shapes");
286  PROGRESS_TIME_MESSAGE(before);
287  // resort edges based on the node and edge shapes
290 
291  // APPLY SPEED MODIFICATIONS
292  if (oc.exists("speed.offset")) {
293  const SUMOReal speedOffset = oc.getFloat("speed.offset");
294  const SUMOReal speedFactor = oc.getFloat("speed.factor");
295  if (speedOffset != 0 || speedFactor != 1) {
296  const SUMOReal speedMin = oc.getFloat("speed.minimum");
297  before = SysUtils::getCurrentMillis();
298  PROGRESS_BEGIN_MESSAGE("Applying speed modifications");
299  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
300  (*i).second->setSpeed(-1, MAX2((*i).second->getSpeed() * speedFactor + speedOffset, speedMin));
301  }
302  PROGRESS_TIME_MESSAGE(before);
303  }
304  }
305 
306  // CONNECTIONS COMPUTATION
307  //
308  before = SysUtils::getCurrentMillis();
309  PROGRESS_BEGIN_MESSAGE("Computing node types");
311  PROGRESS_TIME_MESSAGE(before);
312  //
313  myNetworkHaveCrossings = false;
314  if (oc.getBool("crossings.guess")) {
315  myNetworkHaveCrossings = true;
316  int crossings = 0;
317  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
318  crossings += (*i).second->guessCrossings();
319  }
320  WRITE_MESSAGE("Guessed " + toString(crossings) + " pedestrian crossings.");
321  }
322  if (!myNetworkHaveCrossings) {
323  // recheck whether we had crossings in the input
324  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
325  if (i->second->getCrossings().size() > 0) {
326  myNetworkHaveCrossings = true;
327  break;
328  }
329  }
330  }
331 
332  if (oc.isDefault("no-internal-links") && !myNetworkHaveCrossings && myHaveLoadedNetworkWithoutInternalEdges) {
333  oc.set("no-internal-links", "true");
334  } else if (!mayAddOrRemove && myNetworkHaveCrossings) {
335  // crossings added via netedit
336  oc.resetWritable();
337  oc.set("no-internal-links", "false");
338  }
339 
340  //
341  before = SysUtils::getCurrentMillis();
342  PROGRESS_BEGIN_MESSAGE("Computing priorities");
344  PROGRESS_TIME_MESSAGE(before);
345  //
346  before = SysUtils::getCurrentMillis();
347  PROGRESS_BEGIN_MESSAGE("Computing approached edges");
348  myEdgeCont.computeEdge2Edges(oc.getBool("no-left-connections"));
349  PROGRESS_TIME_MESSAGE(before);
350  //
351  if (oc.getBool("roundabouts.guess")) {
352  before = SysUtils::getCurrentMillis();
353  PROGRESS_BEGIN_MESSAGE("Guessing and setting roundabouts");
354  const int numGuessed = myEdgeCont.guessRoundabouts();
355  if (numGuessed > 0) {
356  WRITE_MESSAGE(" Guessed " + toString(numGuessed) + " roundabout(s).");
357  }
358  PROGRESS_TIME_MESSAGE(before);
359  }
361  //
362  before = SysUtils::getCurrentMillis();
363  PROGRESS_BEGIN_MESSAGE("Computing approaching lanes");
365  PROGRESS_TIME_MESSAGE(before);
366  //
367  before = SysUtils::getCurrentMillis();
368  PROGRESS_BEGIN_MESSAGE("Dividing of lanes on approached lanes");
371  PROGRESS_TIME_MESSAGE(before);
372  //
373  before = SysUtils::getCurrentMillis();
374  PROGRESS_BEGIN_MESSAGE("Processing turnarounds");
375  if (!oc.getBool("no-turnarounds")) {
376  myEdgeCont.appendTurnarounds(oc.getBool("no-turnarounds.tls"));
377  } else {
378  myEdgeCont.appendTurnarounds(explicitTurnarounds, oc.getBool("no-turnarounds.tls"));
379  }
380  PROGRESS_TIME_MESSAGE(before);
381  //
382  before = SysUtils::getCurrentMillis();
383  PROGRESS_BEGIN_MESSAGE("Rechecking of lane endings");
385  PROGRESS_TIME_MESSAGE(before);
386 
387  if (myNetworkHaveCrossings && !oc.getBool("no-internal-links")) {
388  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
389  i->second->buildCrossingsAndWalkingAreas();
390  }
391  }
392 
393  // GUESS TLS POSITIONS
394  before = SysUtils::getCurrentMillis();
395  PROGRESS_BEGIN_MESSAGE("Assigning nodes to traffic lights");
396  if (oc.isSet("tls.set")) {
397  std::vector<std::string> tlControlledNodes = oc.getStringVector("tls.set");
399  for (std::vector<std::string>::const_iterator i = tlControlledNodes.begin(); i != tlControlledNodes.end(); ++i) {
400  NBNode* node = myNodeCont.retrieve(*i);
401  if (node == 0) {
402  WRITE_WARNING("Building a tl-logic for junction '" + *i + "' is not possible." + "\n The junction '" + *i + "' is not known.");
403  } else {
405  }
406  }
407  }
409  PROGRESS_TIME_MESSAGE(before);
410  //
411  if (oc.getBool("tls.join")) {
412  before = SysUtils::getCurrentMillis();
413  PROGRESS_BEGIN_MESSAGE("Joining traffic light nodes");
414  myNodeCont.joinTLS(myTLLCont, oc.getFloat("tls.join-dist"));
415  PROGRESS_TIME_MESSAGE(before);
416  }
417 
418 
419  // COMPUTING RIGHT-OF-WAY AND TRAFFIC LIGHT PROGRAMS
420  //
421  before = SysUtils::getCurrentMillis();
422  PROGRESS_BEGIN_MESSAGE("Computing traffic light control information");
424  PROGRESS_TIME_MESSAGE(before);
425  //
426  before = SysUtils::getCurrentMillis();
427  PROGRESS_BEGIN_MESSAGE("Computing node logics");
429  PROGRESS_TIME_MESSAGE(before);
430  //
431  before = SysUtils::getCurrentMillis();
432  PROGRESS_BEGIN_MESSAGE("Computing traffic light logics");
433  std::pair<int, int> numbers = myTLLCont.computeLogics(oc);
434  PROGRESS_TIME_MESSAGE(before);
435  std::string progCount = "";
436  if (numbers.first != numbers.second) {
437  progCount = "(" + toString(numbers.second) + " programs) ";
438  }
439  WRITE_MESSAGE(" " + toString(numbers.first) + " traffic light(s) " + progCount + "computed.");
440  //
441  if (oc.isSet("street-sign-output")) {
442  before = SysUtils::getCurrentMillis();
443  PROGRESS_BEGIN_MESSAGE("Generating street signs");
445  PROGRESS_TIME_MESSAGE(before);
446  }
447 
448  // FINISHING INNER EDGES
449  if (!oc.getBool("no-internal-links")) {
450  before = SysUtils::getCurrentMillis();
451  PROGRESS_BEGIN_MESSAGE("Building inner edges");
452  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
453  (*i).second->sortOutgoingConnectionsByIndex();
454  }
455  // walking areas shall only be built if crossings are wished as well
456  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
457  (*i).second->buildInnerEdges();
458  }
459  PROGRESS_TIME_MESSAGE(before);
460  }
461  // PATCH NODE SHAPES
462  if (oc.getFloat("junctions.scurve-stretch") > 0) {
463  // @note: nodes have collected correction hints in buildInnerEdges()
464  before = SysUtils::getCurrentMillis();
465  PROGRESS_BEGIN_MESSAGE("stretching junctions to smooth geometries");
469  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
470  (*i).second->buildInnerEdges();
471  }
472  PROGRESS_TIME_MESSAGE(before);
473  }
474  if (lefthand) {
475  mirrorX();
476  };
477 
478  if (oc.exists("geometry.check-overlap") && oc.getFloat("geometry.check-overlap") > 0) {
479  before = SysUtils::getCurrentMillis();
480  PROGRESS_BEGIN_MESSAGE("Checking overlapping edges");
481  myEdgeCont.checkOverlap(oc.getFloat("geometry.check-overlap"), oc.getFloat("geometry.check-overlap.vertical-threshold"));
482  PROGRESS_TIME_MESSAGE(before);
483  }
484  if (oc.exists("geometry.max-grade") && oc.getFloat("geometry.max-grade") > 0 && geoConvHelper.getConvBoundary().getZRange() > 0) {
485  before = SysUtils::getCurrentMillis();
486  PROGRESS_BEGIN_MESSAGE("Checking edge grade");
487  // user input is in %
488  myEdgeCont.checkGrade(oc.getFloat("geometry.max-grade") / 100);
489  PROGRESS_TIME_MESSAGE(before);
490  }
491 
492  // report
493  WRITE_MESSAGE("-----------------------------------------------------");
494  WRITE_MESSAGE("Summary:");
496  WRITE_MESSAGE(" Network boundaries:");
497  WRITE_MESSAGE(" Original boundary : " + toString(geoConvHelper.getOrigBoundary()));
498  WRITE_MESSAGE(" Applied offset : " + toString(geoConvHelper.getOffsetBase()));
499  WRITE_MESSAGE(" Converted boundary : " + toString(geoConvHelper.getConvBoundary()));
500  WRITE_MESSAGE("-----------------------------------------------------");
502  // report on very large networks
503  if (MAX2(geoConvHelper.getConvBoundary().xmax(), geoConvHelper.getConvBoundary().ymax()) > 1000000 ||
504  MIN2(geoConvHelper.getConvBoundary().xmin(), geoConvHelper.getConvBoundary().ymin()) < -1000000) {
505  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");
506  }
507 }
508 
509 
510 void
511 NBNetBuilder::moveToOrigin(GeoConvHelper& geoConvHelper, bool lefthand) {
512  long before = SysUtils::getCurrentMillis();
513  PROGRESS_BEGIN_MESSAGE("Moving network to origin");
514  Boundary boundary = geoConvHelper.getConvBoundary();
515  const SUMOReal x = -boundary.xmin();
516  const SUMOReal y = -(lefthand ? boundary.ymax() : boundary.ymin());
517  //if (lefthand) {
518  // y = boundary.ymax();
519  //}
520  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
521  (*i).second->reshiftPosition(x, y);
522  }
523  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
524  (*i).second->reshiftPosition(x, y);
525  }
526  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
527  (*i).second->reshiftPosition(x, y);
528  }
529  geoConvHelper.moveConvertedBy(x, y);
530  PROGRESS_TIME_MESSAGE(before);
531 }
532 
533 
534 void
536  // mirror the network along the X-axis
537  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
538  (*i).second->mirrorX();
539  }
540  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
541  (*i).second->mirrorX();
542  }
543  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
544  (*i).second->mirrorX();
545  }
546 }
547 
548 
549 bool
550 NBNetBuilder::transformCoordinate(Position& from, bool includeInBoundary, GeoConvHelper* from_srs) {
551  Position orig(from);
552  bool ok = GeoConvHelper::getProcessing().x2cartesian(from, includeInBoundary);
553  if (ok) {
554  const NBHeightMapper& hm = NBHeightMapper::get();
555  if (hm.ready()) {
556  if (from_srs != 0 && from_srs->usingGeoProjection()) {
557  from_srs->cartesian2geo(orig);
558  }
559  SUMOReal z = hm.getZ(orig);
560  from = Position(from.x(), from.y(), z);
561  }
562  }
563  return ok;
564 }
565 
566 
567 bool
568 NBNetBuilder::transformCoordinates(PositionVector& from, bool includeInBoundary, GeoConvHelper* from_srs) {
569  const SUMOReal maxLength = OptionsCont::getOptions().getFloat("geometry.max-segment-length");
570  if (maxLength > 0 && from.size() > 1) {
571  // transformation to cartesian coordinates must happen before we can check segment length
572  PositionVector copy = from;
573  for (int i = 0; i < (int) from.size(); i++) {
574  transformCoordinate(copy[i], false);
575  }
576  // check lengths and insert new points where needed (in the original
577  // coordinate system)
578  int inserted = 0;
579  for (int i = 0; i < (int)copy.size() - 1; i++) {
580  Position start = from[i + inserted];
581  Position end = from[i + inserted + 1];
582  SUMOReal length = copy[i].distanceTo(copy[i + 1]);
583  const Position step = (end - start) * (maxLength / length);
584  int steps = 0;
585  while (length > maxLength) {
586  length -= maxLength;
587  steps++;
588  from.insert(from.begin() + i + inserted + 1, start + (step * steps));
589  inserted++;
590  }
591  }
592  // now perform the transformation again so that height mapping can be
593  // performed for the new points
594  }
595  bool ok = true;
596  for (int i = 0; i < (int) from.size(); i++) {
597  ok = ok && transformCoordinate(from[i], includeInBoundary, from_srs);
598  }
599  return ok;
600 }
601 
602 /****************************************************************************/
NBNetBuilder()
Constructor.
NBTypeCont myTypeCont
The used container for street types.
Definition: NBNetBuilder.h:212
int guessSidewalks(SUMOReal width, SUMOReal minSpeed, SUMOReal maxSpeed, bool fromPermissions)
add sidwalks to edges within the given limits or permissions and return the number of edges affected ...
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:181
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:169
void sortOutgoingLanesConnections()
Sorts all lanes of all edges within the container by their direction.
Definition: NBEdgeCont.cpp:610
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 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 addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:450
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:320
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
void mirrorX()
mirror the network along the X-axis
SUMOReal getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
int guessRoundabouts()
Determines which edges belong to roundabouts and increases their priority.
Definition: NBEdgeCont.cpp:911
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
~NBNetBuilder()
Destructor.
SUMOReal ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:142
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:781
SUMOReal xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:130
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:484
T MAX2(T a, T b)
Definition: StdDefs.h:70
void generateStreetSigns()
assigns street signs to edges based on toNode types
void recheckPostProcessConnections()
Try to set any stored connections.
Definition: NBEdgeCont.cpp:840
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:839
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:390
void setDefaults(int defaultNumLanes, SUMOReal defaultLaneWidth, SUMOReal defaultSpeed, int defaultPriority, SVCPermissions defaultPermissions)
Sets the default values.
Definition: NBTypeCont.cpp:51
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:626
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
SUMOReal xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:136
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:69
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void checkGeometries(const SUMOReal maxAngle, const SUMOReal minRadius, bool fix)
Definition: NBEdgeCont.cpp:591
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)
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:778
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:204
void reduceGeometries(const SUMOReal minDist)
Definition: NBEdgeCont.cpp:583
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:55
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
void checkOverlap(SUMOReal threshold, SUMOReal zThreshold) const
check whether edges overlap
int joinJunctions(SUMOReal maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:508
void removeUnwishedEdges(NBDistrictCont &dc)
Removes unwished edges (not in keep-edges)
Definition: NBEdgeCont.cpp:555
void joinTLS(NBTrafficLightLogicCont &tlc, SUMOReal maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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:82
NBEdgeCont myEdgeCont
The used container for edges.
Definition: NBNetBuilder.h:215
bool myNetworkHaveCrossings
flag to indicate that network has crossings
Definition: NBNetBuilder.h:227
void computeEdge2Edges(bool noLeftMovers)
Computes for each edge the approached edges.
Definition: NBEdgeCont.cpp:618
void computeLaneShapes()
Computes the shapes of all lanes of all edges stored in the container.
Definition: NBEdgeCont.cpp:686
NBTrafficLightLogicCont myTLLCont
The used container for traffic light logics.
Definition: NBNetBuilder.h:218
T MIN2(T a, T b)
Definition: StdDefs.h:64
#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:572
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...
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.
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.
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:662
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
void add(SUMOReal x, SUMOReal y, SUMOReal z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:90
void checkGrade(SUMOReal threshold) const
check whether edges are to steep
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
Definition: NBNodeCont.cpp:226
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
A storage for options typed value containers)
Definition: OptionsCont.h:99
void computeNodeShapes(SUMOReal mismatchThreshold=-1)
Compute the junction shape for this node.
void computeEdgeShapes()
Computes the shapes of all edges stored in the container.
Definition: NBEdgeCont.cpp:678
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:221
#define SUMOReal
Definition: config.h:208
SUMOReal getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition: Boundary.cpp:178
SUMOReal ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:148
const Boundary & getOrigBoundary() const
Returns the original boundary.
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:110
void recheckLanes()
Rechecks whether all lanes have a successor for each of the stored edges.
Definition: NBEdgeCont.cpp:634
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:50
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
bool myHaveLoadedNetworkWithoutInternalEdges
whether a .net.xml without internal edges was loaded
Definition: NBNetBuilder.h:224
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:209
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.
Set z-values for all network positions based on data from a height map.
void moveConvertedBy(SUMOReal x, SUMOReal y)
Shifts the converted boundary by the given amounts.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
TrafficLightType
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.