int main(int argc, char *argv[]) { int l, i, c; long long cnt[5], tot; kseq_t *seq; gzFile fp; cnt[0] = cnt[1] = cnt[2] = cnt[3] = cnt[4] = 0; while ((c = getopt(argc, argv, "l:r:")) >= 0) { switch (c) { case 'l': g_len = atoi(optarg); break; case 'r': g_ratio = atof(optarg); break; } } if (argc == optind) { fprintf(stderr, "Usage: gen_mask [-l %d] [-r %.2lf] <in.rawMask.fa>\n", g_len, g_ratio); return 1; } fp = gzopen(argv[optind], "r"); seq = kseq_init(fp); while ((l = kseq_read(seq)) >= 0) { int n_good = 0, n_all = 0, n_mid = 0; printf(">%s %d %.3lf", seq->name.s, g_len, g_ratio); for (i = 0; i < l + g_len - 1; ++i) { int c1, c2; unsigned x = i < l? get_cnt(seq->seq.s[i]) : 0; c1 = x>>16; c2 = x&0xffff; if (c1 == 1) ++cnt[4]; if (c1) { ++n_all; if (is_good(c1, c2)) ++n_good; if (c1 == 1) ++n_mid; } x = i >= g_len? get_cnt(seq->seq.s[i - g_len]) : 0; c1 = x>>16; c2 = x&0xffff; if (c1) { --n_all; if (is_good(c1, c2)) --n_good; if (c1 == 1) --n_mid; } assert(n_all <= g_len && n_good <= n_all); if (i % 60 == 0) putchar('\n'); x = n_all == 0? 0 : (double)n_good/n_all >= g_ratio? 3 : (double)n_mid/n_all >= g_ratio? 2 : 1; putchar(x + '0'); cnt[x]++; } putchar('\n'); } tot = cnt[1] + cnt[2] + cnt[3]; fprintf(stderr, "%lld, %lld, %lld, %lld, %lld\n", cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]); fprintf(stderr, "%lf, %lf, %lf\n", (double)cnt[3] / tot, (double)(cnt[2] + cnt[3]) / tot, (double)cnt[4] / tot); kseq_destroy(seq); gzclose(fp); return 0; }
bool BvertGrid::interp_boundary() { // Assign positions of interior vertices by interpolating from // boundary positions. Uses a Coons patch as defined in: // // Gerald Farin. // Curves and Surfaces for CAGD, 3rd Ed., Section 20.2. // (pp. 365-368). if (!is_good()) return false; // Iterate over interior verts: for (int j=1; j<_RowsCache; j++) { double v = j*_dv; for (int i=1; i<_ColsCache; i++) { double u = i*_du; vert(i,j)->set_loc( interp(loc(i,0), loc(i,_RowsCache), v) + // Rc + (interp(loc(0,j), loc(_ColsCache,j), u) - // Rd - interp( // Rcd interp(loc( 0,0), loc( 0,_RowsCache), v), interp(loc(_ColsCache,0), loc(_ColsCache,_RowsCache), v), u)) ); } } return true; }
bool GetTremulousPk3s(const char* destdir, const char* basegame) { std::string baseuri = "https://github.com/wtfbbqhax/tremulous-data/raw/master/"; std::vector<std::string> files = { "data-gpp1.pk3", "data-1.1.0.pk3", "map-arachnid2-1.1.0.pk3", "map-atcs-1.1.0.pk3", "map-karith-1.1.0.pk3", "map-nexus6-1.1.0.pk3", "map-niveus-1.1.0.pk3", "map-transit-1.1.0.pk3", "map-tremor-1.1.0.pk3", "map-uncreation-1.1.0.pk3" }; RestClient::init(); MakeDir(destdir, basegame); if (!PromptDownloadPk3s(basegame, files)) return false; for (auto f : files ) { std::string destpath(destdir); destpath += "/"; destpath += basegame; destpath += "/"; destpath += f; if ( is_good(destpath) ) { return false; } std::cout << "Downloading " << baseuri << f << std::endl; std::ofstream dl(destpath); //dl.open(destpath); if ( dl.fail() ) { std::cerr << "Error " << strerror(errno) << "\n"; continue; } RestClient::Response resp = RestClient::get(baseuri + f); dl << resp.body; dl.close(); } return true; }
std::vector<Proposals> boxNms( const std::vector<Proposals> & proposals, const std::vector<int> & order, float max_iou, float min_box_size ) { std::multimap<float,int> area_map; area_map.insert(std::make_pair(0.f,-1)); area_map.insert(std::make_pair(1e6f,-1)); std::vector<Vector4i> boxes; for( const Proposals & p: proposals ) { RMatrixXi b = maskToBox( p.s, p.p ); for( int i=0; i<b.rows(); i++ ) boxes.push_back( b.row(i) ); } std::vector<bool> is_good( boxes.size() ); for( int i: order ) { Vector4i b = boxes[i]; float ba = boxArea(b); if (min_box_size > ba) continue; bool overlaps = false; auto i0 = area_map.upper_bound(ba); auto i1 = i0--; while(!overlaps) { if( i1->second >= 0 && ba*ba > i1->first*i0->first && ba > max_iou*i1->first ) { overlaps = boxIou(boxes[i1->second],b) >= max_iou; ++i1; } else if( i0->second >= 0 && ba * max_iou < i0->first ) { overlaps = boxIou(boxes[i0->second],b) >= max_iou; --i0; } else break; } is_good[i] = !overlaps; if( !overlaps ) area_map.insert( std::make_pair(ba,i) ); } std::vector<Proposals> res( proposals.size() ); for( int i=0,k=0; i<proposals.size(); i++ ) { res[i].s = proposals[i].s; std::vector<RowVectorXb> good_p; for( int j=0; j<proposals[i].p.rows(); j++,k++ ) if( is_good[k] ) good_p.push_back( proposals[i].p.row(j) ); res[i].p = RMatrixXb( good_p.size(), proposals[i].p.cols() ); for( int j=0; j<good_p.size(); j++ ) res[i].p.row(j) = good_p[j]; } return res; }
static int modify_damage(int dmg, string type, object foe, string loc, int prot, int resist, int vuln, int ac, object wpn) { object env; if (!objectp(env = environment())) { return 0; } if (lower_case(type) == "fire") { tell_room(env, "The demon does not seem to be affected by the fire.\n"); heal_self(dmg / 2); return -dmg; } if (is_evil(wpn)) { return -dmg / 2; } if (dmg > 30) { command("scream ago"); } if (resist < -10) { command("cackle"); } if (prot < -20) { command("hydr ehv"); } if (dmg < 10 && random(100) > 25) { return 0; } if (is_good(wpn)) { tell_object(foe, "Your " + wpn->query_name() + " rips straight " + "through the demon's skin!\n"); return 2 * dmg; } if (is_good(foe)) { tell_object(foe, "You rip straight through the demon's skin.\n"); return dmg; } return 0; }
void BvertGrid::cache() { assert(is_good()); _RowsCache = nrows() - 1; _ColsCache = ncols() - 1; _mesh = bottom().mesh(); assert(_RowsCache > 0 && _ColsCache > 0 && _mesh != nullptr); _du = 1.0/_ColsCache; _dv = 1.0/_RowsCache; }
bool BvertGrid::add_quads(Patch* p) { // Create quads with uv-coords if (!is_good()) return false; bool ret = true; for (int j=1; j<=_RowsCache; j++) for (int i=1; i<=_ColsCache; i++) if (!add_quad(i, j, p)) ret = false; return ret; }
void Character::spell_enchant_weapon (int sn, int lvl, void *vo) { Object *obj = (Object *) vo; Affect *paf; if (obj->item_type != ITEM_WEAPON || obj->is_obj_stat(ITEM_MAGIC) || !obj->affected.empty()) return; paf = new Affect(); paf->type = sn; paf->duration = -1; paf->location = APPLY_HITROLL; paf->modifier = lvl / 5; paf->bitvector = 0; obj->affected.push_back(paf); paf = new Affect(); paf->type = -1; paf->duration = -1; paf->location = APPLY_DAMROLL; paf->modifier = lvl / 10; paf->bitvector = 0; obj->affected.push_back(paf); obj->level = number_fuzzy (level - 5); if (is_good ()) { SET_BIT (obj->extra_flags, ITEM_ANTI_EVIL); act ("$p glows blue.", obj, NULL, TO_CHAR); } else if (is_evil ()) { SET_BIT (obj->extra_flags, ITEM_ANTI_GOOD); act ("$p glows red.", obj, NULL, TO_CHAR); } else { SET_BIT (obj->extra_flags, ITEM_ANTI_EVIL); SET_BIT (obj->extra_flags, ITEM_ANTI_GOOD); act ("$p glows yellow.", obj, NULL, TO_CHAR); } send_to_char ("Ok.\r\n"); return; }
bool is_aggressive( char_data* ch, char_data* victim ) { char_data* opponent; if( ch == victim || ch->position <= POS_SLEEPING ) return FALSE; if( ( opponent = victim->fighting ) != NULL ) if( join_fight( opponent, victim, ch ) ) return TRUE; if( ch->pcdata != NULL || is_set( &victim->in_room->room_flags, RFLAG_SAFE ) || !victim->Seen( ch ) ) return FALSE; if( ch->shdata->race == RACE_PLANT && is_set( victim->affected_by, AFF_PROT_PLANTS ) ) return FALSE; if( is_evil( victim ) ) if( is_set( &ch->status, STAT_AGGR_EVIL ) && is_set( ch->affected_by, AFF_DETECT_EVIL ) ) return TRUE; else if( is_good( victim ) ) if( is_set( &ch->status, STAT_AGGR_GOOD ) && is_set( ch->affected_by, AFF_DETECT_GOOD ) ) return TRUE; if( is_set( &ch->status, STAT_PET ) ) return FALSE; if( victim->species == NULL ) { if( victim->shdata->level >= LEVEL_BUILDER ) return FALSE; if( is_set( &ch->status, STAT_AGGR_ALL ) || is_enemy( ch, victim ) ) return TRUE; } return FALSE; }