| 20 |
|
double pctcull = 90.; |
| 21 |
|
/* sampling order */ |
| 22 |
|
int samp_order = 6; |
| 23 |
+ |
/* super-sampling threshold */ |
| 24 |
+ |
const double ssamp_thresh = 0.35; |
| 25 |
+ |
/* number of super-samples */ |
| 26 |
+ |
const int nssamp = 100; |
| 27 |
|
|
| 28 |
|
/* Output XML prologue to stdout */ |
| 29 |
|
static void |
| 94 |
|
puts("</WindowElement>"); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
+ |
/* Compute absolute relative difference */ |
| 98 |
+ |
static double |
| 99 |
+ |
abs_diff(double v1, double v0) |
| 100 |
+ |
{ |
| 101 |
+ |
if ((v0 < 0) | (v1 < 0)) |
| 102 |
+ |
return(.0); |
| 103 |
+ |
v1 = (v1-v0)*2./(v0+v1+.0001); |
| 104 |
+ |
if (v1 < 0) |
| 105 |
+ |
return(-v1); |
| 106 |
+ |
return(v1); |
| 107 |
+ |
} |
| 108 |
+ |
|
| 109 |
|
/* Interpolate and output isotropic BSDF data */ |
| 110 |
|
static void |
| 111 |
|
eval_isotropic(char *funame) |
| 116 |
|
int ix, ox, oy; |
| 117 |
|
double iovec[6]; |
| 118 |
|
float bsdf; |
| 119 |
< |
#if DEBUG |
| 104 |
< |
fprintf(stderr, "Writing isotropic order %d ", samp_order); |
| 105 |
< |
if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull); |
| 106 |
< |
else fputs("raw data\n", stderr); |
| 107 |
< |
#endif |
| 119 |
> |
|
| 120 |
|
data_prologue(); /* begin output */ |
| 121 |
|
if (pctcull >= 0) { |
| 122 |
|
sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", |
| 134 |
|
/* run through directions */ |
| 135 |
|
for (ix = 0; ix < sqres/2; ix++) { |
| 136 |
|
RBFNODE *rbf = NULL; |
| 137 |
< |
iovec[0] = (ix+.5)/sqres - 1.; |
| 137 |
> |
iovec[0] = 2.*(ix+.5)/sqres - 1.; |
| 138 |
|
iovec[1] = .0; |
| 139 |
|
iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]); |
| 140 |
|
if (funame == NULL) |
| 141 |
|
rbf = advect_rbf(iovec); |
| 142 |
< |
for (ox = 0; ox < sqres; ox++) |
| 142 |
> |
for (ox = 0; ox < sqres; ox++) { |
| 143 |
> |
float last_bsdf = -1; |
| 144 |
|
for (oy = 0; oy < sqres; oy++) { |
| 145 |
|
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
| 146 |
|
iovec[5] = output_orient * |
| 147 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 148 |
|
if (funame == NULL) |
| 149 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 149 |
> |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 150 |
|
output_orient/iovec[5]; |
| 151 |
< |
else |
| 152 |
< |
bsdf = funvalue(funame, 6, iovec); |
| 151 |
> |
else { |
| 152 |
> |
double ssa[3], ssvec[6]; |
| 153 |
> |
int ssi; |
| 154 |
> |
bsdf = funvalue(funame, 6, iovec); |
| 155 |
> |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 156 |
> |
bsdf = 0; /* super-sample voxel */ |
| 157 |
> |
for (ssi = nssamp; ssi--; ) { |
| 158 |
> |
SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); |
| 159 |
> |
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
| 160 |
> |
ssvec[1] = .0; |
| 161 |
> |
ssvec[2] = input_orient * |
| 162 |
> |
sqrt(1. - ssvec[0]*ssvec[0]); |
| 163 |
> |
SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres, |
| 164 |
> |
(oy+ssa[2])/sqres); |
| 165 |
> |
ssvec[5] = output_orient * |
| 166 |
> |
sqrt(1. - ssvec[3]*ssvec[3] - |
| 167 |
> |
ssvec[4]*ssvec[4]); |
| 168 |
> |
bsdf += funvalue(funame, 6, ssvec); |
| 169 |
> |
} |
| 170 |
> |
bsdf /= (float)nssamp; |
| 171 |
> |
} |
| 172 |
> |
} |
| 173 |
|
if (pctcull >= 0) |
| 174 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 175 |
|
else |
| 176 |
|
printf("\t%.3e\n", bsdf); |
| 177 |
+ |
last_bsdf = bsdf; |
| 178 |
|
} |
| 179 |
+ |
} |
| 180 |
|
if (rbf != NULL) |
| 181 |
|
free(rbf); |
| 182 |
|
} |
| 204 |
|
int ix, iy, ox, oy; |
| 205 |
|
double iovec[6]; |
| 206 |
|
float bsdf; |
| 207 |
< |
#if DEBUG |
| 173 |
< |
fprintf(stderr, "Writing anisotropic order %d ", samp_order); |
| 174 |
< |
if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull); |
| 175 |
< |
else fputs("raw data\n", stderr); |
| 176 |
< |
#endif |
| 207 |
> |
|
| 208 |
|
data_prologue(); /* begin output */ |
| 209 |
|
if (pctcull >= 0) { |
| 210 |
|
sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", |
| 222 |
|
for (ix = 0; ix < sqres; ix++) |
| 223 |
|
for (iy = 0; iy < sqres; iy++) { |
| 224 |
|
RBFNODE *rbf = NULL; /* Klems reversal */ |
| 225 |
< |
SDsquare2disk(iovec, (ix+.5)/sqres, (iy+.5)/sqres); |
| 195 |
< |
iovec[0] = -iovec[0]; iovec[1] = -iovec[1]; |
| 225 |
> |
SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres); |
| 226 |
|
iovec[2] = input_orient * |
| 227 |
|
sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); |
| 228 |
|
if (funame == NULL) |
| 229 |
|
rbf = advect_rbf(iovec); |
| 230 |
< |
for (ox = 0; ox < sqres; ox++) |
| 230 |
> |
for (ox = 0; ox < sqres; ox++) { |
| 231 |
> |
float last_bsdf = -1; |
| 232 |
|
for (oy = 0; oy < sqres; oy++) { |
| 233 |
|
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
| 234 |
|
iovec[5] = output_orient * |
| 235 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 236 |
|
if (funame == NULL) |
| 237 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 237 |
> |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 238 |
|
output_orient/iovec[5]; |
| 239 |
< |
else |
| 240 |
< |
bsdf = funvalue(funame, 6, iovec); |
| 239 |
> |
else { |
| 240 |
> |
double ssa[4], ssvec[6]; |
| 241 |
> |
int ssi; |
| 242 |
> |
bsdf = funvalue(funame, 6, iovec); |
| 243 |
> |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 244 |
> |
bsdf = 0; /* super-sample voxel */ |
| 245 |
> |
for (ssi = nssamp; ssi--; ) { |
| 246 |
> |
SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); |
| 247 |
> |
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
| 248 |
> |
1.-(iy+ssa[1])/sqres); |
| 249 |
> |
ssvec[2] = output_orient * |
| 250 |
> |
sqrt(1. - ssvec[0]*ssvec[0] - |
| 251 |
> |
ssvec[1]*ssvec[1]); |
| 252 |
> |
SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, |
| 253 |
> |
(oy+ssa[3])/sqres); |
| 254 |
> |
ssvec[5] = output_orient * |
| 255 |
> |
sqrt(1. - ssvec[3]*ssvec[3] - |
| 256 |
> |
ssvec[4]*ssvec[4]); |
| 257 |
> |
bsdf += funvalue(funame, 6, ssvec); |
| 258 |
> |
} |
| 259 |
> |
bsdf /= (float)nssamp; |
| 260 |
> |
} |
| 261 |
> |
} |
| 262 |
|
if (pctcull >= 0) |
| 263 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 264 |
|
else |
| 265 |
|
printf("\t%.3e\n", bsdf); |
| 266 |
+ |
last_bsdf = bsdf; |
| 267 |
|
} |
| 268 |
+ |
} |
| 269 |
|
if (rbf != NULL) |
| 270 |
|
free(rbf); |
| 271 |
|
} |