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.5 by gregl, Fri Nov 21 18:17:37 1997 UTC vs.
Revision 3.15 by gregl, Mon Dec 15 20:40:46 1997 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "rhdisp.h"
13   #include "rhdriver.h"
14  
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 88 | 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 156 | Line 164 | int    adopt;
164   }
165  
166  
167 + cbeamadj(v, hr, vr)             /* adjust our beam list */
168 + VIEW    *v;
169 + int     hr, vr;
170 + {
171 +        register PACKHEAD       *pa;
172 +        register int    i;
173 +        int     n;
174 +                                        /* first handle additions */
175 +        pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD));
176 +        if (xcbeams && pa == NULL)
177 +                goto memerr;
178 +        for (i = xcbeams; i--; ) {
179 +                pa[i].hd = cbeam[ncbeams+i].hd;
180 +                pa[i].bi = cbeam[ncbeams+i].bi;
181 +                pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi) + 1;
182 +        }
183 +        n = xcbeams;                    /* now sort list for deletions */
184 +        cbeamsort(0);
185 +        pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD));
186 +        if (n+xcbeams && pa == NULL)
187 +                goto memerr;
188 +        for (i = xcbeams; i--; ) {
189 +                pa[n+i].hd = cbeam[ncbeams+i].hd;
190 +                pa[n+i].bi = cbeam[ncbeams+i].bi;
191 +                pa[n+i].nr = 0;
192 +        }
193 +        n += xcbeams;
194 +        xcbeams = 0;                    /* delete orphans */
195 +        serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa);
196 +        free((char *)pa);
197 +        return;
198 + memerr:
199 +        error(SYSTEM, "out of memory in cbeamadj");
200 + }
201 +
202 +
203   cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
204   int     op;
205   register struct beamcomp        *bl;
# Line 257 | Line 301 | FVECT  vp;
301                          n++;
302                  }
303          }
304 +                                        /* check for really stupid move */
305 +        if (bestd > MAXDIST) {
306 +                error(COMMAND, "move past outer limits");
307 +                return(0);
308 +        }
309                                          /* warn of dangerous moves */
310          if (n < lastn && bestd >= lastd)
311                  error(WARNING, "moving outside holodeck section");
# Line 305 | Line 354 | docell(gcp, cap)       /* find beams corresponding to cell a
354   GCOORD  *gcp;
355   register struct cellact *cap;
356   {
357 +        register HOLO   *hp = hdlist[voxel[cap->vi].hd];
358          FVECT   org, dir[4];
359 <        FVECT   gp, cv[4], vc;
359 >        FVECT   vgp, cgp, vc;
360 >        FVECT   v1, v2;
361          struct beamact  bo;
362 +        int     axmax, j;
363 +        double  d, avmax;
364          register int    i;
365 <                                /* compute cell vertices */
366 <        hdcell(cv, hdlist[voxel[cap->vi].hd], gcp);
367 <                                /* compute cell and voxel centers */
368 <        for (i = 0; i < 3; i++) {
369 <                org[i] = 0.5*(cv[0][i] + cv[2][i]);
370 <                gp[i] = voxel[cap->vi].i[i] + 0.5;
371 <        }
372 <        hdworld(vc, hdlist[voxel[cap->vi].hd], gp);
373 <                                /* compute voxel pyramid using vector trick */
374 <        for (i = 0; i < 3; i++) {
375 <                dir[0][i] = vc[i] - cv[0][i];           /* to 3 */
376 <                dir[2][i] = vc[i] - cv[3][i];           /* to 0 */
377 <                if (gcp->w & 1) {       /* watch vertex order! */
378 <                        dir[1][i] = vc[i] - cv[2][i];   /* to 1 */
379 <                        dir[3][i] = vc[i] - cv[1][i];   /* to 2 */
380 <                } else {
381 <                        dir[1][i] = vc[i] - cv[1][i];   /* to 2 */
382 <                        dir[3][i] = vc[i] - cv[2][i];   /* to 1 */
365 >                                /* compute cell center */
366 >        cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
367 >        cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5;
368 >        cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5;
369 >        hdworld(org, hp, cgp);
370 >                                /* compute direction to voxel center */
371 >        for (i = 3; i--; )
372 >                vgp[i] = voxel[cap->vi].i[i] + .5;
373 >        hdworld(vc, hp, vgp);
374 >        for (i = 3; i--; )
375 >                vc[i] -= org[i];
376 >                                /* compute maximum area axis */
377 >        axmax = -1; avmax = 0;
378 >        for (i = 3; i--; ) {
379 >                d = vgp[i] - cgp[i];
380 >                if (d < 0.) d = -d;
381 >                if (d > avmax) {
382 >                        avmax = d;
383 >                        axmax = i;
384                  }
385          }
386 + #ifdef DEBUG
387 +        if (axmax < 0.)
388 +                error(CONSISTENCY, "botched axis computation in docell");
389 + #endif
390 +                                /* compute offset vectors */
391 +        d = 0.5/hp->grid[j=(axmax+1)%3];
392 +        for (i = 3; i--; )
393 +                v1[i] = hp->xv[j][i] * d;
394 +        d = 0.5/hp->grid[j=(axmax+2)%3];
395 +        if (DOT(hp->wn[axmax], vc) < 0.)
396 +                d = -d; /* reverse vertex ordering */
397 +        for (i = 3; i--; )
398 +                v2[i] = hp->xv[j][i] * d;
399 +                                /* compute voxel pyramid */
400 +        for (i = 3; i--; ) {
401 +                dir[0][i] = vc[i] - v1[i] - v2[i];
402 +                dir[1][i] = vc[i] + v1[i] - v2[i];
403 +                dir[2][i] = vc[i] + v1[i] + v2[i];
404 +                dir[3][i] = vc[i] - v1[i] + v2[i];
405 +        }
406                                  /* visit beams for opposite cells */
407          copystruct(&bo.ca, cap);
408          copystruct(&bo.gc, gcp);
409 <        return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo));
409 >        return(visit_cells(org, dir, hp, dobeam, &bo));
410   }
411  
412  
# Line 361 | Line 435 | VIEW   *vold, *vnew;
435          struct cellact  oca, nca;
436          int     ocnt, ncnt;
437          int     c;
438 +        GCOORD  *ogcl, *ngcl;
439          register GCOORD *ogcp, *ngcp;
440                                  /* get old and new cell lists */
441 <        ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
442 <        ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
441 >        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
442 >        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
443                                  /* set up actions */
444          oca.vi = nca.vi = voxi;
370        oca.rev = nca.rev = 0;
445          oca.add = 0; nca.add = 1;
446          if ((oca.rev = ocnt < 0))
447                  ocnt = -ocnt;
448          if ((nca.rev = ncnt < 0))
449                  ncnt = -ncnt;
450 <                                /* add and delete cells in order */
451 <        while (ocnt > 0 & ncnt > 0)
452 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
453 <                        netchange += docell(ngcp++, &nca);
454 <                        ncnt--;
455 <                } else if (c < 0) {                     /* obsolete cell */
456 <                        netchange -= docell(ogcp++, &oca);
457 <                        ocnt--;
458 <                } else {                                /* same cell? */
459 <                        if (oca.rev != nca.rev)         /* not */
460 <                                netchange += docell(ngcp, &nca) -
461 <                                                docell(ogcp, &oca);
388 <                        ogcp++; ocnt--;
389 <                        ngcp++; ncnt--;
390 <                }
450 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
451 >                while (ocnt > 0 & ncnt > 0)
452 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
453 >                                netchange += docell(ngcp++, &nca);
454 >                                ncnt--;
455 >                        } else if (c < 0) {                     /* old cell */
456 >                                netchange -= docell(ogcp++, &oca);
457 >                                ocnt--;
458 >                        } else {                                /* same cell */
459 >                                ogcp++; ocnt--;
460 >                                ngcp++; ncnt--;
461 >                        }
462                                  /* take care of list tails */
463          for ( ; ncnt > 0; ncnt--)
464                  netchange += docell(ngcp++, &nca);
465          for ( ; ocnt > 0; ocnt--)
466                  netchange -= docell(ogcp++, &oca);
467                                  /* clean up */
468 <        if (ogcp != NULL) free((char *)ogcp);
469 <        if (ngcp != NULL) free((char *)ngcp);
468 >        if (ogcl != NULL) free((char *)ogcl);
469 >        if (ngcl != NULL) free((char *)ngcl);
470          return(netchange);
471   }
472  
473  
474 + int
475   beam_sync()             /* synchronize beams on server */
476   {
477          cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
478 +        return(ncbeams);
479   }
480  
481  
482 < beam_view(vo, vn)       /* change beam view */
483 < VIEW    *vo, *vn;
482 > beam_view(vn)                   /* change beam view (if advisable) */
483 > VIEW    *vn;
484   {
485          struct cellact  ca;
486          VOXL    vlnew[8];
487          int     n, comn;
488  
489 <        if (!vn->type) {                /* clear our beam list */
489 >        if (vn == NULL || !vn->type) {  /* clear our beam list */
490                  set_voxels(vlnew, 0);
491                  cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
492                  ncbeams = 0;
493 <                return;
493 >                dvw.type = 0;
494 >                return(1);
495          }
496                                          /* find our new voxels */
497          n = get_voxels(vlnew, vn->vp);
498 +        if (dvw.type && !n) {
499 +                copystruct(vn, &dvw);           /* cancel move */
500 +                return(0);
501 +        }
502                                          /* set the new voxels */
503          comn = set_voxels(vlnew, n);
504 <        if (!vo->type)
504 >        if (!dvw.type)
505                  comn = 0;
506          ca.add = 1;                     /* update our beam list */
507          for (ca.vi = n; ca.vi--; )
508                  if (comn & 1<<ca.vi)    /* change which cells we see */
509 <                        mvview(ca.vi, vo, vn);
509 >                        mvview(ca.vi, &dvw, vn);
510                  else                    /* else add all new cells */
511                          doview(&ca, vn);
512 + #if 1
513 +        cbeamadj(vn, odev.hres, odev.vres);
514 + #else
515                                          /* inform server of new beams */
516          cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
517                                          /* sort list to put orphans at end */
# Line 438 | Line 519 | VIEW   *vo, *vn;
519                                          /* tell server to delete orphans */
520          cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
521          xcbeams = 0;                    /* truncate our list */
522 + #endif
523 +        copystruct(&dvw, vn);           /* record new view */
524 +        return(1);
525   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines