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.16 by gregl, Tue Dec 16 11:57:32 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 164 | 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
167   cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
168   int     op;
169   register struct beamcomp        *bl;
# Line 297 | Line 235 | get_voxels(vl, vp)     /* find voxels corresponding to vie
235   VOXL    vl[8];
236   FVECT   vp;
237   {
300        static int      lastn = 0, lastd = -1;
238          int     n = 0;
239          FVECT   gp;
240          double  d;
# Line 333 | Line 270 | FVECT  vp;
270                  error(COMMAND, "move past outer limits");
271                  return(0);
272          }
273 <                                        /* warn of dangerous moves */
337 <        if (n < lastn && bestd >= lastd)
338 <                error(WARNING, "moving outside holodeck section");
339 <        else if (n > lastn && bestd <= lastd)
340 <                error(WARNING, "moving inside holodeck section");
341 <        lastd = bestd;
342 <        return(lastn = n);
273 >        return(n);
274   }
275  
276  
# Line 391 | Line 322 | register struct cellact        *cap;
322          register int    i;
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;
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--; )
# Line 419 | Line 350 | register struct cellact        *cap;
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 */
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 */
# Line 461 | 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);
# Line 474 | Line 406 | VIEW   *vold, *vnew;
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 536 | Line 487 | VIEW   *vn;
487                          mvview(ca.vi, &dvw, vn);
488                  else                    /* else add all new cells */
489                          doview(&ca, vn);
539 #if 1
540        cbeamadj(vn, odev.hres, odev.vres);
541 #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 546 | 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 */
549 #endif
497          copystruct(&dvw, vn);           /* record new view */
498          return(1);
499   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines