本文整理汇总了C++中NBEdge::getGeometry方法的典型用法代码示例。如果您正苦于以下问题:C++ NBEdge::getGeometry方法的具体用法?C++ NBEdge::getGeometry怎么用?C++ NBEdge::getGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBEdge
的用法示例。
在下文中一共展示了NBEdge::getGeometry方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: writeHeader
void
NWWriter_DlrNavteq::writeLinksUnsplitted(const OptionsCont& oc, NBEdgeCont& ec) {
std::map<const std::string, std::string> nameIDs;
OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_links_unsplitted.txt");
writeHeader(device, oc);
// write format specifier
device << "# LINK_ID\tNODE_ID_FROM\tNODE_ID_TO\tBETWEEN_NODE_ID\tLENGTH\tVEHICLE_TYPE\tFORM_OF_WAY\tBRUNNEL_TYPE\tFUNCTIONAL_ROAD_CLASS\tSPEED_CATEGORY\tNUMBER_OF_LANES\tSPEED_LIMIT\tSPEED_RESTRICTION\tNAME_ID1_REGIONAL\tNAME_ID2_LOCAL\tHOUSENUMBERS_RIGHT\tHOUSENUMBERS_LEFT\tZIP_CODE\tAREA_ID\tSUBAREA_ID\tTHROUGH_TRAFFIC\tSPECIAL_RESTRICTIONS\tEXTENDED_NUMBER_OF_LANES\tISRAMP\tCONNECTION\n";
// write edges
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
NBEdge* e = (*i).second;
const int kph = speedInKph(e->getSpeed());
const std::string& betweenNodeID = (e->getGeometry().size() > 2) ? e->getID() : UNDEFINED;
std::string nameID = UNDEFINED;
if (oc.getBool("output.street-names")) {
const std::string& name = i->second->getStreetName();
if (name != "" && nameIDs.count(name) == 0) {
nameID = toString(nameIDs.size());
nameIDs[name] = nameID;
}
}
device << e->getID() << "\t"
<< e->getFromNode()->getID() << "\t"
<< e->getToNode()->getID() << "\t"
<< betweenNodeID << "\t"
<< getGraphLength(e) << "\t"
<< getAllowedTypes(e->getPermissions()) << "\t"
<< "3\t" // Speed Category 1-8 XXX refine this
<< UNDEFINED << "\t" // no special brunnel type (we don't know yet)
<< getRoadClass(e) << "\t"
<< getSpeedCategory(kph) << "\t"
<< getNavteqLaneCode(e->getNumLanes()) << "\t"
<< getSpeedCategoryUpperBound(kph) << "\t"
<< kph << "\t"
<< nameID << "\t" // NAME_ID1_REGIONAL XXX
<< UNDEFINED << "\t" // NAME_ID2_LOCAL XXX
<< UNDEFINED << "\t" // housenumbers_right
<< UNDEFINED << "\t" // housenumbers_left
<< UNDEFINED << "\t" // ZIP_CODE
<< UNDEFINED << "\t" // AREA_ID
<< UNDEFINED << "\t" // SUBAREA_ID
<< "1\t" // through_traffic (allowed)
<< UNDEFINED << "\t" // special_restrictions
<< UNDEFINED << "\t" // extended_number_of_lanes
<< UNDEFINED << "\t" // isRamp
<< "0\t" // connection (between nodes always in order)
<< "\n";
}
if (oc.getBool("output.street-names")) {
OutputDevice& namesDevice = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_names.txt");
writeHeader(namesDevice, oc);
// write format specifier
namesDevice << "# NAME_ID\tName\n" << nameIDs.size() << "\n";
for (std::map<const std::string, std::string>::const_iterator i = nameIDs.begin(); i != nameIDs.end(); ++i) {
namesDevice << i->second << "\t" << i->first << "\n";
}
}
}
示例3: 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();
}
示例4: catch
void
NIXMLEdgesHandler::myEndElement(int element) {
if (element == SUMO_TAG_EDGE && myCurrentEdge != 0) {
if (!myIsUpdate) {
try {
if (!myEdgeCont.insert(myCurrentEdge)) {
WRITE_ERROR("Duplicate edge occured. ID='" + myCurrentID + "'");
delete myCurrentEdge;
}
} catch (InvalidArgument& e) {
WRITE_ERROR(e.what());
throw;
} catch (...) {
WRITE_ERROR("An important information is missing in edge '" + myCurrentID + "'.");
}
}
if (mySplits.size() != 0) {
std::vector<Split>::iterator i;
NBEdge* e = myCurrentEdge;
sort(mySplits.begin(), mySplits.end(), split_sorter());
unsigned int noLanesMax = e->getNumLanes();
// compute the node positions and sort the lanes
for (i = mySplits.begin(); i != mySplits.end(); ++i) {
(*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;
//.........这里部分代码省略.........
示例5: ProcessError
void
NBRampsComputer::buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, SUMOReal rampLength, bool dontSplit, std::set<NBEdge*>& incremented) {
NBEdge* potHighway, *potRamp, *prev;
getOffRampEdges(cur, &potHighway, &potRamp, &prev);
// compute the number of lanes to append
const unsigned int firstLaneNumber = prev->getNumLanes();
int toAdd = (potRamp->getNumLanes() + potHighway->getNumLanes()) - firstLaneNumber;
NBEdge* first = prev;
NBEdge* last = prev;
NBEdge* curr = prev;
if (toAdd > 0 && find(incremented.begin(), incremented.end(), prev) == incremented.end()) {
SUMOReal currLength = 0;
while (curr != 0 && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
curr->incLaneNo(toAdd);
curr->invalidateConnections(true);
incremented.insert(curr);
moveRampRight(curr, toAdd);
currLength += curr->getLength(); // !!! loaded length?
last = curr;
}
NBNode* prevN = curr->getFromNode();
if (prevN->getIncomingEdges().size() == 1) {
curr = prevN->getIncomingEdges()[0];
if (curr->getNumLanes() != firstLaneNumber) {
// the number of lanes changes along the computation; we'll stop...
curr = 0;
} else if (last->isTurningDirectionAt(curr)) {
// turnarounds certainly should not be included in a ramp
curr = 0;
} else if (curr == potHighway || curr == potRamp) {
// circular connectivity. do not split!
curr = 0;
}
} else {
// ambigous; and, in fact, what should it be? ...stop
curr = 0;
}
}
// check whether a further split is necessary
if (curr != 0 && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
// there is enough place to build a ramp; do it
bool wasFirst = first == curr;
Position pos = curr->getGeometry().positionAtOffset(curr->getGeometry().length() - (rampLength - currLength));
NBNode* rn = new NBNode(curr->getID() + "-AddedOffRampNode", pos);
if (!nc.insert(rn)) {
throw ProcessError("Ups - could not build on-ramp for edge '" + curr->getID() + "' (node could not be build)!");
}
std::string name = curr->getID();
bool ok = ec.splitAt(dc, curr, rn, curr->getID(), curr->getID() + "-AddedOffRampEdge", curr->getNumLanes(), curr->getNumLanes() + toAdd);
if (!ok) {
WRITE_ERROR("Ups - could not build on-ramp for edge '" + curr->getID() + "'!");
return;
}
curr = ec.retrieve(name + "-AddedOffRampEdge");
incremented.insert(curr);
last = curr;
moveRampRight(curr, toAdd);
if (wasFirst) {
first = curr;
}
}
if (curr == prev && dontSplit) {
WRITE_WARNING("Could not build off-ramp for edge '" + curr->getID() + "' due to option '--ramps.no-split'");
return;
}
}
// set connections from added ramp to ramp/highway
if (!first->addLane2LaneConnections(potRamp->getNumLanes(), potHighway, 0, MIN2(first->getNumLanes() - 1, potHighway->getNumLanes()), NBEdge::L2L_VALIDATED, true)) {
throw ProcessError("Could not set connection!");
}
if (!first->addLane2LaneConnections(0, potRamp, 0, potRamp->getNumLanes(), NBEdge::L2L_VALIDATED, false)) {
throw ProcessError("Could not set connection!");
}
// patch ramp geometry
PositionVector p = potRamp->getGeometry();
p.pop_front();
p.push_front(first->getLaneShape(0)[-1]);
potRamp->setGeometry(p);
}
示例6: catch
void
NIXMLEdgesHandler::myEndElement(int element) {
if (element == SUMO_TAG_EDGE && myCurrentEdge != 0) {
// add bike lane, wait until lanes are loaded to avoid building if it already exists
if (myBikeLaneWidth != NBEdge::UNSPECIFIED_WIDTH) {
myCurrentEdge->addBikeLane(myBikeLaneWidth);
}
// add sidewalk, wait until lanes are loaded to avoid building if it already exists
if (mySidewalkWidth != NBEdge::UNSPECIFIED_WIDTH) {
myCurrentEdge->addSidewalk(mySidewalkWidth);
}
if (!myIsUpdate) {
try {
if (!myEdgeCont.insert(myCurrentEdge)) {
WRITE_ERROR("Duplicate edge occured. ID='" + myCurrentID + "'");
delete myCurrentEdge;
}
} catch (InvalidArgument& e) {
WRITE_ERROR(e.what());
throw;
} catch (...) {
WRITE_ERROR("An important information is missing in edge '" + myCurrentID + "'.");
}
}
if (mySplits.size() != 0) {
std::vector<Split>::iterator i;
NBEdge* e = myCurrentEdge;
sort(mySplits.begin(), mySplits.end(), split_sorter());
unsigned int noLanesMax = e->getNumLanes();
// compute the node positions and sort the lanes
for (i = mySplits.begin(); i != mySplits.end(); ++i) {
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);
}
if (e->getNumLanes() != mySplits.back().lanes.size()) {
// invalidate traffic light definitions loaded from a SUMO network
// XXX it would be preferable to reconstruct the phase definitions heuristically
e->getToNode()->invalidateTLS(myTLLogicCont);
// if the number of lanes changes the connections should be
// recomputed
e->invalidateConnections(true);
}
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());
}
//.........这里部分代码省略.........
示例7: ProcessError
//.........这里部分代码省略.........
return;
}
// get the direction
std::string dirS = NBHelpers::normalIDRepresentation(myLineParser.get("RICHTTYP"));
int prevLaneNo = baseEdge->getNumLanes();
if ((dirS == "1" && !(node->hasIncoming(edge))) || (dirS == "0" && !(node->hasOutgoing(edge)))) {
// get the last part of the turnaround direction
edge = getReversedContinuating(edge, node);
}
// get the length
std::string lengthS = NBHelpers::normalIDRepresentation(myLineParser.get("LAENGE"));
SUMOReal length = -1;
try {
length = TplConvert::_2SUMOReal(lengthS.c_str());
} catch (NumberFormatException&) {
WRITE_ERROR("A lane length for edge '" + edge->getID() + "' is not numeric (" + lengthS + ").");
return;
}
if (length < 0) {
WRITE_ERROR("A lane length for edge '" + edge->getID() + "' is not positive (" + lengthS + ").");
return;
}
//
if (dirS == "1") {
lane -= prevLaneNo;
}
//
if (length == 0) {
if ((int) edge->getNumLanes() > lane) {
// ok, we know this already...
return;
}
// increment by one
edge->incLaneNo(1);
} else {
// check whether this edge already has been created
if (edge->getID().substr(edge->getID().length() - node->getID().length() - 1) == "_" + node->getID()) {
if (edge->getID().substr(edge->getID().find('_')) == "_" + toString(length) + "_" + node->getID()) {
if ((int) edge->getNumLanes() > lane) {
// ok, we know this already...
return;
}
// increment by one
edge->incLaneNo(1);
return;
}
}
// nope, we have to split the edge...
// maybe it is not the proper edge to split - VISUM seems not to sort the splits...
bool mustRecheck = true;
SUMOReal seenLength = 0;
while (mustRecheck) {
if (edge->getID().substr(edge->getID().length() - node->getID().length() - 1) == "_" + node->getID()) {
// ok, we have a previously created edge here
std::string sub = edge->getID();
sub = sub.substr(sub.rfind('_', sub.rfind('_') - 1));
sub = sub.substr(1, sub.find('_', 1) - 1);
SUMOReal dist = TplConvert::_2SUMOReal(sub.c_str());
if (dist < length) {
seenLength += edge->getLength();
if (dirS == "1") {
// incoming -> move back
edge = edge->getFromNode()->getIncomingEdges()[0];
} else {
// outgoing -> move forward
edge = edge->getToNode()->getOutgoingEdges()[0];
}
} else {
mustRecheck = false;
}
} else {
// we have the center edge - do not continue...
mustRecheck = false;
}
}
// compute position
Position p;
SUMOReal useLength = length - seenLength;
useLength = edge->getLength() - useLength;
std::string edgeID = edge->getID();
p = edge->getGeometry().positionAtLengthPosition(useLength);
if (edgeID.substr(edgeID.length() - node->getID().length() - 1) == "_" + node->getID()) {
edgeID = edgeID.substr(0, edgeID.find('_'));
}
NBNode* rn = new NBNode(edgeID + "_" + toString((size_t) length) + "_" + node->getID(), p);
if (!myNetBuilder.getNodeCont().insert(rn)) {
throw ProcessError("Ups - could not insert node!");
}
std::string nid = edgeID + "_" + toString((size_t) length) + "_" + node->getID();
myNetBuilder.getEdgeCont().splitAt(myNetBuilder.getDistrictCont(), edge, useLength, rn,
edge->getID(), nid, edge->getNumLanes() + 0, edge->getNumLanes() + 1);
NBEdge* nedge = myNetBuilder.getEdgeCont().retrieve(nid);
nedge = nedge->getToNode()->getOutgoingEdges()[0];
while (nedge->getID().substr(nedge->getID().length() - node->getID().length() - 1) == "_" + node->getID()) {
assert(nedge->getToNode()->getOutgoingEdges().size() > 0);
nedge->incLaneNo(1);
nedge = nedge->getToNode()->getOutgoingEdges()[0];
}
}
}
示例8: ProcessError
void
NBRampsComputer::buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, SUMOReal rampLength, bool dontSplit, std::set<NBEdge*>& incremented) {
NBEdge* potHighway, *potRamp, *cont;
getOnRampEdges(cur, &potHighway, &potRamp, &cont);
// compute the number of lanes to append
const unsigned int firstLaneNumber = potHighway->getNumLanes();
int toAdd = (potRamp->getNumLanes() + firstLaneNumber) - cont->getNumLanes();
NBEdge* first = cont;
NBEdge* last = cont;
NBEdge* curr = cont;
if (toAdd > 0 && find(incremented.begin(), incremented.end(), cont) == incremented.end()) {
SUMOReal currLength = 0;
while (curr != 0 && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
curr->incLaneNo(toAdd);
curr->invalidateConnections(true);
incremented.insert(curr);
moveRampRight(curr, toAdd);
currLength += curr->getLength(); // !!! loaded length?
last = curr;
}
NBNode* nextN = curr->getToNode();
if (nextN->getOutgoingEdges().size() == 1) {
curr = nextN->getOutgoingEdges()[0];
if (curr->getNumLanes() != firstLaneNumber) {
// the number of lanes changes along the computation; we'll stop...
curr = 0;
}
} else {
// ambigous; and, in fact, what should it be? ...stop
curr = 0;
}
}
// check whether a further split is necessary
if (curr != 0 && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
// there is enough place to build a ramp; do it
bool wasFirst = first == curr;
NBNode* rn = new NBNode(curr->getID() + "-AddedOnRampNode", curr->getGeometry().positionAtLengthPosition(rampLength - currLength));
if (!nc.insert(rn)) {
throw ProcessError("Ups - could not build on-ramp for edge '" + curr->getID() + "' (node could not be build)!");
}
std::string name = curr->getID();
bool ok = ec.splitAt(dc, curr, rn, curr->getID() + ADDED_ON_RAMP_EDGE, curr->getID(), curr->getNumLanes() + toAdd, curr->getNumLanes());
if (!ok) {
WRITE_ERROR("Ups - could not build on-ramp for edge '" + curr->getID() + "'!");
return;
}
//ec.retrieve(name)->invalidateConnections();
curr = ec.retrieve(name + ADDED_ON_RAMP_EDGE);
curr->invalidateConnections(true);
incremented.insert(curr);
last = curr;
moveRampRight(curr, toAdd);
if (wasFirst) {
first = curr;
}
}
}
// set connections from ramp/highway to added ramp
if (!potHighway->addLane2LaneConnections(0, first, potRamp->getNumLanes(), MIN2(first->getNumLanes() - potRamp->getNumLanes(), potHighway->getNumLanes()), NBEdge::L2L_VALIDATED, true, true)) {
throw ProcessError("Could not set connection!");
}
if (!potRamp->addLane2LaneConnections(0, first, 0, potRamp->getNumLanes(), NBEdge::L2L_VALIDATED, true, true)) {
throw ProcessError("Could not set connection!");
}
// patch ramp geometry
PositionVector p = potRamp->getGeometry();
p.pop_back();
p.push_back(first->getLaneShape(0)[0]);
potRamp->setGeometry(p);
// set connections from added ramp to following highway
NBNode* nextN = last->getToNode();
if (nextN->getOutgoingEdges().size() == 1) {
NBEdge* next = nextN->getOutgoingEdges()[0];//const EdgeVector& o1 = cont->getToNode()->getOutgoingEdges();
if (next->getNumLanes() < last->getNumLanes()) {
last->addLane2LaneConnections(last->getNumLanes() - next->getNumLanes(), next, 0, next->getNumLanes(), NBEdge::L2L_VALIDATED);
}
}
}
示例9: 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";
}
}
//.........这里部分代码省略.........
示例10: 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());
}
//.........这里部分代码省略.........