57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
157 std::map<std::string, OpenDriveEdge*> edges;
160 std::vector<std::string> files = oc.
getStringVector(
"opendrive-files");
161 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
163 WRITE_ERROR(
"Could not open opendrive file '" + *file +
"'.");
172 std::map<std::string, OpenDriveEdge*> innerEdges, outerEdges;
173 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
174 if ((*i).second->isInner) {
175 innerEdges[(*i).first] = (*i).second;
177 outerEdges[(*i).first] = (*i).second;
190 std::map<std::string, Boundary> posMap;
191 std::map<std::string, std::string> edge2junction;
193 for (std::map<std::string, OpenDriveEdge*>::iterator i = innerEdges.begin(); i != innerEdges.end(); ++i) {
197 if (posMap.find(e->
junction) == posMap.end()) {
203 for (std::map<std::string, Boundary>::iterator i = posMap.begin(); i != posMap.end(); ++i) {
205 throw ProcessError(
"Could not add node '" + (*i).first +
"'.");
209 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
211 for (std::vector<OpenDriveLink>::iterator j = e->
links.begin(); j != e->
links.end(); ++j) {
218 if (edge2junction.find(l.
elementID) != edge2junction.end()) {
230 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
232 for (std::vector<OpenDriveLink>::iterator j = e->
links.begin(); j != e->
links.end(); ++j) {
239 std::string id1 = e->
id;
244 std::string nid = id1 +
"." + id2;
249 throw ProcessError(
"Could not build node '" + nid +
"'.");
267 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
269 if (e->
to != 0 && e->
from != 0) {
272 for (std::map<std::string, OpenDriveEdge*>::iterator j = innerEdges.begin(); j != innerEdges.end(); ++j) {
274 for (std::vector<OpenDriveLink>::iterator k = ie->
links.begin(); k != ie->
links.end(); ++k) {
280 std::string nid = edge2junction[ie->
id];
293 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
296 const std::string nid = e->
id +
".begin";
300 const std::string nid = e->
id +
".end";
312 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
317 if (noLanesRight == 0 && noLanesLeft == 0) {
345 WRITE_WARNING(
"Edge '" + e->
id +
"' has to be split as it connects same junctions.")
363 (*j).buildLaneMapping();
364 std::string
id = e->
id;
365 if (sFrom != e->
from || sTo != e->
to) {
372 if (rightLanesSection > 0) {
373 currRight =
new NBEdge(
"-" +
id, sFrom, sTo,
"", defaultSpeed, rightLanesSection, priorityR,
379 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
380 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
381 if (lp != (*j).laneMap.end()) {
382 int sumoLaneIndex = lp->second;
392 sumoLane.
width = width;
398 if (prevRight != 0) {
400 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
404 prevRight = currRight;
410 if (leftLanesSection > 0) {
411 currLeft =
new NBEdge(
id, sTo, sFrom,
"", defaultSpeed, leftLanesSection, priorityL,
417 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
418 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
419 if (lp != (*j).laneMap.end()) {
420 int sumoLaneIndex = lp->second;
430 sumoLane.
width = width;
437 std::map<int, int> connections = (*j).getInnerConnections(
OPENDRIVE_TAG_LEFT, *(j - 1));
438 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
457 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
461 std::vector<Connection> connections2;
462 for (std::map<std::string, OpenDriveEdge*>::iterator j = edges.begin(); j != edges.end(); ++j) {
463 const std::set<Connection>& conns = (*j).second->connections;
465 for (std::set<Connection>::const_iterator i = conns.begin(); i != conns.end(); ++i) {
466 if (innerEdges.find((*i).fromEdge) != innerEdges.end()) {
470 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
473 connections2.push_back(*i);
478 for (std::vector<Connection>::const_iterator i = connections2.begin(); i != connections2.end(); ++i) {
479 std::string fromEdge = (*i).fromEdge;
480 if (edges.find(fromEdge) == edges.end()) {
481 WRITE_WARNING(
"While setting connections: from-edge '" + fromEdge +
"' is not known.");
485 int fromLane = (*i).fromLane;
486 bool fromLast = ((*i).fromCP ==
OPENDRIVE_CP_END) ^ ((*i).fromLane > 0 && !(*i).all);
489 std::string toEdge = (*i).toEdge;
490 if (edges.find(toEdge) == edges.end()) {
491 WRITE_WARNING(
"While setting connections: to-edge '" + toEdge +
"' is not known.");
496 int toLane = (*i).toLane;
501 fromLane = toLast ? odTo->
laneSections.back().laneMap.begin()->first : odTo->
laneSections[0].laneMap.begin()->first;
517 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
520 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
522 if (from == 0 || to == 0) {
528 if ((*i).origID !=
"") {
531 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); ++k) {
532 if ((*k).fromLane == fromLane && (*k).toEdge == to && (*k).toLane == toLane) {
533 (*k).origID = (*i).origID +
" " +
toString((*i).origLane);
540 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
541 oc.
unSet(
"geometry.min-dist");
543 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
558 const std::set<Connection>& conts = dest->
connections;
559 for (std::set<Connection>::const_iterator i = conts.begin(); i != conts.end(); ++i) {
560 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
561 std::vector<Connection> t;
563 for (std::vector<Connection>::const_iterator j = t.begin(); j != t.end(); ++j) {
574 if ((*i).fromLane == c.
toLane) {
591 for (std::vector<OpenDriveLink>::iterator i = e.
links.begin(); i != e.
links.end(); ++i) {
599 std::string edgeID = e.
id;
604 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
621 if (edges.find(c.
fromEdge) == edges.end()) {
622 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
631 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
648 if (edges.find(c.
fromEdge) == edges.end()) {
649 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
672 if (!nc.
insert(
id, pos)) {
686 throw ProcessError(
"Could not find node '" + nodeID +
"'.");
689 if (e.
to != 0 && e.
to != n) {
710 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
712 for (std::vector<OpenDriveGeometry>::iterator j = e.
geometries.begin(); j != e.
geometries.end(); ++j) {
714 std::vector<Position> geom;
729 if (geom.size() == 1) {
736 for (std::vector<Position>::iterator k = geom.begin(); k != geom.end(); ++k) {
740 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
743 for (
unsigned int j = 0; j < e.
geom.size(); ++j) {
752 std::vector<Position>
755 std::vector<Position> ret;
762 std::vector<Position>
765 std::vector<Position> ret;
770 std::vector<Point2D<double> > into;
772 for (std::vector<
Point2D<double> >::iterator i = into.begin(); i != into.end(); ++i) {
773 ret.push_back(
Position((*i).getX(), (*i).getY()));
779 std::vector<Position>
782 std::vector<Position> ret;
802 if (geo_posE - g.
s > g.
length) {
805 if (geo_posE - g.
s > g.
length) {
808 calcPointOnCurve(&endX, &endY, centerX, centerY, radius, geo_posE - geo_posS);
810 dist += (geo_posE - geo_posS);
811 if (curvature > 0.0) {
812 hdgE = g.
hdg + dist / fabs(radius);
814 hdgE = g.
hdg - dist / fabs(radius);
817 ret.push_back(
Position(startX, startY));
824 if (geo_posE - (g.
s + g.
length) < 0.001 && geo_posE - (g.
s + g.
length) > -0.001) {
832 std::vector<Position>
835 std::vector<Position> ret;
844 ret.push_back(
Position(g.
x + xnew, g.
y + ynew));
854 double x2 = normx * cos(hdg) - normy * sin(hdg);
855 double y2 = normx * sin(hdg) + normy * cos(hdg);
858 return Position(start.
x() + normx, start.
y() + normy);
875 normX = normX * cos(ad_hdg) + normY * sin(ad_hdg);
876 normY = tmpX * sin(ad_hdg) + normY * cos(ad_hdg);
879 normX = normX * cos(90 *
PI / 180) + turn * normY * sin(90 *
PI / 180);
880 normY = -1 * turn * tmpX * sin(90 *
PI / 180) + normY * cos(90 *
PI / 180);
882 normX = fabs(ad_radius) * normX;
883 normY = fabs(ad_radius) * normY;
893 double rotAngle = ad_length / fabs(ad_r);
894 double vx = *ad_x - ad_centerX;
895 double vy = *ad_y - ad_centerY;
905 vx = vx * cos(rotAngle) + turn * vy * sin(rotAngle);
906 vy = -1 * turn * tmpx * sin(rotAngle) + vy * cos(rotAngle);
907 *ad_x = vx + ad_centerX;
908 *ad_y = vy + ad_centerY;
924 unsigned int laneNum = 0;
925 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
926 for (std::vector<OpenDriveLane>::const_iterator i = dirLanes.begin(); i != dirLanes.end(); ++i) {
937 unsigned int sumoLane = 0;
938 const std::vector<OpenDriveLane>& dirLanesR = lanesByDir.find(
OPENDRIVE_TAG_RIGHT)->second;
939 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanesR.rbegin(); i != dirLanesR.rend(); ++i) {
941 laneMap[(*i).id] = sumoLane++;
945 const std::vector<OpenDriveLane>& dirLanesL = lanesByDir.find(
OPENDRIVE_TAG_LEFT)->second;
946 for (std::vector<OpenDriveLane>::const_iterator i = dirLanesL.begin(); i != dirLanesL.end(); ++i) {
948 laneMap[(*i).id] = sumoLane++;
956 std::map<int, int> ret;
957 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
958 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
959 std::map<int, int>::const_iterator toP = laneMap.find((*i).id);
960 if (toP == laneMap.end()) {
964 int to = (*toP).second;
967 from = (*i).predecessor;
970 std::map<int, int>::const_iterator fromP = prev.
laneMap.find(from);
971 if (fromP != prev.
laneMap.end()) {
972 from = (*fromP).second;
978 if (ret.find(from) != ret.end()) {
999 unsigned int maxLaneNum = 0;
1000 for (std::vector<OpenDriveLaneSection>::const_iterator i = laneSections.begin(); i != laneSections.end(); ++i) {
1001 maxLaneNum =
MAX2(maxLaneNum, (*i).getLaneNumber(dir));
1010 for (std::vector<OpenDriveSignal>::const_iterator i = signals.begin(); i != signals.end(); ++i) {
1012 if ((*i).type ==
"301" || (*i).type ==
"306") {
1015 if ((*i).type ==
"205") {
1052 if (majorVersion != 1 || minorVersion != 2) {
1106 std::vector<SUMOReal> vals;
1111 std::vector<SUMOReal> vals;
1118 std::vector<SUMOReal> vals;
1124 std::vector<SUMOReal> vals;
1189 WRITE_ERROR(
"In laneLink-element: incoming road '" + c.fromEdge +
"' is not known.");
1201 l.width =
MAX2(l.width, width);
1253 const std::string& elementID,
1254 const std::string& contactPoint) {
1257 if (elementType ==
"road") {
1259 }
else if (elementType ==
"junction") {
1263 if (contactPoint ==
"start") {
1265 }
else if (contactPoint ==
"end") {