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.9 by gregl, Fri Dec 5 15:50:43 1997 UTC

# 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         13      /* 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 155 | Line 162 | int    adopt;
162   }
163  
164  
165 < cbeamadd(bl, n, v, hr, vr)      /* add beams to server list */
159 < register struct beamcomp        *bl;
160 < int     n;
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 <
172 <        if (n <= 0)
173 <                return;
174 <        pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
175 <        if (pa == NULL)
176 <                error(SYSTEM, "out of memory in cbeamadd");
177 <        for (i = 0; i < n; i++)
178 <                pa[i].nr = npixels(v, hr, vr,
179 <                                hdlist[pa[i].hd=bl[i].hd],
180 <                                pa[i].bi=bl[i].bi) / 8;
181 <
182 <        serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa);
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  
201 < cbeamdel(bl, n)         /* delete unwanted beam requests */
201 > cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
202 > int     op;
203   register struct beamcomp        *bl;
204   int     n;
205 + VIEW    *v;
206 + int     hr, vr;
207   {
208          register PACKHEAD       *pa;
209          register int    i;
# Line 190 | Line 212 | int    n;
212                  return;
213          pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
214          if (pa == NULL)
215 <                error(SYSTEM, "out of memory in cbeamdel");
215 >                error(SYSTEM, "out of memory in cbeamadd");
216          for (i = 0; i < n; i++) {
217                  pa[i].hd = bl[i].hd;
218                  pa[i].bi = bl[i].bi;
219 <                pa[i].nr = 0;           /* removes any request */
219 >                pa[i].nr = v==NULL ? 0 :
220 >                                npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
221          }
222 <        serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa);
222 >        serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
223          free((char *)pa);
224   }
225  
# Line 245 | Line 268 | get_voxels(vl, vp)     /* find voxels corresponding to vie
268   VOXL    vl[8];
269   FVECT   vp;
270   {
271 +        static int      lastn = 0, lastd = -1;
272          int     n = 0;
273          FVECT   gp;
274          double  d;
# Line 275 | Line 299 | FVECT  vp;
299                          n++;
300                  }
301          }
302 <        return(n);
302 >                                        /* check for really stupid move */
303 >        if (bestd > MAXDIST) {
304 >                error(WARNING, "move to outer solar system");
305 >                return(0);
306 >        }
307 >                                        /* 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);
314   }
315  
316  
# Line 287 | Line 322 | register struct beamact        *bp;
322          GCOORD  gc[2];
323          int     bi, i;
324                                          /* compute beam index */
325 <        copystruct(gc, gcp);
326 <        copystruct(gc+1, &bp->gc);
325 >        if (bp->ca.rev) {
326 >                copystruct(gc, &bp->gc);
327 >                copystruct(gc+1, gcp);
328 >        } else {
329 >                copystruct(gc, gcp);
330 >                copystruct(gc+1, &bp->gc);
331 >        }
332          if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0)
333                  error(CONSISTENCY, "bad grid coordinate in dobeam");
334          if (bp->ca.add) {               /* add it in */
# Line 348 | Line 388 | doview(cap, vp)                        /* visit cells for a given view */
388   struct cellact  *cap;
389   VIEW    *vp;
390   {
391 +        int     orient;
392          FVECT   org, dir[4];
393                                          /* compute view pyramid */
394 <        if (vp->type == VT_PAR) goto viewerr;
395 <        if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr;
396 <        if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr;
397 <        if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr;
357 <        if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr;
394 >        orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp);
395 >        if (!orient)
396 >                error(INTERNAL, "unusable view in doview");
397 >        cap->rev = orient < 0;
398                                          /* visit cells within pyramid */
399          return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap));
360 viewerr:
361        error(INTERNAL, "unusable view in doview");
400   }
401  
402  
# Line 367 | Line 405 | int    voxi;
405   VIEW    *vold, *vnew;
406   {
407          int     netchange = 0;
408 <        int     *ocl, *ncl;
371 <        struct cellact  ca;
408 >        struct cellact  oca, nca;
409          int     ocnt, ncnt;
410          int     c;
411 +        GCOORD  *ogcl, *ngcl;
412          register GCOORD *ogcp, *ngcp;
413                                  /* get old and new cell lists */
414 <        ocl = getviewcells(hdlist[voxel[voxi].hd], vold);
415 <        ncl = getviewcells(hdlist[voxel[voxi].hd], vnew);
416 <        if (ocl != NULL) {
417 <                ocnt = *ocl; ogcp = (GCOORD *)(ocl+1);
418 <        } else {
419 <                ocnt = 0; ogcp = NULL;
420 <        }
421 <        if (ncl != NULL) {
422 <                ncnt = *ncl; ngcp = (GCOORD *)(ncl+1);
423 <        } else {
424 <                ncnt = 0; ngcp = NULL;
425 <        }
426 <        ca.vi = voxi;           /* add and delete cells */
427 <        while (ocnt > 0 & ncnt > 0)
428 <                if ((c = cellcmp(ogcp, ngcp)) > 0) {
429 <                        ca.add = 1;             /* new cell */
430 <                        netchange += docell(ngcp++, &ca);
431 <                        ncnt--;
432 <                } else if (c < 0) {
433 <                        ca.add = 0;             /* obsolete cell */
434 <                        netchange -= docell(ogcp++, &ca);
435 <                        ocnt--;
398 <                } else {
399 <                        ogcp++; ocnt--;         /* unchanged cell */
400 <                        ngcp++; ncnt--;
401 <                }
414 >        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
415 >        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
416 >                                /* set up actions */
417 >        oca.vi = nca.vi = voxi;
418 >        oca.rev = nca.rev = 0;
419 >        oca.add = 0; nca.add = 1;
420 >        if ((oca.rev = ocnt < 0))
421 >                ocnt = -ocnt;
422 >        if ((nca.rev = ncnt < 0))
423 >                ncnt = -ncnt;
424 >        if (nca.rev == oca.rev)         /* add and delete cells in order */
425 >                while (ocnt > 0 & ncnt > 0)
426 >                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
427 >                                netchange += docell(ngcp++, &nca);
428 >                                ncnt--;
429 >                        } else if (c < 0) {                     /* old cell */
430 >                                netchange -= docell(ogcp++, &oca);
431 >                                ocnt--;
432 >                        } else {                                /* same cell */
433 >                                ogcp++; ocnt--;
434 >                                ngcp++; ncnt--;
435 >                        }
436                                  /* take care of list tails */
437 <        for (ca.add = 1; ncnt > 0; ncnt--)
438 <                netchange += docell(ngcp++, &ca);
439 <        for (ca.add = 0; ocnt > 0; ocnt--)
440 <                netchange -= docell(ogcp++, &ca);
437 >        for ( ; ncnt > 0; ncnt--)
438 >                netchange += docell(ngcp++, &nca);
439 >        for ( ; ocnt > 0; ocnt--)
440 >                netchange -= docell(ogcp++, &oca);
441                                  /* clean up */
442 <        if (ocl != NULL) free((char *)ocl);
443 <        if (ncl != NULL) free((char *)ncl);
442 >        if (ogcl != NULL) free((char *)ogcl);
443 >        if (ngcl != NULL) free((char *)ngcl);
444          return(netchange);
445   }
446  
447  
448 < beam_view(vo, vn)       /* change beam view */
415 < VIEW    *vo, *vn;
448 > beam_sync()             /* synchronize beams on server */
449   {
450 +        cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
451 + }
452 +
453 +
454 + beam_view(vn)                   /* change beam view (if advisable) */
455 + VIEW    *vn;
456 + {
457          struct cellact  ca;
458          VOXL    vlnew[8];
459          int     n, comn;
460  
461          if (!vn->type) {                /* clear our beam list */
462                  set_voxels(vlnew, 0);
463 <                cbeamdel(cbeam, ncbeams);
463 >                cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
464                  ncbeams = 0;
465 <                return;
465 >                copystruct(&dvw, vn);
466 >                return(1);
467          }
468                                          /* find our new voxels */
469          n = get_voxels(vlnew, vn->vp);
470 +        if (dvw.type && !n) {
471 +                copystruct(vn, &dvw);           /* cancel move */
472 +                return(0);
473 +        }
474                                          /* set the new voxels */
475          comn = set_voxels(vlnew, n);
476 <        if (!vo->type)
476 >        if (!dvw.type)
477                  comn = 0;
478          ca.add = 1;                     /* update our beam list */
479          for (ca.vi = n; ca.vi--; )
480                  if (comn & 1<<ca.vi)    /* change which cells we see */
481 <                        mvview(ca.vi, vo, vn);
481 >                        mvview(ca.vi, &dvw, vn);
482                  else                    /* else add all new cells */
483                          doview(&ca, vn);
484 + #if 1
485 +        cbeamadj(vn, odev.hres, odev.vres);
486 + #else
487                                          /* inform server of new beams */
488 <        cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
488 >        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
489                                          /* sort list to put orphans at end */
490          cbeamsort(0);
491                                          /* tell server to delete orphans */
492 <        cbeamdel(cbeam+ncbeams, xcbeams);
492 >        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
493          xcbeams = 0;                    /* truncate our list */
494 + #endif
495 +        copystruct(&dvw, vn);           /* record new view */
496 +        return(1);
497   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines