本文整理汇总了C++中NBEdgeCont::splitAt方法的典型用法代码示例。如果您正苦于以下问题:C++ NBEdgeCont::splitAt方法的具体用法?C++ NBEdgeCont::splitAt怎么用?C++ NBEdgeCont::splitAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBEdgeCont
的用法示例。
在下文中一共展示了NBEdgeCont::splitAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: assert
bool
NIVissimDisturbance::addToNode(NBNode* node, NBDistrictCont& dc,
NBNodeCont& nc, NBEdgeCont& ec) {
myNode = 0;
NIVissimConnection* pc =
NIVissimConnection::dictionary(myEdge.getEdgeID());
NIVissimConnection* bc =
NIVissimConnection::dictionary(myDisturbance.getEdgeID());
if (pc == nullptr && bc == nullptr) {
// This has not been tested completely, yet
// Both competing abstract edges are normal edges
// We have to find a crossing point, build a node here,
// split both edges and add the connections
NIVissimEdge* e1 = NIVissimEdge::dictionary(myEdge.getEdgeID());
NIVissimEdge* e2 = NIVissimEdge::dictionary(myDisturbance.getEdgeID());
WRITE_WARNING("Ugly split to prohibit '" + toString<int>(e1->getID()) + "' by '" + toString<int>(e2->getID()) + "'.");
Position pos = e1->crossesEdgeAtPoint(e2);
std::string id1 = toString<int>(e1->getID()) + "x" + toString<int>(e2->getID());
std::string id2 = toString<int>(e2->getID()) + "x" + toString<int>(e1->getID());
NBNode* node1 = nc.retrieve(id1);
NBNode* node2 = nc.retrieve(id2);
NBNode* node = nullptr;
assert(node1 == 0 || node2 == 0);
if (node1 == nullptr && node2 == nullptr) {
refusedProhibits++;
return false;
/* node = new NBNode(id1, pos.x(), pos.y(), "priority");
if(!myNodeCont.insert(node)) {
"nope, NIVissimDisturbance" << endl;
throw 1;
}*/
} else {
node = node1 == nullptr ? node2 : node1;
}
ec.splitAt(dc, ec.retrievePossiblySplit(toString<int>(e1->getID()), myEdge.getPosition()), node);
ec.splitAt(dc, ec.retrievePossiblySplit(toString<int>(e2->getID()), myDisturbance.getPosition()), node);
// !!! in some cases, one of the edges is not being build because it's too short
// !!! what to do in these cases?
NBEdge* mayDriveFrom = ec.retrieve(toString<int>(e1->getID()) + "[0]");
NBEdge* mayDriveTo = ec.retrieve(toString<int>(e1->getID()) + "[1]");
NBEdge* mustStopFrom = ec.retrieve(toString<int>(e2->getID()) + "[0]");
NBEdge* mustStopTo = ec.retrieve(toString<int>(e2->getID()) + "[1]");
if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {
node->addSortedLinkFoes(
NBConnection(mayDriveFrom, mayDriveTo),
NBConnection(mayDriveFrom, mayDriveTo));
} else {
refusedProhibits++;
return false;
// !!! warning
}
// }
} else if (pc != nullptr && bc == nullptr) {
// The prohibited abstract edge is a connection, the other
// is not;
// The connection will be prohibitesd by all connections
// outgoing from the "real" edge
NBEdge* e = ec.retrievePossiblySplit(toString<int>(myDisturbance.getEdgeID()), myDisturbance.getPosition());
if (e == nullptr) {
WRITE_WARNING("Could not prohibit '" + toString<int>(myEdge.getEdgeID()) + "' by '" + toString<int>(myDisturbance.getEdgeID()) + "'. Have not found disturbance.");
refusedProhibits++;
return false;
}
if (e->getFromNode() == e->getToNode()) {
WRITE_WARNING("Could not prohibit '" + toString<int>(myEdge.getEdgeID()) + "' by '" + toString<int>(myDisturbance.getEdgeID()) + "'. Disturbance connects same node.");
refusedProhibits++;
// What to do with self-looping edges?
return false;
}
// get the begin of the prohibited connection
std::string id_pcoe = toString<int>(pc->getFromEdgeID());
std::string id_pcie = toString<int>(pc->getToEdgeID());
NBEdge* pcoe = ec.retrievePossiblySplit(id_pcoe, id_pcie, true);
NBEdge* pcie = ec.retrievePossiblySplit(id_pcie, id_pcoe, false);
// check whether it's ending node is the node the prohibited
// edge end at
if (pcoe != nullptr && pcie != nullptr && pcoe->getToNode() == e->getToNode()) {
// if so, simply prohibit the connections
NBNode* node = e->getToNode();
const EdgeVector& connected = e->getConnectedEdges();
for (EdgeVector::const_iterator i = connected.begin(); i != connected.end(); i++) {
node->addSortedLinkFoes(
NBConnection(e, *i),
NBConnection(pcoe, pcie));
}
} else {
WRITE_WARNING("Would have to split edge '" + e->getID() + "' to build a prohibition");
refusedProhibits++;
// quite ugly - why was it not build?
return false;
/*
std::string nid1 = e->getID() + "[0]";
std::string nid2 = e->getID() + "[1]";
if(ec.splitAt(e, node)) {
node->addSortedLinkFoes(
NBConnection(
ec.retrieve(nid1),
ec.retrieve(nid2)
//.........这里部分代码省略.........
示例3: 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);
}
}
}