void PositionVector::append(const PositionVector& v, SUMOReal sameThreshold) { if (size() > 0 && v.size() > 0 && back().distanceTo(v[0]) < sameThreshold) { copy(v.begin() + 1, v.end(), back_inserter(*this)); } else { copy(v.begin(), v.end(), back_inserter(*this)); } }
void FeatureInvestigator::printBayesian ( Persistance::TextWriter& writer, Feature& feature, const PositionVector& positions) { const int motifLength = feature.assignment ().length (); CPositionIterator it (positions.begin (), positions.end ()); for (; it.hasNext () ; it.next()) { const SeqPosition& position = *(*it); StrBuffer buf; USELESS (int middleSection = ) position.getSeedString (buf, motifLength, _outputLength, '?'); writer << '('; int length = buf.length(); for (int i=0 ; i<length ; i++) { writer << buf [i] << ' '; } writer << ')'; writer.writeln (); } }
void BinaryFormatter::writeAttr(std::ostream& into, const SumoXMLAttr attr, const PositionVector& val) { BinaryFormatter::writeAttrHeader(into, attr, BF_LIST); FileHelpers::writeInt(into, static_cast<int>(val.size())); for (PositionVector::const_iterator pos = val.begin(); pos != val.end(); ++pos) { writePosition(into, *pos); } }
bool NBNetBuilder::transformCoordinates(PositionVector& from, bool includeInBoundary, GeoConvHelper* from_srs) { const SUMOReal maxLength = OptionsCont::getOptions().getFloat("geometry.max-segment-length"); if (maxLength > 0 && from.size() > 1) { // transformation to cartesian coordinates must happen before we can check segment length PositionVector copy = from; for (int i = 0; i < (int) from.size(); i++) { transformCoordinates(copy[i], false); } // check lengths and insert new points where needed (in the original // coordinate system) int inserted = 0; for (int i = 0; i < (int)copy.size() - 1; i++) { Position start = from[i + inserted]; Position end = from[i + inserted + 1]; SUMOReal length = copy[i].distanceTo(copy[i + 1]); const Position step = (end - start) * (maxLength / length); int steps = 0; while (length > maxLength) { length -= maxLength; steps++; from.insert(from.begin() + i + inserted + 1, start + (step * steps)); inserted++; } } // now perform the transformation again so that height mapping can be // performed for the new points } bool ok = true; for (int i = 0; i < (int) from.size(); i++) { ok = ok && transformCoordinates(from[i], includeInBoundary, from_srs); } return ok; }
void GLHelper::drawFilledPoly(const PositionVector& v, bool close) { if (v.size() == 0) { return; } glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) { const Position& p = *i; glVertex2d(p.x(), p.y()); } if (close) { const Position& p = *(v.begin()); glVertex2d(p.x(), p.y()); } glEnd(); }
std::vector<SUMOReal> PositionVector::intersectsAtLengths2D(const PositionVector& other) const { std::vector<SUMOReal> ret; for (const_iterator i = other.begin(); i != other.end() - 1; i++) { std::vector<SUMOReal> atSegment = intersectsAtLengths2D(Line(*i, *(i + 1))); copy(atSegment.begin(), atSegment.end(), back_inserter(ret)); } return ret; }
void FeatureInvestigator::printMotif ( Persistance::TextTableReport::Output& writer, Feature& feature, const PositionVector& positions) { CPositionIterator it (positions.begin (), positions.end ()); for (; it.hasNext () ; it.next ()) { printMotifPosition (writer, feature, *(*it)); } }
int PositionVector::appendWithCrossingPoint(const PositionVector& v) { if (back().distanceTo(v[0]) < 2) { // !!! heuristic copy(v.begin() + 1, v.end(), back_inserter(*this)); return 1; } // Line l1((*this)[static_cast<int>(size()) - 2], back()); l1.extrapolateBy(100); Line l2(v[0], v[1]); l2.extrapolateBy(100); if (l1.intersects(l2) && l1.intersectsAtLength2D(l2) < l1.length2D() - 100) { // !!! heuristic Position p = l1.intersectsAt(l2); (*this)[static_cast<int>(size()) - 1] = p; copy(v.begin() + 1, v.end(), back_inserter(*this)); return 2; } else { copy(v.begin(), v.end(), back_inserter(*this)); return 3; } }
NIVissimAbstractEdge::NIVissimAbstractEdge(int id, const PositionVector& geom) : myID(id), myNode(-1) { // convert/publicate geometry for (PositionVector::const_iterator i = geom.begin(); i != geom.end(); ++i) { Position p = *i; if (!NBNetBuilder::transformCoordinates(p)) { WRITE_WARNING("Unable to project coordinates for edge '" + toString(id) + "'."); } myGeom.push_back_noDoublePos(p); } // dictionary(id, this); }
std::vector<SUMOReal> PositionVector::distances(const PositionVector& s, bool perpendicular) const { std::vector<SUMOReal> ret; const_iterator i; for (i = begin(); i != end(); i++) { const SUMOReal dist = s.distance(*i, perpendicular); if (dist != GeomHelper::INVALID_OFFSET) { ret.push_back(dist); } } for (i = s.begin(); i != s.end(); i++) { const SUMOReal dist = distance(*i, perpendicular); if (dist != GeomHelper::INVALID_OFFSET) { ret.push_back(dist); } } return ret; }
bool NIImporter_DlrNavteq::EdgesHandler::report(const std::string& result) { // parse version number from first comment line and initialize column definitions if (result[0] == '#') { if (!myColumns.empty()) { return true; } const double version = readVersion(result, myFile); if (version > 0) { myVersion = version; // init columns const int NUM_COLUMNS = 25; // @note arrays must match this size! const int MC = MISSING_COLUMN; if (myVersion < 3) { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, MC, MC, -21}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } else if (myVersion < 6) { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, -23}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } else { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } } return true; } if (myColumns.empty()) { throw ProcessError("Missing version string in file '" + myFile + "'."); } // interpret link attributes StringTokenizer st(result, StringTokenizer::WHITECHARS); const std::string id = getColumn(st, LINK_ID); // form of way (for priority and permissions) int form_of_way; try { form_of_way = StringUtils::toInt(getColumn(st, FORM_OF_WAY)); } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for form_of_way of link '" + id + "'."); } // brunnel type (bridge/tunnel/ferry (for permissions) int brunnel_type; try { brunnel_type = StringUtils::toInt(getColumn(st, BRUNNEL_TYPE)); } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for brunnel_type of link '" + id + "'."); } // priority based on street_type / frc int priority; try { priority = -StringUtils::toInt(getColumn(st, FUNCTIONAL_ROAD_CLASS)); // lower priority using form_of_way if (form_of_way == 11) { priority -= 1; // frontage road, very often with lowered curb } else if (form_of_way > 11) { priority -= 2; // parking/service access assume lowered curb } } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for street_type of link '" + id + "')."); } // street name std::string streetName = getStreetNameFromIDs( getColumn(st, NAME_ID1_REGIONAL), getColumn(st, NAME_ID2_LOCAL)); // try to get the nodes const std::string fromID = getColumn(st, NODE_ID_FROM); const std::string toID = getColumn(st, NODE_ID_TO); NBNode* from = myNodeCont.retrieve(fromID); NBNode* to = myNodeCont.retrieve(toID); if (from == nullptr) { throw ProcessError("The from-node '" + fromID + "' of link '" + id + "' could not be found"); } if (to == nullptr) { throw ProcessError("The to-node '" + toID + "' of link '" + id + "' could not be found"); } // speed double speed; try { speed = StringUtils::toInt(getColumn(st, SPEED_RESTRICTION, "-1")) / 3.6; } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for the SPEED_RESTRICTION of link '" + id + "'."); } if (speed < 0) { // speed category as fallback speed = NINavTeqHelper::getSpeed(id, getColumn(st, SPEED_CATEGORY)); } // number of lanes int numLanes; try { // EXTENDED_NUMBER_OF_LANES is prefered but may not be defined numLanes = StringUtils::toInt(getColumn(st, EXTENDED_NUMBER_OF_LANES, "-1")); if (numLanes == -1) { numLanes = NINavTeqHelper::getLaneNumber(id, getColumn(st, NUMBER_OF_LANES), speed); } } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for the number of lanes of link '" + id + "'."); } const std::string navTeqTypeId = getColumn(st, VEHICLE_TYPE) + "_" + getColumn(st, FORM_OF_WAY); // build the edge NBEdge* e = nullptr; const std::string interID = getColumn(st, BETWEEN_NODE_ID); if (interID == "-1") { e = new NBEdge(id, from, to, myTypeCont.knows(navTeqTypeId) ? navTeqTypeId : "", speed, numLanes, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, streetName); } else { PositionVector geoms = myGeoms[interID]; if (getColumn(st, CONNECTION, "0") == "1") { geoms = geoms.reverse(); } geoms.insert(geoms.begin(), from->getPosition()); geoms.push_back(to->getPosition()); const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? id : ""; e = new NBEdge(id, from, to, myTypeCont.knows(navTeqTypeId) ? navTeqTypeId : "", speed, numLanes, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, geoms, streetName, origID, LANESPREAD_CENTER); } // NavTeq imports can be done with a typemap (if supplied), if not, the old defaults are used if (myTypeCont.knows(navTeqTypeId)) { e->setPermissions(myTypeCont.getPermissions(navTeqTypeId)); } else { // add vehicle type information to the edge if (myVersion < 6.0) { NINavTeqHelper::addVehicleClasses(*e, getColumn(st, VEHICLE_TYPE)); } else { NINavTeqHelper::addVehicleClassesV6(*e, getColumn(st, VEHICLE_TYPE)); } if (e->getPermissions() == SVCAll) { e->setPermissions(myTypeCont.getPermissions("")); } // permission modifications based on form_of_way if (form_of_way == 14) { // pedestrian area (fussgaengerzone) // unfortunately, the veh_type string is misleading in this case e->disallowVehicleClass(-1, SVC_PASSENGER); } // permission modifications based on brunnel_type if (brunnel_type == 10) { // ferry e->setPermissions(SVC_SHIP, -1); } } // insert the edge to the network if (!myEdgeCont.insert(e)) { delete e; throw ProcessError("Could not add edge '" + id + "'."); } return true; }
void PCLoaderXML::myStartElement(int element, const SUMOSAXAttributes& attrs) { if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) { return; } if (element == SUMO_TAG_POI) { bool ok = true; // get the id, report an error if not given or empty... std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); SUMOReal x = attrs.get<SUMOReal>(SUMO_ATTR_X, id.c_str(), ok); SUMOReal y = attrs.get<SUMOReal>(SUMO_ATTR_Y, id.c_str(), ok); std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type")); if (!ok) { return; } Position pos(x, y); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for POI '" + id + "'."); } // patch the values bool discard = myOptions.getBool("discard"); SUMOReal layer = (SUMOReal)myOptions.getInt("layer"); RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = def.color; discard = def.discard; layer = (SUMOReal)def.layer; } else { id = myOptions.getString("prefix") + id; color = RGBColor::parseColor(myOptions.getString("color")); } layer = attrs.getOpt<SUMOReal>(SUMO_ATTR_LAYER, id.c_str(), ok, layer); if (attrs.hasAttribute(SUMO_ATTR_COLOR)) { color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, id.c_str(), ok); } SUMOReal angle = attrs.getOpt<SUMOReal>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE); std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE); if (imgFile != "" && !FileHelpers::isAbsolute(imgFile)) { imgFile = FileHelpers::getConfigurationRelative(getFileName(), imgFile); } SUMOReal imgWidth = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, id.c_str(), ok, Shape::DEFAULT_IMG_WIDTH); SUMOReal imgHeight = attrs.getOpt<SUMOReal>(SUMO_ATTR_HEIGHT, id.c_str(), ok, Shape::DEFAULT_IMG_HEIGHT); if (!ok) { return; } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } PointOfInterest* poi = new PointOfInterest(id, type, color, pos, layer, angle, imgFile, imgWidth, imgHeight); if (!myCont.insert(id, poi, (int)layer, ignorePrunning)) { WRITE_ERROR("POI '" + id + "' could not be added."); delete poi; } } } if (element == SUMO_TAG_POLY) { bool discard = myOptions.getBool("discard"); SUMOReal layer = (SUMOReal)myOptions.getInt("layer"); bool ok = true; std::string id = attrs.getOpt<std::string>(SUMO_ATTR_ID, myCurrentID.c_str(), ok, ""); std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, myCurrentID.c_str(), ok, myOptions.getString("type")); if (!ok) { return; } RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = def.color; discard = def.discard; layer = (SUMOReal)def.layer; } else { id = myOptions.getString("prefix") + id; color = RGBColor::parseColor(myOptions.getString("color")); } layer = attrs.getOpt<SUMOReal>(SUMO_ATTR_LAYER, id.c_str(), ok, layer); if (attrs.hasAttribute(SUMO_ATTR_COLOR)) { color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, id.c_str(), ok); } SUMOReal angle = attrs.getOpt<SUMOReal>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE); std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE); if (imgFile != "" && !FileHelpers::isAbsolute(imgFile)) { imgFile = FileHelpers::getConfigurationRelative(getFileName(), imgFile); } bool fill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, false); if (!ok) { return; } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } myCurrentID = id; myCurrentType = type; myCurrentColor = color; myCurrentIgnorePrunning = ignorePrunning; myCurrentLayer = layer; PositionVector pshape = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, myCurrentID.c_str(), ok); if (!ok) { return; } PositionVector shape; for (PositionVector::ContType::const_iterator i = pshape.begin(); i != pshape.end(); ++i) { Position pos((*i)); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for polygon '" + myCurrentID + "'."); } shape.push_back(pos); } Polygon* poly = new Polygon(myCurrentID, myCurrentType, myCurrentColor, shape, fill, layer, angle, imgFile); if (!myCont.insert(myCurrentID, poly, (int)myCurrentLayer, myCurrentIgnorePrunning)) { WRITE_ERROR("Polygon '" + myCurrentID + "' could not be added."); delete poly; } } } }
// ------------ Adding items to the container void PositionVector::push_back(const PositionVector& p) { copy(p.begin(), p.end(), back_inserter(*this)); }