26 |
|
|
27 |
|
unsigned long nsamps = 10000; /* desired number of initial samples */ |
28 |
|
unsigned long nssamps = 9000; /* number of super-samples */ |
29 |
< |
int ndsamps = 16; /* number of direct samples */ |
29 |
> |
int ndsamps = 32; /* number of direct samples */ |
30 |
|
int nprocs = 1; /* number of rendering processes */ |
31 |
|
|
32 |
|
float *sensor = NULL; /* current sensor data */ |
38 |
|
int nphi = 0; /* azimuthal angle divisions */ |
39 |
|
double gscale = 1.; /* global scaling value */ |
40 |
|
|
41 |
+ |
#define s_theta(t) sensor[(t+1)*(sntp[1]+1)] |
42 |
+ |
#define s_phi(p) sensor[(p)+1] |
43 |
+ |
#define s_val(t,p) sensor[(p)+1+(t+1)*(sntp[1]+1)] |
44 |
+ |
|
45 |
|
static void comp_sensor(char *sfile); |
46 |
|
|
47 |
|
static void |
48 |
< |
print_defaults() |
48 |
> |
over_options() /* overriding options */ |
49 |
|
{ |
50 |
+ |
directvis = (ndsamps <= 0); |
51 |
+ |
do_irrad = 0; |
52 |
+ |
} |
53 |
+ |
|
54 |
+ |
static void |
55 |
+ |
print_defaults() /* print out default parameters */ |
56 |
+ |
{ |
57 |
+ |
over_options(); |
58 |
|
printf("-n %-9d\t\t\t# number of processes\n", nprocs); |
59 |
|
printf("-rd %-9ld\t\t\t# ray directions\n", nsamps); |
60 |
|
/* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */ |
76 |
|
) |
77 |
|
{ |
78 |
|
int doheader = 1; |
79 |
+ |
int optwarn = 0; |
80 |
|
int i, rval; |
81 |
|
|
82 |
|
progname = argv[0]; |
83 |
|
/* set up rendering defaults */ |
84 |
< |
dstrsrc = 0.25; |
84 |
> |
rand_samp = 1; |
85 |
> |
dstrsrc = 0.5; |
86 |
> |
srcsizerat = 0.1; |
87 |
|
directrelay = 3; |
88 |
|
ambounce = 1; |
89 |
< |
/* just asking defaults? */ |
75 |
< |
if (argc == 2 && !strcmp(argv[1], "-defaults")) { |
76 |
< |
print_defaults(); |
77 |
< |
return(0); |
78 |
< |
} |
79 |
< |
/* check octree */ |
80 |
< |
if (argc < 2 || argv[argc-1][0] == '-') |
81 |
< |
error(USER, "missing octree argument"); |
89 |
> |
maxdepth = -10; |
90 |
|
/* get options from command line */ |
91 |
< |
for (i = 1; i < argc-1; i++) { |
91 |
> |
for (i = 1; i < argc; i++) { |
92 |
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
93 |
|
; |
94 |
|
if (rval < 0) { |
95 |
|
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
96 |
|
error(SYSTEM, errmsg); |
97 |
|
} |
98 |
< |
if (argv[i][0] != '-') { /* process a sensor file */ |
98 |
> |
if (argv[i][0] != '-') { |
99 |
> |
if (i >= argc-1) |
100 |
> |
break; /* final octree argument */ |
101 |
|
if (!ray_pnprocs) { |
102 |
< |
/* overriding options */ |
93 |
< |
directvis = (ndsamps <= 0); |
94 |
< |
do_irrad = 0; |
102 |
> |
over_options(); |
103 |
|
if (doheader) { /* print header */ |
104 |
|
printargs(argc, argv, stdout); |
105 |
|
fputformat("ascii", stdout); |
108 |
|
/* start process(es) */ |
109 |
|
ray_pinit(argv[argc-1], nprocs); |
110 |
|
} |
111 |
< |
comp_sensor(argv[i]); |
111 |
> |
comp_sensor(argv[i]); /* process a sensor file */ |
112 |
|
continue; |
113 |
|
} |
114 |
|
if (argv[i][1] == 'r') { /* sampling options */ |
151 |
|
sprintf(errmsg, "bad view option at '%s'", argv[i]); |
152 |
|
error(USER, errmsg); |
153 |
|
} |
154 |
< |
if (!strcmp(argv[i], "-w")) { /* turn off warnings */ |
155 |
< |
nowarn = 1; |
154 |
> |
if (!strcmp(argv[i], "-w")) { /* toggle warnings */ |
155 |
> |
nowarn = !nowarn; |
156 |
|
continue; |
157 |
|
} |
158 |
|
if (ray_pnprocs) { |
159 |
< |
error(WARNING, |
159 |
> |
if (!optwarn++) |
160 |
> |
error(WARNING, |
161 |
|
"rendering options should appear before first sensor"); |
162 |
|
} else if (!strcmp(argv[i], "-defaults")) { |
163 |
|
print_defaults(); |
180 |
|
} |
181 |
|
i += rval; |
182 |
|
} |
183 |
+ |
if (!ray_pnprocs) |
184 |
+ |
error(USER, i<argc ? "missing sensor file" : "missing octree"); |
185 |
|
quit(0); |
186 |
|
} |
187 |
|
|
293 |
|
if (pvals != NULL) |
294 |
|
free((void *)pvals); |
295 |
|
if (sfile == NULL || !*sfile) { |
296 |
+ |
sensor = NULL; |
297 |
+ |
sntp[0] = sntp[1] = 0; |
298 |
|
pvals = NULL; |
299 |
|
ntheta = nphi = 0; |
300 |
|
return; |
312 |
|
error(INTERNAL, errmsg); |
313 |
|
} |
314 |
|
/* compute boundary angles */ |
315 |
< |
maxtheta = 1.5f*sensor[sntp[0]*(sntp[1]+1)] - |
303 |
< |
0.5f*sensor[sntp[0]*sntp[1]]; |
315 |
> |
maxtheta = 1.5f*s_theta(sntp[0]-1) - 0.5f*s_theta(sntp[0]-2); |
316 |
|
thdiv[0] = .0; |
317 |
|
for (t = 1; t < sntp[0]; t++) |
318 |
< |
thdiv[t] = DEGREE/2.*(sensor[t*(sntp[1]+1)] + |
307 |
< |
sensor[(t+1)*(sntp[1]+1)]); |
318 |
> |
thdiv[t] = DEGREE/2.*(s_theta(t-1) + s_theta(t)); |
319 |
|
thdiv[sntp[0]] = maxtheta*DEGREE; |
320 |
|
phdiv[0] = .0; |
321 |
|
for (p = 1; p < sntp[1]; p++) |
322 |
< |
phdiv[p] = DEGREE/2.*(sensor[p] + sensor[p+1]); |
322 |
> |
phdiv[p] = DEGREE/2.*(s_phi(p-1) + s_phi(p)); |
323 |
|
phdiv[sntp[1]] = 2.*PI; |
324 |
|
/* size our table */ |
325 |
|
tsize = 1. - cos(maxtheta*DEGREE); |
326 |
< |
psize = PI*tsize/maxtheta; |
326 |
> |
psize = PI*tsize/(maxtheta*DEGREE); |
327 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
328 |
|
samptot = sntp[0]*sntp[1]; |
329 |
< |
ntheta = (int)(sqrt(samptot*tsize/psize) + 0.5); |
329 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
330 |
|
if (ntheta > MAXNT) |
331 |
|
ntheta = MAXNT; |
332 |
|
nphi = samptot/ntheta; |
335 |
|
error(SYSTEM, "out of memory in init_ptable()"); |
336 |
|
gscale = .0; /* compute our inverse table */ |
337 |
|
for (i = 0; i < sntp[0]; i++) { |
338 |
< |
rowp = sensor + (i+1)*(sntp[1]+1) + 1; |
338 |
> |
rowp = &s_val(i,0); |
339 |
|
rowsum[i] = 0.; |
340 |
|
for (j = 0; j < sntp[1]; j++) |
341 |
|
rowsum[i] += *rowp++; |
343 |
|
rowomega[i] *= 2.*PI / (double)sntp[1]; |
344 |
|
gscale += rowsum[i] * rowomega[i]; |
345 |
|
} |
346 |
< |
tvals[0] = .0f; |
336 |
< |
for (i = 1; i < ntheta; i++) { |
346 |
> |
for (i = 0; i < ntheta; i++) { |
347 |
|
prob = (double)i / (double)ntheta; |
348 |
|
for (t = 0; t < sntp[0]; t++) |
349 |
|
if ((prob -= rowsum[t]*rowomega[t]/gscale) <= .0) |
353 |
|
frac = 1. + prob/(rowsum[t]*rowomega[t]/gscale); |
354 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
355 |
|
frac*cos(thdiv[t+1]) ); |
356 |
+ |
/* offset b/c sensor values are centered */ |
357 |
+ |
if (t <= 0 || frac > 0.5) |
358 |
+ |
frac -= 0.5; |
359 |
+ |
else if (t >= sntp[0]-1 || frac < 0.5) { |
360 |
+ |
frac += 0.5; |
361 |
+ |
--t; |
362 |
+ |
} |
363 |
|
pvals[i*(nphi+1)] = .0f; |
364 |
|
for (j = 1; j < nphi; j++) { |
365 |
|
prob = (double)j / (double)nphi; |
366 |
< |
rowp = sensor + t*(sntp[1]+1) + 1; |
367 |
< |
rowp1 = rowp + sntp[1]+1; |
366 |
> |
rowp = &s_val(t,0); |
367 |
> |
rowp1 = &s_val(t+1,0); |
368 |
|
for (p = 0; p < sntp[1]; p++) { |
369 |
< |
if ((prob -= (1.-frac)*rowp[p]/rowsum[t-1] + |
370 |
< |
frac*rowp1[p]/rowsum[t]) <= .0) |
369 |
> |
if ((prob -= (1.-frac)*rowp[p]/rowsum[t] + |
370 |
> |
frac*rowp1[p]/rowsum[t+1]) <= .0) |
371 |
|
break; |
372 |
|
if (p >= sntp[1]) |
373 |
|
error(INTERNAL, |
374 |
|
"code error 2 in init_ptable()"); |
375 |
< |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t-1] |
376 |
< |
+ frac*rowp1[p]/rowsum[t]); |
375 |
> |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t] |
376 |
> |
+ frac*rowp1[p]/rowsum[t+1]); |
377 |
|
pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] + |
378 |
|
frac1*phdiv[p+1]; |
379 |
|
} |
380 |
|
} |
381 |
|
pvals[i*(nphi+1) + nphi] = (float)(2.*PI); |
382 |
|
} |
383 |
+ |
tvals[0] = .0f; |
384 |
|
tvals[ntheta] = (float)tsize; |
385 |
|
} |
386 |
|
|
436 |
|
t = (int)(theta/maxtheta * sntp[0]); |
437 |
|
p = (int)(phi*(1./360.) * sntp[1]); |
438 |
|
/* hack for non-uniform sensor grid */ |
439 |
< |
while (t+1 < sntp[0] && theta >= sensor[(t+2)*(sntp[1]+1)]) |
439 |
> |
while (t+1 < sntp[0] && theta >= s_theta(t+1)) |
440 |
|
++t; |
441 |
< |
while (t-1 >= 0 && theta < sensor[t*(sntp[1]+1)]) |
441 |
> |
while (t-1 >= 0 && theta <= s_theta(t-1)) |
442 |
|
--t; |
443 |
< |
while (p+1 < sntp[1] && phi >= sensor[p+2]) |
443 |
> |
while (p+1 < sntp[1] && phi >= s_phi(p+1)) |
444 |
|
++p; |
445 |
< |
while (p-1 >= 0 && phi < sensor[p]) |
445 |
> |
while (p-1 >= 0 && phi <= s_phi(p-1)) |
446 |
|
--p; |
447 |
< |
return(sensor[t*(sntp[1]+1) + p + 1]); |
447 |
> |
return(s_val(t,p)); |
448 |
|
} |
449 |
|
|
450 |
|
/* Compute sensor output */ |
476 |
|
VCOPY(rr.rorg, ourview.vp); |
477 |
|
rr.rmax = .0; |
478 |
|
for (i = 0; i < nt; i++) |
479 |
< |
for (j =0; j < np; j++) { |
480 |
< |
get_direc(rr.rdir, (i+frandom())/nt, |
463 |
< |
(j + frandom())/np); |
479 |
> |
for (j = 0; j < np; j++) { |
480 |
> |
get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np); |
481 |
|
rayorigin(&rr, PRIMARY, NULL, NULL); |
482 |
|
if (ray_pqueue(&rr) == 1) |
483 |
|
addcolor(vsum, rr.rcol); |