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.4 by gregl, Fri Nov 21 16:10:17 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 274 | 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 335 | 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;
344 <        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));
347 viewerr:
348        error(INTERNAL, "unusable view in doview");
353   }
354  
355  
# Line 354 | Line 358 | int    voxi;
358   VIEW    *vold, *vnew;
359   {
360          int     netchange = 0;
361 <        int     *ocl, *ncl;
358 <        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;
374 <        }
375 <        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 */
379 <                        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 */
383 <                        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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines