本文整理汇总了C++中OptionsCont::exists方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionsCont::exists方法的具体用法?C++ OptionsCont::exists怎么用?C++ OptionsCont::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionsCont
的用法示例。
在下文中一共展示了OptionsCont::exists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toString
void
NWWriter_XML::writeNodes(const OptionsCont& oc, NBNodeCont& nc) {
const GeoConvHelper& gch = GeoConvHelper::getFinal();
bool useGeo = oc.exists("proj.plain-geo") && oc.getBool("proj.plain-geo");
if (useGeo && !gch.usingGeoProjection()) {
WRITE_WARNING("Ignoring option \"proj.plain-geo\" because no geo-conversion has been defined");
useGeo = false;
}
const bool geoAccuracy = useGeo || gch.usingInverseGeoProjection();
OutputDevice& device = OutputDevice::getDevice(oc.getString("plain-output-prefix") + ".nod.xml");
device.writeXMLHeader("nodes", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/nodes_file.xsd\"");
// write network offsets and projection to allow reconstruction of original coordinates
if (!useGeo) {
NWWriter_SUMO::writeLocation(device);
}
// write nodes
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
NBNode* n = (*i).second;
device.openTag(SUMO_TAG_NODE);
device.writeAttr(SUMO_ATTR_ID, n->getID());
// write position
Position pos = n->getPosition();
if (useGeo) {
gch.cartesian2geo(pos);
}
if (geoAccuracy) {
device.setPrecision(GEO_OUTPUT_ACCURACY);
}
NWFrame::writePositionLong(pos, device);
if (geoAccuracy) {
device.setPrecision();
}
device.writeAttr(SUMO_ATTR_TYPE, toString(n->getType()));
if (n->isTLControlled()) {
const std::set<NBTrafficLightDefinition*>& tlss = n->getControllingTLS();
// set may contain multiple programs for the same id.
// make sure ids are unique and sorted
std::set<std::string> tlsIDs;
for (std::set<NBTrafficLightDefinition*>::const_iterator it_tl = tlss.begin(); it_tl != tlss.end(); it_tl++) {
tlsIDs.insert((*it_tl)->getID());
}
std::vector<std::string> sortedIDs(tlsIDs.begin(), tlsIDs.end());
sort(sortedIDs.begin(), sortedIDs.end());
device.writeAttr(SUMO_ATTR_TLID, sortedIDs);
}
device.closeTag();
}
device.close();
}
示例2: Position
bool
GeoConvHelper::init(OptionsCont& oc) {
std::string proj = "!"; // the default
double scale = oc.getFloat("proj.scale");
double rot = oc.getFloat("proj.rotate");
Position offset = Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));
bool inverse = oc.exists("proj.inverse") && oc.getBool("proj.inverse");
bool flatten = oc.exists("flatten") && oc.getBool("flatten");
if (oc.getBool("simple-projection")) {
proj = "-";
}
#ifdef PROJ_API_FILE
if (oc.getBool("proj.inverse") && oc.getString("proj") == "!") {
WRITE_ERROR("Inverse projection works only with explicit proj parameters.");
return false;
}
unsigned numProjections = oc.getBool("simple-projection") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + oc.getBool("proj.dhdnutm") + (oc.getString("proj").length() > 1);
if (numProjections > 1) {
WRITE_ERROR("The projection method needs to be uniquely defined.");
return false;
}
if (oc.getBool("proj.utm")) {
proj = "UTM";
} else if (oc.getBool("proj.dhdn")) {
proj = "DHDN";
} else if (oc.getBool("proj.dhdnutm")) {
proj = "DHDN_UTM";
} else if (!oc.isDefault("proj")) {
proj = oc.getString("proj");
}
#endif
myProcessing = GeoConvHelper(proj, offset, Boundary(), Boundary(), scale, rot, inverse, flatten);
myFinal = myProcessing;
return true;
}
示例3: ProcessError
void
NBEdgeCont::applyOptions(OptionsCont& oc) {
myAmLeftHanded = oc.getBool("lefthand");
// set edges dismiss/accept options
myEdgesMinSpeed = oc.isSet("keep-edges.min-speed") ? oc.getFloat("keep-edges.min-speed") : -1;
myRemoveEdgesAfterJoining = oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload");
if (oc.isSet("keep-edges.explicit")) {
const std::vector<std::string> edges = oc.getStringVector("keep-edges.explicit");
myEdges2Keep.insert(edges.begin(), edges.end());
}
if (oc.isSet("remove-edges.explicit")) {
const std::vector<std::string> edges = oc.getStringVector("remove-edges.explicit");
myEdges2Remove.insert(edges.begin(), edges.end());
}
if (oc.exists("keep-edges.by-vclass") && oc.isSet("keep-edges.by-vclass")) {
const std::vector<std::string> classes = oc.getStringVector("keep-edges.by-vclass");
for (std::vector<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
myVehicleClasses2Keep |= getVehicleClassID(*i);
}
}
if (oc.exists("remove-edges.by-vclass") && oc.isSet("remove-edges.by-vclass")) {
const std::vector<std::string> classes = oc.getStringVector("remove-edges.by-vclass");
for (std::vector<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
myVehicleClasses2Remove |= getVehicleClassID(*i);
}
}
if (oc.exists("keep-edges.by-type") && oc.isSet("keep-edges.by-type")) {
const std::vector<std::string> types = oc.getStringVector("keep-edges.by-type");
myTypes2Keep.insert(types.begin(), types.end());
}
if (oc.exists("remove-edges.by-type") && oc.isSet("remove-edges.by-type")) {
const std::vector<std::string> types = oc.getStringVector("remove-edges.by-type");
myTypes2Remove.insert(types.begin(), types.end());
}
if (oc.isSet("keep-edges.in-boundary") || oc.isSet("keep-edges.in-geo-boundary")) {
std::vector<std::string> polyS = oc.getStringVector(oc.isSet("keep-edges.in-boundary") ?
"keep-edges.in-boundary" : "keep-edges.in-geo-boundary");
// !!! throw something if length<4 || length%2!=0?
std::vector<SUMOReal> poly;
for (std::vector<std::string>::iterator i = polyS.begin(); i != polyS.end(); ++i) {
poly.push_back(TplConvert::_2SUMOReal((*i).c_str())); // !!! may throw something anyhow...
}
if (poly.size() < 4) {
throw ProcessError("Invalid boundary: need at least 2 coordinates");
} else if (poly.size() % 2 != 0) {
throw ProcessError("Invalid boundary: malformed coordinate");
} else if (poly.size() == 4) {
// prunning boundary (box)
myPrunningBoundary.push_back(Position(poly[0], poly[1]));
myPrunningBoundary.push_back(Position(poly[2], poly[1]));
myPrunningBoundary.push_back(Position(poly[2], poly[3]));
myPrunningBoundary.push_back(Position(poly[0], poly[3]));
} else {
for (std::vector<SUMOReal>::iterator j = poly.begin(); j != poly.end();) {
SUMOReal x = *j++;
SUMOReal y = *j++;
myPrunningBoundary.push_back(Position(x, y));
}
}
if (oc.isSet("keep-edges.in-geo-boundary")) {
NBNetBuilder::transformCoordinates(myPrunningBoundary, false);
}
}
}
示例4: ProcessError
void
NBNodeCont::guessTLs(OptionsCont& oc, NBTrafficLightLogicCont& tlc) {
// build list of definitely not tls-controlled junctions
std::vector<NBNode*> ncontrolled;
if (oc.isSet("tls.unset")) {
std::vector<std::string> notTLControlledNodes = oc.getStringVector("tls.unset");
for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
NBNode* n = NBNodeCont::retrieve(*i);
if (n == 0) {
throw ProcessError(" The node '" + *i + "' to set as not-controlled is not known.");
}
std::set<NBTrafficLightDefinition*> tls = n->getControllingTLS();
for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
(*j)->removeNode(n);
}
n->removeTrafficLights();
ncontrolled.push_back(n);
}
}
TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
// loop#1 checking whether the node shall be tls controlled,
// because it is assigned to a district
if (oc.exists("tls.taz-nodes") && oc.getBool("tls.taz-nodes")) {
for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
NBNode* cur = (*i).second;
if (cur->isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
setAsTLControlled(cur, tlc, type);
}
}
}
// maybe no tls shall be guessed
if (!oc.getBool("tls.guess")) {
return;
}
// guess joined tls first, if wished
if (oc.getBool("tls.join")) {
// get node clusters
std::vector<std::set<NBNode*> > cands;
generateNodeClusters(oc.getFloat("tls.join-dist"), cands);
// check these candidates (clusters) whether they should be controlled by a tls
for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
std::set<NBNode*>& c = (*i);
// regard only junctions which are not yet controlled and are not
// forbidden to be controlled
for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
c.erase(j++);
} else {
++j;
}
}
// check whether the cluster should be controlled
if (!shouldBeTLSControlled(c)) {
i = cands.erase(i);
} else {
++i;
}
}
// cands now only contain sets of junctions that shall be joined into being tls-controlled
unsigned int index = 0;
for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
std::vector<NBNode*> nodes;
for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
nodes.push_back(*j);
}
std::string id = "joinedG_" + toString(index++);
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
if (!tlc.insert(tlDef)) {
// actually, nothing should fail here
WRITE_WARNING("Could not build guessed, joined tls");
delete tlDef;
return;
}
}
}
// guess tls
for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
NBNode* cur = (*i).second;
// do nothing if already is tl-controlled
if (cur->isTLControlled()) {
continue;
}
// do nothing if in the list of explicit non-controlled junctions
if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
continue;
}
std::set<NBNode*> c;
c.insert(cur);
if (!shouldBeTLSControlled(c) || cur->getIncomingEdges().size() < 3) {
continue;
}
setAsTLControlled((*i).second, tlc, type);
}
}
示例5: getType
void
ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const {
if (typeos != nullptr && getType() != nullptr && !getType()->saved) {
getType()->write(*typeos);
getType()->saved = true;
}
if (getType() != nullptr && !getType()->saved) {
getType()->write(os);
getType()->saved = asAlternatives;
}
const bool writeTrip = options.exists("write-trips") && options.getBool("write-trips");
const bool writeGeoTrip = writeTrip && options.getBool("write-trips.geo");
// write the vehicle (new style, with included routes)
getParameter().write(os, options, writeTrip ? SUMO_TAG_TRIP : SUMO_TAG_VEHICLE);
// save the route
if (writeTrip) {
const ConstROEdgeVector edges = myRoute->getFirstRoute()->getEdgeVector();
const ROEdge* from = nullptr;
const ROEdge* to = nullptr;
if (edges.size() > 0) {
if (edges.front()->isTazConnector()) {
if (edges.size() > 1) {
from = edges[1];
}
} else {
from = edges[0];
}
if (edges.back()->isTazConnector()) {
if (edges.size() > 1) {
to = edges[edges.size() - 2];
}
} else {
to = edges[edges.size() - 1];
}
}
if (from != nullptr) {
if (writeGeoTrip) {
Position fromPos = from->getLanes()[0]->getShape().positionAtOffset2D(0);
if (GeoConvHelper::getFinal().usingGeoProjection()) {
os.setPrecision(gPrecisionGeo);
GeoConvHelper::getFinal().cartesian2geo(fromPos);
os.writeAttr(SUMO_ATTR_FROMLONLAT, fromPos);
os.setPrecision(gPrecision);
} else {
os.writeAttr(SUMO_ATTR_FROMXY, fromPos);
}
} else {
os.writeAttr(SUMO_ATTR_FROM, from->getID());
}
}
if (to != nullptr) {
if (writeGeoTrip) {
Position toPos = to->getLanes()[0]->getShape().positionAtOffset2D(to->getLanes()[0]->getShape().length2D());
if (GeoConvHelper::getFinal().usingGeoProjection()) {
os.setPrecision(gPrecisionGeo);
GeoConvHelper::getFinal().cartesian2geo(toPos);
os.writeAttr(SUMO_ATTR_TOLONLAT, toPos);
os.setPrecision(gPrecision);
} else {
os.writeAttr(SUMO_ATTR_TOXY, toPos);
}
} else {
os.writeAttr(SUMO_ATTR_TO, to->getID());
}
}
if (getParameter().via.size() > 0) {
if (writeGeoTrip) {
PositionVector viaPositions;
for (const std::string& viaID : getParameter().via) {
const ROEdge* viaEdge = RONet::getInstance()->getEdge(viaID);
assert(viaEdge != nullptr);
Position viaPos = viaEdge->getLanes()[0]->getShape().positionAtOffset2D(viaEdge->getLanes()[0]->getShape().length2D() / 2);
viaPositions.push_back(viaPos);
}
if (GeoConvHelper::getFinal().usingGeoProjection()) {
for (int i = 0; i < (int)viaPositions.size(); i++) {
GeoConvHelper::getFinal().cartesian2geo(viaPositions[i]);
}
os.setPrecision(gPrecisionGeo);
os.writeAttr(SUMO_ATTR_VIALONLAT, viaPositions);
os.setPrecision(gPrecision);
} else {
os.writeAttr(SUMO_ATTR_VIAXY, viaPositions);
}
} else {
os.writeAttr(SUMO_ATTR_VIA, getParameter().via);
}
}
} else {
myRoute->writeXMLDefinition(os, this, asAlternatives, options.getBool("exit-times"));
}
for (std::vector<SUMOVehicleParameter::Stop>::const_iterator stop = getParameter().stops.begin(); stop != getParameter().stops.end(); ++stop) {
stop->write(os);
}
getParameter().writeParams(os);
os.closeTag();
}
示例6: mirrorX
void
NBNetBuilder::compute(OptionsCont& oc,
const std::set<std::string>& explicitTurnarounds,
bool removeElements) {
GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing();
const bool lefthand = oc.getBool("lefthand");
if (lefthand) {
mirrorX();
};
// MODIFYING THE SETS OF NODES AND EDGES
// Removes edges that are connecting the same node
long before = SysUtils::getCurrentMillis();
PROGRESS_BEGIN_MESSAGE("Removing self-loops");
myNodeCont.removeSelfLoops(myDistrictCont, myEdgeCont, myTLLCont);
PROGRESS_TIME_MESSAGE(before);
//
if (oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
before = SysUtils::getCurrentMillis();
PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
myNodeCont.removeIsolatedRoads(myDistrictCont, myEdgeCont, myTLLCont);
PROGRESS_TIME_MESSAGE(before);
}
//
if (oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
if (oc.isSet("keep-edges.explicit") || oc.isSet("keep-edges.input-file")) {
before = SysUtils::getCurrentMillis();
PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
myEdgeCont.removeUnwishedEdges(myDistrictCont);
PROGRESS_TIME_MESSAGE(before);
}
}
if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
// preliminary geometry computations to determine the length of edges
// This depends on turning directions and sorting of edge list
// in case junctions are joined geometry computations have to be repeated
// preliminary roundabout computations to avoid damaging roundabouts via junctions.join or ramps.guess
NBTurningDirectionsComputer::computeTurnDirections(myNodeCont, false);
NBNodesEdgesSorter::sortNodesEdges(myNodeCont);
myEdgeCont.computeLaneShapes();
myNodeCont.computeNodeShapes();
myEdgeCont.computeEdgeShapes();
if (oc.getBool("roundabouts.guess")) {
myEdgeCont.guessRoundabouts();
}
const std::set<EdgeSet>& roundabouts = myEdgeCont.getRoundabouts();
for (std::set<EdgeSet>::const_iterator it_round = roundabouts.begin();
it_round != roundabouts.end(); ++it_round) {
std::vector<std::string> nodeIDs;
for (EdgeSet::const_iterator it_edge = it_round->begin(); it_edge != it_round->end(); ++it_edge) {
nodeIDs.push_back((*it_edge)->getToNode()->getID());
}
myNodeCont.addJoinExclusion(nodeIDs);
}
}
// join junctions (may create new "geometry"-nodes so it needs to come before removing these
if (oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
}
unsigned int numJoined = myNodeCont.joinLoadedClusters(myDistrictCont, myEdgeCont, myTLLCont);
if (oc.getBool("junctions.join")) {
before = SysUtils::getCurrentMillis();
PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont);
PROGRESS_TIME_MESSAGE(before);
}
if (oc.getBool("junctions.join") || (oc.exists("ramps.guess") && oc.getBool("ramps.guess"))) {
// reset geometry to avoid influencing subsequent steps (ramps.guess)
myEdgeCont.computeLaneShapes();
}
if (numJoined > 0) {
// bit of a misnomer since we're already done
WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
}
//
if (removeElements) {
unsigned int no = 0;
const bool removeGeometryNodes = oc.exists("geometry.remove") && oc.getBool("geometry.remove");
before = SysUtils::getCurrentMillis();
PROGRESS_BEGIN_MESSAGE("Removing empty nodes" + std::string(removeGeometryNodes ? " and geometry nodes" : ""));
// removeUnwishedNodes needs turnDirections. @todo: try to call this less often
NBTurningDirectionsComputer::computeTurnDirections(myNodeCont, false);
no = myNodeCont.removeUnwishedNodes(myDistrictCont, myEdgeCont, myTLLCont, removeGeometryNodes);
PROGRESS_TIME_MESSAGE(before);
WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
}
// MOVE TO ORIGIN
// compute new boundary after network modifications have taken place
Boundary boundary;
for (std::map<std::string, NBNode*>::const_iterator it = myNodeCont.begin(); it != myNodeCont.end(); ++it) {
boundary.add(it->second->getPosition());
}
for (std::map<std::string, NBEdge*>::const_iterator it = myEdgeCont.begin(); it != myEdgeCont.end(); ++it) {
boundary.add(it->second->getGeometry().getBoxBoundary());
}
geoConvHelper.setConvBoundary(boundary);
//.........这里部分代码省略.........