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.1 by gregl, Wed Nov 19 18:01:03 1997 UTC vs.
Revision 3.6 by gregl, Mon Nov 24 15:17:28 1997 UTC

# Line 5 | Line 5 | static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
8 < * Holodeck beam tracking
8 > * Holodeck beam tracking for display process
9   */
10  
11   #include "rholo.h"
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 */
18 >        int     hd;             /* holodeck section number (-1 if inactive) */
19          int     i[3];           /* voxel index (may be outside section) */
20   } VOXL;                 /* a voxel */
21  
# Line 36 | Line 36 | static int     ncbeams = 0;    /* number of sorted beams in c
36   static int      xcbeams = 0;    /* extra (unregistered) beams past ncbeams */
37   static int      maxcbeam = 0;   /* size of cbeam array */
38  
39
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
45   struct beamact {
46          struct cellact  ca;     /* cell action */
47          GCOORD  gc;             /* grid coordinate */
# Line 157 | 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 171 | Line 171 | int    hr, vr;
171          pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
172          if (pa == NULL)
173                  error(SYSTEM, "out of memory in cbeamadd");
174        for (i = 0; i < n; i++)
175                pa[i].nr = npixels(v, hr, vr,
176                                hdlist[pa[i].hd=bl[i].hd],
177                                pa[i].bi=bl[i].bi) / 8;
178
179        serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa);
180        free((char *)pa);
181 }
182
183
184 cbeamdel(bl, n)         /* delete unwanted beam requests */
185 register struct beamcomp        *bl;
186 int     n;
187 {
188        register PACKHEAD       *pa;
189        register int    i;
190
191        if (n <= 0)
192                return;
193        pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
194        if (pa == NULL)
195                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 247 | 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 277 | 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 289 | 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 <                return(0);              /* should report an error? */
286 >                error(CONSISTENCY, "bad grid coordinate in dobeam");
287          if (bp->ca.add) {               /* add it in */
288                  i = getcbeam(voxel[bp->ca.vi].hd, bi);
289                  cbeam[i].wants |= 1<<bp->ca.vi; /* say we want it */
# Line 350 | 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;
359 <        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));
362 viewerr:
363        error(INTERNAL, "unusable view in doview");
353   }
354  
355  
# Line 369 | Line 358 | int    voxi;
358   VIEW    *vold, *vnew;
359   {
360          int     netchange = 0;
361 <        int     *ocl, *ncl;
373 <        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;
377 <        }
378 <        ca.vi = voxi;           /* add and delete cells */
379 <        while (ocnt > 0 & ncnt > 0)
380 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {
381 <                        ca.add = 1;             /* new cell */
382 <                        netchange += docell(ngcp++, &ca);
383 <                        ncnt--;
384 <                } else if (c < 0) {
385 <                        ca.add = 0;             /* obsolete cell */
386 <                        netchange -= docell(ogcp++, &ca);
387 <                        ocnt--;
400 <                } else {
401 <                        ogcp++; ocnt--;         /* unchanged cell */
402 <                        ngcp++; ncnt--;
403 <                }
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 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
377 >                while (ocnt > 0 & ncnt > 0)
378 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
379 >                                netchange += docell(ngcp++, &nca);
380 >                                ncnt--;
381 >                        } else if (c < 0) {                     /* old cell */
382 >                                netchange -= docell(ogcp++, &oca);
383 >                                ocnt--;
384 >                        } else {                                /* same cell */
385 >                                ogcp++; ocnt--;
386 >                                ngcp++; ncnt--;
387 >                        }
388                                  /* take care of list tails */
389 <        for (ca.add = 1; ncnt > 0; ncnt--)
390 <                docell(ngcp++, &ca);
391 <        for (ca.add = 0; ocnt > 0; ocnt--)
392 <                docell(ogcp++, &ca);
389 >        for ( ; ncnt > 0; ncnt--)
390 >                netchange += docell(ngcp++, &nca);
391 >        for ( ; ocnt > 0; ocnt--)
392 >                netchange -= docell(ogcp++, &oca);
393                                  /* clean up */
394 <        if (ocl != NULL) free((char *)ocl);
395 <        if (ncl != NULL) free((char *)ncl);
394 >        if (ogcp != NULL) free((char *)ogcp);
395 >        if (ngcp != NULL) free((char *)ngcp);
396          return(netchange);
397   }
398  
399  
400 + beam_sync()             /* synchronize beams on server */
401 + {
402 +        cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
403 + }
404 +
405 +
406   beam_view(vo, vn)       /* change beam view */
407   VIEW    *vo, *vn;
408   {
# Line 422 | Line 412 | VIEW   *vo, *vn;
412  
413          if (!vn->type) {                /* clear our beam list */
414                  set_voxels(vlnew, 0);
415 <                cbeamdel(cbeam, ncbeams);
415 >                cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
416                  ncbeams = 0;
417                  return;
418          }
# Line 439 | Line 429 | VIEW   *vo, *vn;
429                  else                    /* else add all new cells */
430                          doview(&ca, vn);
431                                          /* inform server of new beams */
432 <        cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
432 >        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
433                                          /* sort list to put orphans at end */
434          cbeamsort(0);
435                                          /* tell server to delete orphans */
436 <        cbeamdel(cbeam+ncbeams, xcbeams);
436 >        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
437          xcbeams = 0;                    /* truncate our list */
438   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines