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.3 by gregl, Thu Nov 20 18:06:35 1997 UTC vs.
Revision 3.7 by gregl, Tue Nov 25 10:48:38 1997 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "rhdisp.h"
13   #include "rhdriver.h"
14  
15 < extern int      *getviewcells();
15 > extern GCOORD   *getviewcells();
16  
17 + static VIEW     dvw;            /* current view corresponding to beam list */
18 +
19   typedef struct {
20          int     hd;             /* holodeck section number (-1 if inactive) */
21          int     i[3];           /* voxel index (may be outside section) */
# Line 39 | Line 41 | static int     maxcbeam = 0;   /* size of cbeam array */
41   struct cellact {
42          short   vi;             /* voxel index */
43          short   add;            /* zero means delete */
44 +        short   rev;            /* reverse ray direction? */
45   };              /* action for cell */
46  
47   struct beamact {
# Line 155 | Line 158 | int    adopt;
158   }
159  
160  
161 < cbeamadd(bl, n, v, hr, vr)      /* add beams to server list */
161 > cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
162 > int     op;
163   register struct beamcomp        *bl;
164   int     n;
165   VIEW    *v;
# Line 169 | Line 173 | int    hr, vr;
173          pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
174          if (pa == NULL)
175                  error(SYSTEM, "out of memory in cbeamadd");
172        for (i = 0; i < n; i++)
173                pa[i].nr = npixels(v, hr, vr,
174                                hdlist[pa[i].hd=bl[i].hd],
175                                pa[i].bi=bl[i].bi) / 8;
176
177        serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa);
178        free((char *)pa);
179 }
180
181
182 cbeamdel(bl, n)         /* delete unwanted beam requests */
183 register struct beamcomp        *bl;
184 int     n;
185 {
186        register PACKHEAD       *pa;
187        register int    i;
188
189        if (n <= 0)
190                return;
191        pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
192        if (pa == NULL)
193                error(SYSTEM, "out of memory in cbeamdel");
176          for (i = 0; i < n; i++) {
177                  pa[i].hd = bl[i].hd;
178                  pa[i].bi = bl[i].bi;
179 <                pa[i].nr = 0;           /* removes any request */
179 >                pa[i].nr = v==NULL ? 0 :
180 >                                npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
181          }
182 <        serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa);
182 >        serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
183          free((char *)pa);
184   }
185  
# Line 294 | Line 277 | register struct beamact        *bp;
277          GCOORD  gc[2];
278          int     bi, i;
279                                          /* compute beam index */
280 <        copystruct(gc, gcp);
281 <        copystruct(gc+1, &bp->gc);
280 >        if (bp->ca.rev) {
281 >                copystruct(gc, &bp->gc);
282 >                copystruct(gc+1, gcp);
283 >        } else {
284 >                copystruct(gc, gcp);
285 >                copystruct(gc+1, &bp->gc);
286 >        }
287          if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0)
288                  error(CONSISTENCY, "bad grid coordinate in dobeam");
289          if (bp->ca.add) {               /* add it in */
# Line 355 | Line 343 | doview(cap, vp)                        /* visit cells for a given view */
343   struct cellact  *cap;
344   VIEW    *vp;
345   {
346 +        int     orient;
347          FVECT   org, dir[4];
348                                          /* compute view pyramid */
349 <        if (vp->type == VT_PAR) goto viewerr;
350 <        if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr;
351 <        if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr;
352 <        if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr;
364 <        if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr;
349 >        orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp);
350 >        if (!orient)
351 >                error(INTERNAL, "unusable view in doview");
352 >        cap->rev = orient < 0;
353                                          /* visit cells within pyramid */
354          return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap));
367 viewerr:
368        error(INTERNAL, "unusable view in doview");
355   }
356  
357  
# Line 374 | Line 360 | int    voxi;
360   VIEW    *vold, *vnew;
361   {
362          int     netchange = 0;
363 <        int     *ocl, *ncl;
378 <        struct cellact  ca;
363 >        struct cellact  oca, nca;
364          int     ocnt, ncnt;
365          int     c;
366 +        GCOORD  *ogcl, *ngcl;
367          register GCOORD *ogcp, *ngcp;
368                                  /* get old and new cell lists */
369 <        ocl = getviewcells(hdlist[voxel[voxi].hd], vold);
370 <        ncl = getviewcells(hdlist[voxel[voxi].hd], vnew);
371 <        if (ocl != NULL) {
372 <                ocnt = *ocl; ogcp = (GCOORD *)(ocl+1);
373 <        } else {
374 <                ocnt = 0; ogcp = NULL;
375 <        }
376 <        if (ncl != NULL) {
377 <                ncnt = *ncl; ngcp = (GCOORD *)(ncl+1);
378 <        } else {
379 <                ncnt = 0; ngcp = NULL;
380 <        }
381 <        ca.vi = voxi;           /* add and delete cells */
382 <        while (ocnt > 0 & ncnt > 0)
383 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {
384 <                        ca.add = 1;             /* new cell */
385 <                        netchange += docell(ngcp++, &ca);
386 <                        ncnt--;
387 <                } else if (c < 0) {
388 <                        ca.add = 0;             /* obsolete cell */
389 <                        netchange -= docell(ogcp++, &ca);
390 <                        ocnt--;
405 <                } else {
406 <                        ogcp++; ocnt--;         /* unchanged cell */
407 <                        ngcp++; ncnt--;
408 <                }
369 >        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
370 >        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
371 >                                /* set up actions */
372 >        oca.vi = nca.vi = voxi;
373 >        oca.rev = nca.rev = 0;
374 >        oca.add = 0; nca.add = 1;
375 >        if ((oca.rev = ocnt < 0))
376 >                ocnt = -ocnt;
377 >        if ((nca.rev = ncnt < 0))
378 >                ncnt = -ncnt;
379 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
380 >                while (ocnt > 0 & ncnt > 0)
381 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
382 >                                netchange += docell(ngcp++, &nca);
383 >                                ncnt--;
384 >                        } else if (c < 0) {                     /* old cell */
385 >                                netchange -= docell(ogcp++, &oca);
386 >                                ocnt--;
387 >                        } else {                                /* same cell */
388 >                                ogcp++; ocnt--;
389 >                                ngcp++; ncnt--;
390 >                        }
391                                  /* take care of list tails */
392 <        for (ca.add = 1; ncnt > 0; ncnt--)
393 <                netchange += docell(ngcp++, &ca);
394 <        for (ca.add = 0; ocnt > 0; ocnt--)
395 <                netchange -= docell(ogcp++, &ca);
392 >        for ( ; ncnt > 0; ncnt--)
393 >                netchange += docell(ngcp++, &nca);
394 >        for ( ; ocnt > 0; ocnt--)
395 >                netchange -= docell(ogcp++, &oca);
396                                  /* clean up */
397 <        if (ocl != NULL) free((char *)ocl);
398 <        if (ncl != NULL) free((char *)ncl);
397 >        if (ogcl != NULL) free((char *)ogcl);
398 >        if (ngcl != NULL) free((char *)ngcl);
399          return(netchange);
400   }
401  
402  
403 < beam_view(vo, vn)       /* change beam view */
422 < VIEW    *vo, *vn;
403 > beam_sync()             /* synchronize beams on server */
404   {
405 +        cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
406 + }
407 +
408 +
409 + beam_view(vn)                   /* change beam view */
410 + VIEW    *vn;
411 + {
412          struct cellact  ca;
413          VOXL    vlnew[8];
414          int     n, comn;
415  
416          if (!vn->type) {                /* clear our beam list */
417                  set_voxels(vlnew, 0);
418 <                cbeamdel(cbeam, ncbeams);
418 >                cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
419                  ncbeams = 0;
420 +                copystruct(&dvw, vn);
421                  return;
422          }
423                                          /* find our new voxels */
424          n = get_voxels(vlnew, vn->vp);
425                                          /* set the new voxels */
426          comn = set_voxels(vlnew, n);
427 <        if (!vo->type)
427 >        if (!dvw.type)
428                  comn = 0;
429          ca.add = 1;                     /* update our beam list */
430          for (ca.vi = n; ca.vi--; )
431                  if (comn & 1<<ca.vi)    /* change which cells we see */
432 <                        mvview(ca.vi, vo, vn);
432 >                        mvview(ca.vi, &dvw, vn);
433                  else                    /* else add all new cells */
434                          doview(&ca, vn);
435                                          /* inform server of new beams */
436 <        cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
436 >        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
437                                          /* sort list to put orphans at end */
438          cbeamsort(0);
439                                          /* tell server to delete orphans */
440 <        cbeamdel(cbeam+ncbeams, xcbeams);
440 >        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
441          xcbeams = 0;                    /* truncate our list */
442 +        copystruct(&dvw, vn);           /* record new view */
443   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines