9 |
|
*/ |
10 |
|
|
11 |
|
#include "ray.h" |
12 |
+ |
#include "platform.h" |
13 |
|
#include "source.h" |
14 |
+ |
#include "func.h" |
15 |
|
#include "view.h" |
16 |
|
#include "random.h" |
17 |
|
|
18 |
|
#define DEGREE (PI/180.) |
19 |
|
|
20 |
< |
#define MAXNT 180 /* maximum number of theta divisions */ |
20 |
> |
#define MAXNT 181 /* maximum number of theta divisions */ |
21 |
|
#define MAXNP 360 /* maximum number of phi divisions */ |
22 |
|
|
23 |
|
extern char *progname; /* global argv[0] */ |
28 |
|
1.,180.,180.,0.,0.,0.,0., |
29 |
|
{0.,0.,0.},{0.,0.,0.},0.,0.}; |
30 |
|
|
31 |
< |
unsigned long nsamps = 10000; /* desired number of initial samples */ |
30 |
< |
unsigned long nssamps = 9000; /* number of super-samples */ |
31 |
> |
long nsamps = 10000; /* desired number of initial samples */ |
32 |
|
int ndsamps = 32; /* number of direct samples */ |
33 |
|
int nprocs = 1; /* number of rendering processes */ |
34 |
|
|
60 |
|
over_options(); |
61 |
|
printf("-n %-9d\t\t\t# number of processes\n", nprocs); |
62 |
|
printf("-rd %-9ld\t\t\t# ray directions\n", nsamps); |
62 |
– |
/* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */ |
63 |
|
printf("-dn %-9d\t\t\t# direct number of samples\n", ndsamps); |
64 |
|
printf("-vp %f %f %f\t# view point\n", |
65 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
77 |
|
int ec; |
78 |
|
{ |
79 |
|
if (ray_pnprocs > 0) /* close children if any */ |
80 |
< |
ray_pclose(0); |
80 |
> |
ray_pclose(0); |
81 |
> |
else if (ray_pnprocs < 0) |
82 |
> |
_exit(ec); /* avoid flush in child */ |
83 |
|
exit(ec); |
84 |
|
} |
85 |
|
|
102 |
|
directrelay = 3; |
103 |
|
ambounce = 1; |
104 |
|
maxdepth = -10; |
105 |
+ |
/* initialize calcomp routines */ |
106 |
+ |
initfunc(); |
107 |
|
/* get options from command line */ |
108 |
|
for (i = 1; i < argc; i++) { |
109 |
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
133 |
|
if (argv[i][1] == 'r') { /* sampling options */ |
134 |
|
if (argv[i][2] == 'd') |
135 |
|
nsamps = atol(argv[++i]); |
132 |
– |
else if (argv[i][2] == 's') |
133 |
– |
nssamps = atol(argv[++i]); |
136 |
|
else { |
137 |
|
sprintf(errmsg, "bad option at '%s'", argv[i]); |
138 |
|
error(USER, errmsg); |
211 |
|
{ |
212 |
|
int warnedneg; |
213 |
|
char linebuf[8192]; |
214 |
+ |
int last_pos_val = 0; |
215 |
|
int nelem = 1000; |
216 |
|
float *sarr = (float *)malloc(sizeof(float)*nelem); |
217 |
|
FILE *fp; |
239 |
|
cp = fskip(cp); |
240 |
|
if (cp == NULL) |
241 |
|
break; |
242 |
< |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]) { |
242 |
> |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]+FTINY) { |
243 |
|
sprintf(errmsg, |
244 |
|
"Phi values not monotinically increasing in sensor file '%s'", |
245 |
|
sfile); |
265 |
|
cp = fskip(cp); |
266 |
|
if (cp == NULL) |
267 |
|
break; |
268 |
< |
if (i && sarr[i] < .0) { |
268 |
> |
if (sarr[i] < .0) { |
269 |
|
if (!warnedneg++) { |
270 |
|
sprintf(errmsg, |
271 |
|
"Negative value(s) in sensor file '%s' (ignored)\n", sfile); |
272 |
|
error(WARNING, errmsg); |
273 |
|
} |
274 |
|
sarr[i] = .0; |
275 |
< |
} |
275 |
> |
} else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1)) |
276 |
> |
last_pos_val = i; |
277 |
|
++i; |
278 |
|
} |
279 |
< |
if (i == ntp[0]*(ntp[1]+1)) |
279 |
> |
if (i == ntp[0]*(ntp[1]+1)) /* empty line? */ |
280 |
|
break; |
281 |
|
if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <= |
282 |
|
sarr[(ntp[0]-1)*(ntp[1]+1)]) { |
292 |
|
error(USER, errmsg); |
293 |
|
} |
294 |
|
} |
295 |
< |
nelem = i; |
295 |
> |
/* truncate zero region */ |
296 |
> |
ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; |
297 |
> |
nelem = (ntp[0]+1)*(ntp[1]+1); |
298 |
|
fclose(fp); |
299 |
|
errmsg[0] = '\0'; /* sanity checks */ |
300 |
< |
if (ntp[0] <= 0) |
301 |
< |
sprintf(errmsg, "no data in sensor file '%s'", sfile); |
300 |
> |
if (!last_pos_val) |
301 |
> |
sprintf(errmsg, "no positive sensor values in file '%s'", sfile); |
302 |
|
else if (fabs(sarr[ntp[1]+1]) > FTINY) |
303 |
|
sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'", |
304 |
|
sfile); |
305 |
|
else if (fabs(sarr[1]) > FTINY) |
306 |
|
sprintf(errmsg, "minimum phi must be 0 in sensor file '%s'", |
307 |
|
sfile); |
308 |
< |
else if (sarr[ntp[1]] <= FTINY) |
308 |
> |
else if (sarr[ntp[1]] < 270.-FTINY) |
309 |
|
sprintf(errmsg, |
310 |
< |
"maximum phi must be positive in sensor file '%s'", |
310 |
> |
"maximum phi must be 270 or greater in sensor file '%s'", |
311 |
|
sfile); |
312 |
< |
else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY) |
312 |
> |
else if (sarr[ntp[1]] >= 360.-FTINY) |
313 |
|
sprintf(errmsg, |
314 |
< |
"maximum theta must be positive in sensor file '%s'", |
314 |
> |
"maximum phi must be less than 360 in sensor file '%s'", |
315 |
|
sfile); |
316 |
|
if (errmsg[0]) |
317 |
|
error(USER, errmsg); |
324 |
|
char *sfile |
325 |
|
) |
326 |
|
{ |
327 |
< |
int samptot = nsamps; |
327 |
> |
long samptot = nsamps; |
328 |
|
float *rowp, *rowp1; |
329 |
|
double rowsum[MAXNT], rowomega[MAXNT]; |
330 |
|
double thdiv[MAXNT+1], phdiv[MAXNP+1]; |
372 |
|
psize = PI*tsize/maxtheta; |
373 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
374 |
|
samptot = sntp[0]*sntp[1]; |
375 |
< |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
375 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1; |
376 |
|
if (ntheta > MAXNT) |
377 |
|
ntheta = MAXNT; |
378 |
|
nphi = samptot/ntheta; |
404 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
405 |
|
frac*cos(thdiv[t+1]) ); |
406 |
|
/* offset b/c sensor values are centered */ |
407 |
< |
if (!t || (t < sntp[0]-1) & (frac >= 0.5)) |
407 |
> |
if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { |
408 |
|
frac -= 0.5; |
409 |
< |
else { |
409 |
> |
} else { |
410 |
|
frac += 0.5; |
411 |
|
--t; |
412 |
|
} |
430 |
|
} |
431 |
|
pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; |
432 |
|
} |
433 |
+ |
/* duplicate final row */ |
434 |
+ |
memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), |
435 |
+ |
sizeof(*pvals)*(nphi+1)); |
436 |
|
tvals[0] = .0f; |
437 |
|
tvals[ntheta] = (float)tsize; |
438 |
|
} |
524 |
|
ndsamps > 0 ? 1 : 0; |
525 |
|
char *err; |
526 |
|
int nt, np; |
527 |
< |
COLOR vsum; |
527 |
> |
SCOLOR vsum; |
528 |
|
RAY rr; |
529 |
|
double sf; |
530 |
|
int i, j; |
538 |
|
/* assign probability table */ |
539 |
|
init_ptable(sfile); |
540 |
|
/* stratified MC sampling */ |
541 |
< |
setcolor(vsum, .0f, .0f, .0f); |
541 |
> |
scolorblack(vsum); |
542 |
|
nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); |
543 |
|
np = nsamps/nt; |
544 |
|
sf = gscale/nsamps; |
553 |
|
continue; |
554 |
|
} |
555 |
|
rr.rmax = .0; |
556 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
557 |
< |
scalecolor(rr.rcoef, sf); |
556 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
557 |
> |
scalescolor(rr.rcoef, sf); |
558 |
|
if (ray_pqueue(&rr) == 1) |
559 |
< |
addcolor(vsum, rr.rcol); |
559 |
> |
saddscolor(vsum, rr.rcol); |
560 |
|
} |
561 |
|
/* remaining rays pure MC */ |
562 |
|
for (i = nsamps - nt*np; i-- > 0; ) { |
569 |
|
continue; |
570 |
|
} |
571 |
|
rr.rmax = .0; |
572 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
573 |
< |
scalecolor(rr.rcoef, sf); |
572 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
573 |
> |
scalescolor(rr.rcoef, sf); |
574 |
|
if (ray_pqueue(&rr) == 1) |
575 |
< |
addcolor(vsum, rr.rcol); |
575 |
> |
saddscolor(vsum, rr.rcol); |
576 |
|
} |
577 |
|
if (!ray_pnprocs) /* just printing rays */ |
578 |
|
return; |
579 |
|
/* scale partial result */ |
580 |
< |
scalecolor(vsum, sf); |
580 |
> |
scalescolor(vsum, sf); |
581 |
|
/* add direct component */ |
582 |
|
for (i = ndirs; i-- > 0; ) { |
583 |
|
SRCINDEX si; |
587 |
|
if (sf <= FTINY) |
588 |
|
continue; |
589 |
|
sf *= si.dom/ndirs; |
590 |
< |
scalecolor(rr.rcoef, sf); |
590 |
> |
scalescolor(rr.rcoef, sf); |
591 |
|
if (ray_pqueue(&rr) == 1) { |
592 |
< |
multcolor(rr.rcol, rr.rcoef); |
593 |
< |
addcolor(vsum, rr.rcol); |
592 |
> |
smultscolor(rr.rcol, rr.rcoef); |
593 |
> |
saddscolor(vsum, rr.rcol); |
594 |
|
} |
595 |
|
} |
596 |
|
} |
597 |
< |
/* finish our calculation */ |
598 |
< |
while (ray_presult(&rr, 0) > 0) { |
599 |
< |
multcolor(rr.rcol, rr.rcoef); |
591 |
< |
addcolor(vsum, rr.rcol); |
597 |
> |
while (ray_presult(&rr, 0) > 0) { /* finish our calculation */ |
598 |
> |
smultscolor(rr.rcol, rr.rcoef); |
599 |
> |
saddscolor(vsum, rr.rcol); |
600 |
|
} |
601 |
< |
/* print our result */ |
602 |
< |
printf("%.4e %.4e %.4e\n", colval(vsum,RED), |
603 |
< |
colval(vsum,GRN), colval(vsum,BLU)); |
601 |
> |
for (i = 0; i < NCSAMP; i++) /* print our result */ |
602 |
> |
printf(" %.4e", vsum[i]); |
603 |
> |
fputc('\n', stdout); |
604 |
|
} |