| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include "ray.h" |
| 12 |
+ |
#include "platform.h" |
| 13 |
|
#include "source.h" |
| 14 |
|
#include "view.h" |
| 15 |
|
#include "random.h" |
| 27 |
|
1.,180.,180.,0.,0.,0.,0., |
| 28 |
|
{0.,0.,0.},{0.,0.,0.},0.,0.}; |
| 29 |
|
|
| 30 |
< |
unsigned long nsamps = 10000; /* desired number of initial samples */ |
| 30 |
< |
unsigned long nssamps = 9000; /* number of super-samples */ |
| 30 |
> |
long nsamps = 10000; /* desired number of initial samples */ |
| 31 |
|
int ndsamps = 32; /* number of direct samples */ |
| 32 |
|
int nprocs = 1; /* number of rendering processes */ |
| 33 |
|
|
| 59 |
|
over_options(); |
| 60 |
|
printf("-n %-9d\t\t\t# number of processes\n", nprocs); |
| 61 |
|
printf("-rd %-9ld\t\t\t# ray directions\n", nsamps); |
| 62 |
– |
/* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */ |
| 62 |
|
printf("-dn %-9d\t\t\t# direct number of samples\n", ndsamps); |
| 63 |
|
printf("-vp %f %f %f\t# view point\n", |
| 64 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
| 76 |
|
int ec; |
| 77 |
|
{ |
| 78 |
|
if (ray_pnprocs > 0) /* close children if any */ |
| 79 |
< |
ray_pclose(0); |
| 79 |
> |
ray_pclose(0); |
| 80 |
> |
else if (ray_pnprocs < 0) |
| 81 |
> |
_exit(ec); /* avoid flush in child */ |
| 82 |
|
exit(ec); |
| 83 |
|
} |
| 84 |
|
|
| 130 |
|
if (argv[i][1] == 'r') { /* sampling options */ |
| 131 |
|
if (argv[i][2] == 'd') |
| 132 |
|
nsamps = atol(argv[++i]); |
| 132 |
– |
else if (argv[i][2] == 's') |
| 133 |
– |
nssamps = atol(argv[++i]); |
| 133 |
|
else { |
| 134 |
|
sprintf(errmsg, "bad option at '%s'", argv[i]); |
| 135 |
|
error(USER, errmsg); |
| 236 |
|
cp = fskip(cp); |
| 237 |
|
if (cp == NULL) |
| 238 |
|
break; |
| 239 |
< |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]) { |
| 239 |
> |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]+FTINY) { |
| 240 |
|
sprintf(errmsg, |
| 241 |
|
"Phi values not monotinically increasing in sensor file '%s'", |
| 242 |
|
sfile); |
| 302 |
|
else if (fabs(sarr[1]) > FTINY) |
| 303 |
|
sprintf(errmsg, "minimum phi must be 0 in sensor file '%s'", |
| 304 |
|
sfile); |
| 305 |
< |
else if (sarr[ntp[1]] <= FTINY) |
| 305 |
> |
else if (sarr[ntp[1]] < 270.-FTINY) |
| 306 |
|
sprintf(errmsg, |
| 307 |
< |
"maximum phi must be positive in sensor file '%s'", |
| 307 |
> |
"maximum phi must be 270 or greater in sensor file '%s'", |
| 308 |
|
sfile); |
| 309 |
+ |
else if (sarr[ntp[1]] >= 360.-FTINY) |
| 310 |
+ |
sprintf(errmsg, |
| 311 |
+ |
"maximum phi must be less than 360 in sensor file '%s'", |
| 312 |
+ |
sfile); |
| 313 |
|
if (errmsg[0]) |
| 314 |
|
error(USER, errmsg); |
| 315 |
|
return((float *)realloc((void *)sarr, sizeof(float)*nelem)); |
| 321 |
|
char *sfile |
| 322 |
|
) |
| 323 |
|
{ |
| 324 |
< |
int samptot = nsamps; |
| 324 |
> |
long samptot = nsamps; |
| 325 |
|
float *rowp, *rowp1; |
| 326 |
|
double rowsum[MAXNT], rowomega[MAXNT]; |
| 327 |
|
double thdiv[MAXNT+1], phdiv[MAXNP+1]; |
| 521 |
|
ndsamps > 0 ? 1 : 0; |
| 522 |
|
char *err; |
| 523 |
|
int nt, np; |
| 524 |
< |
COLOR vsum; |
| 524 |
> |
SCOLOR vsum; |
| 525 |
|
RAY rr; |
| 526 |
|
double sf; |
| 527 |
|
int i, j; |
| 535 |
|
/* assign probability table */ |
| 536 |
|
init_ptable(sfile); |
| 537 |
|
/* stratified MC sampling */ |
| 538 |
< |
setcolor(vsum, .0f, .0f, .0f); |
| 538 |
> |
scolorblack(vsum); |
| 539 |
|
nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); |
| 540 |
|
np = nsamps/nt; |
| 541 |
|
sf = gscale/nsamps; |
| 551 |
|
} |
| 552 |
|
rr.rmax = .0; |
| 553 |
|
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
| 554 |
< |
scalecolor(rr.rcoef, sf); |
| 554 |
> |
scalescolor(rr.rcoef, sf); |
| 555 |
|
if (ray_pqueue(&rr) == 1) |
| 556 |
< |
addcolor(vsum, rr.rcol); |
| 556 |
> |
saddscolor(vsum, rr.rcol); |
| 557 |
|
} |
| 558 |
|
/* remaining rays pure MC */ |
| 559 |
|
for (i = nsamps - nt*np; i-- > 0; ) { |
| 567 |
|
} |
| 568 |
|
rr.rmax = .0; |
| 569 |
|
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
| 570 |
< |
scalecolor(rr.rcoef, sf); |
| 570 |
> |
scalescolor(rr.rcoef, sf); |
| 571 |
|
if (ray_pqueue(&rr) == 1) |
| 572 |
< |
addcolor(vsum, rr.rcol); |
| 572 |
> |
saddscolor(vsum, rr.rcol); |
| 573 |
|
} |
| 574 |
|
if (!ray_pnprocs) /* just printing rays */ |
| 575 |
|
return; |
| 576 |
|
/* scale partial result */ |
| 577 |
< |
scalecolor(vsum, sf); |
| 577 |
> |
scalescolor(vsum, sf); |
| 578 |
|
/* add direct component */ |
| 579 |
|
for (i = ndirs; i-- > 0; ) { |
| 580 |
|
SRCINDEX si; |
| 584 |
|
if (sf <= FTINY) |
| 585 |
|
continue; |
| 586 |
|
sf *= si.dom/ndirs; |
| 587 |
< |
scalecolor(rr.rcoef, sf); |
| 587 |
> |
scalescolor(rr.rcoef, sf); |
| 588 |
|
if (ray_pqueue(&rr) == 1) { |
| 589 |
< |
multcolor(rr.rcol, rr.rcoef); |
| 590 |
< |
addcolor(vsum, rr.rcol); |
| 589 |
> |
smultscolor(rr.rcol, rr.rcoef); |
| 590 |
> |
saddscolor(vsum, rr.rcol); |
| 591 |
|
} |
| 592 |
|
} |
| 593 |
|
} |
| 594 |
< |
/* finish our calculation */ |
| 595 |
< |
while (ray_presult(&rr, 0) > 0) { |
| 596 |
< |
multcolor(rr.rcol, rr.rcoef); |
| 594 |
< |
addcolor(vsum, rr.rcol); |
| 594 |
> |
while (ray_presult(&rr, 0) > 0) { /* finish our calculation */ |
| 595 |
> |
smultscolor(rr.rcol, rr.rcoef); |
| 596 |
> |
saddscolor(vsum, rr.rcol); |
| 597 |
|
} |
| 598 |
< |
/* print our result */ |
| 599 |
< |
printf("%.4e %.4e %.4e\n", colval(vsum,RED), |
| 600 |
< |
colval(vsum,GRN), colval(vsum,BLU)); |
| 598 |
> |
for (i = 0; i < NCSAMP; i++) /* print our result */ |
| 599 |
> |
printf(" %.4e", vsum[i]); |
| 600 |
> |
fputc('\n', stdout); |
| 601 |
|
} |