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