| 10 |
|
* |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
+ |
#define _USE_MATH_DEFINES |
| 14 |
|
#include <stdio.h> |
| 15 |
|
#include <stdlib.h> |
| 16 |
+ |
#include <string.h> |
| 17 |
|
#include <math.h> |
| 18 |
+ |
#include <ctype.h> |
| 19 |
|
#include "ezxml.h" |
| 20 |
|
#include "hilbert.h" |
| 21 |
|
#include "bsdf.h" |
| 92 |
|
|
| 93 |
|
if (wdb == NULL) /* no geometry section? */ |
| 94 |
|
return SDEnone; |
| 95 |
+ |
if ((geom = ezxml_child(wdb, "Name")) != NULL) { |
| 96 |
+ |
strncpy(sd->matn, ezxml_txt(geom), SDnameLn); |
| 97 |
+ |
if (sd->matn[SDnameLn-1]) |
| 98 |
+ |
strcpy(sd->matn+(SDnameLn-4), "..."); |
| 99 |
+ |
} |
| 100 |
+ |
if ((geom = ezxml_child(wdb, "Manufacturer")) != NULL) { |
| 101 |
+ |
strncpy(sd->makr, ezxml_txt(geom), SDnameLn); |
| 102 |
+ |
if (sd->makr[SDnameLn-1]) |
| 103 |
+ |
strcpy(sd->makr+(SDnameLn-4), "..."); |
| 104 |
+ |
} |
| 105 |
|
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
| 106 |
+ |
SDerrorDetail[0] = '\0'; |
| 107 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
| 108 |
|
sd->dim[0] = atof(ezxml_txt(geom)) * |
| 109 |
|
to_meters(ezxml_attr(geom, "unit")); |
| 114 |
|
sd->dim[2] = atof(ezxml_txt(geom)) * |
| 115 |
|
to_meters(ezxml_attr(geom, "unit")); |
| 116 |
|
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
| 117 |
< |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
| 117 |
> |
if (!SDerrorDetail[0]) |
| 118 |
> |
sprintf(SDerrorDetail, "Negative dimension in \"%s\"", |
| 119 |
> |
sd->name); |
| 120 |
|
return SDEdata; |
| 121 |
|
} |
| 122 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
| 123 |
|
(mgfstr = ezxml_txt(geom)) == NULL) |
| 124 |
|
return SDEnone; |
| 125 |
+ |
while (isspace(*mgfstr)) |
| 126 |
+ |
++mgfstr; |
| 127 |
+ |
if (!*mgfstr) |
| 128 |
+ |
return SDEnone; |
| 129 |
|
if ((fmt = ezxml_attr(geom, "format")) != NULL && |
| 130 |
|
strcasecmp(fmt, "MGF")) { |
| 131 |
|
sprintf(SDerrorDetail, |
| 134 |
|
return SDEsupport; |
| 135 |
|
} |
| 136 |
|
cfact = to_meters(ezxml_attr(geom, "unit")); |
| 137 |
+ |
if (cfact <= 0) |
| 138 |
+ |
return SDEformat; |
| 139 |
|
sd->mgf = (char *)malloc(strlen(mgfstr)+32); |
| 140 |
|
if (sd->mgf == NULL) { |
| 141 |
|
strcpy(SDerrorDetail, "Out of memory in SDloadGeometry"); |
| 179 |
|
} |
| 180 |
|
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
| 181 |
|
if (wtl == NULL) { |
| 182 |
< |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'", |
| 182 |
> |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'", |
| 183 |
|
sd->name); |
| 184 |
|
ezxml_free(fl); |
| 185 |
|
return SDEformat; |
| 186 |
|
} |
| 187 |
|
/* load geometry if present */ |
| 188 |
|
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
| 189 |
< |
if (lastErr) |
| 189 |
> |
if (lastErr) { |
| 190 |
> |
ezxml_free(fl); |
| 191 |
|
return lastErr; |
| 192 |
+ |
} |
| 193 |
|
/* try loading variable resolution data */ |
| 194 |
|
lastErr = SDloadTre(sd, wtl); |
| 195 |
|
/* check our result */ |
| 196 |
< |
switch (lastErr) { |
| 173 |
< |
case SDEformat: |
| 174 |
< |
case SDEdata: |
| 175 |
< |
case SDEsupport: /* possibly we just tried the wrong format */ |
| 196 |
> |
if (lastErr == SDEsupport) /* try matrix BSDF if not tree data */ |
| 197 |
|
lastErr = SDloadMtx(sd, wtl); |
| 198 |
< |
break; |
| 178 |
< |
default: /* variable res. OK else serious error */ |
| 179 |
< |
break; |
| 180 |
< |
} |
| 198 |
> |
|
| 199 |
|
/* done with XML file */ |
| 200 |
|
ezxml_free(fl); |
| 201 |
|
|
| 241 |
|
return df; |
| 242 |
|
} |
| 243 |
|
|
| 244 |
+ |
/* Add component(s) to spectral distribution function */ |
| 245 |
+ |
SDSpectralDF * |
| 246 |
+ |
SDaddComponent(SDSpectralDF *odf, int nadd) |
| 247 |
+ |
{ |
| 248 |
+ |
SDSpectralDF *df; |
| 249 |
+ |
|
| 250 |
+ |
if (odf == NULL) |
| 251 |
+ |
return SDnewSpectralDF(nadd); |
| 252 |
+ |
if (nadd <= 0) |
| 253 |
+ |
return odf; |
| 254 |
+ |
df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) + |
| 255 |
+ |
(odf->ncomp+nadd-1)*sizeof(SDComponent)); |
| 256 |
+ |
if (df == NULL) { |
| 257 |
+ |
sprintf(SDerrorDetail, |
| 258 |
+ |
"Cannot add %d component(s) to spectral DF", nadd); |
| 259 |
+ |
SDfreeSpectralDF(odf); |
| 260 |
+ |
return NULL; |
| 261 |
+ |
} |
| 262 |
+ |
memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent)); |
| 263 |
+ |
df->ncomp += nadd; |
| 264 |
+ |
return df; |
| 265 |
+ |
} |
| 266 |
+ |
|
| 267 |
|
/* Free cached cumulative distributions for BSDF component */ |
| 268 |
|
void |
| 269 |
|
SDfreeCumulativeCache(SDSpectralDF *df) |
| 290 |
|
return; |
| 291 |
|
SDfreeCumulativeCache(df); |
| 292 |
|
for (n = df->ncomp; n-- > 0; ) |
| 293 |
< |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 293 |
> |
if (df->comp[n].dist != NULL) |
| 294 |
> |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 295 |
|
free(df); |
| 296 |
|
} |
| 297 |
|
|
| 463 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
| 464 |
|
if (cd == NULL) |
| 465 |
|
return SDEmemory; |
| 466 |
< |
if (cd->cTotal <= 1e-7) { /* anything to sample? */ |
| 466 |
> |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
| 467 |
|
sv->spec = c_dfcolor; |
| 468 |
|
sv->cieY = .0; |
| 469 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 500 |
|
unsigned nBits; |
| 501 |
|
double scale; |
| 502 |
|
bitmask_t ndx, coord[MS_MAXDIM]; |
| 503 |
< |
|
| 503 |
> |
|
| 504 |
> |
if (n <= 0) /* check corner cases */ |
| 505 |
> |
return; |
| 506 |
> |
if (randX < 0) randX = 0; |
| 507 |
> |
else if (randX >= 1.) randX = 0.999999999999999; |
| 508 |
> |
if (n == 1) { |
| 509 |
> |
t[0] = randX; |
| 510 |
> |
return; |
| 511 |
> |
} |
| 512 |
|
while (n > MS_MAXDIM) /* punt for higher dimensions */ |
| 513 |
|
t[--n] = rand()*(1./(RAND_MAX+.5)); |
| 514 |
|
nBits = (8*sizeof(bitmask_t) - 1) / n; |
| 733 |
|
} |
| 734 |
|
sv->cieY += cdarr[i]->cTotal; |
| 735 |
|
} |
| 736 |
< |
if (sv->cieY <= 1e-7) { /* anything to sample? */ |
| 736 |
> |
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
| 737 |
|
sv->cieY = .0; |
| 738 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 739 |
|
return SDEnone; |
| 863 |
|
|
| 864 |
|
#include "standard.h" |
| 865 |
|
#include "paths.h" |
| 816 |
– |
#include <ctype.h> |
| 866 |
|
|
| 867 |
|
#define MAXLATS 46 /* maximum number of latitudes */ |
| 868 |
|
|
| 982 |
|
{ |
| 983 |
|
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
| 984 |
|
int li, ndx; |
| 985 |
< |
double pol, azi, d; |
| 985 |
> |
double pol, azi; |
| 986 |
|
|
| 987 |
|
if ((v[2] < -1.0) | (v[2] > 1.0)) |
| 988 |
|
return(-1); |
| 1222 |
|
) |
| 1223 |
|
{ |
| 1224 |
|
double *omega_iarr, *omega_oarr; |
| 1225 |
< |
double dom, contrib, hemi_total, full_total; |
| 1225 |
> |
double dom, hemi_total, full_total; |
| 1226 |
|
int nneg; |
| 1227 |
|
FVECT v; |
| 1228 |
|
int i, o; |
| 1372 |
|
error(WARNING, errmsg); |
| 1373 |
|
ezxml_free(fl); |
| 1374 |
|
return(NULL); |
| 1375 |
< |
} |
| 1376 |
< |
load_angle_basis(ezxml_child(ezxml_child(wtl, |
| 1377 |
< |
"DataDefinition"), "AngleBasis")); |
| 1375 |
> |
} |
| 1376 |
> |
for (wld = ezxml_child(ezxml_child(wtl, |
| 1377 |
> |
"DataDefinition"), "AngleBasis"); |
| 1378 |
> |
wld != NULL; wld = wld->next) |
| 1379 |
> |
load_angle_basis(wld); |
| 1380 |
|
dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); |
| 1381 |
|
load_geometry(dp, ezxml_child(wtl, "Material")); |
| 1382 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |
| 1437 |
|
if (!getBSDF_incvec(v, b, i)) |
| 1438 |
|
return(0); |
| 1439 |
|
rad = sqrt(getBSDF_incohm(b, i) / PI); |
| 1440 |
< |
multisamp(pert, 3, rv); |
| 1440 |
> |
SDmultiSamp(pert, 3, rv); |
| 1441 |
|
for (j = 0; j < 3; j++) |
| 1442 |
|
v[j] += rad*(2.*pert[j] - 1.); |
| 1443 |
|
if (xm != NULL) |
| 1462 |
|
if (!getBSDF_outvec(v, b, o)) |
| 1463 |
|
return(0); |
| 1464 |
|
rad = sqrt(getBSDF_outohm(b, o) / PI); |
| 1465 |
< |
multisamp(pert, 3, rv); |
| 1465 |
> |
SDmultiSamp(pert, 3, rv); |
| 1466 |
|
for (j = 0; j < 3; j++) |
| 1467 |
|
v[j] += rad*(2.*pert[j] - 1.); |
| 1468 |
|
if (xm != NULL) |