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.2 by gregl, Thu Nov 20 14:46:07 1997 UTC vs.
Revision 3.5 by gregl, Fri Nov 21 18:17:37 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   typedef struct {
18          int     hd;             /* holodeck section number (-1 if inactive) */
# Line 39 | Line 39 | static int     maxcbeam = 0;   /* size of cbeam array */
39   struct cellact {
40          short   vi;             /* voxel index */
41          short   add;            /* zero means delete */
42 +        short   rev;            /* reverse ray direction? */
43   };              /* action for cell */
44  
45   struct beamact {
# Line 155 | Line 156 | int    adopt;
156   }
157  
158  
159 < cbeamadd(bl, n, v, hr, vr)      /* add beams to server list */
159 > cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
160 > int     op;
161   register struct beamcomp        *bl;
162   int     n;
163   VIEW    *v;
# Line 169 | Line 171 | int    hr, vr;
171          pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
172          if (pa == NULL)
173                  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");
174          for (i = 0; i < n; i++) {
175                  pa[i].hd = bl[i].hd;
176                  pa[i].bi = bl[i].bi;
177 <                pa[i].nr = 0;           /* removes any request */
177 >                pa[i].nr = v==NULL ? 0 :
178 >                                npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
179          }
180 <        serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa);
180 >        serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
181          free((char *)pa);
182   }
183  
# Line 245 | Line 226 | get_voxels(vl, vp)     /* find voxels corresponding to vie
226   VOXL    vl[8];
227   FVECT   vp;
228   {
229 +        static int      lastn = 0, lastd = -1;
230          int     n = 0;
231          FVECT   gp;
232          double  d;
# Line 275 | Line 257 | FVECT  vp;
257                          n++;
258                  }
259          }
260 <        return(n);
260 >                                        /* warn of dangerous moves */
261 >        if (n < lastn && bestd >= lastd)
262 >                error(WARNING, "moving outside holodeck section");
263 >        else if (n > lastn && bestd <= lastd)
264 >                error(WARNING, "moving inside holodeck section");
265 >        lastd = bestd;
266 >        return(lastn = n);
267   }
268  
269  
# Line 287 | Line 275 | register struct beamact        *bp;
275          GCOORD  gc[2];
276          int     bi, i;
277                                          /* compute beam index */
278 <        copystruct(gc, gcp);
279 <        copystruct(gc+1, &bp->gc);
278 >        if (bp->ca.rev) {
279 >                copystruct(gc, &bp->gc);
280 >                copystruct(gc+1, gcp);
281 >        } else {
282 >                copystruct(gc, gcp);
283 >                copystruct(gc+1, &bp->gc);
284 >        }
285          if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0)
286                  error(CONSISTENCY, "bad grid coordinate in dobeam");
287          if (bp->ca.add) {               /* add it in */
# Line 348 | Line 341 | doview(cap, vp)                        /* visit cells for a given view */
341   struct cellact  *cap;
342   VIEW    *vp;
343   {
344 +        int     orient;
345          FVECT   org, dir[4];
346                                          /* compute view pyramid */
347 <        if (vp->type == VT_PAR) goto viewerr;
348 <        if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr;
349 <        if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr;
350 <        if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr;
357 <        if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr;
347 >        orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp);
348 >        if (!orient)
349 >                error(INTERNAL, "unusable view in doview");
350 >        cap->rev = orient < 0;
351                                          /* visit cells within pyramid */
352          return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap));
360 viewerr:
361        error(INTERNAL, "unusable view in doview");
353   }
354  
355  
# Line 367 | Line 358 | int    voxi;
358   VIEW    *vold, *vnew;
359   {
360          int     netchange = 0;
361 <        int     *ocl, *ncl;
371 <        struct cellact  ca;
361 >        struct cellact  oca, nca;
362          int     ocnt, ncnt;
363          int     c;
364          register GCOORD *ogcp, *ngcp;
365                                  /* get old and new cell lists */
366 <        ocl = getviewcells(hdlist[voxel[voxi].hd], vold);
367 <        ncl = getviewcells(hdlist[voxel[voxi].hd], vnew);
368 <        if (ocl != NULL) {
369 <                ocnt = *ocl; ogcp = (GCOORD *)(ocl+1);
370 <        } else {
371 <                ocnt = 0; ogcp = NULL;
372 <        }
373 <        if (ncl != NULL) {
374 <                ncnt = *ncl; ngcp = (GCOORD *)(ncl+1);
375 <        } else {
376 <                ncnt = 0; ngcp = NULL;
387 <        }
388 <        ca.vi = voxi;           /* add and delete cells */
366 >        ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
367 >        ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
368 >                                /* set up actions */
369 >        oca.vi = nca.vi = voxi;
370 >        oca.rev = nca.rev = 0;
371 >        oca.add = 0; nca.add = 1;
372 >        if ((oca.rev = ocnt < 0))
373 >                ocnt = -ocnt;
374 >        if ((nca.rev = ncnt < 0))
375 >                ncnt = -ncnt;
376 >                                /* add and delete cells in order */
377          while (ocnt > 0 & ncnt > 0)
378 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {
379 <                        ca.add = 1;             /* new cell */
392 <                        netchange += docell(ngcp++, &ca);
378 >                if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
379 >                        netchange += docell(ngcp++, &nca);
380                          ncnt--;
381 <                } else if (c < 0) {
382 <                        ca.add = 0;             /* obsolete cell */
396 <                        netchange -= docell(ogcp++, &ca);
381 >                } else if (c < 0) {                     /* obsolete cell */
382 >                        netchange -= docell(ogcp++, &oca);
383                          ocnt--;
384 <                } else {
385 <                        ogcp++; ocnt--;         /* unchanged cell */
384 >                } else {                                /* same cell? */
385 >                        if (oca.rev != nca.rev)         /* not */
386 >                                netchange += docell(ngcp, &nca) -
387 >                                                docell(ogcp, &oca);
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 (ogcp != NULL) free((char *)ogcp);
398 >        if (ngcp != NULL) free((char *)ngcp);
399          return(netchange);
400   }
401  
402  
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(vo, vn)       /* change beam view */
410   VIEW    *vo, *vn;
411   {
# Line 420 | Line 415 | VIEW   *vo, *vn;
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                  return;
421          }
# Line 437 | Line 432 | VIEW   *vo, *vn;
432                  else                    /* else add all new cells */
433                          doview(&ca, vn);
434                                          /* inform server of new beams */
435 <        cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
435 >        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
436                                          /* sort list to put orphans at end */
437          cbeamsort(0);
438                                          /* tell server to delete orphans */
439 <        cbeamdel(cbeam+ncbeams, xcbeams);
439 >        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
440          xcbeams = 0;                    /* truncate our list */
441   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines