--- ray/src/util/rsensor.c 2008/02/21 20:18:25 2.2 +++ ray/src/util/rsensor.c 2009/12/12 19:01:00 2.7 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rsensor.c,v 2.2 2008/02/21 20:18:25 greg Exp $"; +static const char RCSid[] = "$Id: rsensor.c,v 2.7 2009/12/12 19:01:00 greg Exp $"; #endif /* @@ -22,7 +22,9 @@ extern char *progname; /* global argv[0] */ extern int nowarn; /* don't report warnings? */ /* current sensor's perspective */ -VIEW ourview = STDVIEW; +VIEW ourview = {VT_ANG,{0.,0.,0.},{0.,0.,1.},{1.,0.,0.}, + 1.,180.,180.,0.,0.,0.,0., + {0.,0.,0.},{0.,0.,0.},0.,0.}; unsigned long nsamps = 10000; /* desired number of initial samples */ unsigned long nssamps = 9000; /* number of super-samples */ @@ -45,8 +47,16 @@ double gscale = 1.; /* global scaling value */ static void comp_sensor(char *sfile); static void -print_defaults() +over_options() /* overriding options */ { + directvis = (ndsamps <= 0); + do_irrad = 0; +} + +static void +print_defaults() /* print out default parameters */ +{ + over_options(); printf("-n %-9d\t\t\t# number of processes\n", nprocs); printf("-rd %-9ld\t\t\t# ray directions\n", nsamps); /* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */ @@ -61,6 +71,17 @@ print_defaults() print_rdefaults(); } + +void +quit(ec) /* make sure exit is called */ +int ec; +{ + if (ray_pnprocs > 0) /* close children if any */ + ray_pclose(0); + exit(ec); +} + + int main( int argc, @@ -68,38 +89,32 @@ main( ) { int doheader = 1; + int optwarn = 0; int i, rval; progname = argv[0]; /* set up rendering defaults */ rand_samp = 1; - dstrsrc = 0.5; + dstrsrc = 0.65; srcsizerat = 0.1; directrelay = 3; ambounce = 1; maxdepth = -10; - /* just asking defaults? */ - if (argc == 2 && !strcmp(argv[1], "-defaults")) { - print_defaults(); - return(0); - } - /* check octree */ - if (argc < 2 || argv[argc-1][0] == '-') - error(USER, "missing octree argument"); /* get options from command line */ - for (i = 1; i < argc-1; i++) { + for (i = 1; i < argc; i++) { while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { sprintf(errmsg, "cannot expand '%s'", argv[i]); error(SYSTEM, errmsg); } - if (argv[i][0] != '-') { /* process a sensor file */ + if (argv[i][0] != '-') { + if (i >= argc-1) + break; /* final octree argument */ if (!ray_pnprocs) { - /* overriding options */ - directvis = (ndsamps <= 0); - do_irrad = 0; + over_options(); if (doheader) { /* print header */ + newheader("RADIANCE", stdout); printargs(argc, argv, stdout); fputformat("ascii", stdout); putchar('\n'); @@ -107,7 +122,7 @@ main( /* start process(es) */ ray_pinit(argv[argc-1], nprocs); } - comp_sensor(argv[i]); + comp_sensor(argv[i]); /* process a sensor file */ continue; } if (argv[i][1] == 'r') { /* sampling options */ @@ -150,12 +165,13 @@ main( sprintf(errmsg, "bad view option at '%s'", argv[i]); error(USER, errmsg); } - if (!strcmp(argv[i], "-w")) { /* turn off warnings */ - nowarn = 1; + if (!strcmp(argv[i], "-w")) { /* toggle warnings */ + nowarn = !nowarn; continue; } if (ray_pnprocs) { - error(WARNING, + if (!optwarn++) + error(WARNING, "rendering options should appear before first sensor"); } else if (!strcmp(argv[i], "-defaults")) { print_defaults(); @@ -178,6 +194,8 @@ main( } i += rval; } + if (!ray_pnprocs) + error(USER, i 0.5) - frac1 -= 0.5; - else if (p >= sntp[1]-1 || frac1 < 0.5) { - frac1 += 0.5; - --p; - } pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] + frac1*phdiv[p+1]; } @@ -461,6 +473,7 @@ comp_sensor( int nt, np; COLOR vsum; RAY rr; + double sf; int i, j; /* set view */ ourview.type = VT_ANG; @@ -471,40 +484,54 @@ comp_sensor( error(USER, err); /* assign probability table */ init_ptable(sfile); - /* do Monte Carlo sampling */ + /* stratified MC sampling */ setcolor(vsum, .0f, .0f, .0f); nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); np = nsamps/nt; - VCOPY(rr.rorg, ourview.vp); - rr.rmax = .0; + sf = gscale/nsamps; for (i = 0; i < nt; i++) for (j = 0; j < np; j++) { + VCOPY(rr.rorg, ourview.vp); get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np); + if (ourview.vfore > FTINY) + VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore); + rr.rmax = .0; rayorigin(&rr, PRIMARY, NULL, NULL); + scalecolor(rr.rcoef, sf); if (ray_pqueue(&rr) == 1) addcolor(vsum, rr.rcol); } - /* finish MC calculation */ - while (ray_presult(&rr, 0) > 0) - addcolor(vsum, rr.rcol); - scalecolor(vsum, gscale/(nt*np)); - /* compute direct component */ + /* remaining rays pure MC */ + for (i = nsamps - nt*np; i-- > 0; ) { + VCOPY(rr.rorg, ourview.vp); + get_direc(rr.rdir, frandom(), frandom()); + if (ourview.vfore > FTINY) + VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore); + rr.rmax = .0; + rayorigin(&rr, PRIMARY, NULL, NULL); + scalecolor(rr.rcoef, sf); + if (ray_pqueue(&rr) == 1) + addcolor(vsum, rr.rcol); + } + /* scale partial result */ + scalecolor(vsum, sf); + /* add direct component */ for (i = ndirs; i-- > 0; ) { SRCINDEX si; initsrcindex(&si); while (srcray(&rr, NULL, &si)) { - double d = sens_val(rr.rdir); - if (d <= FTINY) + sf = sens_val(rr.rdir); + if (sf <= FTINY) continue; - d *= si.dom/ndirs; - scalecolor(rr.rcoef, d); + sf *= si.dom/ndirs; + scalecolor(rr.rcoef, sf); if (ray_pqueue(&rr) == 1) { multcolor(rr.rcol, rr.rcoef); addcolor(vsum, rr.rcol); } } } - /* finish direct calculation */ + /* finish our calculation */ while (ray_presult(&rr, 0) > 0) { multcolor(rr.rcol, rr.rcoef); addcolor(vsum, rr.rcol);