9 |
|
*/ |
10 |
|
|
11 |
|
#include "ray.h" |
12 |
+ |
#include "platform.h" |
13 |
|
#include "source.h" |
14 |
|
#include "view.h" |
15 |
|
#include "random.h" |
16 |
|
|
17 |
|
#define DEGREE (PI/180.) |
18 |
|
|
19 |
< |
#define MAXNT 180 /* maximum number of theta divisions */ |
19 |
> |
#define MAXNT 181 /* maximum number of theta divisions */ |
20 |
|
#define MAXNP 360 /* maximum number of phi divisions */ |
21 |
|
|
22 |
|
extern char *progname; /* global argv[0] */ |
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); |
208 |
|
{ |
209 |
|
int warnedneg; |
210 |
|
char linebuf[8192]; |
211 |
+ |
int last_pos_val = 0; |
212 |
|
int nelem = 1000; |
213 |
|
float *sarr = (float *)malloc(sizeof(float)*nelem); |
214 |
|
FILE *fp; |
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); |
262 |
|
cp = fskip(cp); |
263 |
|
if (cp == NULL) |
264 |
|
break; |
265 |
< |
if (i && sarr[i] < .0) { |
265 |
> |
if (sarr[i] < .0) { |
266 |
|
if (!warnedneg++) { |
267 |
|
sprintf(errmsg, |
268 |
|
"Negative value(s) in sensor file '%s' (ignored)\n", sfile); |
269 |
|
error(WARNING, errmsg); |
270 |
|
} |
271 |
|
sarr[i] = .0; |
272 |
< |
} |
272 |
> |
} else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1)) |
273 |
> |
last_pos_val = i; |
274 |
|
++i; |
275 |
|
} |
276 |
< |
if (i == ntp[0]*(ntp[1]+1)) |
276 |
> |
if (i == ntp[0]*(ntp[1]+1)) /* empty line? */ |
277 |
|
break; |
278 |
|
if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <= |
279 |
|
sarr[(ntp[0]-1)*(ntp[1]+1)]) { |
289 |
|
error(USER, errmsg); |
290 |
|
} |
291 |
|
} |
292 |
< |
nelem = i; |
292 |
> |
/* truncate zero region */ |
293 |
> |
ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; |
294 |
> |
nelem = (ntp[0]+1)*(ntp[1]+1); |
295 |
|
fclose(fp); |
296 |
|
errmsg[0] = '\0'; /* sanity checks */ |
297 |
< |
if (ntp[0] <= 0) |
298 |
< |
sprintf(errmsg, "no data in sensor file '%s'", sfile); |
297 |
> |
if (!last_pos_val) |
298 |
> |
sprintf(errmsg, "no positive sensor values in file '%s'", sfile); |
299 |
|
else if (fabs(sarr[ntp[1]+1]) > FTINY) |
300 |
|
sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'", |
301 |
|
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[0]*(ntp[1]+1)] <= FTINY) |
309 |
> |
else if (sarr[ntp[1]] >= 360.-FTINY) |
310 |
|
sprintf(errmsg, |
311 |
< |
"maximum theta must be positive in sensor file '%s'", |
311 |
> |
"maximum phi must be less than 360 in sensor file '%s'", |
312 |
|
sfile); |
313 |
|
if (errmsg[0]) |
314 |
|
error(USER, errmsg); |
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]; |
369 |
|
psize = PI*tsize/maxtheta; |
370 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
371 |
|
samptot = sntp[0]*sntp[1]; |
372 |
< |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
372 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1; |
373 |
|
if (ntheta > MAXNT) |
374 |
|
ntheta = MAXNT; |
375 |
|
nphi = samptot/ntheta; |
401 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
402 |
|
frac*cos(thdiv[t+1]) ); |
403 |
|
/* offset b/c sensor values are centered */ |
404 |
< |
if (!t || (t < sntp[0]-1) & (frac >= 0.5)) |
404 |
> |
if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { |
405 |
|
frac -= 0.5; |
406 |
< |
else { |
406 |
> |
} else { |
407 |
|
frac += 0.5; |
408 |
|
--t; |
409 |
|
} |
427 |
|
} |
428 |
|
pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; |
429 |
|
} |
430 |
+ |
/* duplicate final row */ |
431 |
+ |
memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), |
432 |
+ |
sizeof(*pvals)*(nphi+1)); |
433 |
|
tvals[0] = .0f; |
434 |
|
tvals[ntheta] = (float)tsize; |
435 |
|
} |
521 |
|
ndsamps > 0 ? 1 : 0; |
522 |
|
char *err; |
523 |
|
int nt, np; |
524 |
< |
COLOR vsum; |
524 |
> |
SCOLOR vsum; |
525 |
> |
COLOR cres; |
526 |
|
RAY rr; |
527 |
|
double sf; |
528 |
|
int i, j; |
536 |
|
/* assign probability table */ |
537 |
|
init_ptable(sfile); |
538 |
|
/* stratified MC sampling */ |
539 |
< |
setcolor(vsum, .0f, .0f, .0f); |
539 |
> |
scolorblack(vsum); |
540 |
|
nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); |
541 |
|
np = nsamps/nt; |
542 |
|
sf = gscale/nsamps; |
551 |
|
continue; |
552 |
|
} |
553 |
|
rr.rmax = .0; |
554 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
555 |
< |
scalecolor(rr.rcoef, sf); |
554 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
555 |
> |
scalescolor(rr.rcoef, sf); |
556 |
|
if (ray_pqueue(&rr) == 1) |
557 |
< |
addcolor(vsum, rr.rcol); |
557 |
> |
saddscolor(vsum, rr.rcol); |
558 |
|
} |
559 |
|
/* remaining rays pure MC */ |
560 |
|
for (i = nsamps - nt*np; i-- > 0; ) { |
567 |
|
continue; |
568 |
|
} |
569 |
|
rr.rmax = .0; |
570 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
571 |
< |
scalecolor(rr.rcoef, sf); |
570 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
571 |
> |
scalescolor(rr.rcoef, sf); |
572 |
|
if (ray_pqueue(&rr) == 1) |
573 |
< |
addcolor(vsum, rr.rcol); |
573 |
> |
saddscolor(vsum, rr.rcol); |
574 |
|
} |
575 |
|
if (!ray_pnprocs) /* just printing rays */ |
576 |
|
return; |
577 |
|
/* scale partial result */ |
578 |
< |
scalecolor(vsum, sf); |
578 |
> |
scalescolor(vsum, sf); |
579 |
|
/* add direct component */ |
580 |
|
for (i = ndirs; i-- > 0; ) { |
581 |
|
SRCINDEX si; |
585 |
|
if (sf <= FTINY) |
586 |
|
continue; |
587 |
|
sf *= si.dom/ndirs; |
588 |
< |
scalecolor(rr.rcoef, sf); |
588 |
> |
scalescolor(rr.rcoef, sf); |
589 |
|
if (ray_pqueue(&rr) == 1) { |
590 |
< |
multcolor(rr.rcol, rr.rcoef); |
591 |
< |
addcolor(vsum, rr.rcol); |
590 |
> |
smultscolor(rr.rcol, rr.rcoef); |
591 |
> |
saddscolor(vsum, rr.rcol); |
592 |
|
} |
593 |
|
} |
594 |
|
} |
595 |
|
/* finish our calculation */ |
596 |
|
while (ray_presult(&rr, 0) > 0) { |
597 |
< |
multcolor(rr.rcol, rr.rcoef); |
598 |
< |
addcolor(vsum, rr.rcol); |
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)); |
601 |
> |
scolor_rgb(cres, vsum); |
602 |
> |
printf("%.4e %.4e %.4e\n", colval(cres,RED), |
603 |
> |
colval(cres,GRN), colval(cres,BLU)); |
604 |
|
} |