--- ray/src/hd/rhdisp2.c 1998/01/07 16:04:14 3.19 +++ ray/src/hd/rhdisp2.c 1998/05/22 15:12:36 3.22 @@ -16,26 +16,21 @@ static char SCCSid[] = "$SunId$ SGI"; #define MAXDIST 42 /* maximum distance outside section */ #endif -extern GCOORD *getviewcells(); +#define MAXVOXEL 32 /* maximum number of active voxels */ -static VIEW dvw; /* current view corresponding to beam list */ - typedef struct { int hd; /* holodeck section number (-1 if inactive) */ int i[3]; /* voxel index (may be outside section) */ } VOXL; /* a voxel */ -static VOXL voxel[8] = { /* current voxel list */ - {-1}, {-1}, {-1}, {-1}, - {-1}, {-1}, {-1}, {-1} -}; +static VOXL voxel[MAXVOXEL] = {{-1}}; /* current voxel list */ #define CBEAMBLK 1024 /* cbeam allocation block size */ static struct beamcomp { - short wants; /* flags telling which voxels want us */ - short hd; /* holodeck section number */ - int bi; /* beam index */ + int hd; /* holodeck section number */ + int4 bi; /* beam index */ + int4 nr; /* number of samples desired */ } *cbeam = NULL; /* current beam list */ static int ncbeams = 0; /* number of sorted beams in cbeam */ @@ -44,8 +39,9 @@ static int maxcbeam = 0; /* size of cbeam array */ struct cellact { short vi; /* voxel index */ - short add; /* zero means delete */ short rev; /* reverse ray direction? */ + VIEW *vp; /* view for image */ + short hr, vr; /* image resolution */ }; /* action for cell */ struct beamact { @@ -92,9 +88,9 @@ register struct beamcomp *cb1, *cb2; { register int c; - if (!cb1->wants) /* put orphans at the end, unsorted */ - return(cb2->wants); - if (!cb2->wants) + if (!cb1->nr) /* put orphans at the end, unsorted */ + return(cb2->nr); + if (!cb2->nr) return(-1); if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ return(c); @@ -111,7 +107,7 @@ int hd, bi; if (ncbeams <= 0) return(-1); - cb.wants = 0; cb.hd = hd; cb.bi = bi; + cb.hd = hd; cb.bi = bi; cb.nr = 0; p = (struct beamcomp *)bsearch((char *)&cb, (char *)cbeam, ncbeams, sizeof(struct beamcomp), cbeamcmp); if (p == NULL) @@ -139,7 +135,7 @@ int bi; if (bi < 1 | bi > nbeams(hdlist[hd])) error(INTERNAL, "illegal beam index in getcbeam"); n = newcbeam(); /* allocate and assign */ - cbeam[n].wants = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; + cbeam[n].nr = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; return(n); } @@ -157,19 +153,17 @@ int adopt; if (adopt) return; for (i = ncbeams; i--; ) /* identify orphans */ - if (cbeam[i].wants) + if (cbeam[i].nr) break; xcbeams = ncbeams - ++i; /* put orphans after ncbeams */ ncbeams = i; } -cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ +cbeamop(op, bl, n) /* update beams on server list */ int op; register struct beamcomp *bl; int n; -VIEW *v; -int hr, vr; { register PACKHEAD *pa; register int i; @@ -178,12 +172,11 @@ int hr, vr; return; pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); if (pa == NULL) - error(SYSTEM, "out of memory in cbeamadd"); + error(SYSTEM, "out of memory in cbeamop"); for (i = 0; i < n; i++) { pa[i].hd = bl[i].hd; pa[i].bi = bl[i].bi; - pa[i].nr = v==NULL ? 0 : - npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); + pa[i].nr = bl[i].nr; pa[i].nc = 0; } serv_request(op, n*sizeof(PACKHEAD), (char *)pa); @@ -191,60 +184,23 @@ int hr, vr; } -int -set_voxels(vl, n) /* set new voxel array */ -VOXL vl[8]; -int n; -{ - short wmap[256]; - int vmap[8]; - int comn = 0; - int no; - register int i, j; - /* find common voxels */ - for (j = 0; j < 8 && voxel[j].hd >= 0; j++) { - vmap[j] = -1; - for (i = n; i--; ) - if (!bcmp((char *)(vl+i), (char *)(voxel+j), - sizeof(VOXL))) { - vmap[j] = i; - comn |= 1<= 0 && i & 1<= 0; first++) + ; /* find closest voxels */ - for (i = 0; n < 8 && hdlist[i]; i++) { + for (n = first, i = 0; n < MAXVOXEL && hdlist[i]; i++) { hdgrid(gp, hdlist[i], vp); - for (j = 0; n < 8 && j < 8; j++) { + for (j = 0; n < MAXVOXEL && j < 8; j++) { dist = 0; for (k = 0; k < 3; k++) { d = gp[k] - .5 + (j>>k & 1); @@ -257,12 +213,24 @@ FVECT vp; if (dist > bestd) /* others were closer */ continue; if (dist < bestd) { /* start closer list */ - n = 0; + n = first; bestd = dist; + rfl = 0; } + /* check if already in list */ + for (k = first; k--; ) + if (voxel[k].hd == i && + voxel[k].i[0] == vox.i[0] && + voxel[k].i[1] == vox.i[1] && + voxel[k].i[2] == vox.i[2]) + break; + if (k >= 0) { + rfl |= 1<ca.rev) { copystruct(gc, &bp->gc); @@ -291,18 +261,13 @@ register struct beamact *bp; } if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) error(CONSISTENCY, "bad grid coordinate in dobeam"); - if (bp->ca.add) { /* add it in */ - i = getcbeam(voxel[bp->ca.vi].hd, bi); - cbeam[i].wants |= 1<ca.vi; /* say we want it */ - return(i == ncbeams+xcbeams-1); /* return 1 if totally new */ - } - /* else delete it */ - i = findcbeam(voxel[bp->ca.vi].hd, bi); - if (i >= 0 && cbeam[i].wants & 1<ca.vi) { - cbeam[i].wants &= ~(1<ca.vi); /* we don't want it */ - return(1); /* indicate change */ - } - return(0); + /* add it in */ + i = getcbeam(voxel[bp->ca.vi].hd, bi); + n = npixels(bp->ca.vp, bp->ca.hr, bp->ca.vr, + hdlist[cbeam[i].hd], cbeam[i].bi); + if (n > cbeam[i].nr) + cbeam[i].nr = n; + return(i == ncbeams+xcbeams-1); /* return 1 if totally new */ } @@ -369,14 +334,13 @@ register struct cellact *cap; int -doview(cap, vp) /* visit cells for a given view */ +doview(cap) /* visit cells for a given view */ struct cellact *cap; -VIEW *vp; { int orient; FVECT org, dir[4]; /* compute view pyramid */ - orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); + orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], cap->vp); if (!orient) error(INTERNAL, "unusable view in doview"); cap->rev = orient < 0; @@ -385,115 +349,47 @@ VIEW *vp; } -mvview(voxi, vold, vnew) /* move view for a voxel */ -int voxi; -VIEW *vold, *vnew; +beam_init() /* clear beam list for new view(s) */ { - int netchange = 0; - struct cellact oca, nca; - int ocnt, ncnt; - int nmatch = 0; - GCOORD *ogcl, *ngcl; - register int c; - register GCOORD *ogcp, *ngcp; - /* get old and new cell lists */ - ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); - ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); - /* set up actions */ - oca.vi = nca.vi = voxi; - oca.add = 0; nca.add = 1; - if ((oca.rev = ocnt < 0)) - ocnt = -ocnt; - if ((nca.rev = ncnt < 0)) - ncnt = -ncnt; - if (oca.rev == nca.rev) { /* count matches */ - int oc = ocnt, nc = ncnt; - while (oc > 0 & nc > 0) { - c = cellcmp(ogcp, ngcp); - if (c >= 0) { ngcp++; nc--; } - if (c <= 0) { ogcp++; oc--; } - nmatch += c==0; - } - ogcp = ogcl; ngcp = ngcl; - } - if (nmatch < ocnt>>1) { /* faster to just delete old cells? */ - for (c = ncbeams; c--; ) - if (cbeam[c].wants & 1< 0 & ncnt > 0) - if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ - netchange += docell(ngcp++, &nca); - ncnt--; - } else if (c < 0) { /* old cell */ - netchange -= docell(ogcp++, &oca); - ocnt--; - } else { /* same cell */ - ogcp++; ocnt--; - ngcp++; ncnt--; - } - /* take care of list tails */ - for ( ; ncnt > 0; ncnt--) - netchange += docell(ngcp++, &nca); - for ( ; ocnt > 0; ocnt--) - netchange -= docell(ogcp++, &oca); - /* clean up */ - if (ogcl != NULL) free((char *)ogcl); - if (ngcl != NULL) free((char *)ngcl); - return(netchange); + register int i; + /* clear desire flags */ + for (i = ncbeams+xcbeams; i--; ) + cbeam[i].nr = 0; + voxel[0].hd = -1; /* clear voxel list */ } -int -beam_sync() /* synchronize beams on server */ +beam_view(vn, hr, vr) /* add beam view (if advisable) */ +VIEW *vn; +int hr, vr; { - cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); - return(ncbeams); + struct cellact ca; + unsigned int4 vfl; + /* sort our list */ + cbeamsort(1); + /* add new voxels */ + vfl = add_voxels(vn->vp); + if (!vfl) + return(0); + ca.vp = vn; ca.hr = hr; ca.vr = vr; + /* update our beam list */ + for (ca.vi = 0; vfl; vfl >>= 1, ca.vi++) + if (vfl & 1) + doview(&ca); + return(1); } -beam_view(vn) /* change beam view (if advisable) */ -VIEW *vn; +int +beam_sync(all) /* update beam list on server */ +int all; { - struct cellact ca; - VOXL vlnew[8]; - int n, comn; - - if (vn == NULL || !vn->type) { /* clear our beam list */ - set_voxels(vlnew, 0); - cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); - ncbeams = 0; - dvw.type = 0; - return(1); - } - /* find our new voxels */ - n = get_voxels(vlnew, vn->vp); - if (dvw.type && !n) { - copystruct(vn, &dvw); /* cancel move */ - return(0); - } - /* set the new voxels */ - comn = set_voxels(vlnew, n); - if (!dvw.type) - comn = 0; - ca.add = 1; /* update our beam list */ - for (ca.vi = n; ca.vi--; ) - if (comn & 1<