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.9 by gregl, Fri Dec 5 15:50:43 1997 UTC vs.
Revision 3.19 by gregl, Wed Jan 7 16:04:14 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 13 | Line 13 | static char SCCSid[] = "$SunId$ SGI";
13   #include "rhdriver.h"
14  
15   #ifndef MAXDIST
16 < #define MAXDIST         13      /* maximum distance outside section */
16 > #define MAXDIST         42      /* maximum distance outside section */
17   #endif
18  
19   extern GCOORD   *getviewcells();
# Line 94 | 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 162 | Line 164 | int    adopt;
164   }
165  
166  
165 cbeamadj(v, hr, vr)             /* adjust our beam list */
166 VIEW    *v;
167 int     hr, vr;
168 {
169        register PACKHEAD       *pa;
170        register int    i;
171        int     n;
172                                        /* first handle additions */
173        pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD));
174        if (xcbeams && pa == NULL)
175                goto memerr;
176        for (i = xcbeams; i--; ) {
177                pa[i].hd = cbeam[ncbeams+i].hd;
178                pa[i].bi = cbeam[ncbeams+i].bi;
179                pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi);
180        }
181        n = xcbeams;                    /* now sort list for deletions */
182        cbeamsort(0);
183        pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD));
184        if (n+xcbeams && pa == NULL)
185                goto memerr;
186        for (i = xcbeams; i--; ) {
187                pa[n+i].hd = cbeam[ncbeams+i].hd;
188                pa[n+i].bi = cbeam[ncbeams+i].bi;
189                pa[n+i].nr = 0;
190        }
191        n += xcbeams;
192        xcbeams = 0;                    /* delete orphans */
193        serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa);
194        free((char *)pa);
195        return;
196 memerr:
197        error(SYSTEM, "out of memory in cbeamadj");
198 }
199
200
167   cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
168   int     op;
169   register struct beamcomp        *bl;
# Line 218 | Line 184 | int    hr, vr;
184                  pa[i].bi = bl[i].bi;
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(op, n*sizeof(PACKHEAD), (char *)pa);
190          free((char *)pa);
# Line 268 | Line 235 | get_voxels(vl, vp)     /* find voxels corresponding to vie
235   VOXL    vl[8];
236   FVECT   vp;
237   {
271        static int      lastn = 0, lastd = -1;
238          int     n = 0;
239          FVECT   gp;
240          double  d;
# Line 301 | Line 267 | FVECT  vp;
267          }
268                                          /* check for really stupid move */
269          if (bestd > MAXDIST) {
270 <                error(WARNING, "move to outer solar system");
270 >                error(COMMAND, "move past outer limits");
271                  return(0);
272          }
273 <                                        /* warn of dangerous moves */
308 <        if (n < lastn && bestd >= lastd)
309 <                error(WARNING, "moving outside holodeck section");
310 <        else if (n > lastn && bestd <= lastd)
311 <                error(WARNING, "moving inside holodeck section");
312 <        lastd = bestd;
313 <        return(lastn = n);
273 >        return(n);
274   }
275  
276  
# Line 352 | 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[hdwg0[gcp->w]] = gcp->i[0] + .5;
326 >        cgp[hdwg1[gcp->w]] = 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->wg[axmax], vc) < 0.)
354 +                d = -d; /* reverse vertex order */
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 407 | Line 392 | VIEW   *vold, *vnew;
392          int     netchange = 0;
393          struct cellact  oca, nca;
394          int     ocnt, ncnt;
395 <        int     c;
395 >        int     nmatch = 0;
396          GCOORD  *ogcl, *ngcl;
397 +        register int    c;
398          register GCOORD *ogcp, *ngcp;
399                                  /* get old and new cell lists */
400          ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
401          ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
402                                  /* set up actions */
403          oca.vi = nca.vi = voxi;
418        oca.rev = nca.rev = 0;
404          oca.add = 0; nca.add = 1;
405          if ((oca.rev = ocnt < 0))
406                  ocnt = -ocnt;
407          if ((nca.rev = ncnt < 0))
408                  ncnt = -ncnt;
409 <        if (nca.rev == oca.rev)         /* add and delete cells in order */
410 <                while (ocnt > 0 & ncnt > 0)
411 <                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
412 <                                netchange += docell(ngcp++, &nca);
413 <                                ncnt--;
414 <                        } else if (c < 0) {                     /* old cell */
415 <                                netchange -= docell(ogcp++, &oca);
416 <                                ocnt--;
417 <                        } else {                                /* same cell */
418 <                                ogcp++; ocnt--;
419 <                                ngcp++; ncnt--;
409 >        if (oca.rev == nca.rev) {       /* count matches */
410 >                int     oc = ocnt, nc = ncnt;
411 >                while (oc > 0 & nc > 0) {
412 >                        c = cellcmp(ogcp, ngcp);
413 >                        if (c >= 0) { ngcp++; nc--; }
414 >                        if (c <= 0) { ogcp++; oc--; }
415 >                        nmatch += c==0;
416 >                }
417 >                ogcp = ogcl; ngcp = ngcl;
418 >        }
419 >        if (nmatch < ocnt>>1) {         /* faster to just delete old cells? */
420 >                for (c = ncbeams; c--; )
421 >                        if (cbeam[c].wants & 1<<voxi) {
422 >                                cbeam[c].wants &= ~(1<<voxi);
423 >                                netchange--;
424                          }
425 +                free((char *)ogcl);
426 +                ogcl = NULL; ocnt = 0;
427 +        }
428 +                                /* add and delete cells in order */
429 +        while (ocnt > 0 & ncnt > 0)
430 +                if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
431 +                        netchange += docell(ngcp++, &nca);
432 +                        ncnt--;
433 +                } else if (c < 0) {                     /* old cell */
434 +                        netchange -= docell(ogcp++, &oca);
435 +                        ocnt--;
436 +                } else {                                /* same cell */
437 +                        ogcp++; ocnt--;
438 +                        ngcp++; ncnt--;
439 +                }
440                                  /* take care of list tails */
441          for ( ; ncnt > 0; ncnt--)
442                  netchange += docell(ngcp++, &nca);
# Line 445 | Line 449 | VIEW   *vold, *vnew;
449   }
450  
451  
452 + int
453   beam_sync()             /* synchronize beams on server */
454   {
455          cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
456 +        return(ncbeams);
457   }
458  
459  
# Line 458 | Line 464 | VIEW   *vn;
464          VOXL    vlnew[8];
465          int     n, comn;
466  
467 <        if (!vn->type) {                /* clear our beam list */
467 >        if (vn == NULL || !vn->type) {  /* clear our beam list */
468                  set_voxels(vlnew, 0);
469                  cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
470                  ncbeams = 0;
471 <                copystruct(&dvw, vn);
471 >                dvw.type = 0;
472                  return(1);
473          }
474                                          /* find our new voxels */
# Line 481 | Line 487 | VIEW   *vn;
487                          mvview(ca.vi, &dvw, vn);
488                  else                    /* else add all new cells */
489                          doview(&ca, vn);
484 #if 1
485        cbeamadj(vn, odev.hres, odev.vres);
486 #else
490                                          /* inform server of new beams */
491          cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
492                                          /* sort list to put orphans at end */
# Line 491 | Line 494 | VIEW   *vn;
494                                          /* tell server to delete orphans */
495          cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
496          xcbeams = 0;                    /* truncate our list */
494 #endif
497          copystruct(&dvw, vn);           /* record new view */
498          return(1);
499   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines