--- ray/src/hd/rholo3.c 1997/12/18 14:46:00 3.14 +++ ray/src/hd/rholo3.c 1998/01/22 11:25:51 3.20 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -61,51 +61,59 @@ int op; register PACKHEAD *clist; int nents; { + int oldnr; register int i, n; - + /* look for common members */ + for (n = 0; n < nents; n++) { + for (i = 0; i < complen; i++) + if (clist[n].bi == complist[i].bi && + clist[n].hd == complist[i].hd) { + oldnr = complist[i].nr; + clist[n].nc = complist[i].nc; + switch (op) { + case BS_ADD: /* add to count */ + complist[i].nr += clist[n].nr; + clist[n].nr = 0; + break; + case BS_ADJ: /* reset count */ + complist[i].nr = clist[n].nr; + clist[n].nr = 0; + break; + case BS_DEL: /* delete count */ + if (clist[n].nr == 0 || + clist[n].nr >= complist[i].nr) + complist[i].nr = 0; + else + complist[i].nr -= clist[n].nr; + break; + } + if (complist[i].nr != oldnr) + lastin = -1; /* flag sort */ + break; + } + if (i >= complen) + clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); + } + /* complete list operations */ switch (op) { case BS_NEW: /* new computation set */ - if (complen) + listpos = 0; + lastin = -1; + if (complen) /* free old list */ free((char *)complist); - if (nents <= 0) { - complist = NULL; - listpos = complen = 0; - lastin = -1; + complist = NULL; + if (!(complen = nents)) return; - } complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); if (complist == NULL) goto memerr; bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); - complen = nents; /* finish initialization below */ break; case BS_ADD: /* add to computation set */ case BS_ADJ: /* adjust set quantities */ if (nents <= 0) return; - /* merge any common members */ - for (n = 0; n < nents; n++) { - for (i = 0; i < complen; i++) - if (clist[n].bi == complist[i].bi && - clist[n].hd == complist[i].hd) { - int oldnr = complist[i].nr; - if (op == BS_ADD) - complist[i].nr += clist[n].nr; - else /* op == BS_ADJ */ - complist[i].nr = clist[n].nr; - clist[n].nr = 0; - clist[n].nc = complist[i].nc; - if (complist[i].nr != oldnr) - lastin = -1; /* flag sort */ - break; - } - if (i >= complen) - clist[n].nc = bnrays(hdlist[clist[n].hd], - clist[n].bi); - } - /* sort updated list */ - sortcomplist(); - /* sort new entries */ + sortcomplist(); /* sort updated list & new entries */ qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); /* what can't we satisfy? */ for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) @@ -129,22 +137,7 @@ int nents; lastin = complen-1; /* list is now sorted */ break; case BS_DEL: /* delete from computation set */ - if (nents <= 0) - return; - /* find each member */ - for (i = 0; i < complen; i++) - for (n = 0; n < nents; n++) - if (clist[n].bi == complist[i].bi && - clist[n].hd == complist[i].hd) { - if (clist[n].nr == 0 || - clist[n].nr >= complist[i].nr) - complist[i].nr = 0; - else - complist[i].nr -= clist[n].nr; - lastin = -1; /* flag full sort */ - break; - } - return; /* no display */ + return; /* already done */ default: error(CONSISTENCY, "bundle_set called with unknown operation"); } @@ -159,14 +152,6 @@ int nents; hdloadbeams(hb, nents, dispbeam); free((char *)hb); } - if (op == BS_NEW) { - done_packets(flush_queue()); /* empty queue, so we can... */ - for (i = 0; i < complen; i++) /* ...get number computed */ - complist[i].nc = bnrays(hdlist[complist[i].hd], - complist[i].bi); - listpos = 0; - lastin = -1; /* flag for initial sort */ - } return; memerr: error(SYSTEM, "out of memory in bundle_set"); @@ -191,10 +176,6 @@ int bi; VSUM(edgeA, cp[1], cp[0], -1.0); VSUM(edgeB, cp[3], cp[1], -1.0); fcross(crossp[i], edgeA, edgeB); - VSUM(edgeA, cp[2], cp[3], -1.0); - VSUM(edgeB, cp[0], cp[2], -1.0); - fcross(v, edgeA, edgeB); - VSUM(crossp[i], crossp[i], v, 1.0); /* compute center */ cent[i][0] = 0.5*(cp[0][0] + cp[2][0]); cent[i][1] = 0.5*(cp[0][1] + cp[2][1]); @@ -203,7 +184,7 @@ int bi; /* compute difference vector */ VSUM(diffv, cent[1], cent[0], -1.0); for (i = 0; i < 2; i++) { /* compute volume contributions */ - vol[i] = 0.25*DOT(crossp[i], diffv); + vol[i] = 0.5*DOT(crossp[i], diffv); if (vol[i] < 0.) vol[i] = -vol[i]; } return(vol[0] + vol[1]); /* return total volume */ @@ -216,9 +197,11 @@ init_global() /* initialize global ray computation * double frac; int i; register int j, k; - /* free old list */ - if (complen > 0) + /* free old list and empty queue */ + if (complen > 0) { free((char *)complist); + done_packets(flush_queue()); + } /* allocate beam list */ complen = 0; for (j = 0; hdlist[j] != NULL; j++) @@ -229,12 +212,14 @@ init_global() /* initialize global ray computation * /* compute beam weights */ k = 0; for (j = 0; hdlist[j] != NULL; j++) { - frac = 512. * hdlist[j]->wg[0] * - hdlist[j]->wg[1] * hdlist[j]->wg[2]; + frac = 512. * VLEN(hdlist[j]->wg[0]) * + VLEN(hdlist[j]->wg[1]) * + VLEN(hdlist[j]->wg[2]); for (i = nbeams(hdlist[j]); i > 0; i--) { complist[k].hd = j; complist[k].bi = i; complist[k].nr = frac*beamvolume(hdlist[j], i) + 0.5; + complist[k].nc = bnrays(hdlist[j], i); wtotal += complist[k++].nr; } } @@ -250,11 +235,11 @@ init_global() /* initialize global ray computation * mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ -PACKHEAD *cdest; -PACKHEAD *cl1, *cl2; +register PACKHEAD *cdest; +register PACKHEAD *cl1, *cl2; int n1, n2; { - int cmp; + register int cmp; while (n1 | n2) { if (!n1) cmp = 1; @@ -319,8 +304,9 @@ sortcomplist() /* fix our list order */ * list and start again from the beginning. Since * a merge sort is used, the sorting costs are minimal. */ -next_packet(p) /* prepare packet for computation */ +next_packet(p, n) /* prepare packet for computation */ register PACKET *p; +int n; { register int i; @@ -334,8 +320,12 @@ register PACKET *p; p->nr = complist[listpos].nr - p->nc; if (p->nr <= 0) return(0); - if (p->nr > RPACKSIZ) - p->nr = RPACKSIZ; +#ifdef DEBUG + if (n < 1 | n > RPACKSIZ) + error(CONSISTENCY, "next_packet called with bad n value"); +#endif + if (p->nr > n) + p->nr = n; complist[listpos].nc += p->nr; /* find where this one would go */ while (lastin > listpos && beamcmp(complist+lastin, complist+listpos) > 0)