ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2.c
Revision: 3.15
Committed: Mon Nov 23 18:17:53 1998 UTC (25 years, 4 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.14: +10 -51 lines
Log Message:
took duplicate ray checking out again (too expensive)

File Contents

# User Rev Content
1 gwlarson 3.12 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 gregl 3.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Rtrace support routines for holodeck rendering
9     */
10    
11     #include "rholo.h"
12 gregl 3.5 #include "paths.h"
13 gregl 3.1 #include "random.h"
14    
15    
16     packrays(rod, p) /* pack ray origins and directions */
17 gwlarson 3.15 register float *rod;
18 gregl 3.1 register PACKET *p;
19     {
20 gwlarson 3.15 static FVECT ro, rd;
21 gregl 3.3 GCOORD gc[2];
22 gwlarson 3.15 int ila[2], hsh;
23 gregl 3.4 double d, sl[4];
24 gwlarson 3.15 register int i;
25 gregl 3.1
26     if (!hdbcoord(gc, hdlist[p->hd], p->bi))
27     error(CONSISTENCY, "bad beam index in packrays");
28 gregl 3.4 ila[0] = p->hd; ila[1] = p->bi;
29 gwlarson 3.15 hsh = ilhash(ila,2) + p->nc;
30 gregl 3.1 for (i = 0; i < p->nr; i++) {
31 gwlarson 3.15 multisamp(sl, 4, urand(hsh+i));
32     p->ra[i].r[0][0] = sl[0] * 256.;
33     p->ra[i].r[0][1] = sl[1] * 256.;
34     p->ra[i].r[1][0] = sl[2] * 256.;
35     p->ra[i].r[1][1] = sl[3] * 256.;
36 gregl 3.1 d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r);
37 gregl 3.8 if (!vdef(OBSTRUCTIONS))
38     d *= frandom(); /* random offset */
39 gregl 3.1 if (p->offset != NULL) {
40 gregl 3.8 VSUM(ro, ro, rd, d); /* advance ray */
41 gregl 3.1 p->offset[i] = d;
42     }
43     VCOPY(rod, ro);
44     rod += 3;
45     VCOPY(rod, rd);
46     rod += 3;
47     }
48     }
49    
50    
51     donerays(p, rvl) /* encode finished ray computations */
52     register PACKET *p;
53     register float *rvl;
54     {
55     double d;
56     register int i;
57    
58     for (i = 0; i < p->nr; i++) {
59     setcolr(p->ra[i].v, rvl[0], rvl[1], rvl[2]);
60     d = rvl[3];
61     if (p->offset != NULL)
62     d += p->offset[i];
63     p->ra[i].d = hdcode(hdlist[p->hd], d);
64     rvl += 4;
65     }
66 gregl 3.4 p->nc += p->nr;
67 gregl 3.5 }
68    
69    
70     int
71     done_rtrace() /* clean up and close rtrace calculation */
72     {
73     int status;
74     /* already closed? */
75     if (!nprocs)
76     return;
77     /* flush beam queue */
78     done_packets(flush_queue());
79 gregl 3.7 /* sync holodeck */
80     hdsync(NULL, 1);
81 gregl 3.5 /* close rtrace */
82     if ((status = end_rtrace()))
83     error(WARNING, "bad exit status from rtrace");
84 gregl 3.9 if (vdef(REPORT)) { /* report time */
85 gregl 3.10 eputs("rtrace process closed\n");
86 gregl 3.5 report(0);
87 gregl 3.9 }
88 gregl 3.5 return(status); /* return status */
89     }
90    
91    
92     new_rtrace() /* restart rtrace calculation */
93     {
94     char combuf[128];
95    
96     if (nprocs > 0) /* already running? */
97     return;
98 gregl 3.6 starttime = time(NULL); /* reset start time and counts */
99     npacksdone = nraysdone = 0L;
100     if (vdef(TIME)) /* reset end time */
101     endtime = starttime + vflt(TIME)*3600. + .5;
102 gregl 3.5 if (vdef(RIF)) { /* rerun rad to update octree */
103     sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
104     if (system(combuf))
105     error(WARNING, "error running rad");
106     }
107     if (start_rtrace() < 1) /* start rtrace */
108     error(WARNING, "cannot restart rtrace");
109 gregl 3.9 else if (vdef(REPORT)) {
110     eputs("rtrace process restarted\n");
111 gregl 3.5 report(0);
112 gregl 3.9 }
113 gregl 3.5 }
114    
115    
116     getradfile() /* run rad and get needed variables */
117     {
118 gwlarson 3.12 static short mvar[] = {OCTREE,EYESEP,-1};
119 gregl 3.5 static char tf1[] = TEMPLATE;
120     char tf2[64];
121     char combuf[256];
122     char *pippt;
123     register int i;
124     register char *cp;
125     /* check if rad file specified */
126     if (!vdef(RIF))
127 gregl 3.11 return(0);
128 gregl 3.5 /* create rad command */
129     mktemp(tf1);
130     sprintf(tf2, "%s.rif", tf1);
131     sprintf(combuf,
132     "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
133     vval(RIF), tf1);
134     cp = combuf;
135     while (*cp){
136     if (*cp == '|') pippt = cp;
137     cp++;
138     } /* match unset variables */
139     for (i = 0; mvar[i] >= 0; i++)
140     if (!vdef(mvar[i])) {
141     *cp++ = '|';
142     strcpy(cp, vnam(mvar[i]));
143     while (*cp) cp++;
144     pippt = NULL;
145     }
146     if (pippt != NULL)
147     strcpy(pippt, "> /dev/null"); /* nothing to match */
148     else
149     sprintf(cp, ")[ \t]*=' > %s", tf2);
150 gwlarson 3.13 #ifdef DEBUG
151     wputs(combuf); wputs("\n");
152     #endif
153     system(combuf); /* ignore exit code */
154 gregl 3.5 if (pippt == NULL) {
155     loadvars(tf2); /* load variables */
156     unlink(tf2);
157     }
158     rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
159     unlink(tf1); /* clean up */
160 gregl 3.11 return(1);
161 gregl 3.6 }
162    
163    
164     report(t) /* report progress so far */
165     time_t t;
166     {
167     static time_t seconds2go = 1000000;
168    
169     if (t == 0L)
170     t = time(NULL);
171     sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
172     npacksdone, nraysdone, (t-starttime)/3600.);
173     eputs(errmsg);
174     if (seconds2go == 1000000)
175     seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
176     if (seconds2go)
177     reporttime = t + seconds2go;
178 gregl 3.1 }