--- ray/src/hd/rhdisp2.c 1997/12/16 11:57:32 3.16 +++ ray/src/hd/rhdisp2.c 1998/05/14 13:23:00 3.21 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -16,26 +16,22 @@ static char SCCSid[] = "$SunId$ SGI"; #define MAXDIST 42 /* maximum distance outside section */ #endif -extern GCOORD *getviewcells(); +#define MAXVOXEL 16 /* 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 */ + unsigned int2 wants; /* flags telling which voxels want us */ + unsigned int2 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 */ @@ -46,6 +42,8 @@ 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 { @@ -111,7 +109,7 @@ int hd, bi; if (ncbeams <= 0) return(-1); - cb.wants = 0; cb.hd = hd; cb.bi = bi; + cb.wants = 0; 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 +137,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].wants = cbeam[n].nr = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; return(n); } @@ -164,74 +162,10 @@ int adopt; } -cbeamadj(v, hr, vr) /* adjust our beam list */ -VIEW *v; -int hr, vr; -{ - PACKHEAD *pa, *pa2; - register PACKHEAD *pp; - int n, n2; - FVECT gp; - int igp[3], vcflgs; - register int i; - /* figure out center voxel(s) */ - n = -1; vcflgs = 0; - for (i = 0; i < 8 && voxel[i].hd >= 0; i++) { - if (voxel[i].hd != n) { - hdgrid(gp, hdlist[n=voxel[i].hd], v->vp); - igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2]; - } - if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] && - voxel[i].i[2] == igp[2]) - vcflgs |= 1<hd = cbeam[ncbeams+i].hd; - pp->bi = cbeam[ncbeams+i].bi; - pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1; - pp->nc = 0; - } - n = xcbeams - n2; - /* now sort list for deletions */ - cbeamsort(0); - pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD)); - if (n+n2+xcbeams && pa2 == NULL) - goto memerr; - pa = pa2 + n2; - for (i = xcbeams; i--; ) { - pp = pa + n++; - pp->hd = cbeam[ncbeams+i].hd; - pp->bi = cbeam[ncbeams+i].bi; - pp->nr = 0; - pp->nc = 0; - } - if (n) /* adjust the set */ - serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); - if (n2) /* make secondary additions */ - serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2); - xcbeams = 0; /* clean up */ - free((char *)pa2); - return; -memerr: - error(SYSTEM, "out of memory in cbeamadj"); -} - - -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; @@ -240,12 +174,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); @@ -253,61 +186,22 @@ 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); @@ -320,12 +214,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<= lastd) - error(WARNING, "moving outside holodeck section"); - else if (n > lastn && bestd <= lastd) - error(WARNING, "moving inside holodeck section"); - lastd = bestd; - return(lastn = n); + if (n < MAXVOXEL) + voxel[n].hd = -1; + return(rfl); } @@ -349,7 +251,7 @@ GCOORD *gcp; register struct beamact *bp; { GCOORD gc[2]; - int bi, i; + int bi, i, n; /* compute beam index */ if (bp->ca.rev) { copystruct(gc, &bp->gc); @@ -363,12 +265,18 @@ register struct beamact *bp; 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 */ + 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 */ } /* 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 */ + if (!cbeam[i].wants) + cbeam[i].nr = 0; return(1); /* indicate change */ } return(0); @@ -391,8 +299,8 @@ register struct cellact *cap; register int i; /* compute cell center */ cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; - cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5; - cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5; + cgp[hdwg0[gcp->w]] = gcp->i[0] + .5; + cgp[hdwg1[gcp->w]] = gcp->i[1] + .5; hdworld(org, hp, cgp); /* compute direction to voxel center */ for (i = 3; i--; ) @@ -419,8 +327,8 @@ register struct cellact *cap; for (i = 3; i--; ) v1[i] = hp->xv[j][i] * d; d = 0.5/hp->grid[j=(axmax+2)%3]; - if (DOT(hp->wn[axmax], vc) < 0.) - d = -d; /* reverse vertex ordering */ + if (DOT(hp->wg[axmax], vc) < 0.) + d = -d; /* reverse vertex order */ for (i = 3; i--; ) v2[i] = hp->xv[j][i] * d; /* compute voxel pyramid */ @@ -438,14 +346,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; @@ -454,99 +361,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 c; - GCOORD *ogcl, *ngcl; - 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 (nca.rev == oca.rev) /* add and delete cells in order */ - while (ocnt > 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].wants = cbeam[i].nr = 0; + voxel[0].hd = -1; /* clear voxel list */ } -int -beam_sync() /* synchronize beams on server */ -{ - cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); - return(ncbeams); -} - - -beam_view(vn) /* change beam view (if advisable) */ +beam_view(vn, hr, vr) /* add beam view (if advisable) */ VIEW *vn; +int hr, vr; { 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 */ + int vfl; + /* sort our list */ + cbeamsort(1); + /* add new voxels */ + vfl = add_voxels(vn->vp); + if (!vfl) return(0); - } - /* set the new voxels */ - comn = set_voxels(vlnew, n); - if (!dvw.type) - comn = 0; + ca.vp = vn; ca.hr = hr; ca.vr = vr; ca.add = 1; /* update our beam list */ - for (ca.vi = n; ca.vi--; ) - if (comn & 1<>= 1, ca.vi++) + if (vfl & 1) + doview(&ca); + return(1); +} + + +int +beam_sync(all) /* update beam list on server */ +int all; +{ /* sort list to put orphans at end */ cbeamsort(0); - /* tell server to delete orphans */ - cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); + if (all) + cbeamop(DR_NEWSET, cbeam, ncbeams); + else + cbeamop(DR_ADJSET, cbeam, ncbeams+xcbeams); xcbeams = 0; /* truncate our list */ -#endif - copystruct(&dvw, vn); /* record new view */ - return(1); + return(ncbeams); }