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); |
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]; |
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); |
598 |
< |
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 |
|
} |