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); } }
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); }
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::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; }
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)); }