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) {
316 if (noLanesRight == 0 && noLanesLeft == 0) {
344 WRITE_WARNING(
"Edge '" + e->
id +
"' has to be split as it connects same junctions.")
362 (*j).buildLaneMapping();
363 std::string
id = e->
id;
364 if (sFrom != e->
from || sTo != e->
to) {
371 if (rightLanesSection > 0) {
372 currRight =
new NBEdge(
"-" +
id, sFrom, sTo,
"", defaultSpeed, rightLanesSection, priorityR,
378 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
379 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
380 if (lp != (*j).laneMap.end()) {
381 int sumoLaneIndex = lp->second;
391 sumoLane.
width = width;
397 if (prevRight != 0) {
399 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
403 prevRight = currRight;
409 if (leftLanesSection > 0) {
410 currLeft =
new NBEdge(
id, sTo, sFrom,
"", defaultSpeed, leftLanesSection, priorityL,
416 for (std::vector<OpenDriveLane>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
417 std::map<int, int>::const_iterator lp = (*j).laneMap.find((*k).id);
418 if (lp != (*j).laneMap.end()) {
419 int sumoLaneIndex = lp->second;
429 sumoLane.
width = width;
436 std::map<int, int> connections = (*j).getInnerConnections(
OPENDRIVE_TAG_LEFT, *(j - 1));
437 for (std::map<int, int>::const_iterator k = connections.begin(); k != connections.end(); ++k) {
456 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
460 std::vector<Connection> connections2;
461 for (std::map<std::string, OpenDriveEdge*>::iterator j = edges.begin(); j != edges.end(); ++j) {
462 const std::set<Connection>& conns = (*j).second->connections;
464 for (std::set<Connection>::const_iterator i = conns.begin(); i != conns.end(); ++i) {
465 if (innerEdges.find((*i).fromEdge) != innerEdges.end()) {
469 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
472 connections2.push_back(*i);
477 for (std::vector<Connection>::const_iterator i = connections2.begin(); i != connections2.end(); ++i) {
478 std::string fromEdge = (*i).fromEdge;
479 if (edges.find(fromEdge) == edges.end()) {
480 WRITE_WARNING(
"While setting connections: from-edge '" + fromEdge +
"' is not known.");
484 int fromLane = (*i).fromLane;
485 bool fromLast = ((*i).fromCP ==
OPENDRIVE_CP_END) ^ ((*i).fromLane > 0 && !(*i).all);
488 std::string toEdge = (*i).toEdge;
489 if (edges.find(toEdge) == edges.end()) {
490 WRITE_WARNING(
"While setting connections: to-edge '" + toEdge +
"' is not known.");
495 int toLane = (*i).toLane;
500 fromLane = toLast ? odTo->
laneSections.back().laneMap.begin()->first : odTo->
laneSections[0].laneMap.begin()->first;
516 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
519 WRITE_WARNING(
"Could not find fromEdge representation of '' in connection ''.");
521 if (from == 0 || to == 0) {
527 if ((*i).origID !=
"") {
530 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); ++k) {
531 if ((*k).fromLane == fromLane && (*k).toEdge == to && (*k).toLane == toLane) {
532 (*k).origID = (*i).origID +
" " +
toString((*i).origLane);
539 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
540 oc.
unSet(
"geometry.min-dist");
542 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
557 const std::set<Connection>& conts = dest->
connections;
558 for (std::set<Connection>::const_iterator i = conts.begin(); i != conts.end(); ++i) {
559 if (innerEdges.find((*i).toEdge) != innerEdges.end()) {
560 std::vector<Connection> t;
562 for (std::vector<Connection>::const_iterator j = t.begin(); j != t.end(); ++j) {
572 if ((*i).fromLane == c.
toLane) {
589 for (std::vector<OpenDriveLink>::iterator i = e.
links.begin(); i != e.
links.end(); ++i) {
597 std::string edgeID = e.
id;
602 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
619 if (edges.find(c.
fromEdge) == edges.end()) {
620 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
629 for (std::vector<OpenDriveLane>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
646 if (edges.find(c.
fromEdge) == edges.end()) {
647 WRITE_ERROR(
"While setting connections: incoming road '" + c.
fromEdge +
"' is not known.");
670 if (!nc.
insert(
id, pos)) {
684 throw ProcessError(
"Could not find node '" + nodeID +
"'.");
687 if (e.
to != 0 && e.
to != n) {
708 for (std::map<std::string, OpenDriveEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
710 for (std::vector<OpenDriveGeometry>::iterator j = e.
geometries.begin(); j != e.
geometries.end(); ++j) {
712 std::vector<Position> geom;
727 if (geom.size() == 1) {
734 for (std::vector<Position>::iterator k = geom.begin(); k != geom.end(); ++k) {
738 if (oc.
exists(
"geometry.min-dist") && oc.
isSet(
"geometry.min-dist")) {
741 for (
unsigned int j = 0; j < e.
geom.size(); ++j) {
750 std::vector<Position>
753 std::vector<Position> ret;
760 std::vector<Position>
763 std::vector<Position> ret;
768 std::vector<Point2D<double> > into;
770 for (std::vector<
Point2D<double> >::iterator i = into.begin(); i != into.end(); ++i) {
771 ret.push_back(
Position((*i).getX(), (*i).getY()));
777 std::vector<Position>
780 std::vector<Position> ret;
798 if (geo_posE - g.
s > g.
length) {
801 if (geo_posE - g.
s > g.
length) {
804 calcPointOnCurve(&endX, &endY, centerX, centerY, radius, geo_posE - geo_posS);
806 dist += (geo_posE - geo_posS);
808 ret.push_back(
Position(startX, startY));
814 if (geo_posE - (g.
s + g.
length) < 0.001 && geo_posE - (g.
s + g.
length) > -0.001) {
822 std::vector<Position>
825 std::vector<Position> ret;
834 ret.push_back(
Position(g.
x + xnew, g.
y + ynew));
844 double x2 = normx * cos(hdg) - normy * sin(hdg);
845 double y2 = normx * sin(hdg) + normy * cos(hdg);
848 return Position(start.
x() + normx, start.
y() + normy);
865 normX = normX * cos(ad_hdg) + normY * sin(ad_hdg);
866 normY = tmpX * sin(ad_hdg) + normY * cos(ad_hdg);
869 normX = turn * normY;
870 normY = -turn * tmpX;
872 normX = fabs(ad_radius) * normX;
873 normY = fabs(ad_radius) * normY;
883 double rotAngle = ad_length / fabs(ad_r);
884 double vx = *ad_x - ad_centerX;
885 double vy = *ad_y - ad_centerY;
895 vx = vx * cos(rotAngle) + turn * vy * sin(rotAngle);
896 vy = -1 * turn * tmpx * sin(rotAngle) + vy * cos(rotAngle);
897 *ad_x = vx + ad_centerX;
898 *ad_y = vy + ad_centerY;
914 unsigned int laneNum = 0;
915 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
916 for (std::vector<OpenDriveLane>::const_iterator i = dirLanes.begin(); i != dirLanes.end(); ++i) {
927 unsigned int sumoLane = 0;
928 const std::vector<OpenDriveLane>& dirLanesR = lanesByDir.find(
OPENDRIVE_TAG_RIGHT)->second;
929 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanesR.rbegin(); i != dirLanesR.rend(); ++i) {
931 laneMap[(*i).id] = sumoLane++;
935 const std::vector<OpenDriveLane>& dirLanesL = lanesByDir.find(
OPENDRIVE_TAG_LEFT)->second;
936 for (std::vector<OpenDriveLane>::const_iterator i = dirLanesL.begin(); i != dirLanesL.end(); ++i) {
938 laneMap[(*i).id] = sumoLane++;
946 std::map<int, int> ret;
947 const std::vector<OpenDriveLane>& dirLanes = lanesByDir.find(dir)->second;
948 for (std::vector<OpenDriveLane>::const_reverse_iterator i = dirLanes.rbegin(); i != dirLanes.rend(); ++i) {
949 std::map<int, int>::const_iterator toP = laneMap.find((*i).id);
950 if (toP == laneMap.end()) {
954 int to = (*toP).second;
957 from = (*i).predecessor;
960 std::map<int, int>::const_iterator fromP = prev.
laneMap.find(from);
961 if (fromP != prev.
laneMap.end()) {
962 from = (*fromP).second;
968 if (ret.find(from) != ret.end()) {
989 unsigned int maxLaneNum = 0;
990 for (std::vector<OpenDriveLaneSection>::const_iterator i = laneSections.begin(); i != laneSections.end(); ++i) {
991 maxLaneNum =
MAX2(maxLaneNum, (*i).getLaneNumber(dir));
1000 for (std::vector<OpenDriveSignal>::const_iterator i = signals.begin(); i != signals.end(); ++i) {
1002 if ((*i).type ==
"301" || (*i).type ==
"306") {
1005 if ((*i).type ==
"205") {
1042 if (majorVersion != 1 || minorVersion != 2) {
1096 std::vector<SUMOReal> vals;
1101 std::vector<SUMOReal> vals;
1108 std::vector<SUMOReal> vals;
1114 std::vector<SUMOReal> vals;
1179 WRITE_ERROR(
"In laneLink-element: incoming road '" + c.fromEdge +
"' is not known.");
1191 l.width =
MAX2(l.width, width);
1243 const std::string& elementID,
1244 const std::string& contactPoint) {
1247 if (elementType ==
"road") {
1249 }
else if (elementType ==
"junction") {
1253 if (contactPoint ==
"start") {
1255 }
else if (contactPoint ==
"end") {
std::map< std::string, OpenDriveEdge * > & myEdges
ContactPoint contactPoint
static void calculateCurveCenter(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_radius, SUMOReal ad_hdg)
std::vector< int > myElementStack
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 buildLaneMapping()
Build the mapping from OpenDrive to SUMO lanes.
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
static StringBijection< int >::Entry openDriveAttrs[]
The names of openDrive-XML attributes (for passing to GenericSAXHandler)
NBTypeCont & getTypeCont()
Returns the type container.
bool insert(const std::string &id, const Position &position, NBDistrict *district)
Inserts a node into the map.
static bool transformCoordinates(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
Position positionAtOffset(SUMOReal pos) const
Returns the position at the given length.
void addLink(LinkType lt, const std::string &elementType, const std::string &elementID, const std::string &contactPoint)
Representation of an OpenDrive link.
std::string junction
The id of the junction the edge belongs to.
GeometryType
OpenDrive geometry type enumeration.
static std::vector< Position > geomFromPoly(const OpenDriveEdge &e, const OpenDriveGeometry &g)
static void buildConnectionsToOuter(const Connection &c, const std::map< std::string, OpenDriveEdge * > &innerEdges, std::vector< Connection > &into)
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
Representation of a lane section.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Representation of an openDrive "link".
ContactPoint myCurrentContactPoint
bool addLane2LaneConnection(unsigned int fromLane, NBEdge *dest, unsigned int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false)
Adds a connection between the specified this edge's lane and an approached one.
SUMOReal s
The starting offset of this lane section.
std::map< OpenDriveXMLTag, std::vector< OpenDriveLane > > lanesByDir
The lanes, sorted by their direction.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
std::set< Connection > connections
Representation of a signal.
static bool runParser(GenericSAXHandler &handler, const std::string &file)
Runs the given handler on the given file; returns if everything's ok.
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
SUMOReal x() const
Returns the x-position.
unsigned int getLaneNumber(OpenDriveXMLTag dir) const
Returns the number of lanes for the given direction.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
#define UNUSED_PARAMETER(x)
OpenDriveEdge myCurrentEdge
A class that stores a 2D geometrical boundary.
static NBNode * getOrBuildNode(const std::string &id, const Position &pos, NBNodeCont &nc)
Builds a node or returns the already built.
#define WRITE_WARNING(msg)
The connection was computed and validated.
static OptionsCont & getOptions()
Retrieves the options.
static std::string revertID(const std::string &id)
std::string myCurrentConnectingRoad
PositionVector reverse() const
Representation of a lane.
SUMOReal speed
The speed allowed on this lane.
OpenDriveXMLTag myCurrentLaneDirection
static void calcPointOnCurve(SUMOReal *ad_x, SUMOReal *ad_y, SUMOReal ad_centerX, SUMOReal ad_centerY, SUMOReal ad_r, SUMOReal ad_length)
An (internal) definition of a single lane of an edge.
const std::string & getID() const
Returns the id.
std::vector< OpenDriveLink > links
A handler which converts occuring elements and attributes into enums.
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
bool operator<(const NBConnection &c1, const NBConnection &c2)
const std::string & getFileName() const
returns the current file name
void setFileName(const std::string &name)
Sets the current file name.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
int getPriority(OpenDriveXMLTag dir) const
Encapsulated SAX-Attributes.
static Position calculateStraightEndPoint(double hdg, double length, const Position &start)
A point in 2D or 3D with translation and scaling methods.
unsigned int getMaxLaneNumber(OpenDriveXMLTag dir) const
NBEdgeCont & getEdgeCont()
Returns the edge container.
void computeSpiral(std::vector< Point2D< double > > &spiral, double ds=0, int NPts=0)
std::string id
The id of the edge.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file) ...
bool myConnectionWasEmpty
static bool exists(std::string path)
Checks whether the given file exists.
std::string myCurrentJunctionID
std::vector< OpenDriveLaneSection > laneSections
std::map< int, int > laneMap
A mapping from OpenDrive to SUMO-index (the first is signed, the second unsigned) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
OpenDriveXMLTag
Numbers representing openDrive-XML - element names.
static bool myImportWidths
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
The connection was given by the user.
static StringBijection< int >::Entry openDriveTags[]
The names of openDrive-XML elements (for passing to GenericSAXHandler)
static bool myImportAllTypes
static std::vector< Position > geomFromLine(const OpenDriveEdge &e, const OpenDriveGeometry &g)
std::string origID
An original ID, if given (.
std::vector< OpenDriveSignal > signals
LinkType
OpenDrive link type enumeration.
SUMOReal length() const
Returns the length.
static void computeShapes(std::map< std::string, OpenDriveEdge * > &edges)
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
~NIImporter_OpenDrive()
Destructor.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
std::map< int, int > getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection &prev)
NBNodeCont & getNodeCont()
Returns the node container.
Instance responsible for building networks.
Representation of an OpenDrive geometry part.
SUMOReal y() const
Returns the y-position.
A storage for options typed value containers)
static std::set< std::string > myLaneTypes2Import
static void setEdgeLinks2(OpenDriveEdge &e, const std::map< std::string, OpenDriveEdge * > &edges)
std::vector< OpenDriveGeometry > geometries
Represents a single node (junction) during network building.
Lane & getLaneStruct(unsigned int lane)
static void setNodeSecure(NBNodeCont &nc, OpenDriveEdge &e, const std::string &nodeID, NIImporter_OpenDrive::LinkType lt)
void push_back_noDoublePos(const Position &p)
A connection between two roads.
std::vector< SUMOReal > params
void addGeometryShape(GeometryType type, const std::vector< SUMOReal > &vals)
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Container for nodes during the netbuilding process.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOReal length
The length of the edge.
#define PROGRESS_DONE_MESSAGE()
static std::vector< Position > geomFromArc(const OpenDriveEdge &e, const OpenDriveGeometry &g)
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
const std::vector< Connection > & getConnections() const
Returns the connections.
Importer for networks stored in openDrive format.
std::string myCurrentIncomingRoad
OpenDriveLaneSection(SUMOReal sArg)
Constructor.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
static std::vector< Position > geomFromSpiral(const OpenDriveEdge &e, const OpenDriveGeometry &g)
NIImporter_OpenDrive(std::map< std::string, OpenDriveEdge * > &edges)
Constructor.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
SUMOReal width
This lane's width.
void myEndElement(int element)
Called when a closing tag occurs.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.