--- ray/src/hd/rholo3.c 1999/01/09 19:48:28 3.29 +++ ray/src/hd/rholo3.c 1999/03/04 15:44:10 3.32 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ SGI"; */ #include "rholo.h" +#include "view.h" #include #ifndef NFRAG2CHUNK @@ -26,11 +27,12 @@ static char SCCSid[] = "$SunId$ SGI"; extern time_t time(); +int chunkycmp = 0; /* clump beams together on disk */ + static PACKHEAD *complist=NULL; /* list of beams to compute */ static int complen=0; /* length of complist */ static int listpos=0; /* current list position for next_packet */ static int lastin= -1; /* last ordered position in list */ -static int chunky=0; /* clump beams together on disk */ int @@ -40,7 +42,7 @@ register PACKHEAD *b0, *b1; BEAMI *bip0, *bip1; register long c; /* first check desired quantities */ - if (chunky) + if (chunkycmp) c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) - rchunk(b0->nr)*(rchunk(b1->nc)+1L); else @@ -91,8 +93,7 @@ register HDBEAMI *hb; n = b->nrm; if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); - if (p == NULL) - error(SYSTEM, "out of memory in dispbeam"); + CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); } /* assign packet fields */ bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); @@ -134,6 +135,11 @@ int nents; complist[i].nr += csm->nr; csm->nr = 0; break; + case BS_MAX: /* maximum of counts */ + if (csm->nr > complist[i].nr) + complist[i].nr = csm->nr; + csm->nr = 0; + break; case BS_ADJ: /* reset count */ complist[i].nr = csm->nr; csm->nr = 0; @@ -167,6 +173,7 @@ int nents; bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); break; case BS_ADD: /* add to computation set */ + case BS_MAX: /* maximum of quantities */ case BS_ADJ: /* adjust set quantities */ if (nents <= 0) return; @@ -176,7 +183,7 @@ int nents; for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) ; n = csm - clist; - if (op == BS_ADJ) { /* don't regenerate adjusted beams */ + if (op != BS_ADD) { /* don't regenerate adjusted beams */ for (++i; i-- && csm->nr > 0; csm++) ; nents = csm - clist; @@ -255,28 +262,20 @@ int bi; } -init_global() /* initialize global ray computation */ +ambient_list() /* compute ambient beam list */ { - long wtotal = 0; + int4 wtotal, minrt; double frac; int i; register int j, k; - /* free old list and empty queue */ - if (complen > 0) { - free((char *)complist); - done_packets(flush_queue()); - } - /* reseed random number generator */ - srandom(time(NULL)); - /* allocate beam list */ + complen = 0; for (j = 0; hdlist[j] != NULL; j++) complen += nbeams(hdlist[j]); complist = (PACKHEAD *)malloc(complen*sizeof(PACKHEAD)); - if (complist == NULL) - error(SYSTEM, "out of memory in init_global"); + CHECK(complist==NULL, SYSTEM, "out of memory in ambient_list"); /* compute beam weights */ - k = 0; + k = 0; wtotal = 0; for (j = 0; hdlist[j] != NULL; j++) { frac = 512. * VLEN(hdlist[j]->wg[0]) * VLEN(hdlist[j]->wg[1]) * @@ -289,15 +288,60 @@ init_global() /* initialize global ray computation * wtotal += complist[k++].nr; } } - /* adjust weights */ + /* adjust sample weights */ if (vdef(DISKSPACE)) frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL)); else - frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); - while (k--) - complist[k].nr = frac*complist[k].nr + 0.5; - listpos = 0; lastin = -1; /* perform initial sort */ - sortcomplist(); + frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL)); + minrt = .02*frac*wtotal/complen + .5; /* heuristic mimimum */ + if (minrt > RPACKSIZ) + minrt = RPACKSIZ; + for (k = complen; k--; ) + if ((complist[k].nr = frac*complist[k].nr + 0.5) < minrt) + complist[k].nr = minrt; + listpos = 0; lastin = -1; /* flag initial sort */ +} + + +view_list(fp) /* assign beam priority from view list */ +FILE *fp; +{ + double pa = 1.; + VIEW curview; + int xr, yr; + char *err; + BEAMLIST blist; + + copystruct(&curview, &stdview); + while (nextview(&curview, fp) != EOF) { + if ((err = setview(&curview)) != NULL) { + error(WARNING, err); + continue; + } + xr = yr = 1024; + normaspect(viewaspect(&curview), &pa, &xr, &yr); + viewbeams(&curview, xr, yr, &blist); + bundle_set(BS_MAX, blist.bl, blist.nb); + free((char *)blist.bl); + } +} + + +init_global() /* initialize global ray computation */ +{ + register int k; + /* free old list and empty queue */ + if (complen > 0) { + free((char *)complist); + done_packets(flush_queue()); + } + /* reseed random number generator */ + srandom(time(NULL)); + /* allocate beam list */ + if (readinp) + view_list(stdin); + else + ambient_list(); /* no view vicinity */ myeye.rng = 0; } @@ -334,29 +378,23 @@ sortcomplist() /* fix our list order */ if (complen <= 0) /* check to see if there is even a list */ return; - if (!chunky) /* check to see if fragment list is full */ + if (!chunkycmp) /* check to see if fragment list is full */ if (!hdfragOK(hdlist[0]->fd, &listlen, NULL) #if NFRAG2CHUNK || listlen >= NFRAG2CHUNK #endif ) { + chunkycmp++; /* use "chunky" comparison */ + lastin = -1; /* need to re-sort list */ #ifdef DEBUG error(WARNING, "using chunky comparison mode"); #endif - chunky++; /* use "chunky" comparison */ - lastin = -1; /* need to re-sort list */ } -#ifdef DEBUG - else - fprintf(stderr, "sortcomplist: %d fragments\n", - listlen); -#endif if (lastin < 0 || listpos*4 >= complen*3) qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); else if (listpos) { /* else sort and merge sublist */ list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); - if (list2 == NULL) - error(SYSTEM, "out of memory in sortcomplist"); + CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist"); bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD)); qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp); mergeclists(complist, list2, listpos,