| 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" |
| 48 |
|
SDError |
| 49 |
|
SDreportEnglish(SDError ec, FILE *fp) |
| 50 |
|
{ |
| 48 |
– |
if (fp == NULL) |
| 49 |
– |
return ec; |
| 51 |
|
if (!ec) |
| 52 |
|
return SDEnone; |
| 53 |
+ |
if ((ec < SDEnone) | (ec > SDEunknown)) { |
| 54 |
+ |
SDerrorDetail[0] = '\0'; |
| 55 |
+ |
ec = SDEunknown; |
| 56 |
+ |
} |
| 57 |
+ |
if (fp == NULL) |
| 58 |
+ |
return ec; |
| 59 |
|
fputs(SDerrorEnglish[ec], fp); |
| 60 |
|
if (SDerrorDetail[0]) { |
| 61 |
|
fputs(": ", fp); |
| 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")); |
| 113 |
|
if ((geom = ezxml_child(wdb, "Thickness")) != NULL) |
| 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); |
| 116 |
> |
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
| 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) { |
| 169 |
< |
case SDEformat: |
| 170 |
< |
case SDEdata: |
| 171 |
< |
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; |
| 174 |
< |
default: /* variable res. OK else serious error */ |
| 175 |
< |
break; |
| 176 |
< |
} |
| 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 |
|
|
| 315 |
|
|
| 316 |
|
/* Initialize an unused BSDF struct (simply clears to zeroes) */ |
| 317 |
|
void |
| 318 |
< |
SDclearBSDF(SDData *sd) |
| 318 |
> |
SDclearBSDF(SDData *sd, const char *fname) |
| 319 |
|
{ |
| 320 |
< |
if (sd != NULL) |
| 321 |
< |
memset(sd, 0, sizeof(SDData)); |
| 320 |
> |
if (sd == NULL) |
| 321 |
> |
return; |
| 322 |
> |
memset(sd, 0, sizeof(SDData)); |
| 323 |
> |
if (fname == NULL) |
| 324 |
> |
return; |
| 325 |
> |
SDclipName(sd->name, fname); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
/* Free data associated with BSDF struct */ |
| 380 |
|
sdl->next = SDcacheList; |
| 381 |
|
SDcacheList = sdl; |
| 382 |
|
|
| 383 |
< |
sdl->refcnt++; |
| 383 |
> |
sdl->refcnt = 1; |
| 384 |
|
return &sdl->bsdf; |
| 385 |
|
} |
| 386 |
|
|
| 424 |
|
for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next) |
| 425 |
|
if (&sdl->bsdf == sd) |
| 426 |
|
break; |
| 427 |
< |
if (sdl == NULL || --sdl->refcnt) |
| 427 |
> |
if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0))) |
| 428 |
|
return; /* missing or still in use */ |
| 429 |
|
/* keep unreferenced data? */ |
| 430 |
|
if (SDisLoaded(sd) && SDretainSet) { |
| 447 |
|
|
| 448 |
|
/* Sample an individual BSDF component */ |
| 449 |
|
SDError |
| 450 |
< |
SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec, |
| 401 |
< |
double randX, SDComponent *sdc) |
| 450 |
> |
SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc) |
| 451 |
|
{ |
| 452 |
|
float coef[SDmaxCh]; |
| 453 |
|
SDError ec; |
| 454 |
+ |
FVECT inVec; |
| 455 |
|
const SDCDst *cd; |
| 456 |
|
double d; |
| 457 |
|
int n; |
| 458 |
|
/* check arguments */ |
| 459 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL)) |
| 459 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL)) |
| 460 |
|
return SDEargument; |
| 461 |
|
/* get cumulative distribution */ |
| 462 |
+ |
VCOPY(inVec, ioVec); |
| 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(outVec, 0, 3*sizeof(double)); |
| 469 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
| 470 |
|
return SDEnone; |
| 471 |
|
} |
| 472 |
|
sv->cieY = cd->cTotal; |
| 473 |
|
/* compute sample direction */ |
| 474 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX, cd); |
| 474 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
| 475 |
|
if (ec) |
| 476 |
|
return ec; |
| 477 |
|
/* get BSDF color */ |
| 478 |
< |
n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
| 478 |
> |
n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
| 479 |
|
if (n <= 0) { |
| 480 |
|
strcpy(SDerrorDetail, "BSDF sample value error"); |
| 481 |
|
return SDEinternal; |
| 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); |
| 513 |
> |
t[--n] = rand()*(1./(RAND_MAX+.5)); |
| 514 |
|
nBits = (8*sizeof(bitmask_t) - 1) / n; |
| 515 |
|
ndx = randX * (double)((bitmask_t)1 << (nBits*n)); |
| 516 |
|
/* get coordinate on Hilbert curve */ |
| 518 |
|
/* convert back to [0,1) range */ |
| 519 |
|
scale = 1. / (double)((bitmask_t)1 << nBits); |
| 520 |
|
while (n--) |
| 521 |
< |
t[n] = scale * ((double)coord[n] + rand()*(1./RAND_MAX)); |
| 521 |
> |
t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5))); |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
#undef MS_MAXDIM |
| 531 |
|
SDmultiSamp(outVec, 2, randX); |
| 532 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
| 533 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
| 534 |
< |
if (outVec[2] > .0) /* a bit of paranoia */ |
| 534 |
> |
if (outVec[2] > 0) /* a bit of paranoia */ |
| 535 |
|
outVec[2] = sqrt(outVec[2]); |
| 536 |
|
if (!outFront) /* going out back? */ |
| 537 |
|
outVec[2] = -outVec[2]; |
| 539 |
|
|
| 540 |
|
/* Query projected solid angle coverage for non-diffuse BSDF direction */ |
| 541 |
|
SDError |
| 542 |
< |
SDsizeBSDF(double *projSA, const FVECT vec, int qflags, const SDData *sd) |
| 542 |
> |
SDsizeBSDF(double *projSA, const FVECT v1, const RREAL *v2, |
| 543 |
> |
int qflags, const SDData *sd) |
| 544 |
|
{ |
| 545 |
< |
SDSpectralDF *rdf; |
| 545 |
> |
SDSpectralDF *rdf, *tdf; |
| 546 |
|
SDError ec; |
| 547 |
|
int i; |
| 548 |
|
/* check arguments */ |
| 549 |
< |
if ((projSA == NULL) | (vec == NULL) | (sd == NULL)) |
| 549 |
> |
if ((projSA == NULL) | (v1 == NULL) | (sd == NULL)) |
| 550 |
|
return SDEargument; |
| 551 |
|
/* initialize extrema */ |
| 552 |
|
switch (qflags) { |
| 562 |
|
case 0: |
| 563 |
|
return SDEargument; |
| 564 |
|
} |
| 565 |
< |
if (vec[2] > .0) /* front surface query? */ |
| 565 |
> |
if (v1[2] > 0) /* front surface query? */ |
| 566 |
|
rdf = sd->rf; |
| 567 |
|
else |
| 568 |
|
rdf = sd->rb; |
| 569 |
+ |
tdf = sd->tf; |
| 570 |
+ |
if (v2 != NULL) /* bidirectional? */ |
| 571 |
+ |
if (v1[2] > 0 ^ v2[2] > 0) |
| 572 |
+ |
rdf = NULL; |
| 573 |
+ |
else |
| 574 |
+ |
tdf = NULL; |
| 575 |
|
ec = SDEdata; /* run through components */ |
| 576 |
|
for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { |
| 577 |
< |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
| 578 |
< |
rdf->comp[i].dist); |
| 577 |
> |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
| 578 |
> |
qflags, &rdf->comp[i]); |
| 579 |
|
if (ec) |
| 580 |
|
return ec; |
| 581 |
|
} |
| 582 |
< |
for (i = (sd->tf==NULL) ? 0 : sd->tf->ncomp; i--; ) { |
| 583 |
< |
ec = (*sd->tf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
| 584 |
< |
sd->tf->comp[i].dist); |
| 582 |
> |
for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) { |
| 583 |
> |
ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
| 584 |
> |
qflags, &tdf->comp[i]); |
| 585 |
|
if (ec) |
| 586 |
|
return ec; |
| 587 |
|
} |
| 605 |
|
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL)) |
| 606 |
|
return SDEargument; |
| 607 |
|
/* whose side are we on? */ |
| 608 |
< |
inFront = (inVec[2] > .0); |
| 609 |
< |
outFront = (outVec[2] > .0); |
| 608 |
> |
inFront = (inVec[2] > 0); |
| 609 |
> |
outFront = (outVec[2] > 0); |
| 610 |
|
/* start with diffuse portion */ |
| 611 |
|
if (inFront & outFront) { |
| 612 |
|
*sv = sd->rLambFront; |
| 623 |
|
i = (sdf != NULL) ? sdf->ncomp : 0; |
| 624 |
|
while (i-- > 0) { |
| 625 |
|
nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec, |
| 626 |
< |
sdf->comp[i].dist); |
| 626 |
> |
&sdf->comp[i]); |
| 627 |
|
while (nch-- > 0) { |
| 628 |
|
c_cmix(&sv->spec, sv->cieY, &sv->spec, |
| 629 |
|
coef[nch], &sdf->comp[i].cspec[nch]); |
| 647 |
|
if ((inVec == NULL) | (sd == NULL)) |
| 648 |
|
return .0; |
| 649 |
|
/* gather diffuse components */ |
| 650 |
< |
if (inVec[2] > .0) { |
| 650 |
> |
if (inVec[2] > 0) { |
| 651 |
|
hsum = sd->rLambFront.cieY; |
| 652 |
|
rdf = sd->rf; |
| 653 |
|
} else /* !inFront */ { |
| 678 |
|
|
| 679 |
|
/* Sample BSDF direction based on the given random variable */ |
| 680 |
|
SDError |
| 681 |
< |
SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec, |
| 616 |
< |
double randX, int sflags, const SDData *sd) |
| 681 |
> |
SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd) |
| 682 |
|
{ |
| 683 |
|
SDError ec; |
| 684 |
+ |
FVECT inVec; |
| 685 |
|
int inFront; |
| 686 |
|
SDSpectralDF *rdf; |
| 687 |
|
double rdiff; |
| 690 |
|
SDComponent *sdc; |
| 691 |
|
const SDCDst **cdarr = NULL; |
| 692 |
|
/* check arguments */ |
| 693 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) | |
| 694 |
< |
(randX < .0) | (randX >= 1.)) |
| 693 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) | |
| 694 |
> |
(randX < 0) | (randX >= 1.)) |
| 695 |
|
return SDEargument; |
| 696 |
|
/* whose side are we on? */ |
| 697 |
< |
inFront = (inVec[2] > .0); |
| 697 |
> |
VCOPY(inVec, ioVec); |
| 698 |
> |
inFront = (inVec[2] > 0); |
| 699 |
|
/* remember diffuse portions */ |
| 700 |
|
if (inFront) { |
| 701 |
|
*sv = sd->rLambFront; |
| 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(outVec, 0, 3*sizeof(double)); |
| 738 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
| 739 |
|
return SDEnone; |
| 740 |
|
} |
| 741 |
|
/* scale random variable */ |
| 742 |
|
randX *= sv->cieY; |
| 743 |
|
/* diffuse reflection? */ |
| 744 |
|
if (randX < rdiff) { |
| 745 |
< |
SDdiffuseSamp(outVec, inFront, randX/rdiff); |
| 745 |
> |
SDdiffuseSamp(ioVec, inFront, randX/rdiff); |
| 746 |
|
goto done; |
| 747 |
|
} |
| 748 |
|
randX -= rdiff; |
| 750 |
|
if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) { |
| 751 |
|
if (randX < sd->tLamb.cieY) { |
| 752 |
|
sv->spec = sd->tLamb.spec; |
| 753 |
< |
SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY); |
| 753 |
> |
SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY); |
| 754 |
|
goto done; |
| 755 |
|
} |
| 756 |
|
randX -= sd->tLamb.cieY; |
| 762 |
|
return SDEinternal; |
| 763 |
|
/* compute sample direction */ |
| 764 |
|
sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr]; |
| 765 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]); |
| 765 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]); |
| 766 |
|
if (ec) |
| 767 |
|
return ec; |
| 768 |
|
/* compute color */ |
| 769 |
< |
j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
| 769 |
> |
j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
| 770 |
|
if (j <= 0) { |
| 771 |
|
sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error", |
| 772 |
|
sd->name); |
| 793 |
|
if ((vMtx == NULL) | (sNrm == NULL) | (uVec == NULL)) |
| 794 |
|
return SDEargument; |
| 795 |
|
VCOPY(vMtx[2], sNrm); |
| 796 |
< |
if (normalize(vMtx[2]) == .0) |
| 796 |
> |
if (normalize(vMtx[2]) == 0) |
| 797 |
|
return SDEargument; |
| 798 |
|
fcross(vMtx[0], uVec, vMtx[2]); |
| 799 |
< |
if (normalize(vMtx[0]) == .0) |
| 799 |
> |
if (normalize(vMtx[0]) == 0) |
| 800 |
|
return SDEargument; |
| 801 |
|
fcross(vMtx[1], vMtx[2], vMtx[0]); |
| 802 |
|
return SDEnone; |
| 816 |
|
mTmp[0][1] = vMtx[2][1]*vMtx[0][2] - vMtx[2][2]*vMtx[0][1]; |
| 817 |
|
mTmp[0][2] = vMtx[1][2]*vMtx[0][1] - vMtx[1][1]*vMtx[0][2]; |
| 818 |
|
d = vMtx[0][0]*mTmp[0][0] + vMtx[1][0]*mTmp[0][1] + vMtx[2][0]*mTmp[0][2]; |
| 819 |
< |
if (d == .0) { |
| 819 |
> |
if (d == 0) { |
| 820 |
|
strcpy(SDerrorDetail, "Zero determinant in matrix inversion"); |
| 821 |
|
return SDEargument; |
| 822 |
|
} |
| 843 |
|
if (vMtx == NULL) { /* assume they just want to normalize */ |
| 844 |
|
if (resVec != inpVec) |
| 845 |
|
VCOPY(resVec, inpVec); |
| 846 |
< |
return (normalize(resVec) > .0) ? SDEnone : SDEargument; |
| 846 |
> |
return (normalize(resVec) > 0) ? SDEnone : SDEargument; |
| 847 |
|
} |
| 848 |
|
vTmp[0] = DOT(vMtx[0], inpVec); |
| 849 |
|
vTmp[1] = DOT(vMtx[1], inpVec); |
| 850 |
|
vTmp[2] = DOT(vMtx[2], inpVec); |
| 851 |
< |
if (normalize(vTmp) == .0) |
| 851 |
> |
if (normalize(vTmp) == 0) |
| 852 |
|
return SDEargument; |
| 853 |
|
VCOPY(resVec, vTmp); |
| 854 |
|
return SDEnone; |
| 863 |
|
|
| 864 |
|
#include "standard.h" |
| 865 |
|
#include "paths.h" |
| 799 |
– |
#include <ctype.h> |
| 866 |
|
|
| 867 |
|
#define MAXLATS 46 /* maximum number of latitudes */ |
| 868 |
|
|
| 919 |
|
static int |
| 920 |
|
fequal(double a, double b) |
| 921 |
|
{ |
| 922 |
< |
if (b != .0) |
| 922 |
> |
if (b != 0) |
| 923 |
|
a = a/b - 1.; |
| 924 |
|
return((a <= 1e-6) & (a >= -1e-6)); |
| 925 |
|
} |
| 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; |
| 1237 |
|
hemi_total = .0; |
| 1238 |
|
for (i = dp->ninc; i--; ) { |
| 1239 |
|
dom = getBSDF_incohm(dp,i); |
| 1240 |
< |
if (dom <= .0) { |
| 1240 |
> |
if (dom <= 0) { |
| 1241 |
|
error(WARNING, "zero/negative incoming solid angle"); |
| 1242 |
|
continue; |
| 1243 |
|
} |
| 1260 |
|
hemi_total = .0; |
| 1261 |
|
for (o = dp->nout; o--; ) { |
| 1262 |
|
dom = getBSDF_outohm(dp,o); |
| 1263 |
< |
if (dom <= .0) { |
| 1263 |
> |
if (dom <= 0) { |
| 1264 |
|
error(WARNING, "zero/negative outgoing solid angle"); |
| 1265 |
|
continue; |
| 1266 |
|
} |
| 1284 |
|
hemi_total = .0; |
| 1285 |
|
for (o = dp->nout; o--; ) { |
| 1286 |
|
double f = BSDF_value(dp,i,o); |
| 1287 |
< |
if (f >= .0) |
| 1287 |
> |
if (f >= 0) |
| 1288 |
|
hemi_total += f*omega_oarr[o]; |
| 1289 |
|
else { |
| 1290 |
|
nneg += (f < -FTINY); |
| 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) |