ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp3.c
(Generate patch)

Comparing ray/src/hd/rhdisp3.c (file contents):
Revision 3.8 by gregl, Fri Dec 19 11:54:16 1997 UTC vs.
Revision 3.16 by greg, Tue Jun 8 19:48:30 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Holodeck beam support for display process
6   */
7  
8   #include "rholo.h"
9   #include "rhdisp.h"
13 #include "view.h"
10  
11   struct cellist {
12          GCOORD  *cl;
# Line 19 | Line 15 | struct cellist {
15  
16  
17   int
18 < npixels(vp, hr, vr, hp, bi)     /* compute appropriate number to evaluate */
18 > npixels(vp, hr, vr, hp, bi)     /* compute appropriate nrays to evaluate */
19   register VIEW   *vp;
20   int     hr, vr;
21   HOLO    *hp;
# Line 27 | Line 23 | int    bi;
23   {
24          VIEW    vrev;
25          GCOORD  gc[2];
26 <        FVECT   cp[4], ip[4];
27 <        double  af, ab;
26 >        FVECT   cp[4], ip[4], pf, pb;
27 >        double  af, ab, sf2, sb2, dfb2, df2, db2, penalty;
28          register int    i;
29 +                                        /* special case */
30 +        if (hr <= 0 | vr <= 0)
31 +                return(0);
32                                          /* compute cell corners in image */
33          if (!hdbcoord(gc, hp, bi))
34                  error(CONSISTENCY, "bad beam index in npixels");
35          hdcell(cp, hp, gc+1);           /* find cell on front image */
36 <        for (i = 0; i < 4; i++) {
36 >        for (i = 3; i--; )              /* compute front center */
37 >                pf[i] = 0.5*(cp[0][i] + cp[2][i]);
38 >        sf2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */
39 >        for (i = 0; i < 4; i++) {       /* compute visible quad */
40                  viewloc(ip[i], vp, cp[i]);
41                  if (ip[i][2] < 0.) {
42                          af = 0;
# Line 48 | Line 50 | int    bi;
50                  (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]);
51          af += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) -
52                  (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]);
53 <        if (af >= 0) af *= 0.5;
52 <        else af *= -0.5;
53 >        af *= af >= 0 ? 0.5 : -0.5;
54   getback:
55 <        copystruct(&vrev, vp);          /* compute reverse view */
55 >        vrev = *vp;             /* compute reverse view */
56          for (i = 0; i < 3; i++) {
57                  vrev.vdir[i] = -vp->vdir[i];
58                  vrev.vup[i] = -vp->vup[i];
# Line 59 | Line 60 | getback:
60                  vrev.vvec[i] = -vp->vvec[i];
61          }
62          hdcell(cp, hp, gc);             /* find cell on back image */
63 <        for (i = 0; i < 4; i++) {
63 >        for (i = 3; i--; )              /* compute rear center */
64 >                pb[i] = 0.5*(cp[0][i] + cp[2][i]);
65 >        sb2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */
66 >        for (i = 0; i < 4; i++) {       /* compute visible quad */
67                  viewloc(ip[i], &vrev, cp[i]);
68 <                if (ip[i][2] < 0.)
69 <                        return((int)(af + 0.5));
68 >                if (ip[i][2] < 0.) {
69 >                        ab = 0;
70 >                        goto finish;
71 >                }
72                  ip[i][0] *= (double)hr; /* scale by resolution */
73                  ip[i][1] *= (double)vr;
74          }
# Line 71 | Line 77 | getback:
77                  (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]);
78          ab += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) -
79                  (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]);
80 <        if (ab >= 0) ab *= 0.5;
81 <        else ab *= -0.5;
82 <                                        /* round off smaller area */
83 <        if (af <= ab)
84 <                return((int)(af + 0.5));
85 <        return((int)(ab + 0.5));
80 >        ab *= ab >= 0 ? 0.5 : -0.5;
81 > finish:         /* compute penalty based on dist. sightline - viewpoint */
82 >        df2 = dist2(vp->vp, pf);
83 >        db2 = dist2(vp->vp, pb);
84 >        dfb2 = dist2(pf, pb);
85 >        penalty = dfb2 + df2 - db2;
86 >        penalty = df2 - 0.25*penalty*penalty/dfb2;
87 >        if (df2 > db2)  penalty /= df2 <= dfb2 ? sb2 : sb2*df2/dfb2;
88 >        else            penalty /= db2 <= dfb2 ? sf2 : sf2*db2/dfb2;
89 >        if (penalty < 1.) penalty = 1.;
90 >                                        /* round off smaller non-zero area */
91 >        if (ab <= FTINY || (af > FTINY && af <= ab))
92 >                return((int)(af/penalty + 0.5));
93 >        return((int)(ab/penalty + 0.5));
94   }
95  
96  
# Line 115 | Line 129 | char   *dp;
129                  if (!(inflags & 1<<gc.w))       /* origin on wrong side */
130                          continue;
131                                          /* scanline algorithm */
132 <                for (gc.i[1] = hp->grid[((gc.w>>1)+2)%3]; gc.i[1]--; ) {
132 >                for (gc.i[1] = hp->grid[hdwg1[gc.w]]; gc.i[1]--; ) {
133                                                  /* compute scanline */
134                          gp[gc.w>>1] = gc.w&1 ? hp->grid[gc.w>>1] : 0;
135 <                        gp[((gc.w>>1)+1)%3] = 0;
136 <                        gp[((gc.w>>1)+2)%3] = gc.i[1] + 0.5;
135 >                        gp[hdwg0[gc.w]] = 0;
136 >                        gp[hdwg1[gc.w]] = gc.i[1] + 0.5;
137                          hdworld(lo, hp, gp);
138 <                        gp[((gc.w>>1)+1)%3] = 1;
138 >                        gp[hdwg0[gc.w]] = 1;
139                          hdworld(ld, hp, gp);
140                          ld[0] -= lo[0]; ld[1] -= lo[1]; ld[2] -= lo[2];
141                                                  /* find scanline limits */
142 <                        lbeg = 0; lend = hp->grid[((gc.w>>1)+1)%3];
142 >                        lbeg = 0; lend = hp->grid[hdwg0[gc.w]];
143                          for (i = 0; i < 4; i++) {
144                                  t = DOT(pn[i], lo) - po[i];
145                                  d = -DOT(pn[i], ld);
# Line 224 | Line 238 | addcell(gcp, cl)               /* add a cell to a list */
238   GCOORD  *gcp;
239   register struct cellist *cl;
240   {
241 <        copystruct(cl->cl+cl->n, gcp);
241 >        *(cl->cl+cl->n) = *gcp;
242          cl->n++;
243          return(1);
244   }
# Line 266 | Line 280 | VIEW   *vp;
280          if (cl.cl == NULL)
281                  goto memerr;
282          cl.n = 0;                       /* add cells within pyramid */
283 <        visit_cells(org, dir, hp, addcell, &cl);
283 >        visit_cells(org, dir, hp, addcell, (char *)&cl);
284          if (!cl.n) {
285 <                free((char *)cl.cl);
285 >                free((void *)cl.cl);
286                  return(NULL);
287          }
288          *np = cl.n * orient;
# Line 277 | Line 291 | VIEW   *vp;
291           * sorted automatically by visit_cells(), so we don't need this.
292           */
293                                          /* optimize memory use */
294 <        cl.cl = (GCOORD *)realloc((char *)cl.cl, cl.n*sizeof(GCOORD));
294 >        cl.cl = (GCOORD *)realloc((void *)cl.cl, cl.n*sizeof(GCOORD));
295          if (cl.cl == NULL)
296                  goto memerr;
297                                          /* sort the list */
# Line 289 | Line 303 | memerr:
303   }
304  
305  
306 < gridlines(f)                    /* run through holodeck section grid lines */
307 < int     (*f)();
306 > extern void
307 > gridlines(                      /* run through holodeck section grid lines */
308 >        void    (*f)(FVECT wp[2])
309 > )
310   {
311          register int    hd, w, i;
312          int     g0, g1;
# Line 299 | Line 315 | int    (*f)();
315                                          /* do each wall on each section */
316          for (hd = 0; hdlist[hd] != NULL; hd++)
317                  for (w = 0; w < 6; w++) {
318 <                        g0 = ((w>>1)+1)%3;
319 <                        g1 = ((w>>1)+2)%3;
318 >                        g0 = hdwg0[w];
319 >                        g1 = hdwg1[w];
320                          d = 1.0/hdlist[hd]->grid[g0];
321                          mov[0] = d * hdlist[hd]->xv[g0][0];
322                          mov[1] = d * hdlist[hd]->xv[g0][1];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines