void btDbvt::optimizeTopDown(int bu_treshold) { if(m_root) { tNodeArray leaves; leaves.reserve(m_leaves); fetchleaves(this,m_root,leaves); m_root=topdown(this,leaves,bu_treshold); } }
void topdown(int l,int t,int r,int b) { //printf("a %i %i %i %i\n",l,t,r-l,b-t); List<Pixel> vs; for (int i=l;i<r;i++) for (int j=t;j<b;j++) vs.add(newPixel(i,j)); float c=classify(&vs); vs.freedom(); if (r-l>botres || b-t>botres) { if (c>istext) { bin->setrectangle(l,t,r-l,b-t,depower(r-l,2)); } else if (c>notext) { int mx=(l+r)/2; int my=(t+b)/2; topdown(l,t,mx,my); topdown(mx,t,r,my); topdown(l,my,mx,b); topdown(mx,my,r,b); } } else if(c>0.5) bin->setrectangle(l,t,r-l,b-t,true); }
command() { double tval; int i,echeck; int pmin,pmax,pstep; while (echeck = getstring(": ")) { if (echeck == EOF) { fileinput(EOF); } else if (in[0] == '\0') { errprint(""); } else if (startsame(in,"cycle")) { cycle(); } else if (startsame(in,"clear")) { clear(); } else if (startsame(in,"coarticulation")) { getint(&coartflag); } else if (startsame(in,"rc")) { zarrays(); cycle(); } else if (startsame(in,"wordacts")) { scr_words(printmin,printmax,3,0,"MAX"); } else if (startsame(in,"wtacts")) { scr_words(printmin,printmax,3,0,"ALL"); } else if (startsame(in,"owtacts")) { getstring("word: "); scr_words(printmin,printmax,3,0,in); } else if (startsame(in,"phonacts")) { scr_phonemes(printmin,printmax,3,0); } else if (startsame(in,"featacts")) { scr_features(); } else if (startsame(in,"sfeatacts")) { getstring("fname: "); sfeatacts(in); } else if (startsame(in,"memo")) { getstring("string: "); strcpy(memo,in); } else if (startsame(in,"expr")) { setex(); } else if (startsame(in,"fcopt")) { getint(&fcflag); } else if (startsame(in,"fpcyc")) { getint(&fpcyc); } else if (startsame(in,"finput")) { fileinput(NONSTD); } else if (startsame(in,"inoise")) { getval(&inoise); } else if (startsame(in,"inspecs")) { getstring("File name (- = stdin): "); inspecs(in); } else if (startsame(in,"infeatures")) { getstring("File name: "); infeats(in); } /* NOT PRESENTLY OPERATIVE -- JLM 10-5-82 else if (startsame(in,"wsubset")) { wordsubset(); } */ else if (startsame(in,"test")) { getstring("test string: "); strcpy(memo,in); test(in); } else if (startsame(in,"topdown")) { topdown(); } else if (startsame(in,"output")) { setout(); } else if (startsame(in,"ofile")) { getstring("give filename (or - for none): "); setoutfile(in); } else if (in[0] == '?') { help(); } else if (startsame(in,"help")) { help(); } else if (startsame(in,"lexicon")) { getlex(); } else if (startsame(in,"params")) { getpars(); } else if (startsame(in,"quit")) { quit(); } else if (startsame(in,"decay")) { getdouble(decay,NLEVS,levlabs); } else if (startsame(in,"alpha")) { getdouble(alpha,NPARAMS,conlabs); } else if (startsame(in,"gamma")) { getdouble(ga,NLEVS,levlabs); } else if (startsame(in,"grace")) { getint(&grace); } else if (startsame(in,"rest")) { tval = rest[W]; getdouble(rest,NLEVS,levlabs); if (tval != rest[W]) { initialize(); } } else if (startsame(in,"fweight")) { getdouble(fweight,NCONTINS,contname); } else if (startsame(in,"pthresh")) { getdouble(pthresh,NLEVS,levlabs); } else if (startsame(in,"ngraph")) { newgraph(pmin,ng_max,pstep); } else if (startsame(in,"ngmax")) { getint(&ng_max); } else if (startsame(in,"ngwscale")) { getval(&ng_wscale); } else if (startsame(in,"ngsscale")) { getval(&ng_sscale); } else if (startsame(in,"ngpscale")) { getval(&ng_pscale); } else if (startsame(in,"nreps")) { getint(&nreps); } else if (startsame(in,"pfreq")) { getint(&printfreq); } else if (startsame(in,"rarate")) { getval(&rarate); } else if (startsame(in,"sumpr")) { scr_sum(pmin,pmax,pstep); } else if (startsame(in,"sinspec")) { sinspec(); } else if (startsame(in,"sfeatures")) { getstring("Filename: "); sfeatures(in); } else if (startsame(in,"dinspec")) { dinspec(); } else if (startsame(in,"sumopt")) { getint(&sumflag); } else if (startsame(in,"pmin")) { getint(&pmin); } else if (startsame(in,"pmax")) { getint(&pmax); } else if (startsame(in,"pstep")) { getint(&pstep); } else if (startsame(in,"min")) { getval(&min); } else if (startsame(in,"max")) { getval(&max); } else if (startsame(in,"windowcent")) { getval(&windowcent); } else if (startsame(in,"wbase")) { getval(&wbase); } else if (startsame(in,"wgraph")) { wgraph(pmin,ng_max,pstep); } else if (startsame(in,"wchange")) { getval(&wchange); } else if (startsame(in,"wgain")) { getval(&wgain); } else if (startsame(in,"wramp")) { getval(&wramp); } else if (startsame(in,"imax")) { getval(&imax); } else if (startsame(in,"sscale")) { getval(&sscale); } else if (startsame(in,"nsscale")) { getval(&nsscale); } else if (startsame(in,"freqscale")) { tval = fscale; getval(&fscale); if (tval != fscale) { initialize(); } } else if (startsame(in,"abort")) { abort(); /* to get a core dump for sdb */ } else { errprint("Unrecognized request: For help type ?."); if (infp != stdin) fileinput(STD); } wait(0); } }
static btDbvtNode* topdown(btDbvt* pdbvt, tNodeArray& leaves, int bu_treshold) { static const btVector3 axis[]={btVector3(1,0,0), btVector3(0,1,0), btVector3(0,0,1)}; if(leaves.size()>1) { if(leaves.size()>bu_treshold) { const btDbvtVolume vol=bounds(leaves); const btVector3 org=vol.Center(); tNodeArray sets[2]; int bestaxis=-1; int bestmidp=leaves.size(); int splitcount[3][2]={{0,0},{0,0},{0,0}}; int i; for( i=0;i<leaves.size();++i) { const btVector3 x=leaves[i]->volume.Center()-org; for(int j=0;j<3;++j) { ++splitcount[j][btDot(x,axis[j])>0?1:0]; } } for( i=0;i<3;++i) { if((splitcount[i][0]>0)&&(splitcount[i][1]>0)) { const int midp=(int)btFabs(btScalar(splitcount[i][0]-splitcount[i][1])); if(midp<bestmidp) { bestaxis=i; bestmidp=midp; } } } if(bestaxis>=0) { sets[0].reserve(splitcount[bestaxis][0]); sets[1].reserve(splitcount[bestaxis][1]); split(leaves,sets[0],sets[1],org,axis[bestaxis]); } else { sets[0].reserve(leaves.size()/2+1); sets[1].reserve(leaves.size()/2); for(int i=0,ni=leaves.size();i<ni;++i) { sets[i&1].push_back(leaves[i]); } } btDbvtNode* node=createnode(pdbvt,0,vol,0); node->childs[0]=topdown(pdbvt,sets[0],bu_treshold); node->childs[1]=topdown(pdbvt,sets[1],bu_treshold); node->childs[0]->parent=node; node->childs[1]->parent=node; return(node); } else { bottomup(pdbvt,leaves); return(leaves[0]); } } return(leaves[0]); }
command() { float tval; int i,echeck; int pmin,pmax,pstep; char tbuf[20]; while (echeck = getstring(": ")) { if (echeck == EOF) { fileinput(STD); } else if (startsame(in,"cycle")) { cycle(); } else if (startsame(in,"coarticulation")) { ttyprint("coarticulation %s: change? ",(coartflag ? "ON":"OFF")); fscanf(infp,"%s",in); if(in[0] == 'n') continue; coartflag = 1 - coartflag; } else if (startsame(in,"rc")) { printf("reset and cycle\n"); zarrays(); cycle(); } else if (startsame(in,"wordacts")) { printwords(printmin,printmax,3,stdout); if (outfile) printwords(printmin,printmax,3,outfile); } else if (startsame(in,"wtacts")) { printwt(printmin,printmax,3,stdout); if (outfile) printwt(printmin,printmax,3,outfile); } else if (startsame(in,"owtacts")) { getstring("word: "); strcpy(tbuf,in); printonewt(tbuf,printmin,printmax,3,stdout); if (outfile) printonewt(tbuf,printmin,printmax,3,outfile); } else if (startsame(in,"phonacts")) { printphonemes(printmin,printmax,3,stdout); if (outfile) printphonemes(printmin,printmax,3,outfile); } else if (startsame(in,"featacts")) { printf("feature activations - give min,max,step: "); scanf("%d %d %d",&pmin,&pmax,&pstep); printfeatures(pmin,pmax,pstep,stdout); if (outfile) printfeatures(pmin,pmax,pstep,outfile); } else if (startsame(in,"expression")) { setex(); } else if (startsame(in,"fileinput")) { fileinput(NONSTD); } else if (startsame(in,"inspecs")) { ttyprint("File name (- = stdin): "); fscanf(infp,"%s",in); inspecs(in); } else if (startsame(in,"infeatures")) { ttyprint("File name: "); fscanf(infp,"%s",in); infeats(in); } /* NOT PRESENTLY OPERATIVE -- JLM 10-5-82 else if (startsame(in,"wsubset")) { wordsubset(); } */ else if (startsame(in,"test")) { getstring("test string: "); test(in); } else if (startsame(in,"topdown")) { topdown(); } else if (startsame(in,"output")) { setout(); } else if (startsame(in,"ofile")) { getstring("give filename (or - for none): "); setoutfile(in); } else if (in[0] == '!') { system(&in[1]); } else if (in[0] == '?') { help(); } else if (startsame(in,"help")) { help(); } else if (startsame(in,"lexicon")) { getlex(); } else if (startsame(in,"parameters")) { getpars(); } else if (startsame(in,"quit")) { quit(); } else if (startsame(in,"decay")) { ttyprint ("decay values:\n"); getfloat(decay,NLEVS,"F","P","W"); } else if (startsame(in,"alpha")) { ttyprint ("alpha values:\n"); getfloat(alpha,NPARAMS, "IF","FF","FP","PP","PW","WW","WP","PF","PFC"); } else if (startsame(in,"gamma")) { ttyprint ("gamma values:\n"); getfloat(ga,NLEVS,"F","P","W"); } else if (startsame(in,"grace")) { ttyprint ("grace %s: change? ",(grace ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; grace = 1 - grace; } else if (startsame(in,"rest")) { tval = rest[W]; ttyprint ("rest values:\n"); getfloat(rest,NLEVS,"F","P","W"); if (tval != rest[W]) { initialize(); } } else if (startsame(in,"fweight")) { ttyprint ("fweight values:\n"); getfloat(fweight,NCONTINS, "POW","PIT","VOI","ABT","DIF","ACU","CON","LWS", "MDS", "HIS","FT1","FT2","FT3","FT4","FT5","FT6"); } else if (startsame(in,"pthresh")) { ttyprint ("pthresh values:\n"); getfloat(pthresh,NLEVS,"F","P","W"); } else if (startsame(in,"nreps")) { ttyprint ("%d nreps: change? ",nreps); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sscanf(in,"%d",&nreps); } else if (startsame(in,"pfreq")) { ttyprint ("%d pfreq: change? ",printfreq); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sscanf(in,"%d",&printfreq); } else if (startsame(in,"summarypr")) { ttyprint("give min, max, and step: "); fscanf(infp,"%d %d %d",&pmin,&pmax,&pstep); summarypr(pmin,pmax,pstep,stdout); if (outfile) summarypr(pmin,pmax,pstep,outfile); } else if (startsame(in,"spointers")) { qsort(wordptr,nwptrs,sizeof(struct word *),ecomp); } else if (startsame(in,"sinspec")) { sinspec(); } else if (startsame(in,"sfeatures")) { ttyprint("file name: "); fscanf(infp,"%s",in); sfeatures(in); } else if (startsame(in,"dinspec")) { dinspec(); } else if (startsame(in,"acoustinput")) { ttyprint("give min, max, and step: "); fscanf(infp,"%d %d %d",&pmin,&pmax,&pstep); acoustinput(pmin,pmax,pstep,stdout); if (outfile) acoustinput(pmin,pmax,pstep,outfile); } else if (startsame(in,"sumopt")) { ttyprint ("summaryprint %s: change? ",(sumflag ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sumflag = 1 - sumflag; } else if (startsame(in,"echooutput")) { ttyprint ("echooutput %s: change? ",(echoflag ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; echoflag = 1 - echoflag; } else if (startsame(in,"min")) { ttyprint ("min = "); getval(&min); } else if (startsame(in,"max")) { ttyprint ("max = "); getval(&max); } else if (startsame(in,"windowcent")) { ttyprint ("windowcent = "); getval(&windowcent); } else if (startsame(in,"wbase")) { ttyprint ("wbase = "); getval(&wbase); } else if (startsame(in,"wchange")) { ttyprint ("wchange = "); getval(&wchange); } else if (startsame(in,"wgain")) { ttyprint ("wgain = "); getval(&wgain); } else if (startsame(in,"wramp")) { ttyprint ("wramp = "); getval(&wramp); } else if (startsame(in,"imax")) { ttyprint ("imax = "); getval(&imax); } else if (startsame(in,"freqscale")) { ttyprint ("freqscale = "); tval = fscale; getval(&fscale); if (tval != fscale) { initialize(); } } else if (startsame(in,"abort")) { abort(); /* to get a core dump for sdb */ } else { printf("Unrecognized request: For help type ?.\n"); if (infp != stdin) fileinput(STD); } wait(0); } }
Map2d<bool> *classifytopdown() { // Big blocks sometimes wrongly classified bin=new Map2d<bool>(image->width,image->height,false); topdown(0,0,image->width-1,image->height-1); return bin; }