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.7 by gregl, Wed Nov 26 20:12:19 1997 UTC vs.
Revision 3.17 by greg, Wed Jan 24 04:39:52 2018 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++) {
37 <                viewloc(ip[i], vp, cp[i]);
38 <                if (ip[i][2] < 0.) {
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 >                if (viewloc(ip[i], vp, cp[i]) <= 0) {
41                          af = 0;
42                          goto getback;
43                  }
# Line 48 | Line 49 | int    bi;
49                  (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]);
50          af += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) -
51                  (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]);
52 <        if (af >= 0) af *= 0.5;
52 <        else af *= -0.5;
52 >        af *= af >= 0 ? 0.5 : -0.5;
53   getback:
54 <        copystruct(&vrev, vp);          /* compute reverse view */
54 >        vrev = *vp;             /* compute reverse view */
55          for (i = 0; i < 3; i++) {
56                  vrev.vdir[i] = -vp->vdir[i];
57                  vrev.vup[i] = -vp->vup[i];
# Line 59 | Line 59 | getback:
59                  vrev.vvec[i] = -vp->vvec[i];
60          }
61          hdcell(cp, hp, gc);             /* find cell on back image */
62 <        for (i = 0; i < 4; i++) {
63 <                viewloc(ip[i], &vrev, cp[i]);
64 <                if (ip[i][2] < 0.)
65 <                        return((int)(af + 0.5));
62 >        for (i = 3; i--; )              /* compute rear center */
63 >                pb[i] = 0.5*(cp[0][i] + cp[2][i]);
64 >        sb2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */
65 >        for (i = 0; i < 4; i++) {       /* compute visible quad */
66 >                if (viewloc(ip[i], &vrev, cp[i]) <= 0) {
67 >                        ab = 0;
68 >                        goto finish;
69 >                }
70                  ip[i][0] *= (double)hr; /* scale by resolution */
71                  ip[i][1] *= (double)vr;
72          }
# Line 71 | Line 75 | getback:
75                  (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]);
76          ab += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) -
77                  (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]);
78 <        if (ab >= 0) ab *= 0.5;
79 <        else ab *= -0.5;
80 <                                        /* round off smaller area */
81 <        if (af <= ab)
82 <                return((int)(af + 0.5));
83 <        return((int)(ab + 0.5));
78 >        ab *= ab >= 0 ? 0.5 : -0.5;
79 > finish:         /* compute penalty based on dist. sightline - viewpoint */
80 >        df2 = dist2(vp->vp, pf);
81 >        db2 = dist2(vp->vp, pb);
82 >        dfb2 = dist2(pf, pb);
83 >        penalty = dfb2 + df2 - db2;
84 >        penalty = df2 - 0.25*penalty*penalty/dfb2;
85 >        if (df2 > db2)  penalty /= df2 <= dfb2 ? sb2 : sb2*df2/dfb2;
86 >        else            penalty /= db2 <= dfb2 ? sf2 : sf2*db2/dfb2;
87 >        if (penalty < 1.) penalty = 1.;
88 >                                        /* round off smaller non-zero area */
89 >        if (ab <= FTINY || (af > FTINY && af <= ab))
90 >                return((int)(af/penalty + 0.5));
91 >        return((int)(ab/penalty + 0.5));
92   }
93  
94  
# Line 84 | Line 96 | getback:
96   * The ray directions that define the pyramid in visit_cells() needn't
97   * be normalized, but they must be given in clockwise order as seen
98   * from the pyramid's apex (origin).
99 + * If no cell centers fall within the domain, the closest cell is visited.
100   */
101   int
102   visit_cells(orig, pyrd, hp, vf, dp)     /* visit cells within a pyramid */
103   FVECT   orig, pyrd[4];          /* pyramid ray directions in clockwise order */
104 < HOLO    *hp;
104 > register HOLO   *hp;
105   int     (*vf)();
106   char    *dp;
107   {
108 <        int     n = 0;
108 >        int     ncalls = 0, n = 0;
109          int     inflags = 0;
110          FVECT   gp, pn[4], lo, ld;
111          double  po[4], lbeg, lend, d, t;
112 <        GCOORD  gc;
112 >        GCOORD  gc, gc2[2];
113          register int    i;
114                                          /* figure out whose side we're on */
115          hdgrid(gp, hp, orig);
# Line 114 | Line 127 | char   *dp;
127                  if (!(inflags & 1<<gc.w))       /* origin on wrong side */
128                          continue;
129                                          /* scanline algorithm */
130 <                for (gc.i[1] = hp->grid[((gc.w>>1)+2)%3]; gc.i[1]--; ) {
130 >                for (gc.i[1] = hp->grid[hdwg1[gc.w]]; gc.i[1]--; ) {
131                                                  /* compute scanline */
132                          gp[gc.w>>1] = gc.w&1 ? hp->grid[gc.w>>1] : 0;
133 <                        gp[((gc.w>>1)+1)%3] = 0;
134 <                        gp[((gc.w>>1)+2)%3] = gc.i[1] + 0.5;
133 >                        gp[hdwg0[gc.w]] = 0;
134 >                        gp[hdwg1[gc.w]] = gc.i[1] + 0.5;
135                          hdworld(lo, hp, gp);
136 <                        gp[((gc.w>>1)+1)%3] = 1;
136 >                        gp[hdwg0[gc.w]] = 1;
137                          hdworld(ld, hp, gp);
138                          ld[0] -= lo[0]; ld[1] -= lo[1]; ld[2] -= lo[2];
139                                                  /* find scanline limits */
140 <                        lbeg = 0; lend = hp->grid[((gc.w>>1)+1)%3];
140 >                        lbeg = 0; lend = hp->grid[hdwg0[gc.w]];
141                          for (i = 0; i < 4; i++) {
142                                  t = DOT(pn[i], lo) - po[i];
143                                  d = -DOT(pn[i], ld);
# Line 142 | Line 155 | char   *dp;
155                          if (lbeg >= lend)
156                                  continue;
157                          i = lend + .5;          /* visit cells on this scan */
158 <                        for (gc.i[0] = lbeg + .5; gc.i[0] < i; gc.i[0]++)
158 >                        for (gc.i[0] = lbeg + .5; gc.i[0] < i; gc.i[0]++) {
159                                  n += (*vf)(&gc, dp);
160 +                                ncalls++;
161 +                        }
162                  }
163          }
164 <        return(n);
164 >        if (ncalls)                     /* got one at least */
165 >                return(n);
166 >                                        /* else find closest cell */
167 >        VSUM(ld, pyrd[0], pyrd[1], 1.);
168 >        VSUM(ld, ld, pyrd[2], 1.);
169 >        VSUM(ld, ld, pyrd[3], 1.);
170 > #if 0
171 >        if (normalize(ld) == 0.0)       /* technically not necessary */
172 >                return(0);
173 > #endif
174 >        d = hdinter(gc2, NULL, &t, hp, orig, ld);
175 >        if (d >= FHUGE || t <= 0.)
176 >                return(0);
177 >        return((*vf)(gc2+1, dp));       /* visit it */
178   }
179  
180  
# Line 208 | Line 236 | addcell(gcp, cl)               /* add a cell to a list */
236   GCOORD  *gcp;
237   register struct cellist *cl;
238   {
239 <        copystruct(cl->cl+cl->n, gcp);
239 >        *(cl->cl+cl->n) = *gcp;
240          cl->n++;
241          return(1);
242   }
# Line 250 | Line 278 | VIEW   *vp;
278          if (cl.cl == NULL)
279                  goto memerr;
280          cl.n = 0;                       /* add cells within pyramid */
281 <        visit_cells(org, dir, hp, addcell, &cl);
281 >        visit_cells(org, dir, hp, addcell, (char *)&cl);
282          if (!cl.n) {
283 <                free((char *)cl.cl);
283 >                free((void *)cl.cl);
284                  return(NULL);
285          }
286          *np = cl.n * orient;
# Line 261 | Line 289 | VIEW   *vp;
289           * sorted automatically by visit_cells(), so we don't need this.
290           */
291                                          /* optimize memory use */
292 <        cl.cl = (GCOORD *)realloc((char *)cl.cl, cl.n*sizeof(GCOORD));
292 >        cl.cl = (GCOORD *)realloc((void *)cl.cl, cl.n*sizeof(GCOORD));
293          if (cl.cl == NULL)
294                  goto memerr;
295                                          /* sort the list */
# Line 273 | Line 301 | memerr:
301   }
302  
303  
304 < gridlines(f)                    /* run through holodeck section grid lines */
305 < int     (*f)();
304 > extern void
305 > gridlines(                      /* run through holodeck section grid lines */
306 >        void    (*f)(FVECT wp[2])
307 > )
308   {
309          register int    hd, w, i;
310          int     g0, g1;
# Line 283 | Line 313 | int    (*f)();
313                                          /* do each wall on each section */
314          for (hd = 0; hdlist[hd] != NULL; hd++)
315                  for (w = 0; w < 6; w++) {
316 <                        g0 = ((w>>1)+1)%3;
317 <                        g1 = ((w>>1)+2)%3;
316 >                        g0 = hdwg0[w];
317 >                        g1 = hdwg1[w];
318                          d = 1.0/hdlist[hd]->grid[g0];
319                          mov[0] = d * hdlist[hd]->xv[g0][0];
320                          mov[1] = d * hdlist[hd]->xv[g0][1];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines