11 |
|
#include "face.h" |
12 |
|
#include "cone.h" |
13 |
|
#include "random.h" |
14 |
+ |
#include "selcall.h" |
15 |
|
|
16 |
|
|
17 |
< |
int o_default(FUN_ARGLIST); |
18 |
< |
int o_face(FUN_ARGLIST); |
19 |
< |
int o_sphere(FUN_ARGLIST); |
19 |
< |
int o_ring(FUN_ARGLIST); |
20 |
< |
void raysamp(float res[3], FVECT org, FVECT dir, struct rtproc *rt); |
21 |
< |
void rayflush(struct rtproc *rt); |
22 |
< |
void mkaxes(FVECT u, FVECT v, FVECT n); |
23 |
< |
void rounddir(FVECT dv, double alt, double azi); |
24 |
< |
void flatdir(FVECT dv, double alt, double azi); |
17 |
> |
static void mkaxes(FVECT u, FVECT v, FVECT n); |
18 |
> |
static void rounddir(FVECT dv, double alt, double azi); |
19 |
> |
static void flatdir(FVECT dv, double alt, double azi); |
20 |
|
|
21 |
|
|
22 |
+ |
static void |
23 |
+ |
rayclean( /* finish all pending rays */ |
24 |
+ |
struct rtproc *rt0 |
25 |
+ |
) |
26 |
+ |
{ |
27 |
+ |
rayflush(rt0, 1); |
28 |
+ |
while (raywait(rt0) != NULL) |
29 |
+ |
; |
30 |
+ |
} |
31 |
+ |
|
32 |
+ |
|
33 |
|
int /* XXX type conflict with otypes.h */ |
34 |
|
o_default( /* default illum action */ |
35 |
|
OBJREC *ob, |
36 |
|
struct illum_args *il, |
37 |
< |
struct rtproc *rt, |
37 |
> |
struct rtproc *rt0, |
38 |
|
char *nm |
39 |
|
) |
40 |
|
{ |
50 |
|
o_face( /* make an illum face */ |
51 |
|
OBJREC *ob, |
52 |
|
struct illum_args *il, |
53 |
< |
struct rtproc *rt, |
53 |
> |
struct rtproc *rt0, |
54 |
|
char *nm |
55 |
|
) |
56 |
|
{ |
69 |
|
fa = getface(ob); |
70 |
|
if (fa->area == 0.0) { |
71 |
|
freeface(ob); |
72 |
< |
return(o_default(ob, il, rt, nm)); |
72 |
> |
return(o_default(ob, il, rt0, nm)); |
73 |
|
} |
74 |
|
/* set up sampling */ |
75 |
|
if (il->sampdens <= 0) |
133 |
|
} while (!inface(org, fa) && nmisses++ < MAXMISS); |
134 |
|
if (nmisses > MAXMISS) { |
135 |
|
objerror(ob, WARNING, "bad aspect"); |
136 |
< |
rt->nrays = 0; |
136 |
> |
rayclean(rt0); |
137 |
|
freeface(ob); |
138 |
|
free((void *)distarr); |
139 |
< |
return(o_default(ob, il, rt, nm)); |
139 |
> |
return(o_default(ob, il, rt0, nm)); |
140 |
|
} |
141 |
|
for (j = 0; j < 3; j++) |
142 |
|
org[j] += .001*fa->norm[j]; |
143 |
|
/* send sample */ |
144 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
144 |
> |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt0); |
145 |
|
} |
146 |
< |
rayflush(rt); |
146 |
> |
rayclean(rt0); |
147 |
|
/* write out the face and its distribution */ |
148 |
|
if (average(il, distarr, nalt*nazi)) { |
149 |
|
if (il->sampdens > 0) |
154 |
|
/* clean up */ |
155 |
|
freeface(ob); |
156 |
|
free((void *)distarr); |
157 |
+ |
return(0); |
158 |
|
#undef MAXMISS |
152 |
– |
/* XXX we need to return something here. what is it? */ |
159 |
|
} |
160 |
|
|
161 |
|
|
163 |
|
o_sphere( /* make an illum sphere */ |
164 |
|
register OBJREC *ob, |
165 |
|
struct illum_args *il, |
166 |
< |
struct rtproc *rt, |
166 |
> |
struct rtproc *rt0, |
167 |
|
char *nm |
168 |
|
) |
169 |
|
{ |
213 |
|
dir[j] = -dir[j]; |
214 |
|
} |
215 |
|
/* send sample */ |
216 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
216 |
> |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt0); |
217 |
|
} |
218 |
< |
rayflush(rt); |
218 |
> |
rayclean(rt0); |
219 |
|
/* write out the sphere and its distribution */ |
220 |
|
if (average(il, distarr, nalt*nazi)) { |
221 |
|
if (il->sampdens > 0) |
235 |
|
o_ring( /* make an illum ring */ |
236 |
|
OBJREC *ob, |
237 |
|
struct illum_args *il, |
238 |
< |
struct rtproc *rt, |
238 |
> |
struct rtproc *rt0, |
239 |
|
char *nm |
240 |
|
) |
241 |
|
{ |
286 |
|
.001*co->ad[j]; |
287 |
|
|
288 |
|
/* send sample */ |
289 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
289 |
> |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt0); |
290 |
|
} |
291 |
< |
rayflush(rt); |
291 |
> |
rayclean(rt0); |
292 |
|
/* write out the ring and its distribution */ |
293 |
|
if (average(il, distarr, nalt*nazi)) { |
294 |
|
if (il->sampdens > 0) |
304 |
|
|
305 |
|
|
306 |
|
void |
307 |
< |
raysamp( /* compute a ray sample */ |
307 |
> |
raysamp( /* queue a ray sample */ |
308 |
|
float res[3], |
309 |
|
FVECT org, |
310 |
|
FVECT dir, |
311 |
< |
register struct rtproc *rt |
311 |
> |
struct rtproc *rt0 |
312 |
|
) |
313 |
|
{ |
314 |
+ |
register struct rtproc *rt; |
315 |
|
register float *fp; |
316 |
|
|
317 |
< |
if (rt->nrays == rt->bsiz) |
318 |
< |
rayflush(rt); |
319 |
< |
rt->dest[rt->nrays] = res; |
320 |
< |
fp = rt->buf + 6*rt->nrays++; |
317 |
> |
for (rt = rt0; rt != NULL; rt = rt->next) |
318 |
> |
if (rt->nrays < rt->bsiz && rt->dest[rt->nrays] == NULL) |
319 |
> |
break; |
320 |
> |
if (rt == NULL) /* need to free up buffer? */ |
321 |
> |
rt = raywait(rt0); |
322 |
> |
if (rt == NULL) |
323 |
> |
error(SYSTEM, "raywait() returned NULL"); |
324 |
> |
fp = rt->buf + 6*rt->nrays; |
325 |
|
*fp++ = org[0]; *fp++ = org[1]; *fp++ = org[2]; |
326 |
|
*fp++ = dir[0]; *fp++ = dir[1]; *fp = dir[2]; |
327 |
+ |
rt->dest[rt->nrays++] = res; |
328 |
+ |
if (rt->nrays == rt->bsiz) |
329 |
+ |
rayflush(rt, 0); |
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
|
void |
334 |
< |
rayflush( /* flush buffered rays */ |
335 |
< |
register struct rtproc *rt |
334 |
> |
rayflush( /* flush queued rays to rtrace */ |
335 |
> |
register struct rtproc *rt, |
336 |
> |
int doall |
337 |
|
) |
338 |
|
{ |
339 |
< |
register int i; |
339 |
> |
int nw; |
340 |
|
|
341 |
< |
if (rt->nrays <= 0) |
342 |
< |
return; |
343 |
< |
memset(rt->buf+6*rt->nrays, '\0', 6*sizeof(float)); |
344 |
< |
errno = 0; |
345 |
< |
if ( process(&(rt->pd), (char *)rt->buf, (char *)rt->buf, |
346 |
< |
3*sizeof(float)*(rt->nrays+1), |
347 |
< |
6*sizeof(float)*(rt->nrays+1)) < |
348 |
< |
3*sizeof(float)*(rt->nrays+1) ) |
349 |
< |
error(SYSTEM, "error reading from rtrace process"); |
350 |
< |
i = rt->nrays; |
351 |
< |
while (i--) { |
352 |
< |
rt->dest[i][0] += rt->buf[3*i]; |
353 |
< |
rt->dest[i][1] += rt->buf[3*i+1]; |
354 |
< |
rt->dest[i][2] += rt->buf[3*i+2]; |
341 |
> |
do { |
342 |
> |
if (rt->nrays <= 0) |
343 |
> |
continue; |
344 |
> |
memset(rt->buf+6*rt->nrays, 0, 6*sizeof(float)); |
345 |
> |
nw = 6*sizeof(float)*(rt->nrays+1); |
346 |
> |
errno = 0; |
347 |
> |
if (writebuf(rt->pd.w, (char *)rt->buf, nw) < nw) |
348 |
> |
error(SYSTEM, "error writing to rtrace process"); |
349 |
> |
rt->nrays = 0; /* flag buffer as flushed */ |
350 |
> |
} while (doall && (rt = rt->next) != NULL); |
351 |
> |
} |
352 |
> |
|
353 |
> |
|
354 |
> |
struct rtproc * |
355 |
> |
raywait( /* retrieve rtrace results */ |
356 |
> |
struct rtproc *rt0 |
357 |
> |
) |
358 |
> |
{ |
359 |
> |
fd_set readset, errset; |
360 |
> |
int nr; |
361 |
> |
struct rtproc *rt, *rtfree; |
362 |
> |
register int n; |
363 |
> |
/* prepare select call */ |
364 |
> |
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
365 |
> |
nr = 0; |
366 |
> |
for (rt = rt0; rt != NULL; rt = rt->next) { |
367 |
> |
if (rt->nrays == 0 && rt->dest[0] != NULL) { |
368 |
> |
FD_SET(rt->pd.r, &readset); |
369 |
> |
++nr; |
370 |
> |
} |
371 |
> |
FD_SET(rt->pd.r, &errset); |
372 |
> |
if (rt->pd.r >= n) |
373 |
> |
n = rt->pd.r + 1; |
374 |
|
} |
375 |
< |
rt->nrays = 0; |
375 |
> |
if (!nr) /* no rays pending */ |
376 |
> |
return(NULL); |
377 |
> |
if (nr > 1) /* call select for multiple processes */ |
378 |
> |
n = select(n, &readset, (fd_set *)NULL, &errset, |
379 |
> |
(struct timeval *)NULL); |
380 |
> |
else |
381 |
> |
FD_ZERO(&errset); |
382 |
> |
if (n <= 0) |
383 |
> |
return(NULL); |
384 |
> |
rtfree = NULL; /* read from ready process(es) */ |
385 |
> |
for (rt = rt0; rt != NULL; rt = rt->next) { |
386 |
> |
if (!FD_ISSET(rt->pd.r, &readset) && |
387 |
> |
!FD_ISSET(rt->pd.r, &errset)) |
388 |
> |
continue; |
389 |
> |
for (n = 0; n < rt->bsiz && rt->dest[n] != NULL; n++) |
390 |
> |
; |
391 |
> |
errno = 0; |
392 |
> |
nr = read(rt->pd.r, (char *)rt->buf, 3*sizeof(float)*(n+1)); |
393 |
> |
if (nr < 0) |
394 |
> |
error(SYSTEM, "read error in raywait()"); |
395 |
> |
if (nr == 0) /* unexpected EOF */ |
396 |
> |
error(USER, "rtrace process died"); |
397 |
> |
if (nr < 3*sizeof(float)*(n+1)) { /* read the rest */ |
398 |
> |
nr = readbuf(rt->pd.r, (char *)rt->buf, |
399 |
> |
3*sizeof(float)*(n+1) - nr); |
400 |
> |
if (nr < 0) |
401 |
> |
error(USER, "readbuf error in raywait()"); |
402 |
> |
} |
403 |
> |
while (n-- > 0) { |
404 |
> |
rt->dest[n][0] += rt->buf[3*n]; |
405 |
> |
rt->dest[n][1] += rt->buf[3*n+1]; |
406 |
> |
rt->dest[n][2] += rt->buf[3*n+2]; |
407 |
> |
rt->dest[n] = NULL; |
408 |
> |
} |
409 |
> |
rtfree = rt; |
410 |
> |
} |
411 |
> |
return(rtfree); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
< |
void |
415 |
> |
static void |
416 |
|
mkaxes( /* compute u and v to go with n */ |
417 |
|
FVECT u, |
418 |
|
FVECT v, |
432 |
|
} |
433 |
|
|
434 |
|
|
435 |
< |
void |
435 |
> |
static void |
436 |
|
rounddir( /* compute uniform spherical direction */ |
437 |
|
register FVECT dv, |
438 |
|
double alt, |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
< |
void |
452 |
> |
static void |
453 |
|
flatdir( /* compute uniform hemispherical direction */ |
454 |
|
register FVECT dv, |
455 |
|
double alt, |