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.10 by gregl, Thu Dec 18 09:33:35 1997 UTC vs.
Revision 3.16 by gwlarson, Tue Nov 24 17:05:36 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 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   packdc[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, dc, meandist;
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 >        for (i = 0, meandist = 0.; i < p->nr || meandist > myeye.rng+FTINY; ) {
36 >                rpos[0][0] = frandom() * 256.;
37 >                rpos[0][1] = frandom() * 256.;
38 >                rpos[1][0] = frandom() * 256.;
39 >                rpos[1][1] = frandom() * 256.;
40 >                d = hdray(ro, rd, hdlist[p->hd], gc, rpos);
41 >                if (myeye.rng > FTINY) {                /* check eyepoint */
42 >                        register int    nexti;
43 >
44 >                        VSUM(rp1, ro, rd, d);
45 >                        dc = sqrt(dist2line(myeye.vpt, ro, rp1)) / p->nr;
46 >                        if (i == p->nr) {               /* packet full */
47 >                                nexti = packord[i-1];
48 >                                if (!iterleft--)
49 >                                        break;          /* tried enough! */
50 >                                if (dc >= packdc[nexti])
51 >                                        continue;       /* worse than worst */
52 >                                meandist -= packdc[nexti];
53 >                        } else
54 >                                nexti = i++;
55 >                        meandist += packdc[nexti] = dc; /* new distance */
56 >                        for (ii = i; --ii; ) {          /* insertion sort */
57 >                                if (dc > packdc[packord[ii-1]])
58 >                                        break;
59 >                                packord[ii] = packord[ii-1];
60 >                        }
61 >                        packord[ii] = nexti;
62 >                        ii = nexti;                     /* put it here */
63 >                } else
64 >                        ii = i++;
65                  if (p->offset != NULL) {
66 +                        if (!vdef(OBSTRUCTIONS))
67 +                                d *= frandom();         /* random offset */
68                          VSUM(ro, ro, rd, d);            /* advance ray */
69 <                        p->offset[i] = d;
69 >                        p->offset[ii] = d;
70                  }
71 <                VCOPY(rod, ro);
72 <                rod += 3;
73 <                VCOPY(rod, rd);
74 <                rod += 3;
71 >                p->ra[ii].r[0][0] = rpos[0][0];
72 >                p->ra[ii].r[0][1] = rpos[0][1];
73 >                p->ra[ii].r[1][0] = rpos[1][0];
74 >                p->ra[ii].r[1][1] = rpos[1][1];
75 >                VCOPY(rod+6*ii, ro);
76 >                VCOPY(rod+6*ii+3, rd);
77          }
78 + #ifdef DEBUG
79 +        fprintf(stderr, "%f mean distance for target %f (%d iterations)\n",
80 +                        meandist, myeye.rng, 3*p->nr - iterleft);
81 + #endif
82   }
83  
84  
# Line 115 | Line 149 | new_rtrace()                   /* restart rtrace calculation */
149  
150   getradfile()                    /* run rad and get needed variables */
151   {
152 <        static short    mvar[] = {OCTREE,-1};
152 >        static short    mvar[] = {OCTREE,EYESEP,-1};
153          static char     tf1[] = TEMPLATE;
154          char    tf2[64];
155          char    combuf[256];
# Line 124 | Line 158 | getradfile()                   /* run rad and get needed variables */
158          register char   *cp;
159                                          /* check if rad file specified */
160          if (!vdef(RIF))
161 <                return;
161 >                return(0);
162                                          /* create rad command */
163          mktemp(tf1);
164          sprintf(tf2, "%s.rif", tf1);
# Line 147 | Line 181 | getradfile()                   /* run rad and get needed variables */
181                  strcpy(pippt, "> /dev/null");   /* nothing to match */
182          else
183                  sprintf(cp, ")[ \t]*=' > %s", tf2);
184 <        if (system(combuf)) {
185 <                unlink(tf2);                    /* clean up */
186 <                unlink(tf1);
187 <                error(USER, "error executing rad command");
154 <        }
184 > #ifdef DEBUG
185 >        wputs(combuf); wputs("\n");
186 > #endif
187 >        system(combuf);                         /* ignore exit code */
188          if (pippt == NULL) {
189                  loadvars(tf2);                  /* load variables */
190                  unlink(tf2);
191          }
192          rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
193          unlink(tf1);                    /* clean up */
194 +        return(1);
195   }
196  
197  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines