ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2.c
Revision: 3.8
Committed: Sat Dec 13 10:30:55 1997 UTC (26 years, 4 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.7: +3 -1 lines
Log Message:
allow OBSTRUCTIONS to be undefined, and use random offset in that case

File Contents

# Content
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
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 #include "paths.h"
13 #include "random.h"
14
15
16 packrays(rod, p) /* pack ray origins and directions */
17 register float *rod;
18 register PACKET *p;
19 {
20 static FVECT ro, rd;
21 GCOORD gc[2];
22 int ila[2], hsh;
23 double d, sl[4];
24 register int i;
25
26 if (!hdbcoord(gc, hdlist[p->hd], p->bi))
27 error(CONSISTENCY, "bad beam index in packrays");
28 ila[0] = p->hd; ila[1] = p->bi;
29 hsh = ilhash(ila,2) + p->nc;
30 for (i = 0; i < p->nr; i++) {
31 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 d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r);
37 if (!vdef(OBSTRUCTIONS))
38 d *= frandom(); /* random offset */
39 if (p->offset != NULL) {
40 VSUM(ro, ro, rd, d); /* advance ray */
41 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 p->nc += p->nr;
67 }
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 wputs("closing rtrace process...\n");
78 /* flush beam queue */
79 done_packets(flush_queue());
80 /* sync holodeck */
81 hdsync(NULL, 1);
82 /* close rtrace */
83 if ((status = end_rtrace()))
84 error(WARNING, "bad exit status from rtrace");
85 if (vdef(REPORT)) /* report time */
86 report(0);
87 return(status); /* return status */
88 }
89
90
91 new_rtrace() /* restart rtrace calculation */
92 {
93 char combuf[128];
94
95 if (nprocs > 0) /* already running? */
96 return;
97 wputs("restarting rtrace process...\n");
98 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 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 else if (vdef(REPORT))
110 report(0);
111 }
112
113
114 getradfile() /* run rad and get needed variables */
115 {
116 static short mvar[] = {OCTREE,-1};
117 static char tf1[] = TEMPLATE;
118 char tf2[64];
119 char combuf[256];
120 char *pippt;
121 register int i;
122 register char *cp;
123 /* check if rad file specified */
124 if (!vdef(RIF))
125 return;
126 /* create rad command */
127 mktemp(tf1);
128 sprintf(tf2, "%s.rif", tf1);
129 sprintf(combuf,
130 "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
131 vval(RIF), tf1);
132 cp = combuf;
133 while (*cp){
134 if (*cp == '|') pippt = cp;
135 cp++;
136 } /* match unset variables */
137 for (i = 0; mvar[i] >= 0; i++)
138 if (!vdef(mvar[i])) {
139 *cp++ = '|';
140 strcpy(cp, vnam(mvar[i]));
141 while (*cp) cp++;
142 pippt = NULL;
143 }
144 if (pippt != NULL)
145 strcpy(pippt, "> /dev/null"); /* nothing to match */
146 else
147 sprintf(cp, ")[ \t]*=' > %s", tf2);
148 if (system(combuf)) {
149 unlink(tf2); /* clean up */
150 unlink(tf1);
151 error(SYSTEM, "cannot execute rad command");
152 }
153 if (pippt == NULL) {
154 loadvars(tf2); /* load variables */
155 unlink(tf2);
156 }
157 rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
158 unlink(tf1); /* clean up */
159 }
160
161
162 report(t) /* report progress so far */
163 time_t t;
164 {
165 static time_t seconds2go = 1000000;
166
167 if (t == 0L)
168 t = time(NULL);
169 sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
170 npacksdone, nraysdone, (t-starttime)/3600.);
171 eputs(errmsg);
172 if (seconds2go == 1000000)
173 seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
174 if (seconds2go)
175 reporttime = t + seconds2go;
176 }