Eclipse SUMO - Simulation of Urban MObility
NWWriter_OpenDrive.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2011-2019 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 /****************************************************************************/
16 // Exporter writing networks using the openDRIVE format
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <ctime>
26 #include "NWWriter_OpenDrive.h"
29 #include <netbuild/NBEdgeCont.h>
30 #include <netbuild/NBNode.h>
31 #include <netbuild/NBNodeCont.h>
32 #include <netbuild/NBNetBuilder.h>
36 #include <utils/common/StdDefs.h>
40 
41 #define INVALID_ID -1
42 
43 //#define DEBUG_SMOOTH_GEOM
44 #define DEBUGCOND true
45 
46 #define MIN_TURN_DIAMETER 2.0
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 // ---------------------------------------------------------------------------
53 // static methods
54 // ---------------------------------------------------------------------------
55 void
57  // check whether an opendrive-file shall be generated
58  if (!oc.isSet("opendrive-output")) {
59  return;
60  }
61  const NBNodeCont& nc = nb.getNodeCont();
62  const NBEdgeCont& ec = nb.getEdgeCont();
63  const bool origNames = oc.getBool("output.original-names");
64  const bool lefthand = oc.getBool("lefthand");
65  const double straightThresh = DEG2RAD(oc.getFloat("opendrive-output.straight-threshold"));
66  // some internal mapping containers
67  int nodeID = 1;
68  int edgeID = nc.size() * 10; // distinct from node ids
69  StringBijection<int> edgeMap;
70  StringBijection<int> nodeMap;
71  //
72  OutputDevice& device = OutputDevice::getDevice(oc.getString("opendrive-output"));
73  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
74  device.openTag("OpenDRIVE");
75  time_t now = time(nullptr);
76  std::string dstr(ctime(&now));
78  // write header
79  device.openTag("header");
80  device.writeAttr("revMajor", "1");
81  device.writeAttr("revMinor", "4");
82  device.writeAttr("name", "");
83  device.writeAttr("version", "1.00");
84  device.writeAttr("date", dstr.substr(0, dstr.length() - 1));
85  device.writeAttr("north", b.ymax());
86  device.writeAttr("south", b.ymin());
87  device.writeAttr("east", b.xmax());
88  device.writeAttr("west", b.xmin());
89  /* @note obsolete in 1.4
90  device.writeAttr("maxRoad", ec.size());
91  device.writeAttr("maxJunc", nc.size());
92  device.writeAttr("maxPrg", 0);
93  */
94  device.closeTag();
95  // write optional geo reference
97  if (gch.usingGeoProjection()) {
98  if (gch.getOffsetBase() == Position(0, 0)) {
99  device.openTag("geoReference");
100  device.writePreformattedTag(" <![CDATA[\n "
101  + gch.getProjString()
102  + "\n]]>\n");
103  device.closeTag();
104  } else {
105  WRITE_WARNING("Could not write OpenDRIVE geoReference. Only unshifted Coordinate systems are supported (offset=" + toString(gch.getOffsetBase()) + ")");
106  }
107  }
108 
109  // write normal edges (road)
110  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
111  const NBEdge* e = (*i).second;
112  const int fromNodeID = e->getIncomingEdges().size() > 0 ? getID(e->getFromNode()->getID(), nodeMap, nodeID) : INVALID_ID;
113  const int toNodeID = e->getConnections().size() > 0 ? getID(e->getToNode()->getID(), nodeMap, nodeID) : INVALID_ID;
114  writeNormalEdge(device, e,
115  getID(e->getID(), edgeMap, edgeID),
116  fromNodeID, toNodeID,
117  origNames, straightThresh,
118  nb.getShapeCont());
119  }
120  device.lf();
121 
122  // write junction-internal edges (road). In OpenDRIVE these are called 'paths' or 'connecting roads'
123  OutputDevice_String junctionOSS(false, 3);
124  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
125  NBNode* n = (*i).second;
126  int connectionID = 0; // unique within a junction
127  const int nID = getID(n->getID(), nodeMap, nodeID);
128  if (n->numNormalConnections() > 0) {
129  junctionOSS << " <junction name=\"" << n->getID() << "\" id=\"" << nID << "\">\n";
130  }
131  std::vector<NBEdge*> incoming = (*i).second->getIncomingEdges();
132  if (lefthand) {
133  std::reverse(incoming.begin(), incoming.end());
134  }
135  for (NBEdge* inEdge : incoming) {
136  std::string centerMark = "none";
137  const int inEdgeID = getID(inEdge->getID(), edgeMap, edgeID);
138  // group parallel edges
139  const NBEdge* outEdge = nullptr;
140  bool isOuterEdge = true; // determine where a solid outer border should be drawn
141  int lastFromLane = -1;
142  std::vector<NBEdge::Connection> parallel;
143  std::vector<NBEdge::Connection> connections = inEdge->getConnections();
144  if (lefthand) {
145  std::reverse(connections.begin(), connections.end());
146  }
147  for (const NBEdge::Connection& c : connections) {
148  assert(c.toEdge != 0);
149  if (outEdge != c.toEdge || c.fromLane == lastFromLane) {
150  if (outEdge != nullptr) {
151  if (isOuterEdge) {
152  addPedestrianConnection(inEdge, outEdge, parallel);
153  }
154  connectionID = writeInternalEdge(device, junctionOSS, inEdge, nID,
155  getID(parallel.back().getInternalLaneID(), edgeMap, edgeID),
156  inEdgeID,
157  getID(outEdge->getID(), edgeMap, edgeID),
158  connectionID,
159  parallel, isOuterEdge, straightThresh, centerMark);
160  parallel.clear();
161  isOuterEdge = false;
162  }
163  outEdge = c.toEdge;
164  }
165  lastFromLane = c.fromLane;
166  parallel.push_back(c);
167  }
168  if (isOuterEdge) {
169  addPedestrianConnection(inEdge, outEdge, parallel);
170  }
171  if (!parallel.empty()) {
172  if (!lefthand && (n->geometryLike() || inEdge->isTurningDirectionAt(outEdge))) {
173  centerMark = "solid";
174  }
175  connectionID = writeInternalEdge(device, junctionOSS, inEdge, nID,
176  getID(parallel.back().getInternalLaneID(), edgeMap, edgeID),
177  inEdgeID,
178  getID(outEdge->getID(), edgeMap, edgeID),
179  connectionID,
180  parallel, isOuterEdge, straightThresh, centerMark);
181  parallel.clear();
182  }
183  }
184  if (n->numNormalConnections() > 0) {
185  junctionOSS << " </junction>\n";
186  }
187  }
188  device.lf();
189  // write junctions (junction)
190  device << junctionOSS.getString();
191 
192  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
193  NBNode* n = (*i).second;
194  const std::vector<NBEdge*>& incoming = n->getIncomingEdges();
195  // check if any connections must be written
196  int numConnections = 0;
197  for (std::vector<NBEdge*>::const_iterator j = incoming.begin(); j != incoming.end(); ++j) {
198  numConnections += (int)((*j)->getConnections().size());
199  }
200  if (numConnections == 0) {
201  continue;
202  }
203  for (std::vector<NBEdge*>::const_iterator j = incoming.begin(); j != incoming.end(); ++j) {
204  const NBEdge* inEdge = *j;
205  const std::vector<NBEdge::Connection>& elv = inEdge->getConnections();
206  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
207  const NBEdge::Connection& c = *k;
208  const NBEdge* outEdge = c.toEdge;
209  if (outEdge == nullptr) {
210  continue;
211  }
212  }
213  }
214  }
215 
216  device.closeTag();
217  device.close();
218 }
219 
220 
221 void
223  int edgeID, int fromNodeID, int toNodeID,
224  const bool origNames,
225  const double straightThresh,
226  const ShapeContainer& shc) {
227  // buffer output because some fields are computed out of order
228  OutputDevice_String elevationOSS(false, 3);
229  elevationOSS.setPrecision(8);
230  OutputDevice_String planViewOSS(false, 2);
231  planViewOSS.setPrecision(8);
232  double length = 0;
233 
234  planViewOSS.openTag("planView");
235  // for the shape we need to use the leftmost border of the leftmost lane
236  const std::vector<NBEdge::Lane>& lanes = e->getLanes();
238 #ifdef DEBUG_SMOOTH_GEOM
239  if (DEBUGCOND) {
240  std::cout << "write planview for edge " << e->getID() << "\n";
241  }
242 #endif
243 
244  if (ls.size() == 2 || e->getPermissions() == SVC_PEDESTRIAN) {
245  // foot paths may contain sharp angles
246  length = writeGeomLines(ls, planViewOSS, elevationOSS);
247  } else {
248  bool ok = writeGeomSmooth(ls, e->getSpeed(), planViewOSS, elevationOSS, straightThresh, length);
249  if (!ok) {
250  WRITE_WARNING("Could not compute smooth shape for edge '" + e->getID() + "'.");
251  }
252  }
253  planViewOSS.closeTag();
254 
255  device.openTag("road");
256  device.writeAttr("name", StringUtils::escapeXML(e->getStreetName()));
257  device.setPrecision(8); // length requires higher precision
258  device.writeAttr("length", MAX2(POSITION_EPS, length));
259  device.setPrecision(gPrecision);
260  device.writeAttr("id", edgeID);
261  device.writeAttr("junction", -1);
262  if (fromNodeID != INVALID_ID || toNodeID != INVALID_ID) {
263  device.openTag("link");
264  if (fromNodeID != INVALID_ID) {
265  device.openTag("predecessor");
266  device.writeAttr("elementType", "junction");
267  device.writeAttr("elementId", fromNodeID);
268  device.closeTag();
269  }
270  if (toNodeID != INVALID_ID) {
271  device.openTag("successor");
272  device.writeAttr("elementType", "junction");
273  device.writeAttr("elementId", toNodeID);
274  device.closeTag();
275  }
276  device.closeTag();
277  }
278  device.openTag("type").writeAttr("s", 0).writeAttr("type", "town").closeTag();
279  device << planViewOSS.getString();
280  writeElevationProfile(ls, device, elevationOSS);
281  device << " <lateralProfile/>\n";
282  device << " <lanes>\n";
283  device << " <laneSection s=\"0\">\n";
284  const std::string centerMark = e->getPermissions(e->getNumLanes() - 1) == 0 ? "none" : "solid";
285  writeEmptyCenterLane(device, centerMark, 0.13);
286  device << " <right>\n";
287  for (int j = e->getNumLanes(); --j >= 0;) {
288  device << " <lane id=\"-" << e->getNumLanes() - j << "\" type=\"" << getLaneType(e->getPermissions(j)) << "\" level=\"true\">\n";
289  device << " <link/>\n";
290  // this could be used for geometry-link junctions without u-turn,
291  // predecessor and sucessors would be lane indices,
292  // road predecessor / succesfors would be of type 'road' rather than
293  // 'junction'
294  //device << " <predecessor id=\"-1\"/>\n";
295  //device << " <successor id=\"-1\"/>\n";
296  //device << " </link>\n";
297  device << " <width sOffset=\"0\" a=\"" << e->getLaneWidth(j) << "\" b=\"0\" c=\"0\" d=\"0\"/>\n";
298  std::string markType = "broken";
299  if (j == 0) {
300  markType = "solid";
301  } else if (j > 0
302  && (e->getPermissions(j - 1) & ~(SVC_PEDESTRIAN | SVC_BICYCLE)) == 0) {
303  // solid road mark to the left of sidewalk or bicycle lane
304  markType = "solid";
305  } else if (e->getPermissions(j) == 0) {
306  // solid road mark to the right of a forbidden lane
307  markType = "solid";
308  }
309  device << " <roadMark sOffset=\"0\" type=\"" << markType << "\" weight=\"standard\" color=\"standard\" width=\"0.13\"/>\n";
310  device << " <speed sOffset=\"0\" max=\"" << lanes[j].speed << "\"/>\n";
311  device << " </lane>\n";
312  }
313  device << " </right>\n";
314  device << " </laneSection>\n";
315  device << " </lanes>\n";
316  writeRoadObjects(device, e, shc);
317  device << " <signals/>\n";
318  if (origNames) {
319  device << " <userData code=\"sumoId\" value=\"" << e->getID() << "\"/>\n";
320  }
321  device.closeTag();
323 }
324 
325 void
326 NWWriter_OpenDrive::addPedestrianConnection(const NBEdge* inEdge, const NBEdge* outEdge, std::vector<NBEdge::Connection>& parallel) {
327  // by default there are no internal lanes for pedestrians. Determine if
328  // one is feasible and does not exist yet.
329  if (outEdge != nullptr
330  && inEdge->getPermissions(0) == SVC_PEDESTRIAN
331  && outEdge->getPermissions(0) == SVC_PEDESTRIAN
332  && (parallel.empty()
333  || parallel.front().fromLane != 0
334  || parallel.front().toLane != 0)) {
335  parallel.insert(parallel.begin(), NBEdge::Connection(0, const_cast<NBEdge*>(outEdge), 0, false));
336  parallel.front().vmax = (inEdge->getLanes()[0].speed + outEdge->getLanes()[0].speed) / (double) 2.0;
337  }
338 }
339 
340 
341 int
342 NWWriter_OpenDrive::writeInternalEdge(OutputDevice& device, OutputDevice& junctionDevice, const NBEdge* inEdge, int nodeID,
343  int edgeID, int inEdgeID, int outEdgeID,
344  int connectionID,
345  const std::vector<NBEdge::Connection>& parallel,
346  const bool isOuterEdge,
347  const double straightThresh,
348  const std::string& centerMark) {
349  assert(parallel.size() != 0);
350  const NBEdge::Connection& cLeft = parallel.back();
351  const NBEdge* outEdge = cLeft.toEdge;
352  PositionVector begShape = getLeftLaneBorder(inEdge, cLeft.fromLane);
353  PositionVector endShape = getLeftLaneBorder(outEdge, cLeft.toLane);
354  //std::cout << "computing reference line for internal lane " << cLeft.getInternalLaneID() << " begLane=" << inEdge->getLaneShape(cLeft.fromLane) << " endLane=" << outEdge->getLaneShape(cLeft.toLane) << "\n";
355 
356  double length;
357  double laneOffset = 0;
358  PositionVector fallBackShape;
359  fallBackShape.push_back(begShape.back());
360  fallBackShape.push_back(endShape.front());
361  const bool turnaround = inEdge->isTurningDirectionAt(outEdge);
362  bool ok = true;
363  PositionVector init = NBNode::bezierControlPoints(begShape, endShape, turnaround, 25, 25, ok, nullptr, straightThresh);
364  if (init.size() == 0) {
365  length = fallBackShape.length2D();
366  // problem with turnarounds is known, method currently returns 'ok' (#2539)
367  if (!ok) {
368  WRITE_WARNING("Could not compute smooth shape from lane '" + inEdge->getLaneID(cLeft.fromLane) + "' to lane '" + outEdge->getLaneID(cLeft.toLane) + "'. Use option 'junctions.scurve-stretch' or increase radius of junction '" + inEdge->getToNode()->getID() + "' to fix this.");
369  } else if (length <= NUMERICAL_EPS) {
370  // left-curving geometry-like edges must use the right
371  // side as reference line and shift
372  begShape = getRightLaneBorder(inEdge, cLeft.fromLane);
373  endShape = getRightLaneBorder(outEdge, cLeft.toLane);
374  init = NBNode::bezierControlPoints(begShape, endShape, turnaround, 25, 25, ok, nullptr, straightThresh);
375  if (init.size() != 0) {
376  length = init.bezier(12).length2D();
377  laneOffset = outEdge->getLaneWidth(cLeft.toLane);
378  //std::cout << " internalLane=" << cLeft.getInternalLaneID() << " length=" << length << "\n";
379  }
380  }
381  } else {
382  length = init.bezier(12).length2D();
383  }
384 
385  junctionDevice << " <connection id=\"" << connectionID << "\" incomingRoad=\"" << inEdgeID << "\" connectingRoad=\"" << edgeID << "\" contactPoint=\"start\">\n";
386  device.openTag("road");
387  device.writeAttr("name", cLeft.id);
388  device.setPrecision(8); // length requires higher precision
389  device.writeAttr("length", MAX2(POSITION_EPS, length));
390  device.setPrecision(gPrecision);
391  device.writeAttr("id", edgeID);
392  device.writeAttr("junction", nodeID);
393  device.openTag("link");
394  device.openTag("predecessor");
395  device.writeAttr("elementType", "road");
396  device.writeAttr("elementId", inEdgeID);
397  device.writeAttr("contactPoint", "end");
398  device.closeTag();
399  device.openTag("successor");
400  device.writeAttr("elementType", "road");
401  device.writeAttr("elementId", outEdgeID);
402  device.writeAttr("contactPoint", "start");
403  device.closeTag();
404  device.closeTag();
405  device.openTag("type").writeAttr("s", 0).writeAttr("type", "town").closeTag();
406  device.openTag("planView");
407  device.setPrecision(8); // geometry hdg requires higher precision
408  OutputDevice_String elevationOSS(false, 3);
409  elevationOSS.setPrecision(8);
410 #ifdef DEBUG_SMOOTH_GEOM
411  if (DEBUGCOND) {
412  std::cout << "write planview for internal edge " << cLeft.id << " init=" << init << " fallback=" << fallBackShape
413  << " begShape=" << begShape << " endShape=" << endShape
414  << "\n";
415  }
416 #endif
417  if (init.size() == 0) {
418  writeGeomLines(fallBackShape, device, elevationOSS);
419  } else {
420  writeGeomPP3(device, elevationOSS, init, length);
421  }
422  device.setPrecision(gPrecision);
423  device.closeTag();
424  writeElevationProfile(fallBackShape, device, elevationOSS);
425  device << " <lateralProfile/>\n";
426  device << " <lanes>\n";
427  if (laneOffset != 0) {
428  device << " <laneOffset s=\"0\" a=\"" << laneOffset << "\" b=\"0\" c=\"0\" d=\"0\"/>\n";
429  }
430  device << " <laneSection s=\"0\">\n";
431  writeEmptyCenterLane(device, centerMark, 0);
432  device << " <right>\n";
433  for (int j = (int)parallel.size(); --j >= 0;) {
434  const NBEdge::Connection& c = parallel[j];
435  const int fromIndex = c.fromLane - inEdge->getNumLanes();
436  const int toIndex = c.toLane - outEdge->getNumLanes();
437  device << " <lane id=\"-" << parallel.size() - j << "\" type=\"" << getLaneType(outEdge->getPermissions(c.toLane)) << "\" level=\"true\">\n";
438  device << " <link>\n";
439  device << " <predecessor id=\"" << fromIndex << "\"/>\n";
440  device << " <successor id=\"" << toIndex << "\"/>\n";
441  device << " </link>\n";
442  device << " <width sOffset=\"0\" a=\"" << outEdge->getLaneWidth(c.toLane) << "\" b=\"0\" c=\"0\" d=\"0\"/>\n";
443  std::string markType = "broken";
444  if (inEdge->isTurningDirectionAt(outEdge)) {
445  markType = "none";
446  } else if (c.fromLane == 0 && c.toLane == 0 && isOuterEdge) {
447  // solid road mark at the outer border
448  markType = "solid";
449  } else if (isOuterEdge && j > 0
450  && (outEdge->getPermissions(parallel[j - 1].toLane) & ~(SVC_PEDESTRIAN | SVC_BICYCLE)) == 0) {
451  // solid road mark to the left of sidewalk or bicycle lane
452  markType = "solid";
453  } else if (!inEdge->getToNode()->geometryLike()) {
454  // draw shorter road marks to indicate turning paths
455  LinkDirection dir = inEdge->getToNode()->getDirection(inEdge, outEdge, OptionsCont::getOptions().getBool("lefthand"));
456  if (dir == LINKDIR_LEFT || dir == LINKDIR_RIGHT || dir == LINKDIR_PARTLEFT || dir == LINKDIR_PARTRIGHT) {
457  // XXX <type><line/><type> is not rendered by odrViewer so cannot be validated
458  // device << " <type name=\"broken\" width=\"0.13\">\n";
459  // device << " <line length=\"0.5\" space=\"0.5\" tOffset=\"0\" sOffset=\"0\" rule=\"none\"/>\n";
460  // device << " </type>\n";
461  markType = "none";
462  }
463  }
464  device << " <roadMark sOffset=\"0\" type=\"" << markType << "\" weight=\"standard\" color=\"standard\" width=\"0.13\"/>\n";
465  device << " <speed sOffset=\"0\" max=\"" << c.vmax << "\"/>\n";
466  device << " </lane>\n";
467 
468  junctionDevice << " <laneLink from=\"" << fromIndex << "\" to=\"" << toIndex << "\"/>\n";
469  connectionID++;
470  }
471  device << " </right>\n";
472  device << " </laneSection>\n";
473  device << " </lanes>\n";
474  device << " <objects/>\n";
475  device << " <signals/>\n";
476  device.closeTag();
477  junctionDevice << " </connection>\n";
478 
479  return connectionID;
480 }
481 
482 
483 double
484 NWWriter_OpenDrive::writeGeomLines(const PositionVector& shape, OutputDevice& device, OutputDevice& elevationDevice, double offset) {
485  for (int j = 0; j < (int)shape.size() - 1; ++j) {
486  const Position& p = shape[j];
487  const Position& p2 = shape[j + 1];
488  const double hdg = shape.angleAt2D(j);
489  const double length = p.distanceTo2D(p2);
490  device.openTag("geometry");
491  device.writeAttr("s", offset);
492  device.writeAttr("x", p.x());
493  device.writeAttr("y", p.y());
494  device.writeAttr("hdg", hdg);
495  device.writeAttr("length", length);
496  device.openTag("line").closeTag();
497  device.closeTag();
498  elevationDevice << " <elevation s=\"" << offset << "\" a=\"" << p.z() << "\" b=\"" << (p2.z() - p.z()) / MAX2(POSITION_EPS, length) << "\" c=\"0\" d=\"0\"/>\n";
499  offset += length;
500  }
501  return offset;
502 }
503 
504 
505 void
506 NWWriter_OpenDrive::writeEmptyCenterLane(OutputDevice& device, const std::string& mark, double markWidth) {
507  device << " <center>\n";
508  device << " <lane id=\"0\" type=\"none\" level=\"true\">\n";
509  device << " <link/>\n";
510  device << " <roadMark sOffset=\"0\" type=\"" << mark << "\" weight=\"standard\" color=\"standard\" width=\"" << markWidth << "\"/>\n";
511  device << " </lane>\n";
512  device << " </center>\n";
513 }
514 
515 
516 int
517 NWWriter_OpenDrive::getID(const std::string& origID, StringBijection<int>& map, int& lastID) {
518  if (map.hasString(origID)) {
519  return map.get(origID);
520  }
521  map.insert(origID, lastID++);
522  return lastID - 1;
523 }
524 
525 
526 std::string
528  switch (permissions) {
529  case SVC_PEDESTRIAN:
530  return "sidewalk";
531  //case (SVC_BICYCLE | SVC_PEDESTRIAN):
532  // WRITE_WARNING("Ambiguous lane type (biking+driving) for road '" + roadID + "'");
533  // return "sidewalk";
534  case SVC_BICYCLE:
535  return "biking";
536  case 0:
537  // ambiguous
538  return "none";
539  case SVC_RAIL:
540  case SVC_RAIL_URBAN:
541  case SVC_RAIL_ELECTRIC:
542  case SVC_RAIL_FAST:
543  return "rail";
544  case SVC_TRAM:
545  return "tram";
546  default: {
547  // complex permissions
548  if (permissions == SVCAll) {
549  return "driving";
550  } else if (isRailway(permissions)) {
551  return "rail";
552  } else if ((permissions & SVC_PASSENGER) != 0) {
553  return "driving";
554  } else {
555  return "restricted";
556  }
557  }
558  }
559 }
560 
561 
563 NWWriter_OpenDrive::getLeftLaneBorder(const NBEdge* edge, int laneIndex, double widthOffset) {
564  const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
565  if (laneIndex == -1) {
566  // leftmost lane
567  laneIndex = lefthand ? 0 : (int)edge->getNumLanes() - 1;
568  }
570  // PositionVector result = edge->getLaneShape(laneIndex);
571  // (and the moveo2side)
572  // However, the lanes in SUMO have a small lateral gap (SUMO_const_laneOffset) to account for markings
573  // In OpenDRIVE this gap does not exists so we have to do all lateral
574  // computations based on the reference line
575  // This assumes that the 'stop line' for all lanes is colinear!
576  const int leftmost = lefthand ? 0 : (int)edge->getNumLanes() - 1;
577  widthOffset -= (edge->getLaneWidth(leftmost) / 2);
578  // collect lane widths from left border of edge to left border of lane to connect to
579  if (lefthand) {
580  for (int i = leftmost; i < laneIndex; i++) {
581  widthOffset += edge->getLaneWidth(i);
582  }
583  } else {
584  for (int i = leftmost; i > laneIndex; i--) {
585  widthOffset += edge->getLaneWidth(i);
586  }
587  }
588  PositionVector result = edge->getLaneShape(leftmost);
589  try {
590  result.move2side(widthOffset);
591  } catch (InvalidArgument&) { }
592  return result;
593 }
594 
596 NWWriter_OpenDrive::getRightLaneBorder(const NBEdge* edge, int laneIndex) {
597  return getLeftLaneBorder(edge, laneIndex, edge->getLaneWidth(laneIndex));
598 }
599 
600 
601 double
603  OutputDevice& device,
604  OutputDevice& elevationDevice,
605  PositionVector init,
606  double length,
607  double offset) {
608  assert(init.size() == 3 || init.size() == 4);
609 
610  // avoid division by 0
611  length = MAX2(POSITION_EPS, length);
612 
613  const Position p = init.front();
614  const double hdg = init.angleAt2D(0);
615 
616  // backup elevation values
617  const PositionVector initZ = init;
618  // translate to u,v coordinates
619  init.add(-p.x(), -p.y(), -p.z());
620  init.rotate2D(-hdg);
621 
622  // parametric coefficients
623  double aU, bU, cU, dU;
624  double aV, bV, cV, dV;
625  double aZ, bZ, cZ, dZ;
626 
627  // unfactor the Bernstein polynomials of degree 2 (or 3) and collect the coefficients
628  if (init.size() == 3) {
629  //f(x, a, b ,c) = a + (2*b - 2*a)*x + (a - 2*b + c)*x*x
630  aU = init[0].x();
631  bU = 2 * init[1].x() - 2 * init[0].x();
632  cU = init[0].x() - 2 * init[1].x() + init[2].x();
633  dU = 0;
634 
635  aV = init[0].y();
636  bV = 2 * init[1].y() - 2 * init[0].y();
637  cV = init[0].y() - 2 * init[1].y() + init[2].y();
638  dV = 0;
639 
640  // elevation is not parameteric on [0:1] but on [0:length]
641  aZ = initZ[0].z();
642  bZ = (2 * initZ[1].z() - 2 * initZ[0].z()) / length;
643  cZ = (initZ[0].z() - 2 * initZ[1].z() + initZ[2].z()) / (length * length);
644  dZ = 0;
645 
646  } else {
647  // f(x, a, b, c, d) = a + (x*((3*b) - (3*a))) + ((x*x)*((3*a) + (3*c) - (6*b))) + ((x*x*x)*((3*b) - (3*c) - a + d))
648  aU = init[0].x();
649  bU = 3 * init[1].x() - 3 * init[0].x();
650  cU = 3 * init[0].x() - 6 * init[1].x() + 3 * init[2].x();
651  dU = -init[0].x() + 3 * init[1].x() - 3 * init[2].x() + init[3].x();
652 
653  aV = init[0].y();
654  bV = 3 * init[1].y() - 3 * init[0].y();
655  cV = 3 * init[0].y() - 6 * init[1].y() + 3 * init[2].y();
656  dV = -init[0].y() + 3 * init[1].y() - 3 * init[2].y() + init[3].y();
657 
658  // elevation is not parameteric on [0:1] but on [0:length]
659  aZ = initZ[0].z();
660  bZ = (3 * initZ[1].z() - 3 * initZ[0].z()) / length;
661  cZ = (3 * initZ[0].z() - 6 * initZ[1].z() + 3 * initZ[2].z()) / (length * length);
662  dZ = (-initZ[0].z() + 3 * initZ[1].z() - 3 * initZ[2].z() + initZ[3].z()) / (length * length * length);
663  }
664 
665  device.openTag("geometry");
666  device.writeAttr("s", offset);
667  device.writeAttr("x", p.x());
668  device.writeAttr("y", p.y());
669  device.writeAttr("hdg", hdg);
670  device.writeAttr("length", length);
671 
672  device.openTag("paramPoly3");
673  device.writeAttr("aU", aU);
674  device.writeAttr("bU", bU);
675  device.writeAttr("cU", cU);
676  device.writeAttr("dU", dU);
677  device.writeAttr("aV", aV);
678  device.writeAttr("bV", bV);
679  device.writeAttr("cV", cV);
680  device.writeAttr("dV", dV);
681  device.closeTag();
682  device.closeTag();
683 
684  // write elevation
685  elevationDevice.openTag("elevation");
686  elevationDevice.writeAttr("s", offset);
687  elevationDevice.writeAttr("a", aZ);
688  elevationDevice.writeAttr("b", bZ);
689  elevationDevice.writeAttr("c", cZ);
690  elevationDevice.writeAttr("d", dZ);
691  elevationDevice.closeTag();
692 
693  return offset + length;
694 }
695 
696 
697 bool
698 NWWriter_OpenDrive::writeGeomSmooth(const PositionVector& shape, double speed, OutputDevice& device, OutputDevice& elevationDevice, double straightThresh, double& length) {
699 #ifdef DEBUG_SMOOTH_GEOM
700  if (DEBUGCOND) {
701  std::cout << "writeGeomSmooth\n n=" << shape.size() << " shape=" << toString(shape) << "\n";
702  }
703 #endif
704  bool ok = true;
705  const double longThresh = speed; // 16.0; // make user-configurable (should match the sampling rate of the source data)
706  const double curveCutout = longThresh / 2; // 8.0; // make user-configurable (related to the maximum turning rate)
707  // the length of the segment that is added for cutting a corner can be bounded by 2*curveCutout (prevent the segment to be classified as 'long')
708  assert(longThresh >= 2 * curveCutout);
709  assert(shape.size() > 2);
710  // add intermediate points wherever there is a strong angular change between long segments
711  // assume the geometry is simplified so as not to contain consecutive colinear points
712  PositionVector shape2 = shape;
713  double maxAngleDiff = 0;
714  double offset = 0;
715  for (int j = 1; j < (int)shape.size() - 1; ++j) {
716  //const double hdg = shape.angleAt2D(j);
717  const Position& p0 = shape[j - 1];
718  const Position& p1 = shape[j];
719  const Position& p2 = shape[j + 1];
720  const double dAngle = fabs(GeomHelper::angleDiff(p0.angleTo2D(p1), p1.angleTo2D(p2)));
721  const double length1 = p0.distanceTo2D(p1);
722  const double length2 = p1.distanceTo2D(p2);
723  maxAngleDiff = MAX2(maxAngleDiff, dAngle);
724 #ifdef DEBUG_SMOOTH_GEOM
725  if (DEBUGCOND) {
726  std::cout << " j=" << j << " dAngle=" << RAD2DEG(dAngle) << " length1=" << length1 << " length2=" << length2 << "\n";
727  }
728 #endif
729  if (dAngle > straightThresh
730  && (length1 > longThresh || j == 1)
731  && (length2 > longThresh || j == (int)shape.size() - 2)) {
732  shape2.insertAtClosest(shape.positionAtOffset2D(offset + length1 - MIN2(length1 - POSITION_EPS, curveCutout)));
733  shape2.insertAtClosest(shape.positionAtOffset2D(offset + length1 + MIN2(length2 - POSITION_EPS, curveCutout)));
734  shape2.removeClosest(p1);
735  }
736  offset += length1;
737  }
738  const int numPoints = (int)shape2.size();
739 #ifdef DEBUG_SMOOTH_GEOM
740  if (DEBUGCOND) {
741  std::cout << " n=" << numPoints << " shape2=" << toString(shape2) << "\n";
742  }
743 #endif
744 
745  if (maxAngleDiff < straightThresh) {
746  length = writeGeomLines(shape2, device, elevationDevice, 0);
747 #ifdef DEBUG_SMOOTH_GEOM
748  if (DEBUGCOND) {
749  std::cout << " special case: all lines. maxAngleDiff=" << maxAngleDiff << "\n";
750  }
751 #endif
752  return ok;
753  }
754 
755  // write the long segments as lines, short segments as curves
756  offset = 0;
757  for (int j = 0; j < numPoints - 1; ++j) {
758  const Position& p0 = shape2[j];
759  const Position& p1 = shape2[j + 1];
760  PositionVector line;
761  line.push_back(p0);
762  line.push_back(p1);
763  const double lineLength = line.length2D();
764  if (lineLength >= longThresh) {
765  offset = writeGeomLines(line, device, elevationDevice, offset);
766 #ifdef DEBUG_SMOOTH_GEOM
767  if (DEBUGCOND) {
768  std::cout << " writeLine=" << toString(line) << "\n";
769  }
770 #endif
771  } else {
772  // find control points
773  PositionVector begShape;
774  PositionVector endShape;
775  if (j == 0 || j == numPoints - 2) {
776  // keep the angle of the first/last segment but end at the front of the shape
777  begShape = line;
778  begShape.add(p0 - begShape.back());
779  } else if (j == 1 || p0.distanceTo2D(shape2[j - 1]) > longThresh) {
780  // use the previous segment if it is long or the first one
781  begShape.push_back(shape2[j - 1]);
782  begShape.push_back(p0);
783  } else {
784  // end at p0 with mean angle of the previous and current segment
785  begShape.push_back(shape2[j - 1]);
786  begShape.push_back(p1);
787  begShape.add(p0 - begShape.back());
788  }
789 
790  if (j == 0 || j == numPoints - 2) {
791  // keep the angle of the first/last segment but start at the end of the shape
792  endShape = line;
793  endShape.add(p1 - endShape.front());
794  } else if (j == numPoints - 3 || p1.distanceTo2D(shape2[j + 2]) > longThresh) {
795  // use the next segment if it is long or the final one
796  endShape.push_back(p1);
797  endShape.push_back(shape2[j + 2]);
798  } else {
799  // start at p1 with mean angle of the current and next segment
800  endShape.push_back(p0);
801  endShape.push_back(shape2[j + 2]);
802  endShape.add(p1 - endShape.front());
803  }
804  const double extrapolateLength = MIN2((double)25, lineLength / 4);
805  PositionVector init = NBNode::bezierControlPoints(begShape, endShape, false, extrapolateLength, extrapolateLength, ok, nullptr, straightThresh);
806  if (init.size() == 0) {
807  // could not compute control points, write line
808  offset = writeGeomLines(line, device, elevationDevice, offset);
809 #ifdef DEBUG_SMOOTH_GEOM
810  if (DEBUGCOND) {
811  std::cout << " writeLine lineLength=" << lineLength << " begShape" << j << "=" << toString(begShape) << " endShape" << j << "=" << toString(endShape) << " init" << j << "=" << toString(init) << "\n";
812  }
813 #endif
814  } else {
815  // write bezier
816  const double curveLength = init.bezier(12).length2D();
817  offset = writeGeomPP3(device, elevationDevice, init, curveLength, offset);
818 #ifdef DEBUG_SMOOTH_GEOM
819  if (DEBUGCOND) {
820  std::cout << " writeCurve lineLength=" << lineLength << " curveLength=" << curveLength << " begShape" << j << "=" << toString(begShape) << " endShape" << j << "=" << toString(endShape) << " init" << j << "=" << toString(init) << "\n";
821  }
822 #endif
823  }
824  }
825  }
826  length = offset;
827  return ok;
828 }
829 
830 
831 void
833  // check if the shape is flat
834  bool flat = true;
835  double z = shape.size() == 0 ? 0 : shape[0].z();
836  for (int i = 1; i < (int)shape.size(); ++i) {
837  if (fabs(shape[i].z() - z) > NUMERICAL_EPS) {
838  flat = false;
839  break;
840  }
841  }
842  device << " <elevationProfile>\n";
843  if (flat) {
844  device << " <elevation s=\"0\" a=\"" << z << "\" b=\"0\" c=\"0\" d=\"0\"/>\n";
845  } else {
846  device << elevationDevice.getString();
847  }
848  device << " </elevationProfile>\n";
849 
850 }
851 
852 
853 void
855  if (e->getNumLanes() > 1) {
856  // compute 'stop line' of rightmost lane
857  const PositionVector shape0 = e->getLaneShape(0);
858  assert(shape0.size() >= 2);
859  const Position& from = shape0[-2];
860  const Position& to = shape0[-1];
861  PositionVector stopLine;
862  stopLine.push_back(to);
863  stopLine.push_back(to - PositionVector::sideOffset(from, to, -1000.0));
864  // endpoints of all other lanes should be on the stop line
865  for (int lane = 1; lane < e->getNumLanes(); ++lane) {
866  const double dist = stopLine.distance2D(e->getLaneShape(lane)[-1]);
867  if (dist > NUMERICAL_EPS) {
868  WRITE_WARNING("Uneven stop line at lane '" + e->getLaneID(lane) + "' (dist=" + toString(dist) + ") cannot be represented in OpenDRIVE.");
869  }
870  }
871  }
872 }
873 
874 void
876  if (e->knowsParameter("roadObjects")) {
877  device.openTag("objects");
878  device.setPrecision(8); // geometry hdg requires higher precision
880  for (std::string id : StringTokenizer(e->getParameter("roadObjects", "")).getVector()) {
881  SUMOPolygon* p = shc.getPolygons().get(id);
882  if (p == nullptr) {
883  WRITE_WARNING("Road object polygon '" + id + "' not found for edge '" + e->getID() + "'");
884  } else if (p->getShape().size() != 4) {
885  WRITE_WARNING("Cannot convert road object polygon '" + id + "' with " + toString(p->getShape().size()) + " points for edge '" + e->getID() + "'");
886  } else {
887  const PositionVector& shape = p->getShape();
888  device.openTag("object");
889  Position center = shape.getPolygonCenter();
890  PositionVector sideline = shape.getSubpartByIndex(0, 2);
891  PositionVector ortholine = shape.getSubpartByIndex(1, 2);
892  const double absAngle = sideline.angleAt2D(0);
893  const double length = sideline.length2D();
894  const double width = ortholine.length2D();
895  const double edgeOffset = road.nearest_offset_to_point2D(center);
896  if (edgeOffset == GeomHelper::INVALID_OFFSET) {
897  WRITE_WARNING("Cannot map road object polygon '" + id + "' with center " + toString(center) + " onto edge '" + e->getID() + "'");
898  continue;
899  }
900  Position edgePos = road.positionAtOffset2D(edgeOffset);
901  const double edgeAngle = road.rotationAtOffset(edgeOffset);
902  const double relAngle = absAngle - edgeAngle;
903  double sideOffset = center.distanceTo2D(edgePos);
904  // determine sign of sideOffset
905  PositionVector tmp = road.getSubpart2D(MAX2(0.0, edgeOffset - 1), MIN2(road.length2D(), edgeOffset + 1));
906  tmp.move2side(sideOffset);
907  if (tmp.distance2D(center) < sideOffset) {
908  sideOffset *= -1;
909  }
910  //std::cout << " id=" << id
911  // << " shape=" << shape
912  // << " center=" << center
913  // << " edgeOffset=" << edgeOffset
914  // << "\n";
915  device.writeAttr("id", id);
916  device.writeAttr("type", p->getShapeType());
917  device.writeAttr("name", p->getParameter("name", ""));
918  device.writeAttr("s", edgeOffset);
919  device.writeAttr("t", sideOffset);
920  device.writeAttr("width", width);
921  device.writeAttr("length", length);
922  device.writeAttr("hdg", relAngle);
923  device.closeTag();
924  }
925  }
926  device.setPrecision(gPrecision);
927  device.closeTag();
928  } else {
929  device << " <objects/>\n";
930  }
931 }
932 
933 /****************************************************************************/
934 
SVC_RAIL_FAST
vehicle that is allowed to drive on high-speed rail tracks
Definition: SUMOVehicleClass.h:193
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
NWWriter_OpenDrive::addPedestrianConnection
static void addPedestrianConnection(const NBEdge *inEdge, const NBEdge *outEdge, std::vector< NBEdge::Connection > &parallel)
Definition: NWWriter_OpenDrive.cpp:326
SVC_PEDESTRIAN
pedestrian
Definition: SUMOVehicleClass.h:157
NBEdge::Connection::toEdge
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:206
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:74
PositionVector::getPolygonCenter
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
Definition: PositionVector.cpp:392
PositionVector::getSubpartByIndex
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
Definition: PositionVector.cpp:781
NBEdge::Connection::vmax
double vmax
maximum velocity
Definition: NBEdge.h:242
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
GeoConvHelper::getConvBoundary
const Boundary & getConvBoundary() const
Returns the converted boundary.
Definition: GeoConvHelper.cpp:490
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
OutputDevice_String
An output device that encapsulates an ofstream.
Definition: OutputDevice_String.h:40
GeomHelper::angleDiff
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:181
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
Boundary::ymin
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
NBNodeCont::end
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:121
NUMERICAL_EPS
#define NUMERICAL_EPS
Definition: config.h:145
PositionVector::getSubpart2D
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
Definition: PositionVector.cpp:738
Position::z
double z() const
Returns the z-position.
Definition: Position.h:67
OptionsCont.h
PositionVector::rotate2D
void rotate2D(double angle)
Definition: PositionVector.cpp:1460
NBNode::bezierControlPoints
static PositionVector bezierControlPoints(const PositionVector &begShape, const PositionVector &endShape, bool isTurnaround, double extrapolateBeg, double extrapolateEnd, bool &ok, NBNode *recordError=0, double straightThresh=DEG2RAD(5), int shapeFlag=0)
get bezier control points
Definition: NBNode.cpp:531
MsgHandler.h
LINKDIR_PARTRIGHT
The link is a partial right direction.
Definition: SUMOXMLDefinitions.h:1185
NWWriter_OpenDrive::writeEmptyCenterLane
static void writeEmptyCenterLane(OutputDevice &device, const std::string &mark, double markWidth)
Definition: NWWriter_OpenDrive.cpp:506
NBEdge::isTurningDirectionAt
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:2783
NWWriter_OpenDrive::writeNetwork
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a openDRIVE-file.
Definition: NWWriter_OpenDrive.cpp:56
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:202
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:222
NBEdgeCont.h
PositionVector::sideOffset
static Position sideOffset(const Position &beg, const Position &end, const double amount)
get a side position of position vector using a offset
Definition: PositionVector.cpp:1079
NWWriter_OpenDrive::getRightLaneBorder
static PositionVector getRightLaneBorder(const NBEdge *edge, int laneIndex=-1)
Definition: NWWriter_OpenDrive.cpp:596
GeoConvHelper.h
Boundary::xmax
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
ShapeContainer
Storage for geometrical objects.
Definition: ShapeContainer.h:50
NBNodeCont::begin
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:116
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:223
SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:180
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
NWWriter_OpenDrive::writeGeomLines
static double writeGeomLines(const PositionVector &shape, OutputDevice &device, OutputDevice &elevationDevice, double offset=0)
write geometry as sequence of lines (sumo style)
Definition: NWWriter_OpenDrive.cpp:484
RAD2DEG
#define RAD2DEG(x)
Definition: GeomHelper.h:39
NBEdge::getPermissions
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3441
LinkDirection
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
Definition: SUMOXMLDefinitions.h:1171
PositionVector
A list of positions.
Definition: PositionVector.h:46
NWWriter_OpenDrive::getLeftLaneBorder
static PositionVector getLeftLaneBorder(const NBEdge *edge, int laneIndex=-1, double widthOffset=0)
get the left border of the given lane (the leftmost one by default)
Definition: NWWriter_OpenDrive.cpp:563
GeoConvHelper
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:56
SVC_RAIL
vehicle is a not electrified rail
Definition: SUMOVehicleClass.h:189
SVC_RAIL_URBAN
vehicle is a city rail
Definition: SUMOVehicleClass.h:187
GeoConvHelper::usingGeoProjection
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Definition: GeoConvHelper.cpp:282
GeoConvHelper::getProjString
const std::string & getProjString() const
Returns the original projection definition.
Definition: GeoConvHelper.cpp:508
NBNetBuilder::getEdgeCont
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:151
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
NBEdge::Connection::fromLane
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:203
OutputDevice_String::getString
std::string getString() const
Returns the current content as a string.
Definition: OutputDevice_String.cpp:44
PositionVector::angleAt2D
double angleAt2D(int pos) const
get angle in certain position of position vector
Definition: PositionVector.cpp:1204
Parameterised::getParameter
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Definition: Parameterised.cpp:71
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
LINKDIR_RIGHT
The link is a (hard) right direction.
Definition: SUMOXMLDefinitions.h:1181
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:80
NWWriter_OpenDrive::getID
static int getID(const std::string &origID, StringBijection< int > &map, int &lastID)
Definition: NWWriter_OpenDrive.cpp:517
PositionVector::add
void add(double xoff, double yoff, double zoff)
Definition: PositionVector.cpp:609
NBEdge::Connection::toLane
int toLane
The lane the connections yields in.
Definition: NBEdge.h:209
SVC_TRAM
vehicle is a light rail
Definition: SUMOVehicleClass.h:185
PositionVector::nearest_offset_to_point2D
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Definition: PositionVector.cpp:809
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
NBEdge::getToNode
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:486
StringBijection< int >
Boundary::xmin
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
NBEdge::getLaneWidth
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:575
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:106
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:219
GeomHelper::INVALID_OFFSET
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:52
StringBijection::insert
void insert(const std::string str, const T key, bool checkDuplicates=true)
Definition: StringBijection.h:72
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:98
NBEdge::getLaneID
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3125
StringTokenizer
Definition: StringTokenizer.h:62
NBNode::getDirection
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:1936
SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
Definition: SUMOVehicleClass.h:160
StringUtils::escapeXML
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition: StringUtils.cpp:158
DEBUGCOND
#define DEBUGCOND
Definition: NWWriter_OpenDrive.cpp:44
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
SVC_RAIL_ELECTRIC
rail vehicle that requires electrified tracks
Definition: SUMOVehicleClass.h:191
NBEdge::getNumLanes
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:465
NBNode::numNormalConnections
int numNormalConnections() const
return the number of lane-to-lane connections at this junction (excluding crossings)
Definition: NBNode.cpp:3160
OutputDevice.h
NBNetBuilder.h
NWWriter_OpenDrive::writeNormalEdge
static void writeNormalEdge(OutputDevice &device, const NBEdge *e, int edgeID, int fromNodeID, int toNodeID, const bool origNames, const double straightThresh, const ShapeContainer &shc)
write normal edge to device
Definition: NWWriter_OpenDrive.cpp:222
isRailway
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
Definition: SUMOVehicleClass.cpp:364
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
GeoConvHelper::getOffsetBase
const Position getOffsetBase() const
Returns the network base.
Definition: GeoConvHelper.cpp:502
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
Shape::getShapeType
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
LINKDIR_LEFT
The link is a (hard) left direction.
Definition: SUMOXMLDefinitions.h:1179
NWWriter_OpenDrive::getLaneType
static std::string getLaneType(SVCPermissions permissions)
Definition: NWWriter_OpenDrive.cpp:527
PositionVector::length2D
double length2D() const
Returns the length.
Definition: PositionVector.cpp:489
SUMOPolygon::getShape
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.h:82
NBEdgeCont::end
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:193
DEG2RAD
#define DEG2RAD(x)
Definition: GeomHelper.h:38
NBEdge::getLanes
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:644
NBEdge::getStreetName
const std::string & getStreetName() const
Returns the street name of this edge.
Definition: NBEdge.h:588
PositionVector::distance2D
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
Definition: PositionVector.cpp:1242
Position::angleTo2D
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:254
Position::distanceTo2D
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
NBEdge::getIncomingEdges
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition: NBEdge.cpp:1238
INVALID_ID
#define INVALID_ID
Definition: NWWriter_OpenDrive.cpp:41
NWWriter_OpenDrive::checkLaneGeometries
static void checkLaneGeometries(const NBEdge *e)
check if the lane geometries are compatible with OpenDRIVE assumptions (colinear stop line)
Definition: NWWriter_OpenDrive.cpp:854
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:209
NWWriter_OpenDrive::writeElevationProfile
static void writeElevationProfile(const PositionVector &shape, OutputDevice &device, const OutputDevice_String &elevationDevice)
Definition: NWWriter_OpenDrive.cpp:832
NBEdge::getLaneShape
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:871
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
SUMOPolygon
Definition: SUMOPolygon.h:47
NBNodeCont.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
StringUtils.h
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:55
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
PositionVector::positionAtOffset2D
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:268
PositionVector::rotationAtOffset
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:286
NBEdge::getSpeed
double getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:559
NBNode::geometryLike
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:3046
InvalidArgument
Definition: UtilExceptions.h:57
SVCAll
const SVCPermissions SVCAll
all VClasses are allowed
Definition: SUMOVehicleClass.cpp:147
OutputDevice_String.h
NBNode::getIncomingEdges
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition: NBNode.h:259
NamedObjectCont::get
T get(const std::string &id) const
Retrieves an item.
Definition: NamedObjectCont.h:99
NBNodeCont::size
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:264
OutputDevice::lf
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:234
config.h
StringBijection::hasString
bool hasString(const std::string &str) const
Definition: StringBijection.h:117
StringTokenizer.h
PositionVector::bezier
PositionVector bezier(int numPoints)
return a bezier interpolation
Definition: PositionVector.cpp:1639
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
StdDefs.h
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
ShapeContainer::getPolygons
const Polygons & getPolygons() const
Returns all polygons.
Definition: ShapeContainer.h:150
NBNetBuilder::getShapeCont
ShapeContainer & getShapeCont()
Definition: NBNetBuilder.h:191
NWWriter_OpenDrive::writeGeomSmooth
static bool writeGeomSmooth(const PositionVector &shape, double speed, OutputDevice &device, OutputDevice &elevationDevice, double straightThresh, double &length)
Definition: NWWriter_OpenDrive.cpp:698
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:156
NBEdge::Connection
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:184
NBNode.h
NWWriter_OpenDrive::writeGeomPP3
static double writeGeomPP3(OutputDevice &device, OutputDevice &elevationDevice, PositionVector init, double length, double offset=0)
write geometry as a single bezier curve (paramPoly3)
Definition: NWWriter_OpenDrive.cpp:602
LINKDIR_PARTLEFT
The link is a partial left direction.
Definition: SUMOXMLDefinitions.h:1183
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
NBEdgeCont::begin
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:185
POSITION_EPS
#define POSITION_EPS
Definition: config.h:169
NBEdge::getConnections
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:924
NBEdge::getFromNode
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:479
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1086
Parameterised::knowsParameter
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
Definition: Parameterised.cpp:65
NWWriter_OpenDrive::writeRoadObjects
static void writeRoadObjects(OutputDevice &device, const NBEdge *e, const ShapeContainer &shc)
write road objects referenced as edge parameters
Definition: NWWriter_OpenDrive.cpp:875
Boundary::ymax
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
NWWriter_OpenDrive.h
NWWriter_OpenDrive::writeInternalEdge
static int writeInternalEdge(OutputDevice &device, OutputDevice &junctionDevice, const NBEdge *inEdge, int nodeID, int edgeID, int inEdgeID, int outEdgeID, int connectionID, const std::vector< NBEdge::Connection > &parallel, const bool isOuterEdge, const double straightThresh, const std::string &centerMark)
write internal edge to device, return next connectionID
Definition: NWWriter_OpenDrive.cpp:342
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1364