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 |
|
|
20 |
|
#define MAXNT 181 /* maximum number of theta divisions */ |
21 |
|
#define MAXNP 360 /* maximum number of phi divisions */ |
22 |
|
|
21 |
– |
extern char *progname; /* global argv[0] */ |
23 |
|
extern int nowarn; /* don't report warnings? */ |
24 |
|
|
25 |
|
/* current sensor's perspective */ |
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 |
|
|
92 |
|
int doheader = 1; |
93 |
|
int optwarn = 0; |
94 |
|
int i, rval; |
95 |
< |
|
96 |
< |
progname = argv[0]; |
95 |
> |
/* set global progname */ |
96 |
> |
fixargv0(argv[0]); |
97 |
|
/* set up rendering defaults */ |
98 |
|
rand_samp = 1; |
99 |
|
dstrsrc = 0.65; |
101 |
|
directrelay = 3; |
102 |
|
ambounce = 1; |
103 |
|
maxdepth = -10; |
104 |
+ |
/* initialize calcomp routines */ |
105 |
+ |
initfunc(); |
106 |
|
/* get options from command line */ |
107 |
|
for (i = 1; i < argc; i++) { |
108 |
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
132 |
|
if (argv[i][1] == 'r') { /* sampling options */ |
133 |
|
if (argv[i][2] == 'd') |
134 |
|
nsamps = atol(argv[++i]); |
132 |
– |
else if (argv[i][2] == 's') |
133 |
– |
nssamps = atol(argv[++i]); |
135 |
|
else { |
136 |
|
sprintf(errmsg, "bad option at '%s'", argv[i]); |
137 |
|
error(USER, errmsg); |
210 |
|
{ |
211 |
|
int warnedneg; |
212 |
|
char linebuf[8192]; |
213 |
+ |
int last_pos_val = 0; |
214 |
|
int nelem = 1000; |
215 |
|
float *sarr = (float *)malloc(sizeof(float)*nelem); |
216 |
|
FILE *fp; |
238 |
|
cp = fskip(cp); |
239 |
|
if (cp == NULL) |
240 |
|
break; |
241 |
< |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]) { |
241 |
> |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]+FTINY) { |
242 |
|
sprintf(errmsg, |
243 |
|
"Phi values not monotinically increasing in sensor file '%s'", |
244 |
|
sfile); |
264 |
|
cp = fskip(cp); |
265 |
|
if (cp == NULL) |
266 |
|
break; |
267 |
< |
if (i && sarr[i] < .0) { |
267 |
> |
if (sarr[i] < .0) { |
268 |
|
if (!warnedneg++) { |
269 |
|
sprintf(errmsg, |
270 |
|
"Negative value(s) in sensor file '%s' (ignored)\n", sfile); |
271 |
|
error(WARNING, errmsg); |
272 |
|
} |
273 |
|
sarr[i] = .0; |
274 |
< |
} |
274 |
> |
} else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1)) |
275 |
> |
last_pos_val = i; |
276 |
|
++i; |
277 |
|
} |
278 |
< |
if (i == ntp[0]*(ntp[1]+1)) |
278 |
> |
if (i == ntp[0]*(ntp[1]+1)) /* empty line? */ |
279 |
|
break; |
280 |
|
if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <= |
281 |
|
sarr[(ntp[0]-1)*(ntp[1]+1)]) { |
291 |
|
error(USER, errmsg); |
292 |
|
} |
293 |
|
} |
294 |
< |
nelem = i; |
294 |
> |
/* truncate zero region */ |
295 |
> |
ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; |
296 |
> |
nelem = (ntp[0]+1)*(ntp[1]+1); |
297 |
|
fclose(fp); |
298 |
|
errmsg[0] = '\0'; /* sanity checks */ |
299 |
< |
if (ntp[0] <= 0) |
300 |
< |
sprintf(errmsg, "no data in sensor file '%s'", sfile); |
299 |
> |
if (!last_pos_val) |
300 |
> |
sprintf(errmsg, "no positive sensor values in file '%s'", sfile); |
301 |
|
else if (fabs(sarr[ntp[1]+1]) > FTINY) |
302 |
|
sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'", |
303 |
|
sfile); |
304 |
|
else if (fabs(sarr[1]) > FTINY) |
305 |
|
sprintf(errmsg, "minimum phi must be 0 in sensor file '%s'", |
306 |
|
sfile); |
307 |
< |
else if (sarr[ntp[1]] <= FTINY) |
307 |
> |
else if (sarr[ntp[1]] < 270.-FTINY) |
308 |
|
sprintf(errmsg, |
309 |
< |
"maximum phi must be positive in sensor file '%s'", |
309 |
> |
"maximum phi must be 270 or greater in sensor file '%s'", |
310 |
|
sfile); |
311 |
< |
else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY) |
311 |
> |
else if (sarr[ntp[1]] >= 360.-FTINY) |
312 |
|
sprintf(errmsg, |
313 |
< |
"maximum theta must be positive in sensor file '%s'", |
313 |
> |
"maximum phi must be less than 360 in sensor file '%s'", |
314 |
|
sfile); |
315 |
|
if (errmsg[0]) |
316 |
|
error(USER, errmsg); |
323 |
|
char *sfile |
324 |
|
) |
325 |
|
{ |
326 |
< |
int samptot = nsamps; |
326 |
> |
long samptot = nsamps; |
327 |
|
float *rowp, *rowp1; |
328 |
|
double rowsum[MAXNT], rowomega[MAXNT]; |
329 |
|
double thdiv[MAXNT+1], phdiv[MAXNP+1]; |
371 |
|
psize = PI*tsize/maxtheta; |
372 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
373 |
|
samptot = sntp[0]*sntp[1]; |
374 |
< |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
374 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1; |
375 |
|
if (ntheta > MAXNT) |
376 |
|
ntheta = MAXNT; |
377 |
|
nphi = samptot/ntheta; |
523 |
|
ndsamps > 0 ? 1 : 0; |
524 |
|
char *err; |
525 |
|
int nt, np; |
526 |
< |
COLOR vsum; |
526 |
> |
SCOLOR vsum; |
527 |
|
RAY rr; |
528 |
|
double sf; |
529 |
|
int i, j; |
537 |
|
/* assign probability table */ |
538 |
|
init_ptable(sfile); |
539 |
|
/* stratified MC sampling */ |
540 |
< |
setcolor(vsum, .0f, .0f, .0f); |
540 |
> |
scolorblack(vsum); |
541 |
|
nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); |
542 |
|
np = nsamps/nt; |
543 |
|
sf = gscale/nsamps; |
553 |
|
} |
554 |
|
rr.rmax = .0; |
555 |
|
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
556 |
< |
scalecolor(rr.rcoef, sf); |
556 |
> |
scalescolor(rr.rcoef, sf); |
557 |
|
if (ray_pqueue(&rr) == 1) |
558 |
< |
addcolor(vsum, rr.rcol); |
558 |
> |
saddscolor(vsum, rr.rcol); |
559 |
|
} |
560 |
|
/* remaining rays pure MC */ |
561 |
|
for (i = nsamps - nt*np; i-- > 0; ) { |
569 |
|
} |
570 |
|
rr.rmax = .0; |
571 |
|
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
572 |
< |
scalecolor(rr.rcoef, sf); |
572 |
> |
scalescolor(rr.rcoef, sf); |
573 |
|
if (ray_pqueue(&rr) == 1) |
574 |
< |
addcolor(vsum, rr.rcol); |
574 |
> |
saddscolor(vsum, rr.rcol); |
575 |
|
} |
576 |
|
if (!ray_pnprocs) /* just printing rays */ |
577 |
|
return; |
578 |
|
/* scale partial result */ |
579 |
< |
scalecolor(vsum, sf); |
579 |
> |
scalescolor(vsum, sf); |
580 |
|
/* add direct component */ |
581 |
|
for (i = ndirs; i-- > 0; ) { |
582 |
|
SRCINDEX si; |
586 |
|
if (sf <= FTINY) |
587 |
|
continue; |
588 |
|
sf *= si.dom/ndirs; |
589 |
< |
scalecolor(rr.rcoef, sf); |
589 |
> |
scalescolor(rr.rcoef, sf); |
590 |
|
if (ray_pqueue(&rr) == 1) { |
591 |
< |
multcolor(rr.rcol, rr.rcoef); |
592 |
< |
addcolor(vsum, rr.rcol); |
591 |
> |
smultscolor(rr.rcol, rr.rcoef); |
592 |
> |
saddscolor(vsum, rr.rcol); |
593 |
|
} |
594 |
|
} |
595 |
|
} |
596 |
< |
/* finish our calculation */ |
597 |
< |
while (ray_presult(&rr, 0) > 0) { |
598 |
< |
multcolor(rr.rcol, rr.rcoef); |
594 |
< |
addcolor(vsum, rr.rcol); |
596 |
> |
while (ray_presult(&rr, 0) > 0) { /* finish our calculation */ |
597 |
> |
smultscolor(rr.rcol, rr.rcoef); |
598 |
> |
saddscolor(vsum, rr.rcol); |
599 |
|
} |
600 |
< |
/* print our result */ |
601 |
< |
printf("%.4e %.4e %.4e\n", colval(vsum,RED), |
602 |
< |
colval(vsum,GRN), colval(vsum,BLU)); |
600 |
> |
for (i = 0; i < NCSAMP; i++) /* print our result */ |
601 |
> |
printf(" %.4e", vsum[i]); |
602 |
> |
fputc('\n', stdout); |
603 |
|
} |