56 #ifdef CHECK_MEMORY_LEAKS
58 #endif // CHECK_MEMORY_LEAKS
156 std::map<std::string, OpenDriveEdge*> edges;
159 std::vector<std::string> files = oc.
getStringVector(
"opendrive-files");
160 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
162 WRITE_ERROR(
"Could not open opendrive file '" + *file +
"'.");
171 std::map<std::string, OpenDriveEdge*> innerEdges, outerEdges;
172 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
173 if ((*i).second->isInner) {
174 innerEdges[(*i).first] = (*i).second;
176 outerEdges[(*i).first] = (*i).second;
189 std::map<std::string, Boundary> posMap;
190 std::map<std::string, std::string> edge2junction;
192 for (std::map<std::string, OpenDriveEdge*>::iterator i = innerEdges.begin(); i != innerEdges.end(); ++i) {
196 if (posMap.find(e->
junction) == posMap.end()) {
202 for (std::map<std::string, Boundary>::iterator i = posMap.begin(); i != posMap.end(); ++i) {
204 throw ProcessError(
"Could not add node '" + (*i).first +
"'.");
208 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
210 for (std::vector<OpenDriveLink>::iterator j = e->
links.begin(); j != e->
links.end(); ++j) {
217 if (edge2junction.find(l.
elementID) != edge2junction.end()) {
229 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
231 for (std::vector<OpenDriveLink>::iterator j = e->
links.begin(); j != e->
links.end(); ++j) {
238 std::string id1 = e->
id;
243 std::string nid = id1 +
"." + id2;
248 throw ProcessError(
"Could not build node '" + nid +
"'.");
266 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
268 if (e->
to != 0 && e->
from != 0) {
271 for (std::map<std::string, OpenDriveEdge*>::iterator j = innerEdges.begin(); j != innerEdges.end(); ++j) {
273 for (std::vector<OpenDriveLink>::iterator k = ie->
links.begin(); k != ie->
links.end(); ++k) {
279 std::string nid = edge2junction[ie->
id];
292 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
295 const std::string nid = e->
id +
".begin";
299 const std::string nid = e->
id +
".end";
311 for (std::map<std::string, OpenDriveEdge*>::iterator i = outerEdges.begin(); i != outerEdges.end(); ++i) {
315 if (noLanesRight == 0 && noLanesLeft == 0) {
343 WRITE_WARNING(
"Edge '" + e->
id +
"' has to be split as it connects same junctions.")
361 (*j).buildLaneMapping();
362 std::string
id = e->
id;
363 if (sFrom != e->
from || sTo != e->
to) {
370 if (rightLanesSection > 0) {
371 currRight =
new NBEdge(
"-" +
id, sFrom, sTo,
"", defaultSpeed, rightLanesSection, priorityR,
377 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
378 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
379 if (lp != (*j).laneMap.end()) {
380 int sumoLaneIndex = lp->second;
390 sumoLane.
width = width;
396 if (prevRight != 0) {
398 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
402 prevRight = currRight;
408 if (leftLanesSection > 0) {
409 currLeft =
new NBEdge(
id, sTo, sFrom,
"", defaultSpeed, leftLanesSection, priorityL,
415 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
416 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
417 if (lp != (*j).laneMap.end()) {
418 int sumoLaneIndex = lp->second;
428 sumoLane.
width = width;
435 std::map<int, int> connections = (*j).getInnerConnections(
OPENDRIVE_TAG_LEFT, *(j - 1));
436 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
455 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
459 std::vector<Connection> connections2;
460 for (std::map<std::string, OpenDriveEdge*>::iterator j = edges.begin(); j != edges.end(); ++j) {
461 const std::set<Connection>& conns = (*j).second->connections;
463 for (std::set<Connection>::const_iterator i = conns.begin(); i != conns.end(); ++i) {
464 if (innerEdges.find((*i).fromEdge) != innerEdges.end()) {
468 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
471 connections2.push_back(*i);
476 for (std::vector<Connection>::const_iterator i = connections2.begin(); i != connections2.end(); ++i) {
477 std::string fromEdge = (*i).fromEdge;
478 if (edges.find(fromEdge) == edges.end()) {
479 WRITE_WARNING(
"While setting connections: from-edge '" + fromEdge +
"' is not known.");
483 int fromLane = (*i).fromLane;
484 bool fromLast = ((*i).fromCP ==
OPENDRIVE_CP_END) ^ ((*i).fromLane > 0 && !(*i).all);
487 std::string toEdge = (*i).toEdge;
488 if (edges.find(toEdge) == edges.end()) {
489 WRITE_WARNING(
"While setting connections: to-edge '" + toEdge +
"' is not known.");
494 int toLane = (*i).toLane;
499 fromLane = toLast ? odTo->
laneSections.back().laneMap.begin()->first : odTo->
laneSections[0].laneMap.begin()->first;
515 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
518 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
520 if (from == 0 || to == 0) {
526 if ((*i).origID !=
"") {
529 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); ++k) {
530 if ((*k).fromLane == fromLane && (*k).toEdge == to && (*k).toLane == toLane) {
531 (*k).origID = (*i).origID +
" " +
toString((*i).origLane);
538 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
539 oc.
unSet(
"geometry.min-dist");
541 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
556 const std::set<Connection>& conts = dest->
connections;
557 for (std::set<Connection>::const_iterator i = conts.begin(); i != conts.end(); ++i) {
558 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
559 std::vector<Connection> t;
561 for (std::vector<Connection>::const_iterator j = t.begin(); j != t.end(); ++j) {
571 if ((*i).fromLane == c.
toLane) {
588 for (std::vector<OpenDriveLink>::iterator i = e.
links.begin(); i != e.
links.end(); ++i) {
596 std::string edgeID = e.
id;
601 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
618 if (edges.find(c.
fromEdge) == edges.end()) {
619 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
628 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
645 if (edges.find(c.
fromEdge) == edges.end()) {
646 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
669 if (!nc.
insert(
id, pos)) {
683 throw ProcessError(
"Could not find node '" + nodeID +
"'.");
686 if (e.
to != 0 && e.
to != n) {
707 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
709 for (std::vector<OpenDriveGeometry>::iterator j = e.
geometries.begin(); j != e.
geometries.end(); ++j) {
711 std::vector<Position> geom;
723 if (geom.size() == 1) {
730 for (std::vector<Position>::iterator k = geom.begin(); k != geom.end(); ++k) {
734 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
737 for (
unsigned int j = 0; j < e.
geom.size(); ++j) {
746 std::vector<Position>
749 std::vector<Position> ret;
756 std::vector<Position>
759 std::vector<Position> ret;
777 if (geo_posE - g.
s > g.
length) {
780 if (geo_posE - g.
s > g.
length) {
783 calcPointOnCurve(&endX, &endY, centerX, centerY, radius, geo_posE - geo_posS);
785 dist += (geo_posE - geo_posS);
787 ret.push_back(
Position(startX, startY));
793 if (geo_posE - (g.
s + g.
length) < 0.001 && geo_posE - (g.
s + g.
length) > -0.001) {
801 std::vector<Position>
804 std::vector<Position> ret;
813 ret.push_back(
Position(g.
x + xnew, g.
y + ynew));
823 double x2 = normx * cos(hdg) - normy * sin(hdg);
824 double y2 = normx * sin(hdg) + normy * cos(hdg);
827 return Position(start.
x() + normx, start.
y() + normy);
844 normX = normX * cos(ad_hdg) + normY * sin(ad_hdg);
845 normY = tmpX * sin(ad_hdg) + normY * cos(ad_hdg);
848 normX = turn * normY;
849 normY = -turn * tmpX;
851 normX = fabs(ad_radius) * normX;
852 normY = fabs(ad_radius) * normY;
862 double rotAngle = ad_length / fabs(ad_r);
863 double vx = *ad_x - ad_centerX;
864 double vy = *ad_y - ad_centerY;
874 vx = vx * cos(rotAngle) + turn * vy * sin(rotAngle);
875 vy = -1 * turn * tmpx * sin(rotAngle) + vy * cos(rotAngle);
876 *ad_x = vx + ad_centerX;
877 *ad_y = vy + ad_centerY;
893 unsigned int laneNum = 0;
894 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
895 for (std::vector<OpenDriveLane>::const_iterator i = dirLanes.begin(); i != dirLanes.end(); ++i) {
906 unsigned int sumoLane = 0;
907 const std::vector<OpenDriveLane>& dirLanesR = lanesByDir.find(
OPENDRIVE_TAG_RIGHT)->second;
908 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanesR.rbegin(); i != dirLanesR.rend(); ++i) {
910 laneMap[(*i).id] = sumoLane++;
914 const std::vector<OpenDriveLane>& dirLanesL = lanesByDir.find(
OPENDRIVE_TAG_LEFT)->second;
915 for (std::vector<OpenDriveLane>::const_iterator i = dirLanesL.begin(); i != dirLanesL.end(); ++i) {
917 laneMap[(*i).id] = sumoLane++;
925 std::map<int, int> ret;
926 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
927 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
928 std::map<int, int>::const_iterator toP = laneMap.find((*i).id);
929 if (toP == laneMap.end()) {
933 int to = (*toP).second;
936 from = (*i).predecessor;
939 std::map<int, int>::const_iterator fromP = prev.
laneMap.find(from);
940 if (fromP != prev.
laneMap.end()) {
941 from = (*fromP).second;
947 if (ret.find(from) != ret.end()) {
968 unsigned int maxLaneNum = 0;
969 for (std::vector<OpenDriveLaneSection>::const_iterator i = laneSections.begin(); i != laneSections.end(); ++i) {
970 maxLaneNum =
MAX2(maxLaneNum, (*i).getLaneNumber(dir));
979 for (std::vector<OpenDriveSignal>::const_iterator i = signals.begin(); i != signals.end(); ++i) {
981 if ((*i).type ==
"301" || (*i).type ==
"306") {
984 if ((*i).type ==
"205") {
1021 if (majorVersion != 1 || minorVersion != 2) {
1075 std::vector<SUMOReal> vals;
1080 std::vector<SUMOReal> vals;
1087 std::vector<SUMOReal> vals;
1093 std::vector<SUMOReal> vals;
1158 WRITE_ERROR(
"In laneLink-element: incoming road '" + c.fromEdge +
"' is not known.");
1170 l.width =
MAX2(l.width, width);
1222 const std::string& elementID,
1223 const std::string& contactPoint) {
1226 if (elementType ==
"road") {
1228 }
else if (elementType ==
"junction") {
1232 if (contactPoint ==
"start") {
1234 }
else if (contactPoint ==
"end") {