ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp2.c
(Generate patch)

Comparing ray/src/hd/rhdisp2.c (file contents):
Revision 3.16 by gregl, Tue Dec 16 11:57:32 1997 UTC vs.
Revision 3.20 by gwlarson, Thu May 14 10:13:50 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ SGI";
16   #define MAXDIST         42      /* maximum distance outside section */
17   #endif
18  
19 + #define MAXVOXEL        16      /* maximum number of active voxels */
20 +
21   extern GCOORD   *getviewcells();
22  
23   static VIEW     dvw;            /* current view corresponding to beam list */
# Line 25 | Line 27 | typedef struct {
27          int     i[3];           /* voxel index (may be outside section) */
28   } VOXL;                 /* a voxel */
29  
30 < static VOXL voxel[8] = {        /* current voxel list */
29 <        {-1}, {-1}, {-1}, {-1},
30 <        {-1}, {-1}, {-1}, {-1}
31 < };
30 > static VOXL voxel[MAXVOXEL] = {{-1}};   /* current voxel list */
31  
32   #define CBEAMBLK        1024    /* cbeam allocation block size */
33  
34   static struct beamcomp {
35 <        short   wants;          /* flags telling which voxels want us */
36 <        short   hd;             /* holodeck section number */
35 >        unsigned short  wants;  /* flags telling which voxels want us */
36 >        unsigned short  hd;     /* holodeck section number */
37          int     bi;             /* beam index */
38   } *cbeam = NULL;        /* current beam list */
39  
# Line 164 | Line 163 | int    adopt;
163   }
164  
165  
167 cbeamadj(v, hr, vr)             /* adjust our beam list */
168 VIEW    *v;
169 int     hr, vr;
170 {
171        PACKHEAD        *pa, *pa2;
172        register PACKHEAD       *pp;
173        int     n, n2;
174        FVECT   gp;
175        int     igp[3], vcflgs;
176        register int    i;
177                                        /* figure out center voxel(s) */
178        n = -1; vcflgs = 0;
179        for (i = 0; i < 8 && voxel[i].hd >= 0; i++) {
180                if (voxel[i].hd != n) {
181                        hdgrid(gp, hdlist[n=voxel[i].hd], v->vp);
182                        igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2];
183                }
184                if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] &&
185                                voxel[i].i[2] == igp[2])
186                        vcflgs |= 1<<i;
187        }
188                                        /* get additions */
189        pa2 = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD));
190        if (xcbeams && pa2 == NULL)
191                goto memerr;
192        pa = pa2 + xcbeams; n2 = 0;
193        for (i = xcbeams; i--; ) {
194                if (cbeam[ncbeams+i].wants & vcflgs)
195                        pp = --pa;              /* priority list */
196                else
197                        pp = pa2 + n2++;        /* secondary list */
198                pp->hd = cbeam[ncbeams+i].hd;
199                pp->bi = cbeam[ncbeams+i].bi;
200                pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1;
201                pp->nc = 0;
202        }
203        n = xcbeams - n2;
204                                        /* now sort list for deletions */
205        cbeamsort(0);
206        pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD));
207        if (n+n2+xcbeams && pa2 == NULL)
208                goto memerr;
209        pa = pa2 + n2;
210        for (i = xcbeams; i--; ) {
211                pp = pa + n++;
212                pp->hd = cbeam[ncbeams+i].hd;
213                pp->bi = cbeam[ncbeams+i].bi;
214                pp->nr = 0;
215                pp->nc = 0;
216        }
217        if (n)                          /* adjust the set */
218                serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa);
219        if (n2)                         /* make secondary additions */
220                serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2);
221        xcbeams = 0;                    /* clean up */
222        free((char *)pa2);
223        return;
224 memerr:
225        error(SYSTEM, "out of memory in cbeamadj");
226 }
227
228
166   cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
167   int     op;
168   register struct beamcomp        *bl;
# Line 255 | Line 192 | int    hr, vr;
192  
193   int
194   set_voxels(vl, n)       /* set new voxel array */
195 < VOXL    vl[8];
195 > VOXL    vl[MAXVOXEL];
196   int     n;
197   {
198          short   wmap[256];
199 <        int     vmap[8];
199 >        int     vmap[MAXVOXEL];
200          int     comn = 0;
201          int     no;
202          register int    i, j;
203                                          /* find common voxels */
204 <        for (j = 0; j < 8 && voxel[j].hd >= 0; j++) {
204 >        for (j = 0; j < MAXVOXEL && voxel[j].hd >= 0; j++) {
205                  vmap[j] = -1;
206                  for (i = n; i--; )
207                          if (!bcmp((char *)(vl+i), (char *)(voxel+j),
# Line 286 | Line 223 | int    n;
223                  cbeam[i].wants = wmap[cbeam[i].wants];
224                                          /* update our voxel list */
225          bcopy((char *)vl, (char *)voxel, n*sizeof(VOXL));
226 <        for (j = n; j < 8; j++)
227 <                voxel[j].hd = -1;
226 >        if (n < MAXVOXEL)
227 >                voxel[n].hd = -1;
228          return(comn);                   /* return bit array of common voxels */
229   }
230  
231  
232   int
233   get_voxels(vl, vp)      /* find voxels corresponding to view point */
234 < VOXL    vl[8];
234 > VOXL    vl[MAXVOXEL];
235   FVECT   vp;
236   {
237 <        static int      lastn = 0, lastd = -1;
301 <        int     n = 0;
237 >        int     first, n;
238          FVECT   gp;
239          double  d;
240          int     dist, bestd = 0x7fff;
241          VOXL    vox;
242          register int    i, j, k;
243 +                                        /* count voxels in list already */
244 +        for (first = 0; first < MAXVOXEL && vl[first].hd >= 0; first++)
245 +                ;
246                                          /* find closest voxels */
247 <        for (i = 0; n < 8 && hdlist[i]; i++) {
247 >        for (n = first, i = 0; n < MAXVOXEL && hdlist[i]; i++) {
248                  hdgrid(gp, hdlist[i], vp);
249 <                for (j = 0; n < 8 && j < 8; j++) {
249 >                for (j = 0; n < MAXVOXEL && j < 8; j++) {
250                          dist = 0;
251                          for (k = 0; k < 3; k++) {
252                                  d = gp[k] - .5 + (j>>k & 1);
# Line 320 | Line 259 | FVECT  vp;
259                          if (dist > bestd)       /* others were closer */
260                                  continue;
261                          if (dist < bestd) {     /* start closer list */
262 <                                n = 0;
262 >                                n = first;
263                                  bestd = dist;
264                          }
265 +                                                /* check if already in list */
266 +                        for (k = first; k--; )
267 +                                if (vl[k].hd == i &&
268 +                                                vl[k].i[0] == vox.i[0] &&
269 +                                                vl[k].i[1] == vox.i[1] &&
270 +                                                vl[k].i[2] == vox.i[2])
271 +                                        break;
272 +                        if (k >= 0)
273 +                                continue;
274                          vox.hd = i;             /* add this voxel */
275                          copystruct(&vl[n], &vox);
276                          n++;
# Line 333 | Line 281 | FVECT  vp;
281                  error(COMMAND, "move past outer limits");
282                  return(0);
283          }
284 <                                        /* warn of dangerous moves */
285 <        if (n < lastn && bestd >= lastd)
286 <                error(WARNING, "moving outside holodeck section");
339 <        else if (n > lastn && bestd <= lastd)
340 <                error(WARNING, "moving inside holodeck section");
341 <        lastd = bestd;
342 <        return(lastn = n);
284 >        if (n < MAXVOXEL)
285 >                vl[n].hd = -1;
286 >        return(n);
287   }
288  
289  
# Line 391 | Line 335 | register struct cellact        *cap;
335          register int    i;
336                                  /* compute cell center */
337          cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
338 <        cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5;
339 <        cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5;
338 >        cgp[hdwg0[gcp->w]] = gcp->i[0] + .5;
339 >        cgp[hdwg1[gcp->w]] = gcp->i[1] + .5;
340          hdworld(org, hp, cgp);
341                                  /* compute direction to voxel center */
342          for (i = 3; i--; )
# Line 419 | Line 363 | register struct cellact        *cap;
363          for (i = 3; i--; )
364                  v1[i] = hp->xv[j][i] * d;
365          d = 0.5/hp->grid[j=(axmax+2)%3];
366 <        if (DOT(hp->wn[axmax], vc) < 0.)
367 <                d = -d; /* reverse vertex ordering */
366 >        if (DOT(hp->wg[axmax], vc) < 0.)
367 >                d = -d; /* reverse vertex order */
368          for (i = 3; i--; )
369                  v2[i] = hp->xv[j][i] * d;
370                                  /* compute voxel pyramid */
# Line 461 | Line 405 | VIEW   *vold, *vnew;
405          int     netchange = 0;
406          struct cellact  oca, nca;
407          int     ocnt, ncnt;
408 <        int     c;
408 >        int     nmatch = 0;
409          GCOORD  *ogcl, *ngcl;
410 +        register int    c;
411          register GCOORD *ogcp, *ngcp;
412                                  /* get old and new cell lists */
413          ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
# Line 474 | Line 419 | VIEW   *vold, *vnew;
419                  ocnt = -ocnt;
420          if ((nca.rev = ncnt < 0))
421                  ncnt = -ncnt;
422 <        if (nca.rev == oca.rev)         /* add and delete cells in order */
423 <                while (ocnt > 0 & ncnt > 0)
424 <                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
425 <                                netchange += docell(ngcp++, &nca);
426 <                                ncnt--;
427 <                        } else if (c < 0) {                     /* old cell */
428 <                                netchange -= docell(ogcp++, &oca);
429 <                                ocnt--;
430 <                        } else {                                /* same cell */
431 <                                ogcp++; ocnt--;
432 <                                ngcp++; ncnt--;
422 >        if (oca.rev == nca.rev) {       /* count matches */
423 >                int     oc = ocnt, nc = ncnt;
424 >                while (oc > 0 & nc > 0) {
425 >                        c = cellcmp(ogcp, ngcp);
426 >                        if (c >= 0) { ngcp++; nc--; }
427 >                        if (c <= 0) { ogcp++; oc--; }
428 >                        nmatch += c==0;
429 >                }
430 >                ogcp = ogcl; ngcp = ngcl;
431 >        }
432 >        if (nmatch < ocnt>>1) {         /* faster to just delete old cells? */
433 >                for (c = ncbeams; c--; )
434 >                        if (cbeam[c].wants & 1<<voxi) {
435 >                                cbeam[c].wants &= ~(1<<voxi);
436 >                                netchange--;
437                          }
438 +                free((char *)ogcl);
439 +                ogcl = NULL; ocnt = 0;
440 +        }
441 +                                /* add and delete cells in order */
442 +        while (ocnt > 0 & ncnt > 0)
443 +                if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
444 +                        netchange += docell(ngcp++, &nca);
445 +                        ncnt--;
446 +                } else if (c < 0) {                     /* old cell */
447 +                        netchange -= docell(ogcp++, &oca);
448 +                        ocnt--;
449 +                } else {                                /* same cell */
450 +                        ogcp++; ocnt--;
451 +                        ngcp++; ncnt--;
452 +                }
453                                  /* take care of list tails */
454          for ( ; ncnt > 0; ncnt--)
455                  netchange += docell(ngcp++, &nca);
# Line 510 | Line 474 | beam_view(vn)                  /* change beam view (if advisable) */
474   VIEW    *vn;
475   {
476          struct cellact  ca;
477 <        VOXL    vlnew[8];
477 >        VOXL    vlnew[MAXVOXEL];
478          int     n, comn;
479  
480          if (vn == NULL || !vn->type) {  /* clear our beam list */
# Line 536 | Line 500 | VIEW   *vn;
500                          mvview(ca.vi, &dvw, vn);
501                  else                    /* else add all new cells */
502                          doview(&ca, vn);
539 #if 1
540        cbeamadj(vn, odev.hres, odev.vres);
541 #else
503                                          /* inform server of new beams */
504          cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
505                                          /* sort list to put orphans at end */
# Line 546 | Line 507 | VIEW   *vn;
507                                          /* tell server to delete orphans */
508          cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
509          xcbeams = 0;                    /* truncate our list */
549 #endif
510          copystruct(&dvw, vn);           /* record new view */
511          return(1);
512   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines