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.16 by gregl, Tue Dec 16 11:57:32 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 +        PACKHEAD        *pa, *pa2;
172 +        register PACKHEAD       *pp;
173 +        int     n, n2;
174 +        FVECT   gp;
175 +        int     igp[3], vcflgs;
176 +        register int    i;
177 +                                        /* figure out center voxel(s) */
178 +        n = -1; vcflgs = 0;
179 +        for (i = 0; i < 8 && voxel[i].hd >= 0; i++) {
180 +                if (voxel[i].hd != n) {
181 +                        hdgrid(gp, hdlist[n=voxel[i].hd], v->vp);
182 +                        igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2];
183 +                }
184 +                if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] &&
185 +                                voxel[i].i[2] == igp[2])
186 +                        vcflgs |= 1<<i;
187 +        }
188 +                                        /* get additions */
189 +        pa2 = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD));
190 +        if (xcbeams && pa2 == NULL)
191 +                goto memerr;
192 +        pa = pa2 + xcbeams; n2 = 0;
193 +        for (i = xcbeams; i--; ) {
194 +                if (cbeam[ncbeams+i].wants & vcflgs)
195 +                        pp = --pa;              /* priority list */
196 +                else
197 +                        pp = pa2 + n2++;        /* secondary list */
198 +                pp->hd = cbeam[ncbeams+i].hd;
199 +                pp->bi = cbeam[ncbeams+i].bi;
200 +                pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1;
201 +                pp->nc = 0;
202 +        }
203 +        n = xcbeams - n2;
204 +                                        /* now sort list for deletions */
205 +        cbeamsort(0);
206 +        pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD));
207 +        if (n+n2+xcbeams && pa2 == NULL)
208 +                goto memerr;
209 +        pa = pa2 + n2;
210 +        for (i = xcbeams; i--; ) {
211 +                pp = pa + n++;
212 +                pp->hd = cbeam[ncbeams+i].hd;
213 +                pp->bi = cbeam[ncbeams+i].bi;
214 +                pp->nr = 0;
215 +                pp->nc = 0;
216 +        }
217 +        if (n)                          /* adjust the set */
218 +                serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa);
219 +        if (n2)                         /* make secondary additions */
220 +                serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2);
221 +        xcbeams = 0;                    /* clean up */
222 +        free((char *)pa2);
223 +        return;
224 + memerr:
225 +        error(SYSTEM, "out of memory in cbeamadj");
226 + }
227 +
228 +
229   cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
230   int     op;
231   register struct beamcomp        *bl;
# Line 176 | Line 246 | int    hr, vr;
246                  pa[i].bi = bl[i].bi;
247                  pa[i].nr = v==NULL ? 0 :
248                                  npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
249 +                pa[i].nc = 0;
250          }
251          serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
252          free((char *)pa);
# Line 257 | Line 328 | FVECT  vp;
328                          n++;
329                  }
330          }
331 +                                        /* check for really stupid move */
332 +        if (bestd > MAXDIST) {
333 +                error(COMMAND, "move past outer limits");
334 +                return(0);
335 +        }
336                                          /* warn of dangerous moves */
337          if (n < lastn && bestd >= lastd)
338                  error(WARNING, "moving outside holodeck section");
# Line 305 | Line 381 | docell(gcp, cap)       /* find beams corresponding to cell a
381   GCOORD  *gcp;
382   register struct cellact *cap;
383   {
384 +        register HOLO   *hp = hdlist[voxel[cap->vi].hd];
385          FVECT   org, dir[4];
386 <        FVECT   gp, cv[4], vc;
386 >        FVECT   vgp, cgp, vc;
387 >        FVECT   v1, v2;
388          struct beamact  bo;
389 +        int     axmax, j;
390 +        double  d, avmax;
391          register int    i;
392 <                                /* compute cell vertices */
393 <        hdcell(cv, hdlist[voxel[cap->vi].hd], gcp);
394 <                                /* compute cell and voxel centers */
395 <        for (i = 0; i < 3; i++) {
396 <                org[i] = 0.5*(cv[0][i] + cv[2][i]);
397 <                gp[i] = voxel[cap->vi].i[i] + 0.5;
398 <        }
399 <        hdworld(vc, hdlist[voxel[cap->vi].hd], gp);
400 <                                /* compute voxel pyramid using vector trick */
401 <        for (i = 0; i < 3; i++) {
402 <                dir[0][i] = vc[i] - cv[0][i];           /* to 3 */
403 <                dir[2][i] = vc[i] - cv[3][i];           /* to 0 */
404 <                if (gcp->w & 1) {       /* watch vertex order! */
405 <                        dir[1][i] = vc[i] - cv[2][i];   /* to 1 */
406 <                        dir[3][i] = vc[i] - cv[1][i];   /* to 2 */
407 <                } else {
408 <                        dir[1][i] = vc[i] - cv[1][i];   /* to 2 */
409 <                        dir[3][i] = vc[i] - cv[2][i];   /* to 1 */
392 >                                /* compute cell center */
393 >        cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
394 >        cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5;
395 >        cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5;
396 >        hdworld(org, hp, cgp);
397 >                                /* compute direction to voxel center */
398 >        for (i = 3; i--; )
399 >                vgp[i] = voxel[cap->vi].i[i] + .5;
400 >        hdworld(vc, hp, vgp);
401 >        for (i = 3; i--; )
402 >                vc[i] -= org[i];
403 >                                /* compute maximum area axis */
404 >        axmax = -1; avmax = 0;
405 >        for (i = 3; i--; ) {
406 >                d = vgp[i] - cgp[i];
407 >                if (d < 0.) d = -d;
408 >                if (d > avmax) {
409 >                        avmax = d;
410 >                        axmax = i;
411                  }
412          }
413 + #ifdef DEBUG
414 +        if (axmax < 0.)
415 +                error(CONSISTENCY, "botched axis computation in docell");
416 + #endif
417 +                                /* compute offset vectors */
418 +        d = 0.5/hp->grid[j=(axmax+1)%3];
419 +        for (i = 3; i--; )
420 +                v1[i] = hp->xv[j][i] * d;
421 +        d = 0.5/hp->grid[j=(axmax+2)%3];
422 +        if (DOT(hp->wn[axmax], vc) < 0.)
423 +                d = -d; /* reverse vertex ordering */
424 +        for (i = 3; i--; )
425 +                v2[i] = hp->xv[j][i] * d;
426 +                                /* compute voxel pyramid */
427 +        for (i = 3; i--; ) {
428 +                dir[0][i] = vc[i] - v1[i] - v2[i];
429 +                dir[1][i] = vc[i] + v1[i] - v2[i];
430 +                dir[2][i] = vc[i] + v1[i] + v2[i];
431 +                dir[3][i] = vc[i] - v1[i] + v2[i];
432 +        }
433                                  /* visit beams for opposite cells */
434          copystruct(&bo.ca, cap);
435          copystruct(&bo.gc, gcp);
436 <        return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo));
436 >        return(visit_cells(org, dir, hp, dobeam, &bo));
437   }
438  
439  
# Line 361 | Line 462 | VIEW   *vold, *vnew;
462          struct cellact  oca, nca;
463          int     ocnt, ncnt;
464          int     c;
465 +        GCOORD  *ogcl, *ngcl;
466          register GCOORD *ogcp, *ngcp;
467                                  /* get old and new cell lists */
468 <        ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
469 <        ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
468 >        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
469 >        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
470                                  /* set up actions */
471          oca.vi = nca.vi = voxi;
370        oca.rev = nca.rev = 0;
472          oca.add = 0; nca.add = 1;
473          if ((oca.rev = ocnt < 0))
474                  ocnt = -ocnt;
475          if ((nca.rev = ncnt < 0))
476                  ncnt = -ncnt;
477 <                                /* add and delete cells in order */
478 <        while (ocnt > 0 & ncnt > 0)
479 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
480 <                        netchange += docell(ngcp++, &nca);
481 <                        ncnt--;
482 <                } else if (c < 0) {                     /* obsolete cell */
483 <                        netchange -= docell(ogcp++, &oca);
484 <                        ocnt--;
485 <                } else {                                /* same cell? */
486 <                        if (oca.rev != nca.rev)         /* not */
487 <                                netchange += docell(ngcp, &nca) -
488 <                                                docell(ogcp, &oca);
388 <                        ogcp++; ocnt--;
389 <                        ngcp++; ncnt--;
390 <                }
477 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
478 >                while (ocnt > 0 & ncnt > 0)
479 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
480 >                                netchange += docell(ngcp++, &nca);
481 >                                ncnt--;
482 >                        } else if (c < 0) {                     /* old cell */
483 >                                netchange -= docell(ogcp++, &oca);
484 >                                ocnt--;
485 >                        } else {                                /* same cell */
486 >                                ogcp++; ocnt--;
487 >                                ngcp++; ncnt--;
488 >                        }
489                                  /* take care of list tails */
490          for ( ; ncnt > 0; ncnt--)
491                  netchange += docell(ngcp++, &nca);
492          for ( ; ocnt > 0; ocnt--)
493                  netchange -= docell(ogcp++, &oca);
494                                  /* clean up */
495 <        if (ogcp != NULL) free((char *)ogcp);
496 <        if (ngcp != NULL) free((char *)ngcp);
495 >        if (ogcl != NULL) free((char *)ogcl);
496 >        if (ngcl != NULL) free((char *)ngcl);
497          return(netchange);
498   }
499  
500  
501 + int
502   beam_sync()             /* synchronize beams on server */
503   {
504          cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
505 +        return(ncbeams);
506   }
507  
508  
509 < beam_view(vo, vn)       /* change beam view */
510 < VIEW    *vo, *vn;
509 > beam_view(vn)                   /* change beam view (if advisable) */
510 > VIEW    *vn;
511   {
512          struct cellact  ca;
513          VOXL    vlnew[8];
514          int     n, comn;
515  
516 <        if (!vn->type) {                /* clear our beam list */
516 >        if (vn == NULL || !vn->type) {  /* clear our beam list */
517                  set_voxels(vlnew, 0);
518                  cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
519                  ncbeams = 0;
520 <                return;
520 >                dvw.type = 0;
521 >                return(1);
522          }
523                                          /* find our new voxels */
524          n = get_voxels(vlnew, vn->vp);
525 +        if (dvw.type && !n) {
526 +                copystruct(vn, &dvw);           /* cancel move */
527 +                return(0);
528 +        }
529                                          /* set the new voxels */
530          comn = set_voxels(vlnew, n);
531 <        if (!vo->type)
531 >        if (!dvw.type)
532                  comn = 0;
533          ca.add = 1;                     /* update our beam list */
534          for (ca.vi = n; ca.vi--; )
535                  if (comn & 1<<ca.vi)    /* change which cells we see */
536 <                        mvview(ca.vi, vo, vn);
536 >                        mvview(ca.vi, &dvw, vn);
537                  else                    /* else add all new cells */
538                          doview(&ca, vn);
539 + #if 1
540 +        cbeamadj(vn, odev.hres, odev.vres);
541 + #else
542                                          /* inform server of new beams */
543          cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
544                                          /* sort list to put orphans at end */
# Line 438 | Line 546 | VIEW   *vo, *vn;
546                                          /* tell server to delete orphans */
547          cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
548          xcbeams = 0;                    /* truncate our list */
549 + #endif
550 +        copystruct(&dvw, vn);           /* record new view */
551 +        return(1);
552   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines