| 19 |
|
/* global argv[0] */ |
| 20 |
|
char *progname; |
| 21 |
|
/* percentage to cull (<0 to turn off) */ |
| 22 |
< |
double pctcull = 90.; |
| 22 |
> |
static double pctcull = 90.; |
| 23 |
|
/* sampling order */ |
| 24 |
< |
int samp_order = 6; |
| 24 |
> |
static int samp_order = 6; |
| 25 |
|
/* super-sampling threshold */ |
| 26 |
|
const double ssamp_thresh = 0.35; |
| 27 |
|
/* number of super-samples */ |
| 28 |
< |
const int nssamp = 100; |
| 28 |
> |
#ifndef NSSAMP |
| 29 |
> |
#define NSSAMP 100 |
| 30 |
> |
#endif |
| 31 |
|
/* limit on number of RBF lobes */ |
| 32 |
|
static int lobe_lim = 15000; |
| 33 |
|
/* progress bar length */ |
| 34 |
|
static int do_prog = 79; |
| 35 |
|
|
| 36 |
|
|
| 37 |
+ |
|
| 38 |
|
/* Start new progress bar */ |
| 39 |
|
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
| 40 |
|
|
| 42 |
|
static void |
| 43 |
|
prog_show(double frac) |
| 44 |
|
{ |
| 45 |
< |
char pbar[256]; |
| 46 |
< |
int nchars; |
| 45 |
> |
static unsigned call_cnt = 0; |
| 46 |
> |
static char lastc[] = "-\\|/"; |
| 47 |
> |
char pbar[256]; |
| 48 |
> |
int nchars; |
| 49 |
|
|
| 50 |
< |
if (do_prog <= 0) return; |
| 50 |
> |
if (do_prog <= 1) return; |
| 51 |
|
if (do_prog > sizeof(pbar)-2) |
| 52 |
|
do_prog = sizeof(pbar)-2; |
| 53 |
|
if (frac < 0) frac = 0; |
| 54 |
< |
else if (frac > 1) frac = 1; |
| 55 |
< |
nchars = do_prog*frac + .5; |
| 54 |
> |
else if (frac >= 1) frac = .9999; |
| 55 |
> |
nchars = do_prog*frac; |
| 56 |
|
pbar[0] = '\r'; |
| 57 |
|
memset(pbar+1, '*', nchars); |
| 58 |
< |
memset(pbar+1+nchars, '-', do_prog-nchars); |
| 58 |
> |
pbar[nchars+1] = lastc[call_cnt++ & 3]; |
| 59 |
> |
memset(pbar+2+nchars, '-', do_prog-nchars-1); |
| 60 |
|
pbar[do_prog+1] = '\0'; |
| 61 |
|
fputs(pbar, stderr); |
| 62 |
|
} |
| 74 |
|
fputc('\r', stderr); |
| 75 |
|
} |
| 76 |
|
|
| 71 |
– |
/* Output XML prologue to stdout */ |
| 72 |
– |
static void |
| 73 |
– |
xml_prologue(int ac, char *av[]) |
| 74 |
– |
{ |
| 75 |
– |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 76 |
– |
puts("<WindowElement xmlns=\"http://windows.lbl.gov\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://windows.lbl.gov/BSDF-v1.4.xsd\">"); |
| 77 |
– |
fputs("<!-- File produced by:", stdout); |
| 78 |
– |
while (ac-- > 0) { |
| 79 |
– |
fputc(' ', stdout); |
| 80 |
– |
fputs(*av++, stdout); |
| 81 |
– |
} |
| 82 |
– |
puts(" -->"); |
| 83 |
– |
puts("<WindowElementType>System</WindowElementType>"); |
| 84 |
– |
puts("<FileType>BSDF</FileType>"); |
| 85 |
– |
puts("<Optical>"); |
| 86 |
– |
puts("<Layer>"); |
| 87 |
– |
puts("\t<Material>"); |
| 88 |
– |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
| 89 |
– |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
| 90 |
– |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
| 91 |
– |
puts("\t\t<DeviceType>Other</DeviceType>"); |
| 92 |
– |
puts("\t</Material>"); |
| 93 |
– |
puts("\t<DataDefinition>"); |
| 94 |
– |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
| 95 |
– |
single_plane_incident ? '3' : '4'); |
| 96 |
– |
puts("\t</DataDefinition>"); |
| 97 |
– |
} |
| 98 |
– |
|
| 99 |
– |
/* Output XML data prologue to stdout */ |
| 100 |
– |
static void |
| 101 |
– |
data_prologue() |
| 102 |
– |
{ |
| 103 |
– |
static const char *bsdf_type[4] = { |
| 104 |
– |
"Reflection Front", |
| 105 |
– |
"Transmission Front", |
| 106 |
– |
"Transmission Back", |
| 107 |
– |
"Reflection Back" |
| 108 |
– |
}; |
| 109 |
– |
|
| 110 |
– |
puts("\t<WavelengthData>"); |
| 111 |
– |
puts("\t\t<LayerNumber>System</LayerNumber>"); |
| 112 |
– |
puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>"); |
| 113 |
– |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
| 114 |
– |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>"); |
| 115 |
– |
puts("\t\t<WavelengthDataBlock>"); |
| 116 |
– |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
| 117 |
– |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
| 118 |
– |
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
| 119 |
– |
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
| 120 |
– |
puts("\t\t\t<ScatteringData>"); |
| 121 |
– |
} |
| 122 |
– |
|
| 123 |
– |
/* Output XML data epilogue to stdout */ |
| 124 |
– |
static void |
| 125 |
– |
data_epilogue(void) |
| 126 |
– |
{ |
| 127 |
– |
puts("\t\t\t</ScatteringData>"); |
| 128 |
– |
puts("\t\t</WavelengthDataBlock>"); |
| 129 |
– |
puts("\t</WavelengthData>"); |
| 130 |
– |
} |
| 131 |
– |
|
| 132 |
– |
/* Output XML epilogue to stdout */ |
| 133 |
– |
static void |
| 134 |
– |
xml_epilogue(void) |
| 135 |
– |
{ |
| 136 |
– |
puts("</Layer>"); |
| 137 |
– |
puts("</Optical>"); |
| 138 |
– |
puts("</WindowElement>"); |
| 139 |
– |
} |
| 140 |
– |
|
| 77 |
|
/* Compute absolute relative difference */ |
| 78 |
|
static double |
| 79 |
|
abs_diff(double v1, double v0) |
| 133 |
|
iovec[5] = output_orient * |
| 134 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 135 |
|
if (funame == NULL) |
| 136 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 201 |
< |
output_orient/iovec[5]; |
| 136 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
| 137 |
|
else { |
| 203 |
– |
double ssa[3], ssvec[6], sum; |
| 204 |
– |
int ssi; |
| 138 |
|
if (assignD) { |
| 139 |
|
varset("Dx", '=', -iovec[3]); |
| 140 |
|
varset("Dy", '=', -iovec[4]); |
| 142 |
|
++eclock; |
| 143 |
|
} |
| 144 |
|
bsdf = funvalue(funame, 6, iovec); |
| 145 |
+ |
#if (NSSAMP > 0) |
| 146 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 147 |
< |
sum = 0; /* super-sample voxel */ |
| 148 |
< |
for (ssi = nssamp; ssi--; ) { |
| 149 |
< |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
| 147 |
> |
int ssi; |
| 148 |
> |
double ssa[3], ssvec[6], sum = 0; |
| 149 |
> |
/* super-sample voxel */ |
| 150 |
> |
for (ssi = NSSAMP; ssi--; ) { |
| 151 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom()) * |
| 152 |
> |
(1./NSSAMP)); |
| 153 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
| 154 |
|
ssvec[1] = .0; |
| 155 |
|
ssvec[2] = input_orient * |
| 160 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
| 161 |
|
ssvec[4]*ssvec[4]); |
| 162 |
|
if (assignD) { |
| 163 |
< |
varset("Dx", '=', -iovec[3]); |
| 164 |
< |
varset("Dy", '=', -iovec[4]); |
| 165 |
< |
varset("Dz", '=', -iovec[5]); |
| 163 |
> |
varset("Dx", '=', -ssvec[3]); |
| 164 |
> |
varset("Dy", '=', -ssvec[4]); |
| 165 |
> |
varset("Dz", '=', -ssvec[5]); |
| 166 |
|
++eclock; |
| 167 |
|
} |
| 168 |
|
sum += funvalue(funame, 6, ssvec); |
| 169 |
|
} |
| 170 |
< |
bsdf = sum/nssamp; |
| 170 |
> |
bsdf = sum/NSSAMP; |
| 171 |
|
} |
| 172 |
+ |
#endif |
| 173 |
|
} |
| 174 |
|
if (pctcull >= 0) |
| 175 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 246 |
|
iovec[5] = output_orient * |
| 247 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 248 |
|
if (funame == NULL) |
| 249 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 312 |
< |
output_orient/iovec[5]; |
| 249 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
| 250 |
|
else { |
| 314 |
– |
double ssa[4], ssvec[6], sum; |
| 315 |
– |
int ssi; |
| 251 |
|
if (assignD) { |
| 252 |
|
varset("Dx", '=', -iovec[3]); |
| 253 |
|
varset("Dy", '=', -iovec[4]); |
| 255 |
|
++eclock; |
| 256 |
|
} |
| 257 |
|
bsdf = funvalue(funame, 6, iovec); |
| 258 |
+ |
#if (NSSAMP > 0) |
| 259 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 260 |
< |
sum = 0; /* super-sample voxel */ |
| 261 |
< |
for (ssi = nssamp; ssi--; ) { |
| 262 |
< |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
| 260 |
> |
int ssi; |
| 261 |
> |
double ssa[4], ssvec[6], sum = 0; |
| 262 |
> |
/* super-sample voxel */ |
| 263 |
> |
for (ssi = NSSAMP; ssi--; ) { |
| 264 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
| 265 |
> |
(1./NSSAMP)); |
| 266 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
| 267 |
|
1.-(iy+ssa[1])/sqres); |
| 268 |
< |
ssvec[2] = output_orient * |
| 268 |
> |
ssvec[2] = input_orient * |
| 269 |
|
sqrt(1. - ssvec[0]*ssvec[0] - |
| 270 |
|
ssvec[1]*ssvec[1]); |
| 271 |
|
SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, |
| 274 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
| 275 |
|
ssvec[4]*ssvec[4]); |
| 276 |
|
if (assignD) { |
| 277 |
< |
varset("Dx", '=', -iovec[3]); |
| 278 |
< |
varset("Dy", '=', -iovec[4]); |
| 279 |
< |
varset("Dz", '=', -iovec[5]); |
| 277 |
> |
varset("Dx", '=', -ssvec[3]); |
| 278 |
> |
varset("Dy", '=', -ssvec[4]); |
| 279 |
> |
varset("Dz", '=', -ssvec[5]); |
| 280 |
|
++eclock; |
| 281 |
|
} |
| 282 |
|
sum += funvalue(funame, 6, ssvec); |
| 283 |
|
} |
| 284 |
< |
bsdf = sum/nssamp; |
| 284 |
> |
bsdf = sum/NSSAMP; |
| 285 |
|
} |
| 286 |
+ |
#endif |
| 287 |
|
} |
| 288 |
|
if (pctcull >= 0) |
| 289 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |