本文整理汇总了C++中NBEdge::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ NBEdge::getLength方法的具体用法?C++ NBEdge::getLength怎么用?C++ NBEdge::getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBEdge
的用法示例。
在下文中一共展示了NBEdge::getLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: retrieve
NBEdge*
NBEdgeCont::retrievePossiblySplit(const std::string& id, SUMOReal pos) const {
// check whether the edge was not split, yet
NBEdge* edge = retrieve(id);
if (edge != 0) {
return edge;
}
size_t maxLength = 0;
std::string tid = id + "[";
for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
if ((*i).first.find(tid) == 0) {
maxLength = MAX2(maxLength, (*i).first.length());
}
}
// find the part of the edge which matches the position
SUMOReal seen = 0;
std::vector<std::string> names;
names.push_back(id + "[1]");
names.push_back(id + "[0]");
while (names.size() > 0) {
// retrieve the first subelement (to follow)
std::string cid = names.back();
names.pop_back();
edge = retrieve(cid);
// The edge was splitted; check its subparts within the
// next step
if (edge == 0) {
if (cid.length() + 3 < maxLength) {
names.push_back(cid + "[1]");
names.push_back(cid + "[0]");
}
}
// an edge with the name was found,
// check whether the position lies within it
else {
seen += edge->getLength();
if (seen >= pos) {
return edge;
}
}
}
return 0;
}
示例2: switch
void
NBEdgeCont::generateStreetSigns() {
for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
NBEdge* e = i->second;
// is this a "real" junction?
// XXX nyi
//continue
const SUMOReal offset = e->getLength() - 3;
switch (e->getToNode()->getType()) {
case NODETYPE_PRIORITY:
// yield or major?
if (e->getJunctionPriority(e->getToNode()) > 0) {
e->addSign(NBSign(NBSign::SIGN_TYPE_PRIORITY, offset));
} else {
e->addSign(NBSign(NBSign::SIGN_TYPE_YIELD, offset));
}
break;
case NODETYPE_PRIORITY_STOP:
// yield or major?
if (e->getJunctionPriority(e->getToNode()) > 0) {
e->addSign(NBSign(NBSign::SIGN_TYPE_PRIORITY, offset));
} else {
e->addSign(NBSign(NBSign::SIGN_TYPE_STOP, offset));
}
break;
case NODETYPE_ALLWAY_STOP:
e->addSign(NBSign(NBSign::SIGN_TYPE_ALLWAY_STOP, offset));
break;
case NODETYPE_RIGHT_BEFORE_LEFT:
e->addSign(NBSign(NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT, offset));
break;
default:
break;
}
}
}
示例3: 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);
}
示例4: NBEdge
void
NIVissimDistrictConnection::dict_BuildDistricts(NBDistrictCont& dc,
NBEdgeCont& ec,
NBNodeCont& nc/*,
NBDistribution &distc*/) {
// add the sources and sinks
// their normalised probability is computed within NBDistrict
// to avoid SUMOReal code writing and more securty within the converter
// go through the district table
for (std::map<int, std::vector<int> >::iterator k = myDistrictsConnections.begin(); k != myDistrictsConnections.end(); k++) {
// get the connections
const std::vector<int>& connections = (*k).second;
// retrieve the current district
NBDistrict* district =
dc.retrieve(toString<int>((*k).first));
NBNode* districtNode = nc.retrieve("District" + district->getID());
assert(district != 0 && districtNode != 0);
for (std::vector<int>::const_iterator l = connections.begin(); l != connections.end(); l++) {
NIVissimDistrictConnection* c = dictionary(*l);
// get the edge to connect the parking place to
NBEdge* e = ec.retrieve(toString<int>(c->myEdgeID));
if (e == 0) {
e = ec.retrievePossiblySplit(toString<int>(c->myEdgeID), c->myPosition);
}
if (e == 0) {
WRITE_WARNING("Could not build district '" + toString<int>((*k).first) + "' - edge '" + toString<int>(c->myEdgeID) + "' is missing.");
continue;
}
std::string id = "ParkingPlace" + toString<int>(*l);
NBNode* parkingPlace = nc.retrieve(id);
if (parkingPlace == 0) {
SUMOReal pos = c->getPosition();
if (pos < e->getLength() - pos) {
parkingPlace = e->getFromNode();
parkingPlace->invalidateIncomingConnections();
} else {
parkingPlace = e->getToNode();
parkingPlace->invalidateOutgoingConnections();
}
}
assert(
e->getToNode() == parkingPlace
||
e->getFromNode() == parkingPlace);
// build the connection to the source
if (e->getFromNode() == parkingPlace) {
id = "VissimFromParkingplace" + toString<int>((*k).first) + "-" + toString<int>(c->myID);
NBEdge* source =
new NBEdge(id, districtNode, parkingPlace,
"Connection", c->getMeanSpeed(/*distc*/) / (SUMOReal) 3.6, 3, -1,
NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET);
if (!ec.insert(source)) { // !!! in den Konstruktor
throw 1; // !!!
}
SUMOReal percNormed =
c->myPercentages[(*k).first];
if (!district->addSource(source, percNormed)) {
throw 1;
}
}
// build the connection to the destination
if (e->getToNode() == parkingPlace) {
id = "VissimToParkingplace" + toString<int>((*k).first) + "-" + toString<int>(c->myID);
NBEdge* destination =
new NBEdge(id, parkingPlace, districtNode,
"Connection", (SUMOReal) 100 / (SUMOReal) 3.6, 2, -1,
NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET);
if (!ec.insert(destination)) { // !!! (in den Konstruktor)
throw 1; // !!!
}
SUMOReal percNormed2 =
c->myPercentages[(*k).first];
if (!district->addSink(destination, percNormed2)) {
throw 1; // !!!
}
}
/*
if(e->getToNode()==districtNode) {
SUMOReal percNormed =
c->myPercentages[(*k).first];
district->addSink(e, percNormed);
}
if(e->getFromNode()==districtNode) {
SUMOReal percNormed =
c->myPercentages[(*k).first];
district->addSource(e, percNormed);
}
*/
}
/*
// add them as sources and sinks to the current district
for(std::vector<int>::const_iterator l=connections.begin(); l!=connections.end(); l++) {
// get the current connections
NIVissimDistrictConnection *c = dictionary(*l);
// get the edge to connect the parking place to
//.........这里部分代码省略.........
示例5: ProcessError
void
NIImporter_VISUM::parse_Lanes() {
// get the node
NBNode* node = getNamedNode("KNOTNR");
// get the edge
NBEdge* baseEdge = getNamedEdge("STRNR");
NBEdge* edge = getNamedEdgeContinuating("STRNR", node);
// check
if (node == 0 || edge == 0) {
return;
}
// get the lane
std::string laneS = myLineParser.know("FSNR")
? NBHelpers::normalIDRepresentation(myLineParser.get("FSNR"))
: NBHelpers::normalIDRepresentation(myLineParser.get("NR"));
int lane = -1;
try {
lane = TplConvert::_2int(laneS.c_str());
} catch (NumberFormatException&) {
WRITE_ERROR("A lane number for edge '" + edge->getID() + "' is not numeric (" + laneS + ").");
return;
}
lane -= 1;
if (lane < 0) {
WRITE_ERROR("A lane number for edge '" + edge->getID() + "' is not positive (" + laneS + ").");
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;
}
}
//.........这里部分代码省略.........
示例6: 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);
}
}
}