本文整理汇总了C++中NBEdge::getLaneSpreadFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ NBEdge::getLaneSpreadFunction方法的具体用法?C++ NBEdge::getLaneSpreadFunction怎么用?C++ NBEdge::getLaneSpreadFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBEdge
的用法示例。
在下文中一共展示了NBEdge::getLaneSpreadFunction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeLane
void
NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) {
// write the edge's begin
into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID());
into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID());
into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
if (!noNames && e.getStreetName() != "") {
into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName()));
}
into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority());
if (e.getTypeID() != "") {
into.writeAttr(SUMO_ATTR_TYPE, e.getTypeID());
}
if (e.isMacroscopicConnector()) {
into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR);
}
// write the spread type if not default ("right")
if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) {
into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction());
}
if (e.hasLoadedLength()) {
into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength());
}
if (!e.hasDefaultGeometry()) {
into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry());
}
// write the lanes
const std::vector<NBEdge::Lane>& lanes = e.getLanes();
SUMOReal length = e.getLoadedLength();
if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) {
// use length to junction center even if a modified geometry was given
PositionVector geom = e.cutAtIntersection(e.getGeometry());
geom.push_back_noDoublePos(e.getToNode()->getCenter());
geom.push_front_noDoublePos(e.getFromNode()->getCenter());
length = geom.length();
}
if (length <= 0) {
length = POSITION_EPS;
}
for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) {
const NBEdge::Lane& l = lanes[i];
writeLane(into, e.getID(), e.getLaneID(i), l.speed,
l.permissions, l.preferred, l.endOffset, l.width, l.shape, l.origID,
length, i, origNames);
}
// close the edge
into.closeTag();
}
示例2: writeLane
void
NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) {
// write the edge's begin
into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID());
into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID());
into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
if (!noNames && e.getStreetName() != "") {
into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName()));
}
into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority());
if (e.getTypeName() != "") {
into.writeAttr(SUMO_ATTR_TYPE, e.getTypeName());
}
if (e.isMacroscopicConnector()) {
into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR);
}
// write the spread type if not default ("right")
if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) {
into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction());
}
if (e.hasLoadedLength()) {
into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength());
}
if (!e.hasDefaultGeometry()) {
into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry());
}
// write the lanes
const std::vector<NBEdge::Lane>& lanes = e.getLanes();
SUMOReal length = e.getLoadedLength();
if (length <= 0) {
length = (SUMOReal) .1;
}
for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) {
writeLane(into, e.getID(), e.getLaneID(i), lanes[i], length, i, origNames);
}
// close the edge
into.closeTag();
}
示例3: catch
//.........这里部分代码省略.........
(*i).gpos = e->getGeometry().positionAtLengthPosition((*i).pos);
sort((*i).lanes.begin(), (*i).lanes.end());
noLanesMax = MAX2(noLanesMax, (unsigned int)(*i).lanes.size());
}
// split the edge
std::vector<int> currLanes;
for (unsigned int l = 0; l < e->getNumLanes(); ++l) {
currLanes.push_back(l);
}
std::string edgeid = e->getID();
SUMOReal seen = 0;
for (i = mySplits.begin(); i != mySplits.end(); ++i) {
const Split& exp = *i;
assert(exp.lanes.size() != 0);
if (exp.pos > 0 && e->getGeometry().length() + seen > exp.pos && exp.pos > seen) {
std::string nid = edgeid + "." + toString(exp.nameid);
NBNode* rn = new NBNode(nid, exp.gpos);
if (myNodeCont.insert(rn)) {
// split the edge
std::string nid = myCurrentID + "." + toString(exp.nameid);
std::string pid = e->getID();
myEdgeCont.splitAt(myDistrictCont, e, exp.pos - seen, rn,
pid, nid, e->getNumLanes(), (unsigned int) exp.lanes.size());
seen = exp.pos;
std::vector<int> newLanes = exp.lanes;
NBEdge* pe = myEdgeCont.retrieve(pid);
NBEdge* ne = myEdgeCont.retrieve(nid);
// reconnect lanes
pe->invalidateConnections(true);
// new on right
unsigned int rightMostP = currLanes[0];
unsigned int rightMostN = newLanes[0];
for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
pe->addLane2LaneConnection(0, ne, l, NBEdge::L2L_VALIDATED, true);
}
// new on left
unsigned int leftMostP = currLanes.back();
unsigned int leftMostN = newLanes.back();
for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// all other connected
for (unsigned int l = 0; l < noLanesMax; ++l) {
if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
continue;
}
if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
continue;
}
pe->addLane2LaneConnection(l - rightMostP, ne, l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// move to next
e = ne;
currLanes = newLanes;
} else {
WRITE_WARNING("Error on parsing a split (edge '" + myCurrentID + "').");
}
} else if (exp.pos == 0) {
if (e->getNumLanes() < exp.lanes.size()) {
e->incLaneNo((int) exp.lanes.size() - e->getNumLanes());
} else {
e->decLaneNo(e->getNumLanes() - (int) exp.lanes.size());
}
currLanes = exp.lanes;
} else {
WRITE_WARNING("Split at '" + toString(exp.pos) + "' lies beyond the edge's length (edge '" + myCurrentID + "').");
}
}
// patch lane offsets
e = myEdgeCont.retrieve(edgeid);
i = mySplits.begin();
if ((*i).pos != 0) {
e = e->getToNode()->getOutgoingEdges()[0];
}
for (; i != mySplits.end(); ++i) {
unsigned int maxLeft = (*i).lanes.back();
SUMOReal offset = 0;
if (maxLeft < noLanesMax) {
if (e->getLaneSpreadFunction() == LANESPREAD_RIGHT) {
offset = SUMO_const_laneWidthAndOffset * (noLanesMax - 1 - maxLeft);
} else {
offset = SUMO_const_halfLaneAndOffset * (noLanesMax - 1 - maxLeft);
}
}
unsigned int maxRight = (*i).lanes.front();
if (maxRight > 0 && e->getLaneSpreadFunction() == LANESPREAD_CENTER) {
offset -= SUMO_const_halfLaneAndOffset * maxRight;
}
if (offset != 0) {
PositionVector g = e->getGeometry();
g.move2side(offset);
e->setGeometry(g);
}
if (e->getToNode()->getOutgoingEdges().size() != 0) {
e = e->getToNode()->getOutgoingEdges()[0];
}
}
}
}
}
示例4: catch
//.........这里部分代码省略.........
}
std::string edgeid = e->getID();
SUMOReal seen = 0;
for (i = mySplits.begin(); i != mySplits.end(); ++i) {
const Split& exp = *i;
assert(exp.lanes.size() != 0);
if (exp.pos > 0 && e->getGeometry().length() + seen > exp.pos && exp.pos > seen) {
if (myNodeCont.insert(exp.node)) {
myNodeCont.markAsSplit(exp.node);
// split the edge
std::string pid = e->getID();
myEdgeCont.splitAt(myDistrictCont, e, exp.pos - seen, exp.node,
pid, exp.node->getID(), e->getNumLanes(), (unsigned int) exp.lanes.size(), exp.speed);
seen = exp.pos;
std::vector<int> newLanes = exp.lanes;
NBEdge* pe = myEdgeCont.retrieve(pid);
NBEdge* ne = myEdgeCont.retrieve(exp.node->getID());
// reconnect lanes
pe->invalidateConnections(true);
// new on right
unsigned int rightMostP = currLanes[0];
unsigned int rightMostN = newLanes[0];
for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
pe->addLane2LaneConnection(0, ne, l, NBEdge::L2L_VALIDATED, true);
}
// new on left
unsigned int leftMostP = currLanes.back();
unsigned int leftMostN = newLanes.back();
for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// all other connected
for (unsigned int l = 0; l < noLanesMax; ++l) {
if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
continue;
}
if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
continue;
}
pe->addLane2LaneConnection(l - rightMostP, ne, l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// move to next
e = ne;
currLanes = newLanes;
} else {
WRITE_WARNING("Error on parsing a split (edge '" + myCurrentID + "').");
}
} else if (exp.pos == 0) {
if (e->getNumLanes() < exp.lanes.size()) {
e->incLaneNo((int) exp.lanes.size() - e->getNumLanes());
} else {
e->decLaneNo(e->getNumLanes() - (int) exp.lanes.size());
}
currLanes = exp.lanes;
// invalidate traffic light definition loaded from a SUMO network
// XXX it would be preferable to reconstruct the phase definitions heuristically
e->getFromNode()->invalidateTLS(myTLLogicCont);
} else {
WRITE_WARNING("Split at '" + toString(exp.pos) + "' lies beyond the edge's length (edge '" + myCurrentID + "').");
}
}
// patch lane offsets
e = myEdgeCont.retrieve(edgeid);
if (mySplits.front().pos != 0) {
// add a dummy split at the beginning to ensure correct offset
Split start;
start.pos = 0;
for (int lane = 0; lane < (int)e->getNumLanes(); ++lane) {
start.lanes.push_back(lane);
}
mySplits.insert(mySplits.begin(), start);
}
i = mySplits.begin();
for (; i != mySplits.end(); ++i) {
unsigned int maxLeft = (*i).lanes.back();
SUMOReal offset = 0;
if (maxLeft < noLanesMax) {
if (e->getLaneSpreadFunction() == LANESPREAD_RIGHT) {
offset = SUMO_const_laneWidthAndOffset * (noLanesMax - 1 - maxLeft);
} else {
offset = SUMO_const_halfLaneAndOffset * (noLanesMax - 1 - maxLeft);
}
}
unsigned int maxRight = (*i).lanes.front();
if (maxRight > 0 && e->getLaneSpreadFunction() == LANESPREAD_CENTER) {
offset -= SUMO_const_halfLaneAndOffset * maxRight;
}
if (offset != 0) {
PositionVector g = e->getGeometry();
g.move2side(offset);
e->setGeometry(g);
}
if (e->getToNode()->getOutgoingEdges().size() != 0) {
e = e->getToNode()->getOutgoingEdges()[0];
}
}
}
}
}
示例5: min
void
NWWriter_DlrNavteq::writeNodesUnsplitted(const OptionsCont& oc, NBNodeCont& nc, NBEdgeCont& ec, std::map<NBEdge*, std::string>& internalNodes) {
// For "real" nodes we simply use the node id.
// For internal nodes (geometry vectors describing edge geometry in the parlance of this format)
// we use the id of the edge and do not bother with
// compression (each direction gets its own internal node).
OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_nodes_unsplitted.txt");
writeHeader(device, oc);
const GeoConvHelper& gch = GeoConvHelper::getFinal();
const bool haveGeo = gch.usingGeoProjection();
const double geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE
device.setPrecision(oc.getInt("dlr-navteq.precision"));
if (!haveGeo) {
WRITE_WARNING("DlrNavteq node data will be written in (floating point) cartesian coordinates");
}
// write format specifier
device << "# NODE_ID\tIS_BETWEEN_NODE\tamount_of_geocoordinates\tx1\ty1\t[x2 y2 ... xn yn]\n";
// write header
Boundary boundary = gch.getConvBoundary();
Position min(boundary.xmin(), boundary.ymin());
Position max(boundary.xmax(), boundary.ymax());
gch.cartesian2geo(min);
min.mul(geoScale);
gch.cartesian2geo(max);
max.mul(geoScale);
int multinodes = 0;
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
if ((*i).second->getGeometry().size() > 2) {
multinodes++;
}
}
device << "# [xmin_region] " << min.x() << "\n";
device << "# [xmax_region] " << max.x() << "\n";
device << "# [ymin_region] " << min.y() << "\n";
device << "# [ymax_region] " << max.y() << "\n";
device << "# [elements_multinode] " << multinodes << "\n";
device << "# [elements_normalnode] " << nc.size() << "\n";
device << "# [xmin] " << min.x() << "\n";
device << "# [xmax] " << max.x() << "\n";
device << "# [ymin] " << min.y() << "\n";
device << "# [ymax] " << max.y() << "\n";
// write normal nodes
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
NBNode* n = (*i).second;
Position pos = n->getPosition();
gch.cartesian2geo(pos);
pos.mul(geoScale);
device << n->getID() << "\t0\t1\t" << pos.x() << "\t" << pos.y() << "\n";
}
// write "internal" nodes
std::vector<std::string> avoid;
std::set<std::string> reservedNodeIDs;
const bool numericalIDs = oc.getBool("numerical-ids");
if (oc.isSet("reserved-ids")) {
NBHelpers::loadPrefixedIDsFomFile(oc.getString("reserved-ids"), "node:", reservedNodeIDs); // backward compatibility
NBHelpers::loadPrefixedIDsFomFile(oc.getString("reserved-ids"), "junction:", reservedNodeIDs); // selection format
}
if (numericalIDs) {
avoid = nc.getAllNames();
std::vector<std::string> avoid2 = ec.getAllNames();
avoid.insert(avoid.end(), avoid2.begin(), avoid2.end());
avoid.insert(avoid.end(), reservedNodeIDs.begin(), reservedNodeIDs.end());
}
IDSupplier idSupplier("", avoid);
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
NBEdge* e = (*i).second;
PositionVector geom = e->getGeometry();
if (geom.size() > 2) {
// the import NIImporter_DlrNavteq checks for the presence of a
// negated edge id to determine spread type. We may need to do some
// shifting to make this consistent
const bool hasOppositeID = ec.getOppositeByID(e->getID()) != nullptr;
if (e->getLaneSpreadFunction() == LANESPREAD_RIGHT && !hasOppositeID) {
// need to write center-line geometry instead
try {
geom.move2side(e->getTotalWidth() / 2);
} catch (InvalidArgument& exception) {
WRITE_WARNING("Could not reconstruct shape for edge:'" + e->getID() + "' (" + exception.what() + ").");
}
} else if (e->getLaneSpreadFunction() == LANESPREAD_CENTER && hasOppositeID) {
// need to write left-border geometry instead
try {
geom.move2side(-e->getTotalWidth() / 2);
} catch (InvalidArgument& exception) {
WRITE_WARNING("Could not reconstruct shape for edge:'" + e->getID() + "' (" + exception.what() + ").");
}
}
std::string internalNodeID = e->getID();
if (internalNodeID == UNDEFINED
|| (nc.retrieve(internalNodeID) != nullptr)
|| reservedNodeIDs.count(internalNodeID) > 0
) {
// need to invent a new name to avoid clashing with the id of a 'real' node or a reserved name
if (numericalIDs) {
internalNodeID = idSupplier.getNext();
} else {
internalNodeID += "_geometry";
}
}
//.........这里部分代码省略.........
示例6: toString
void
NWWriter_XML::writeEdgesAndConnections(const OptionsCont& oc, NBNodeCont& nc, NBEdgeCont& ec) {
const GeoConvHelper& gch = GeoConvHelper::getFinal();
bool useGeo = oc.exists("proj.plain-geo") && oc.getBool("proj.plain-geo");
const bool geoAccuracy = useGeo || gch.usingInverseGeoProjection();
OutputDevice& edevice = OutputDevice::getDevice(oc.getString("plain-output-prefix") + ".edg.xml");
edevice.writeXMLHeader("edges", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/edges_file.xsd\"");
OutputDevice& cdevice = OutputDevice::getDevice(oc.getString("plain-output-prefix") + ".con.xml");
cdevice.writeXMLHeader("connections", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/connections_file.xsd\"");
bool noNames = !oc.getBool("output.street-names");
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
// write the edge itself to the edges-files
NBEdge* e = (*i).second;
edevice.openTag(SUMO_TAG_EDGE);
edevice.writeAttr(SUMO_ATTR_ID, e->getID());
edevice.writeAttr(SUMO_ATTR_FROM, e->getFromNode()->getID());
edevice.writeAttr(SUMO_ATTR_TO, e->getToNode()->getID());
if (!noNames && e->getStreetName() != "") {
edevice.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e->getStreetName()));
}
edevice.writeAttr(SUMO_ATTR_PRIORITY, e->getPriority());
// write the type if given
if (e->getTypeID() != "") {
edevice.writeAttr(SUMO_ATTR_TYPE, e->getTypeID());
}
edevice.writeAttr(SUMO_ATTR_NUMLANES, e->getNumLanes());
if (!e->hasLaneSpecificSpeed()) {
edevice.writeAttr(SUMO_ATTR_SPEED, e->getSpeed());
}
// write non-default geometry
if (!e->hasDefaultGeometry()) {
PositionVector geom = e->getGeometry();
if (useGeo) {
for (int i = 0; i < (int) geom.size(); i++) {
gch.cartesian2geo(geom[i]);
}
}
if (geoAccuracy) {
edevice.setPrecision(GEO_OUTPUT_ACCURACY);
}
edevice.writeAttr(SUMO_ATTR_SHAPE, geom);
if (geoAccuracy) {
edevice.setPrecision();
}
}
// write the spread type if not default ("right")
if (e->getLaneSpreadFunction() != LANESPREAD_RIGHT) {
edevice.writeAttr(SUMO_ATTR_SPREADTYPE, toString(e->getLaneSpreadFunction()));
}
// write the length if it was specified
if (e->hasLoadedLength()) {
edevice.writeAttr(SUMO_ATTR_LENGTH, e->getLoadedLength());
}
// some attributes can be set by edge default or per lane. Write as default if possible (efficiency)
if (e->getLaneWidth() != NBEdge::UNSPECIFIED_WIDTH && !e->hasLaneSpecificWidth()) {
edevice.writeAttr(SUMO_ATTR_WIDTH, e->getLaneWidth());
}
if (e->getOffset() != NBEdge::UNSPECIFIED_OFFSET && !e->hasLaneSpecificOffset()) {
edevice.writeAttr(SUMO_ATTR_OFFSET, e->getOffset());
}
if (!e->needsLaneSpecificOutput()) {
edevice.closeTag();
} else {
for (unsigned int i = 0; i < e->getLanes().size(); ++i) {
const NBEdge::Lane& lane = e->getLanes()[i];
edevice.openTag(SUMO_TAG_LANE);
edevice.writeAttr(SUMO_ATTR_INDEX, i);
// write allowed lanes
NWWriter_SUMO::writePermissions(edevice, lane.permissions);
NWWriter_SUMO::writePreferences(edevice, lane.preferred);
// write other attributes
if (lane.width != NBEdge::UNSPECIFIED_WIDTH && e->hasLaneSpecificWidth()) {
edevice.writeAttr(SUMO_ATTR_WIDTH, lane.width);
}
if (lane.offset != NBEdge::UNSPECIFIED_OFFSET && e->hasLaneSpecificOffset()) {
edevice.writeAttr(SUMO_ATTR_OFFSET, lane.offset);
}
if (e->hasLaneSpecificSpeed()) {
edevice.writeAttr(SUMO_ATTR_SPEED, lane.speed);
}
edevice.closeTag();
}
edevice.closeTag();
}
// write this edge's connections to the connections-files
e->sortOutgoingConnectionsByIndex();
const std::vector<NBEdge::Connection> connections = e->getConnections();
for (std::vector<NBEdge::Connection>::const_iterator c = connections.begin(); c != connections.end(); ++c) {
NWWriter_SUMO::writeConnection(cdevice, *e, *c, false, NWWriter_SUMO::PLAIN);
}
if (connections.size() > 0) {
cdevice << "\n";
}
}
// write loaded prohibitions to the connections-file
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
NWWriter_SUMO::writeProhibitions(cdevice, i->second->getProhibitions());
}
//.........这里部分代码省略.........