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

Comparing ray/src/hd/rholo2.c (file contents):
Revision 3.13 by gwlarson, Mon Jul 6 18:17:20 1998 UTC vs.
Revision 3.17 by gwlarson, Tue Nov 24 17:38:09 1998 UTC

# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ SGI";
13   #include "random.h"
14  
15  
16 + VIEWPOINT       myeye;          /* target view position */
17 +
18 +
19   packrays(rod, p)                /* pack ray origins and directions */
20   register float  *rod;
21   register PACKET *p;
22   {
23 <        static FVECT    ro, rd;
23 >        short   packord[RPACKSIZ];
24 >        float   packdc2[RPACKSIZ];
25 >        int     iterleft = 3*p->nr;
26 >        BYTE    rpos[2][2];
27 >        FVECT   ro, rd, rp1;
28          GCOORD  gc[2];
29 <        int     ila[2], hsh;
30 <        double  d, sl[4];
31 <        register int    i;
29 >        double  d, dc2, md2, td2;
30 >        int     i;
31 >        register int    ii;
32  
33          if (!hdbcoord(gc, hdlist[p->hd], p->bi))
34                  error(CONSISTENCY, "bad beam index in packrays");
35 <        ila[0] = p->hd; ila[1] = p->bi;
36 <        hsh = ilhash(ila,2) + p->nc;
37 <        for (i = 0; i < p->nr; i++) {
38 <                multisamp(sl, 4, urand(hsh+i));
39 <                p->ra[i].r[0][0] = sl[0] * 256.;
40 <                p->ra[i].r[0][1] = sl[1] * 256.;
41 <                p->ra[i].r[1][0] = sl[2] * 256.;
42 <                p->ra[i].r[1][1] = sl[3] * 256.;
43 <                d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r);
44 <                if (!vdef(OBSTRUCTIONS))
45 <                        d *= frandom();                 /* random offset */
35 >        td2 = (myeye.rng+FTINY)*(myeye.rng+FTINY);
36 >        for (i = 0, md2 = 0.; i < p->nr || md2 > td2; ) {
37 >                rpos[0][0] = frandom() * 256.;
38 >                rpos[0][1] = frandom() * 256.;
39 >                rpos[1][0] = frandom() * 256.;
40 >                rpos[1][1] = frandom() * 256.;
41 >                d = hdray(ro, rd, hdlist[p->hd], gc, rpos);
42 >                if (myeye.rng > FTINY) {                /* check eyepoint */
43 >                        register int    nexti;
44 >
45 >                        VSUM(rp1, ro, rd, d);
46 >                        dc2 = dist2line(myeye.vpt, ro, rp1);
47 >                        dc2 /= (double)(p->nr*p->nr);
48 >                        if (i == p->nr) {               /* packet full */
49 >                                nexti = packord[i-1];
50 >                                if (!iterleft--)
51 >                                        break;          /* tried enough! */
52 >                                if (dc2 >= packdc2[nexti])
53 >                                        continue;       /* worse than worst */
54 >                                md2 -= packdc2[nexti];
55 >                        } else
56 >                                nexti = i++;
57 >                        md2 += packdc2[nexti] = dc2;    /* new distance */
58 >                        for (ii = i; --ii; ) {          /* insertion sort */
59 >                                if (dc2 > packdc2[packord[ii-1]])
60 >                                        break;
61 >                                packord[ii] = packord[ii-1];
62 >                        }
63 >                        packord[ii] = nexti;
64 >                        ii = nexti;                     /* put it here */
65 >                } else
66 >                        ii = i++;
67                  if (p->offset != NULL) {
68 +                        if (!vdef(OBSTRUCTIONS))
69 +                                d *= frandom();         /* random offset */
70                          VSUM(ro, ro, rd, d);            /* advance ray */
71 <                        p->offset[i] = d;
71 >                        p->offset[ii] = d;
72                  }
73 <                VCOPY(rod, ro);
74 <                rod += 3;
75 <                VCOPY(rod, rd);
76 <                rod += 3;
73 >                p->ra[ii].r[0][0] = rpos[0][0];
74 >                p->ra[ii].r[0][1] = rpos[0][1];
75 >                p->ra[ii].r[1][0] = rpos[1][0];
76 >                p->ra[ii].r[1][1] = rpos[1][1];
77 >                VCOPY(rod+6*ii, ro);
78 >                VCOPY(rod+6*ii+3, rd);
79          }
80 + #ifdef DEBUG
81 +        fprintf(stderr, "%f mean distance for target %f (%d iterations left)\n",
82 +                        sqrt(md2), myeye.rng, iterleft);
83 + #endif
84   }
85  
86  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines