void ShapeFileOptionsWidget::updateFieldValues() { for (QMap<QTreeWidgetItem*, Feature*>::iterator iter = mFeatures.begin(); iter != mFeatures.end(); ++iter) { QTreeWidgetItem* pItem = iter.key(); Feature* pFeature = iter.value(); if ((pItem != NULL) && (pFeature != NULL)) { vector<string> fieldNames = pFeature->getFieldNames(); for (vector<string>::iterator fieldIter = fieldNames.begin(); fieldIter != fieldNames.end(); ++fieldIter) { string name = *fieldIter; if (!name.empty()) { string type = pFeature->getFieldType(name); QString strValue; const DataVariant &var = pFeature->getFieldValue(name); strValue = QString::fromStdString(var.toDisplayString()); int iColumn = getColumn(QString::fromLatin1(name.c_str())); if (iColumn == -1) { addField(QString::fromLatin1(name.c_str()), QString::fromLatin1(type.c_str())); iColumn = getColumn(QString::fromLatin1(name.c_str())); } if (iColumn != -1) { pItem->setText(iColumn, strValue); } } } } } }
void Characterization::addCommandLineArgs(TCLAP::CmdLine *cmd) { cmd->add(argLevel); cmd->add(argNO); cmd->add(argOnly); list<Feature*>::iterator i; for(i=tasks.begin(); i != tasks.end(); ++i) { Feature* task = *i; list<TCLAP::Arg*>* args = task->getCharacterizationCommandlineArguments(); list<TCLAP::Arg*>::iterator j; for(j=args->begin(); j != args->end(); ++j) { TCLAP::Arg* arg = *j; cmd->add(arg); } } }
bool overlaps_(const Feature& feature, const double rt, const double pc_mz, const double rt_tolerance) const { if (feature.getConvexHulls().empty()) { LOG_WARN << "HighResPrecursorMassCorrector warning: at least one feature has no convex hull - omitting feature for matching" << std::endl; } // get bounding box and extend by retention time tolerance DBoundingBox<2> box = feature.getConvexHull().getBoundingBox(); DPosition<2> extend_rt(rt_tolerance, 0.01); box.setMin(box.minPosition() - extend_rt); box.setMax(box.maxPosition() + extend_rt); DPosition<2> pc_pos(rt, pc_mz); if (box.encloses(pc_pos)) { return true; } else { return false; } }
/* Try insert \a n into the tree with this node as root. n is inserted as a child if it has a dependency to this node. Returns true if child is inserted into the tree, false otherwise. */ bool Node::insert(Node *n) { Feature *f = const_cast<Feature*>(n->feature); if (feature->supports().contains(f)) { children.append(n); qSort(children.begin(), children.end(), nodePtrLessThan); n->parent = this; return true; } foreach (Node *child, children) if (child->insert(n)) return true; return false; }
bool ShapeFile::addField(const string& name, const string& type) { if (hasField(name)) { return false; } mFields[name] = type; for (vector<Feature*>::iterator iter = mFeatures.begin(); iter != mFeatures.end(); ++iter) { Feature* pFeature = *iter; if (pFeature != NULL) { DataVariant value; if (type == "int") { int intValue = 0; value = DataVariant(intValue); } else if (type == "double") { double doubleValue = 0.0; value = DataVariant(doubleValue); } else if (type == "string") { string stringValue; value = DataVariant(stringValue); } pFeature->addField(name, value); } } return true; }
// --------------------------------------------------------- bool InCommand::execute() { if ( myAdventurer->getStrength() < myAdventurer->getInventory()->getWeight() ) cout << "I am too burdened to move.\n\n"; else { Direction dir = myAdventurer->getPreviousDirection(); Feature * next; next = myAdventurer->getCurrentFeature()->getExit( dir ); if ( !next ) { cout << "I can't go that way.\n"; } else { if ( myAdventurer->getCurrentFeature()->isClosed() ) { cout << "The door is closed.\n"; } else { myAdventurer->setCurrentFeature( next ); myAdventurer->setPreviousDirection( dir ); cout << "I am now in "; next->printName( cout ); cout << ".\n"; } } myAdventurer->move(); } return true; }
// TODO void? Handle<Value> Feature::addGeometry(const Arguments& args) { HandleScope scope; Feature* fp = node::ObjectWrap::Unwrap<Feature>(args.This()); if (args.Length() >= 1 ) { Local<Value> value = args[0]; if (value->IsNull() || value->IsUndefined()) { return ThrowException(Exception::TypeError(String::New("mapnik.Geometry instance expected"))); } else { Local<Object> obj = value->ToObject(); if (Geometry::constructor->HasInstance(obj)) { Geometry* g = node::ObjectWrap::Unwrap<Geometry>(obj); try { std::auto_ptr<mapnik::geometry_type> geom_ptr = g->get(); if (geom_ptr.get()) { fp->get()->add_geometry(geom_ptr.get()); geom_ptr.release(); } else { return ThrowException(Exception::Error( String::New("empty geometry!"))); } } catch (std::exception const& ex ) { return ThrowException(Exception::Error( String::New(ex.what()))); } } } } return Undefined(); }
void OGR_FeatureStore::calcExtent() { OGR_SCOPE_LOCK(); OGREnvelope envelope; if ( OGR_L_GetExtent( layer_handle, &envelope, 1 ) == OGRERR_NONE ) { SpatialReference* sr = getSRS(); extent = GeoExtent( GeoPoint( envelope.MinX, envelope.MinY, sr ), GeoPoint( envelope.MaxX, envelope.MaxY, sr ), sr ); } else { osgGIS::notify( osg::WARN ) << "Unable to compute extent for feature store" << std::endl; extent = GeoExtent::invalid(); } if ( extent.isValid() && extent.isEmpty() ) { for( FeatureCursor cursor = getCursor(); cursor.hasNext(); ) { Feature* feature = cursor.next(); const GeoShapeList& shapes = feature->getShapes(); for( GeoShapeList::const_iterator i = shapes.begin(); i != shapes.end(); i++ ) { const GeoExtent& feature_extent = i->getExtent(); extent.expandToInclude( feature_extent ); } } } }
void FeatureInvestigator::createPSSM (PositionWeightType positionWeightType, Feature& feature_i, const PositionVector& positions, PSSM& outPSSM) { const int seed_length = feature_i.assignment ().length (); outPSSM = PSSM ( positionWeightType, _parameters.langauge ().code (), seed_length, _outputLength, positions, *_parameters.wf ()); }
int main(int argc, char* argv[]) { if (argc < 3) { cerr << "too few arguments" << endl; error(); return -1; } Mat image = imread(argv[1]); Feature* feature; if (!strcmp(argv[2], "color")) { feature = new ColorFeature(); } else { cerr << "unsupported feature" << endl; error(); return -1; } feature->getFeature(image); feature->printFeature(); delete feature; return 0; }
/* method: getExtent of class Feature */ static int tolua_Lua_ScriptEngine_tolua_Feature_getExtent00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"Feature",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { Feature* self = (Feature*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getExtent'",NULL); #endif { GeoExtent tolua_ret = (GeoExtent) self->getExtent(); { #ifdef __cplusplus void* tolua_obj = new GeoExtent(tolua_ret); tolua_pushusertype(tolua_S,tolua_clone(tolua_S,tolua_obj,tolua_collect_GeoExtent),"GeoExtent"); #else void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(GeoExtent)); tolua_pushusertype(tolua_S,tolua_clone(tolua_S,tolua_obj,tolua_collect),"GeoExtent"); #endif } } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'getExtent'.",&tolua_err); return 0; #endif }
void FeatureGenerator::run(){ char save[255]; sprintf(save, "%s_%d", _save_prefix, _threadnum); ofstream ofs(save); int end=_part_num+_scope; Feature *feat = new Feature(); for(int i=_part_num; i<end; i++){ if((i-_part_num)%100==0){ printf("thread %d running..., %.2f%\n", _threadnum, ((float)(i-_part_num))/_scope*100.0); } int host=_acc->at(i).uid; map<int, int> uas=_acc->at(i).userAccess; map<int, int>::iterator itrAcc=uas.begin(); for(; itrAcc!=uas.end(); itrAcc++){ int subject=itrAcc->first; int type=itrAcc->second; GetFeature(host, subject, type, _featMap, feat); feat->dump(ofs); feat->reset(); } } ofs.close(); delete feat; }
FeatureNode::FeatureNode(MapNode* mapNode, const Config& conf, const osgDB::Options* dbOptions ) : AnnotationNode(conf) { osg::ref_ptr<Geometry> geom; if ( conf.hasChild("geometry") ) { Config geomconf = conf.child("geometry"); geom = GeometryUtils::geometryFromWKT( geomconf.value() ); if ( !geom.valid() ) OE_WARN << LC << "Config is missing required 'geometry' element" << std::endl; } osg::ref_ptr<const SpatialReference> srs; srs = SpatialReference::create( conf.value("srs"), conf.value("vdatum") ); if ( !srs.valid() ) OE_WARN << LC << "Config is missing required 'srs' element" << std::endl; optional<GeoInterpolation> geoInterp; conf.getObjIfSet( "style", _style ); FeatureNode::setMapNode( mapNode ); if ( srs.valid() && geom.valid() ) { Feature* feature = new Feature(geom.get(), srs.get() ); conf.getIfSet( "geointerp", "greatcircle", feature->geoInterp(), GEOINTERP_GREAT_CIRCLE ); conf.getIfSet( "geointerp", "rhumbline", feature->geoInterp(), GEOINTERP_RHUMB_LINE ); _features.push_back( feature ); build(); } }
double ITRAQLabeler::getRTProfileIntensity_(const Feature& f, const double MS2_RT_time) const { // compute intensity correction factor for feature from RT profile const DoubleList& elution_bounds = f.getMetaValue("elution_profile_bounds"); const DoubleList& elution_ints = f.getMetaValue("elution_profile_intensities"); // check that RT is within the elution bound: OPENMS_POSTCONDITION(f.getConvexHull().getBoundingBox().encloses(MS2_RT_time, f.getMZ()), "The MS2 spectrum has wrong parent features! The feature does not touch the spectrum's RT!") if (MS2_RT_time < elution_bounds[1] || elution_bounds[3] < MS2_RT_time) { LOG_WARN << "Warn: requesting MS2 RT for " << MS2_RT_time << ", but bounds are only from [" << elution_bounds[1] << "," << elution_bounds[3] << "]\n"; return 0; } // do linear interpolation double width = elution_bounds[3] - elution_bounds[1]; double offset = MS2_RT_time - elution_bounds[1]; Int index = floor(offset / (width / (elution_ints.size() - 1)) + 0.5); OPENMS_POSTCONDITION(index < (Int)elution_ints.size(), "Wrong index computation! (Too large)") return elution_ints[index]; }
CByteImage FeatureExtractor::render(const Feature& f, bool normalizeFeat) const { if(normalizeFeat) { CShape shape = f.Shape(); Feature fAux(shape); float fMin, fMax; f.getRangeOfValues(fMin, fMax); for(int y = 0; y < shape.height; y++) { float* fIt = (float*) f.PixelAddress(0,y,0); float* fAuxIt = (float*) fAux.PixelAddress(0,y,0); for(int x = 0; x < shape.width * shape.nBands; x++, fAuxIt++, fIt++) { *fAuxIt = (*fIt) / fMax; } } return this->render(fAux); } else { return this->render(f); } }
void AltitudeFilter::pushAndDontClamp( FeatureList& features, FilterContext& cx ) { NumericExpression scaleExpr; if ( _altitude.valid() && _altitude->verticalScale().isSet() ) scaleExpr = *_altitude->verticalScale(); NumericExpression offsetExpr; if ( _altitude.valid() && _altitude->verticalOffset().isSet() ) offsetExpr = *_altitude->verticalOffset(); for( FeatureList::iterator i = features.begin(); i != features.end(); ++i ) { Feature* feature = i->get(); // run a symbol script if present. if ( _altitude.valid() && _altitude->script().isSet() ) { StringExpression temp( _altitude->script().get() ); feature->eval( temp, &cx ); } double minHAT = DBL_MAX; double maxHAT = -DBL_MAX; double scaleZ = 1.0; if ( _altitude.valid() && _altitude->verticalScale().isSet() ) scaleZ = feature->eval( scaleExpr, &cx ); double offsetZ = 0.0; if ( _altitude.valid() && _altitude->verticalOffset().isSet() ) offsetZ = feature->eval( offsetExpr, &cx ); GeometryIterator gi( feature->getGeometry() ); while( gi.hasMore() ) { Geometry* geom = gi.next(); for( Geometry::iterator g = geom->begin(); g != geom->end(); ++g ) { g->z() *= scaleZ; g->z() += offsetZ; if ( g->z() < minHAT ) minHAT = g->z(); if ( g->z() > maxHAT ) maxHAT = g->z(); } } if ( minHAT != DBL_MAX ) { feature->set( "__min_hat", minHAT ); feature->set( "__max_hat", maxHAT ); } } }
void Labeler::extractFeature(Feature& feat, const Instance* pInstance, int idx) { feat.clear(); const vector<string>& words = pInstance->words; int sentsize = words.size(); string curWord = idx >= 0 && idx < sentsize ? normalize_to_lowerwithdigit(words[idx]) : nullkey; // word features int unknownId = m_wordAlphabet.from_string(unknownkey); int curWordId = m_wordAlphabet.from_string(curWord); if (curWordId >= 0) feat.words.push_back(curWordId); else feat.words.push_back(unknownId); // char features unknownId = m_charAlphabet.from_string(unknownkey); const vector<vector<string> > &charfeatures = pInstance->charfeatures; const vector<string>& cur_chars = charfeatures[idx]; int cur_char_size = cur_chars.size(); // actually we support a max window of m_options.charcontext = 2 for (int i = 0; i < cur_char_size; i++) { string curChar = cur_chars[i]; int curCharId = m_charAlphabet.from_string(curChar); if (curCharId >= 0) feat.chars.push_back(curCharId); else feat.chars.push_back(unknownId); } int nullkeyId = m_charAlphabet.from_string(nullkey); if (feat.chars.empty()) { feat.chars.push_back(nullkeyId); } const vector<string>& linear_features = pInstance->sparsefeatures[idx]; for (int i = 0; i < linear_features.size(); i++) { int curFeatId = m_featAlphabet.from_string(linear_features[i]); if (curFeatId >= 0) feat.linear_features.push_back(curFeatId); } }