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.17 by gregl, Thu Jan 1 13:00:16 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 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "rhdisp.h"
13   #include "rhdriver.h"
14  
15 < extern int      *getviewcells();
15 > #ifndef MAXDIST
16 > #define MAXDIST         42      /* maximum distance outside section */
17 > #endif
18  
19 + extern GCOORD   *getviewcells();
20 +
21 + static VIEW     dvw;            /* current view corresponding to beam list */
22 +
23   typedef struct {
24          int     hd;             /* holodeck section number (-1 if inactive) */
25          int     i[3];           /* voxel index (may be outside section) */
# Line 39 | Line 45 | static int     maxcbeam = 0;   /* size of cbeam array */
45   struct cellact {
46          short   vi;             /* voxel index */
47          short   add;            /* zero means delete */
48 +        short   rev;            /* reverse ray direction? */
49   };              /* action for cell */
50  
51   struct beamact {
# Line 87 | Line 94 | register struct beamcomp       *cb1, *cb2;
94  
95          if (!cb1->wants)                /* put orphans at the end, unsorted */
96                  return(cb2->wants);
97 +        if (!cb2->wants)
98 +                return(-1);
99          if ((c = cb1->bi - cb2->bi))    /* sort on beam index first */
100                  return(c);
101          return(cb1->hd - cb2->hd);      /* use hd to resolve matches */
# Line 155 | Line 164 | int    adopt;
164   }
165  
166  
167 < cbeamadd(bl, n, v, hr, vr)      /* add beams to server list */
167 > cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
168 > int     op;
169   register struct beamcomp        *bl;
170   int     n;
171   VIEW    *v;
# Line 169 | Line 179 | int    hr, vr;
179          pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
180          if (pa == NULL)
181                  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");
182          for (i = 0; i < n; i++) {
183                  pa[i].hd = bl[i].hd;
184                  pa[i].bi = bl[i].bi;
185 <                pa[i].nr = 0;           /* removes any request */
185 >                pa[i].nr = v==NULL ? 0 :
186 >                                npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
187 >                pa[i].nc = 0;
188          }
189 <        serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa);
189 >        serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
190          free((char *)pa);
191   }
192  
# Line 275 | Line 265 | FVECT  vp;
265                          n++;
266                  }
267          }
268 +                                        /* check for really stupid move */
269 +        if (bestd > MAXDIST) {
270 +                error(COMMAND, "move past outer limits");
271 +                return(0);
272 +        }
273          return(n);
274   }
275  
# Line 287 | Line 282 | register struct beamact        *bp;
282          GCOORD  gc[2];
283          int     bi, i;
284                                          /* compute beam index */
285 <        copystruct(gc, gcp);
286 <        copystruct(gc+1, &bp->gc);
285 >        if (bp->ca.rev) {
286 >                copystruct(gc, &bp->gc);
287 >                copystruct(gc+1, gcp);
288 >        } else {
289 >                copystruct(gc, gcp);
290 >                copystruct(gc+1, &bp->gc);
291 >        }
292          if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0)
293                  error(CONSISTENCY, "bad grid coordinate in dobeam");
294          if (bp->ca.add) {               /* add it in */
# Line 312 | Line 312 | docell(gcp, cap)       /* find beams corresponding to cell a
312   GCOORD  *gcp;
313   register struct cellact *cap;
314   {
315 +        register HOLO   *hp = hdlist[voxel[cap->vi].hd];
316          FVECT   org, dir[4];
317 <        FVECT   gp, cv[4], vc;
317 >        FVECT   vgp, cgp, vc;
318 >        FVECT   v1, v2;
319          struct beamact  bo;
320 +        int     axmax, j;
321 +        double  d, avmax;
322          register int    i;
323 <                                /* compute cell vertices */
324 <        hdcell(cv, hdlist[voxel[cap->vi].hd], gcp);
325 <                                /* compute cell and voxel centers */
326 <        for (i = 0; i < 3; i++) {
327 <                org[i] = 0.5*(cv[0][i] + cv[2][i]);
328 <                gp[i] = voxel[cap->vi].i[i] + 0.5;
329 <        }
330 <        hdworld(vc, hdlist[voxel[cap->vi].hd], gp);
331 <                                /* compute voxel pyramid using vector trick */
332 <        for (i = 0; i < 3; i++) {
333 <                dir[0][i] = vc[i] - cv[0][i];           /* to 3 */
334 <                dir[2][i] = vc[i] - cv[3][i];           /* to 0 */
335 <                if (gcp->w & 1) {       /* watch vertex order! */
336 <                        dir[1][i] = vc[i] - cv[2][i];   /* to 1 */
337 <                        dir[3][i] = vc[i] - cv[1][i];   /* to 2 */
338 <                } else {
339 <                        dir[1][i] = vc[i] - cv[1][i];   /* to 2 */
340 <                        dir[3][i] = vc[i] - cv[2][i];   /* to 1 */
323 >                                /* compute cell center */
324 >        cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
325 >        cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5;
326 >        cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5;
327 >        hdworld(org, hp, cgp);
328 >                                /* compute direction to voxel center */
329 >        for (i = 3; i--; )
330 >                vgp[i] = voxel[cap->vi].i[i] + .5;
331 >        hdworld(vc, hp, vgp);
332 >        for (i = 3; i--; )
333 >                vc[i] -= org[i];
334 >                                /* compute maximum area axis */
335 >        axmax = -1; avmax = 0;
336 >        for (i = 3; i--; ) {
337 >                d = vgp[i] - cgp[i];
338 >                if (d < 0.) d = -d;
339 >                if (d > avmax) {
340 >                        avmax = d;
341 >                        axmax = i;
342                  }
343          }
344 + #ifdef DEBUG
345 +        if (axmax < 0.)
346 +                error(CONSISTENCY, "botched axis computation in docell");
347 + #endif
348 +                                /* compute offset vectors */
349 +        d = 0.5/hp->grid[j=(axmax+1)%3];
350 +        for (i = 3; i--; )
351 +                v1[i] = hp->xv[j][i] * d;
352 +        d = 0.5/hp->grid[j=(axmax+2)%3];
353 +        if (DOT(hp->wn[axmax], vc) < 0.)
354 +                d = -d; /* reverse vertex ordering */
355 +        for (i = 3; i--; )
356 +                v2[i] = hp->xv[j][i] * d;
357 +                                /* compute voxel pyramid */
358 +        for (i = 3; i--; ) {
359 +                dir[0][i] = vc[i] - v1[i] - v2[i];
360 +                dir[1][i] = vc[i] + v1[i] - v2[i];
361 +                dir[2][i] = vc[i] + v1[i] + v2[i];
362 +                dir[3][i] = vc[i] - v1[i] + v2[i];
363 +        }
364                                  /* visit beams for opposite cells */
365          copystruct(&bo.ca, cap);
366          copystruct(&bo.gc, gcp);
367 <        return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo));
367 >        return(visit_cells(org, dir, hp, dobeam, &bo));
368   }
369  
370  
# Line 348 | Line 373 | doview(cap, vp)                        /* visit cells for a given view */
373   struct cellact  *cap;
374   VIEW    *vp;
375   {
376 +        int     orient;
377          FVECT   org, dir[4];
378                                          /* compute view pyramid */
379 <        if (vp->type == VT_PAR) goto viewerr;
380 <        if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr;
381 <        if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr;
382 <        if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr;
357 <        if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr;
379 >        orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp);
380 >        if (!orient)
381 >                error(INTERNAL, "unusable view in doview");
382 >        cap->rev = orient < 0;
383                                          /* visit cells within pyramid */
384          return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap));
360 viewerr:
361        error(INTERNAL, "unusable view in doview");
385   }
386  
387  
# Line 367 | Line 390 | int    voxi;
390   VIEW    *vold, *vnew;
391   {
392          int     netchange = 0;
393 <        int     *ocl, *ncl;
371 <        struct cellact  ca;
393 >        struct cellact  oca, nca;
394          int     ocnt, ncnt;
395          int     c;
396 +        GCOORD  *ogcl, *ngcl;
397          register GCOORD *ogcp, *ngcp;
398                                  /* get old and new cell lists */
399 <        ocl = getviewcells(hdlist[voxel[voxi].hd], vold);
400 <        ncl = getviewcells(hdlist[voxel[voxi].hd], vnew);
401 <        if (ocl != NULL) {
402 <                ocnt = *ocl; ogcp = (GCOORD *)(ocl+1);
403 <        } else {
404 <                ocnt = 0; ogcp = NULL;
405 <        }
406 <        if (ncl != NULL) {
407 <                ncnt = *ncl; ngcp = (GCOORD *)(ncl+1);
408 <        } else {
409 <                ncnt = 0; ngcp = NULL;
410 <        }
411 <        ca.vi = voxi;           /* add and delete cells */
412 <        while (ocnt > 0 & ncnt > 0)
413 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {
414 <                        ca.add = 1;             /* new cell */
415 <                        netchange += docell(ngcp++, &ca);
416 <                        ncnt--;
417 <                } else if (c < 0) {
418 <                        ca.add = 0;             /* obsolete cell */
419 <                        netchange -= docell(ogcp++, &ca);
397 <                        ocnt--;
398 <                } else {
399 <                        ogcp++; ocnt--;         /* unchanged cell */
400 <                        ngcp++; ncnt--;
401 <                }
399 >        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
400 >        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
401 >                                /* set up actions */
402 >        oca.vi = nca.vi = voxi;
403 >        oca.add = 0; nca.add = 1;
404 >        if ((oca.rev = ocnt < 0))
405 >                ocnt = -ocnt;
406 >        if ((nca.rev = ncnt < 0))
407 >                ncnt = -ncnt;
408 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
409 >                while (ocnt > 0 & ncnt > 0)
410 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
411 >                                netchange += docell(ngcp++, &nca);
412 >                                ncnt--;
413 >                        } else if (c < 0) {                     /* old cell */
414 >                                netchange -= docell(ogcp++, &oca);
415 >                                ocnt--;
416 >                        } else {                                /* same cell */
417 >                                ogcp++; ocnt--;
418 >                                ngcp++; ncnt--;
419 >                        }
420                                  /* take care of list tails */
421 <        for (ca.add = 1; ncnt > 0; ncnt--)
422 <                netchange += docell(ngcp++, &ca);
423 <        for (ca.add = 0; ocnt > 0; ocnt--)
424 <                netchange -= docell(ogcp++, &ca);
421 >        for ( ; ncnt > 0; ncnt--)
422 >                netchange += docell(ngcp++, &nca);
423 >        for ( ; ocnt > 0; ocnt--)
424 >                netchange -= docell(ogcp++, &oca);
425                                  /* clean up */
426 <        if (ocl != NULL) free((char *)ocl);
427 <        if (ncl != NULL) free((char *)ncl);
426 >        if (ogcl != NULL) free((char *)ogcl);
427 >        if (ngcl != NULL) free((char *)ngcl);
428          return(netchange);
429   }
430  
431  
432 < beam_view(vo, vn)       /* change beam view */
433 < VIEW    *vo, *vn;
432 > int
433 > beam_sync()             /* synchronize beams on server */
434   {
435 +        cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
436 +        return(ncbeams);
437 + }
438 +
439 +
440 + beam_view(vn)                   /* change beam view (if advisable) */
441 + VIEW    *vn;
442 + {
443          struct cellact  ca;
444          VOXL    vlnew[8];
445          int     n, comn;
446  
447 <        if (!vn->type) {                /* clear our beam list */
447 >        if (vn == NULL || !vn->type) {  /* clear our beam list */
448                  set_voxels(vlnew, 0);
449 <                cbeamdel(cbeam, ncbeams);
449 >                cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
450                  ncbeams = 0;
451 <                return;
451 >                dvw.type = 0;
452 >                return(1);
453          }
454                                          /* find our new voxels */
455          n = get_voxels(vlnew, vn->vp);
456 +        if (dvw.type && !n) {
457 +                copystruct(vn, &dvw);           /* cancel move */
458 +                return(0);
459 +        }
460                                          /* set the new voxels */
461          comn = set_voxels(vlnew, n);
462 <        if (!vo->type)
462 >        if (!dvw.type)
463                  comn = 0;
464          ca.add = 1;                     /* update our beam list */
465          for (ca.vi = n; ca.vi--; )
466                  if (comn & 1<<ca.vi)    /* change which cells we see */
467 <                        mvview(ca.vi, vo, vn);
467 >                        mvview(ca.vi, &dvw, vn);
468                  else                    /* else add all new cells */
469                          doview(&ca, vn);
470                                          /* inform server of new beams */
471 <        cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
471 >        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
472                                          /* sort list to put orphans at end */
473          cbeamsort(0);
474                                          /* tell server to delete orphans */
475 <        cbeamdel(cbeam+ncbeams, xcbeams);
475 >        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
476          xcbeams = 0;                    /* truncate our list */
477 +        copystruct(&dvw, vn);           /* record new view */
478 +        return(1);
479   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines