11 |
|
#include <stdio.h> |
12 |
|
#include <stdlib.h> |
13 |
|
#include <math.h> |
14 |
+ |
#include "random.h" |
15 |
|
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" |
17 |
|
#include "calcomp.h" |
18 |
|
#include "bsdfrep.h" |
19 |
|
/* global argv[0] */ |
26 |
|
const double ssamp_thresh = 0.35; |
27 |
|
/* number of super-samples */ |
28 |
|
const int nssamp = 100; |
29 |
+ |
/* limit on number of RBF lobes */ |
30 |
+ |
static int lobe_lim = 15000; |
31 |
|
|
32 |
|
/* Output XML prologue to stdout */ |
33 |
|
static void |
46 |
|
puts("<Optical>"); |
47 |
|
puts("<Layer>"); |
48 |
|
puts("\t<Material>"); |
49 |
< |
puts("\t\t<Name>Name</Name>"); |
50 |
< |
puts("\t\t<Manufacturer>Manufacturer</Manufacturer>"); |
49 |
> |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
50 |
> |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
51 |
> |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
52 |
|
puts("\t\t<DeviceType>Other</DeviceType>"); |
53 |
|
puts("\t</Material>"); |
54 |
|
puts("\t<DataDefinition>"); |
117 |
|
{ |
118 |
|
const int sqres = 1<<samp_order; |
119 |
|
FILE *ofp = NULL; |
120 |
+ |
int assignD = 0; |
121 |
|
char cmd[128]; |
122 |
|
int ix, ox, oy; |
123 |
|
double iovec[6]; |
125 |
|
|
126 |
|
data_prologue(); /* begin output */ |
127 |
|
if (pctcull >= 0) { |
128 |
< |
sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", |
128 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d", |
129 |
|
pctcull, samp_order); |
130 |
|
fflush(stdout); |
131 |
|
ofp = popen(cmd, "w"); |
137 |
|
SET_FILE_BINARY(ofp); |
138 |
|
} else |
139 |
|
fputs("{\n", stdout); |
140 |
+ |
/* need to assign Dx, Dy, Dz? */ |
141 |
+ |
if (funame != NULL) |
142 |
+ |
assignD = (fundefined(funame) < 6); |
143 |
|
/* run through directions */ |
144 |
|
for (ix = 0; ix < sqres/2; ix++) { |
145 |
|
RBFNODE *rbf = NULL; |
147 |
|
iovec[1] = .0; |
148 |
|
iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]); |
149 |
|
if (funame == NULL) |
150 |
< |
rbf = advect_rbf(iovec); |
150 |
> |
rbf = advect_rbf(iovec, lobe_lim); |
151 |
|
for (ox = 0; ox < sqres; ox++) { |
152 |
|
float last_bsdf = -1; |
153 |
|
for (oy = 0; oy < sqres; oy++) { |
160 |
|
else { |
161 |
|
double ssa[3], ssvec[6], sum; |
162 |
|
int ssi; |
163 |
+ |
if (assignD) { |
164 |
+ |
varset("Dx", '=', -iovec[3]); |
165 |
+ |
varset("Dy", '=', -iovec[4]); |
166 |
+ |
varset("Dz", '=', -iovec[5]); |
167 |
+ |
++eclock; |
168 |
+ |
} |
169 |
|
bsdf = funvalue(funame, 6, iovec); |
170 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
171 |
|
sum = 0; /* super-sample voxel */ |
172 |
|
for (ssi = nssamp; ssi--; ) { |
173 |
< |
SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); |
173 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
174 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
175 |
|
ssvec[1] = .0; |
176 |
|
ssvec[2] = input_orient * |
180 |
|
ssvec[5] = output_orient * |
181 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
182 |
|
ssvec[4]*ssvec[4]); |
183 |
+ |
if (assignD) { |
184 |
+ |
varset("Dx", '=', -iovec[3]); |
185 |
+ |
varset("Dy", '=', -iovec[4]); |
186 |
+ |
varset("Dz", '=', -iovec[5]); |
187 |
+ |
++eclock; |
188 |
+ |
} |
189 |
|
sum += funvalue(funame, 6, ssvec); |
190 |
|
} |
191 |
|
bsdf = sum/nssamp; |
221 |
|
{ |
222 |
|
const int sqres = 1<<samp_order; |
223 |
|
FILE *ofp = NULL; |
224 |
+ |
int assignD = 0; |
225 |
|
char cmd[128]; |
226 |
|
int ix, iy, ox, oy; |
227 |
|
double iovec[6]; |
229 |
|
|
230 |
|
data_prologue(); /* begin output */ |
231 |
|
if (pctcull >= 0) { |
232 |
< |
sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", |
232 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d", |
233 |
> |
(input_orient>0 ^ output_orient>0) ? "" : " -a", |
234 |
|
pctcull, samp_order); |
235 |
|
fflush(stdout); |
236 |
|
ofp = popen(cmd, "w"); |
241 |
|
} |
242 |
|
} else |
243 |
|
fputs("{\n", stdout); |
244 |
+ |
/* need to assign Dx, Dy, Dz? */ |
245 |
+ |
if (funame != NULL) |
246 |
+ |
assignD = (fundefined(funame) < 6); |
247 |
|
/* run through directions */ |
248 |
|
for (ix = 0; ix < sqres; ix++) |
249 |
|
for (iy = 0; iy < sqres; iy++) { |
252 |
|
iovec[2] = input_orient * |
253 |
|
sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); |
254 |
|
if (funame == NULL) |
255 |
< |
rbf = advect_rbf(iovec); |
255 |
> |
rbf = advect_rbf(iovec, lobe_lim); |
256 |
|
for (ox = 0; ox < sqres; ox++) { |
257 |
|
float last_bsdf = -1; |
258 |
|
for (oy = 0; oy < sqres; oy++) { |
265 |
|
else { |
266 |
|
double ssa[4], ssvec[6], sum; |
267 |
|
int ssi; |
268 |
+ |
if (assignD) { |
269 |
+ |
varset("Dx", '=', -iovec[3]); |
270 |
+ |
varset("Dy", '=', -iovec[4]); |
271 |
+ |
varset("Dz", '=', -iovec[5]); |
272 |
+ |
++eclock; |
273 |
+ |
} |
274 |
|
bsdf = funvalue(funame, 6, iovec); |
275 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
276 |
|
sum = 0; /* super-sample voxel */ |
277 |
|
for (ssi = nssamp; ssi--; ) { |
278 |
< |
SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); |
278 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
279 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
280 |
|
1.-(iy+ssa[1])/sqres); |
281 |
|
ssvec[2] = output_orient * |
286 |
|
ssvec[5] = output_orient * |
287 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
288 |
|
ssvec[4]*ssvec[4]); |
289 |
+ |
if (assignD) { |
290 |
+ |
varset("Dx", '=', -iovec[3]); |
291 |
+ |
varset("Dy", '=', -iovec[4]); |
292 |
+ |
varset("Dz", '=', -iovec[5]); |
293 |
+ |
++eclock; |
294 |
+ |
} |
295 |
|
sum += funvalue(funame, 6, ssvec); |
296 |
|
} |
297 |
|
bsdf = sum/nssamp; |
362 |
|
case 'g': |
363 |
|
samp_order = atoi(argv[++i]); |
364 |
|
break; |
365 |
+ |
case 'l': |
366 |
+ |
lobe_lim = atoi(argv[++i]); |
367 |
+ |
break; |
368 |
|
default: |
369 |
|
goto userr; |
370 |
|
} |
371 |
|
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
372 |
|
void (*evf)(char *s) = single_plane_incident ? |
373 |
|
&eval_isotropic : &eval_anisotropic; |
374 |
< |
if (i != argc-1 || fundefined(argv[i]) != 6) { |
374 |
> |
if (i != argc-1 || fundefined(argv[i]) < 3) { |
375 |
|
fprintf(stderr, |
376 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
377 |
|
progname); |
378 |
+ |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", |
379 |
+ |
progname); |
380 |
|
goto userr; |
381 |
|
} |
382 |
+ |
++eclock; |
383 |
|
xml_prologue(argc, argv); /* start XML output */ |
384 |
|
if (dofwd) { |
385 |
|
input_orient = -1; |
432 |
|
return(0); |
433 |
|
userr: |
434 |
|
fprintf(stderr, |
435 |
< |
"Usage: %s [-g Nlog2][-t pctcull] [bsdf.sir ..] > bsdf.xml\n", |
435 |
> |
"Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
436 |
|
progname); |
437 |
|
fprintf(stderr, |
438 |
|
" or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |