45 |
|
SDError |
46 |
|
SDreportEnglish(SDError ec, FILE *fp) |
47 |
|
{ |
48 |
– |
if (fp == NULL) |
49 |
– |
return ec; |
48 |
|
if (!ec) |
49 |
|
return SDEnone; |
50 |
+ |
if ((ec < SDEnone) | (ec > SDEunknown)) { |
51 |
+ |
SDerrorDetail[0] = '\0'; |
52 |
+ |
ec = SDEunknown; |
53 |
+ |
} |
54 |
+ |
if (fp == NULL) |
55 |
+ |
return ec; |
56 |
|
fputs(SDerrorEnglish[ec], fp); |
57 |
|
if (SDerrorDetail[0]) { |
58 |
|
fputs(": ", fp); |
81 |
|
|
82 |
|
/* Load geometric dimensions and description (if any) */ |
83 |
|
static SDError |
84 |
< |
SDloadGeometry(SDData *dp, ezxml_t wdb) |
84 |
> |
SDloadGeometry(SDData *sd, ezxml_t wdb) |
85 |
|
{ |
86 |
|
ezxml_t geom; |
87 |
|
double cfact; |
88 |
|
const char *fmt, *mgfstr; |
89 |
|
|
90 |
< |
sprintf(SDerrorDetail, "Negative size in \"%s\"", dp->name); |
91 |
< |
dp->dim[0] = dp->dim[1] = dp->dim[2] = .0; |
90 |
> |
if (wdb == NULL) /* no geometry section? */ |
91 |
> |
return SDEnone; |
92 |
> |
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
93 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
94 |
< |
dp->dim[0] = atof(ezxml_txt(geom)) * |
94 |
> |
sd->dim[0] = atof(ezxml_txt(geom)) * |
95 |
|
to_meters(ezxml_attr(geom, "unit")); |
96 |
|
if ((geom = ezxml_child(wdb, "Height")) != NULL) |
97 |
< |
dp->dim[1] = atof(ezxml_txt(geom)) * |
97 |
> |
sd->dim[1] = atof(ezxml_txt(geom)) * |
98 |
|
to_meters(ezxml_attr(geom, "unit")); |
99 |
|
if ((geom = ezxml_child(wdb, "Thickness")) != NULL) |
100 |
< |
dp->dim[2] = atof(ezxml_txt(geom)) * |
100 |
> |
sd->dim[2] = atof(ezxml_txt(geom)) * |
101 |
|
to_meters(ezxml_attr(geom, "unit")); |
102 |
< |
if ((dp->dim[0] < .0) | (dp->dim[1] < .0) | (dp->dim[2] < .0)) |
102 |
> |
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
103 |
> |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
104 |
|
return SDEdata; |
105 |
+ |
} |
106 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
107 |
|
(mgfstr = ezxml_txt(geom)) == NULL) |
108 |
|
return SDEnone; |
110 |
|
strcasecmp(fmt, "MGF")) { |
111 |
|
sprintf(SDerrorDetail, |
112 |
|
"Unrecognized geometry format '%s' in \"%s\"", |
113 |
< |
fmt, dp->name); |
113 |
> |
fmt, sd->name); |
114 |
|
return SDEsupport; |
115 |
|
} |
116 |
|
cfact = to_meters(ezxml_attr(geom, "unit")); |
117 |
< |
dp->mgf = (char *)malloc(strlen(mgfstr)+32); |
118 |
< |
if (dp->mgf == NULL) { |
117 |
> |
sd->mgf = (char *)malloc(strlen(mgfstr)+32); |
118 |
> |
if (sd->mgf == NULL) { |
119 |
|
strcpy(SDerrorDetail, "Out of memory in SDloadGeometry"); |
120 |
|
return SDEmemory; |
121 |
|
} |
122 |
|
if (cfact < 0.99 || cfact > 1.01) |
123 |
< |
sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr); |
123 |
> |
sprintf(sd->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr); |
124 |
|
else |
125 |
< |
strcpy(dp->mgf, mgfstr); |
125 |
> |
strcpy(sd->mgf, mgfstr); |
126 |
|
return SDEnone; |
127 |
|
} |
128 |
|
|
122 |
– |
|
129 |
|
/* Load a BSDF struct from the given file (free first and keep name) */ |
130 |
|
SDError |
131 |
|
SDloadFile(SDData *sd, const char *fname) |
132 |
|
{ |
133 |
|
SDError lastErr; |
134 |
< |
ezxml_t fl; |
134 |
> |
ezxml_t fl, wtl; |
135 |
|
|
136 |
|
if ((sd == NULL) | (fname == NULL || !*fname)) |
137 |
|
return SDEargument; |
148 |
|
ezxml_free(fl); |
149 |
|
return SDEformat; |
150 |
|
} |
151 |
+ |
if (strcmp(ezxml_name(fl), "WindowElement")) { |
152 |
+ |
sprintf(SDerrorDetail, |
153 |
+ |
"BSDF \"%s\": top level node not 'WindowElement'", |
154 |
+ |
sd->name); |
155 |
+ |
ezxml_free(fl); |
156 |
+ |
return SDEformat; |
157 |
+ |
} |
158 |
+ |
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
159 |
+ |
if (wtl == NULL) { |
160 |
+ |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'", |
161 |
+ |
sd->name); |
162 |
+ |
ezxml_free(fl); |
163 |
+ |
return SDEformat; |
164 |
+ |
} |
165 |
|
/* load geometry if present */ |
166 |
< |
if ((lastErr = SDloadGeometry(sd, fl))) |
166 |
> |
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
167 |
> |
if (lastErr) |
168 |
|
return lastErr; |
169 |
|
/* try loading variable resolution data */ |
170 |
< |
lastErr = SDloadTre(sd, fl); |
170 |
> |
lastErr = SDloadTre(sd, wtl); |
171 |
|
/* check our result */ |
172 |
< |
switch (lastErr) { |
173 |
< |
case SDEformat: |
174 |
< |
case SDEdata: |
154 |
< |
case SDEsupport: /* possibly we just tried the wrong format */ |
155 |
< |
lastErr = SDloadMtx(sd, fl); |
156 |
< |
break; |
157 |
< |
default: /* variable res. OK else serious error */ |
158 |
< |
break; |
159 |
< |
} |
172 |
> |
if (lastErr == SDEsupport) /* try matrix BSDF if not tree data */ |
173 |
> |
lastErr = SDloadMtx(sd, wtl); |
174 |
> |
|
175 |
|
/* done with XML file */ |
176 |
|
ezxml_free(fl); |
177 |
< |
/* return success or failure */ |
178 |
< |
return lastErr; |
177 |
> |
|
178 |
> |
if (lastErr) { /* was there a load error? */ |
179 |
> |
SDfreeBSDF(sd); |
180 |
> |
return lastErr; |
181 |
> |
} |
182 |
> |
/* remove any insignificant components */ |
183 |
> |
if (sd->rf != NULL && sd->rf->maxHemi <= .001) { |
184 |
> |
SDfreeSpectralDF(sd->rf); sd->rf = NULL; |
185 |
> |
} |
186 |
> |
if (sd->rb != NULL && sd->rb->maxHemi <= .001) { |
187 |
> |
SDfreeSpectralDF(sd->rb); sd->rb = NULL; |
188 |
> |
} |
189 |
> |
if (sd->tf != NULL && sd->tf->maxHemi <= .001) { |
190 |
> |
SDfreeSpectralDF(sd->tf); sd->tf = NULL; |
191 |
> |
} |
192 |
> |
/* return success */ |
193 |
> |
return SDEnone; |
194 |
|
} |
195 |
|
|
196 |
|
/* Allocate new spectral distribution function */ |
249 |
|
|
250 |
|
/* Shorten file path to useable BSDF name, removing suffix */ |
251 |
|
void |
252 |
< |
SDclipName(char res[SDnameLn], const char *fname) |
252 |
> |
SDclipName(char *res, const char *fname) |
253 |
|
{ |
254 |
|
const char *cp, *dot = NULL; |
255 |
|
|
267 |
|
|
268 |
|
/* Initialize an unused BSDF struct (simply clears to zeroes) */ |
269 |
|
void |
270 |
< |
SDclearBSDF(SDData *sd) |
270 |
> |
SDclearBSDF(SDData *sd, const char *fname) |
271 |
|
{ |
272 |
< |
if (sd != NULL) |
273 |
< |
memset(sd, 0, sizeof(SDData)); |
272 |
> |
if (sd == NULL) |
273 |
> |
return; |
274 |
> |
memset(sd, 0, sizeof(SDData)); |
275 |
> |
if (fname == NULL) |
276 |
> |
return; |
277 |
> |
SDclipName(sd->name, fname); |
278 |
|
} |
279 |
|
|
280 |
|
/* Free data associated with BSDF struct */ |
300 |
|
sd->tf = NULL; |
301 |
|
} |
302 |
|
sd->rLambFront.cieY = .0; |
303 |
< |
sd->rLambFront.spec.clock = 0; |
303 |
> |
sd->rLambFront.spec.flags = 0; |
304 |
|
sd->rLambBack.cieY = .0; |
305 |
< |
sd->rLambBack.spec.clock = 0; |
305 |
> |
sd->rLambBack.spec.flags = 0; |
306 |
|
sd->tLamb.cieY = .0; |
307 |
< |
sd->tLamb.spec.clock = 0; |
307 |
> |
sd->tLamb.spec.flags = 0; |
308 |
|
} |
309 |
|
|
310 |
|
/* Find writeable BSDF by name, or allocate new cache entry if absent */ |
332 |
|
sdl->next = SDcacheList; |
333 |
|
SDcacheList = sdl; |
334 |
|
|
335 |
< |
sdl->refcnt++; |
335 |
> |
sdl->refcnt = 1; |
336 |
|
return &sdl->bsdf; |
337 |
|
} |
338 |
|
|
376 |
|
for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next) |
377 |
|
if (&sdl->bsdf == sd) |
378 |
|
break; |
379 |
< |
if (sdl == NULL || --sdl->refcnt) |
379 |
> |
if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0))) |
380 |
|
return; /* missing or still in use */ |
381 |
|
/* keep unreferenced data? */ |
382 |
|
if (SDisLoaded(sd) && SDretainSet) { |
399 |
|
|
400 |
|
/* Sample an individual BSDF component */ |
401 |
|
SDError |
402 |
< |
SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec, |
369 |
< |
double randX, SDComponent *sdc) |
402 |
> |
SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc) |
403 |
|
{ |
404 |
|
float coef[SDmaxCh]; |
405 |
|
SDError ec; |
406 |
+ |
FVECT inVec; |
407 |
|
const SDCDst *cd; |
408 |
|
double d; |
409 |
|
int n; |
410 |
|
/* check arguments */ |
411 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL)) |
411 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL)) |
412 |
|
return SDEargument; |
413 |
|
/* get cumulative distribution */ |
414 |
+ |
VCOPY(inVec, ioVec); |
415 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
416 |
|
if (cd == NULL) |
417 |
|
return SDEmemory; |
418 |
|
if (cd->cTotal <= 1e-7) { /* anything to sample? */ |
419 |
|
sv->spec = c_dfcolor; |
420 |
|
sv->cieY = .0; |
421 |
< |
memset(outVec, 0, 3*sizeof(double)); |
421 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
422 |
|
return SDEnone; |
423 |
|
} |
424 |
|
sv->cieY = cd->cTotal; |
425 |
|
/* compute sample direction */ |
426 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX, cd); |
426 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
427 |
|
if (ec) |
428 |
|
return ec; |
429 |
|
/* get BSDF color */ |
430 |
< |
n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
430 |
> |
n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
431 |
|
if (n <= 0) { |
432 |
|
strcpy(SDerrorDetail, "BSDF sample value error"); |
433 |
|
return SDEinternal; |
454 |
|
bitmask_t ndx, coord[MS_MAXDIM]; |
455 |
|
|
456 |
|
while (n > MS_MAXDIM) /* punt for higher dimensions */ |
457 |
< |
t[--n] = drand48(); |
457 |
> |
t[--n] = rand()*(1./(RAND_MAX+.5)); |
458 |
|
nBits = (8*sizeof(bitmask_t) - 1) / n; |
459 |
|
ndx = randX * (double)((bitmask_t)1 << (nBits*n)); |
460 |
|
/* get coordinate on Hilbert curve */ |
462 |
|
/* convert back to [0,1) range */ |
463 |
|
scale = 1. / (double)((bitmask_t)1 << nBits); |
464 |
|
while (n--) |
465 |
< |
t[n] = scale * ((double)coord[n] + drand48()); |
465 |
> |
t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5))); |
466 |
|
} |
467 |
|
|
468 |
|
#undef MS_MAXDIM |
475 |
|
SDmultiSamp(outVec, 2, randX); |
476 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
477 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
478 |
< |
if (outVec[2] > .0) /* a bit of paranoia */ |
478 |
> |
if (outVec[2] > 0) /* a bit of paranoia */ |
479 |
|
outVec[2] = sqrt(outVec[2]); |
480 |
|
if (!outFront) /* going out back? */ |
481 |
|
outVec[2] = -outVec[2]; |
483 |
|
|
484 |
|
/* Query projected solid angle coverage for non-diffuse BSDF direction */ |
485 |
|
SDError |
486 |
< |
SDsizeBSDF(double *projSA, const FVECT vec, int qflags, const SDData *sd) |
486 |
> |
SDsizeBSDF(double *projSA, const FVECT v1, const RREAL *v2, |
487 |
> |
int qflags, const SDData *sd) |
488 |
|
{ |
489 |
< |
SDSpectralDF *rdf; |
489 |
> |
SDSpectralDF *rdf, *tdf; |
490 |
|
SDError ec; |
491 |
|
int i; |
492 |
|
/* check arguments */ |
493 |
< |
if ((projSA == NULL) | (vec == NULL) | (sd == NULL)) |
493 |
> |
if ((projSA == NULL) | (v1 == NULL) | (sd == NULL)) |
494 |
|
return SDEargument; |
495 |
|
/* initialize extrema */ |
496 |
< |
switch (qflags & SDqueryMin+SDqueryMax) { |
496 |
> |
switch (qflags) { |
497 |
|
case SDqueryMax: |
498 |
|
projSA[0] = .0; |
499 |
|
break; |
506 |
|
case 0: |
507 |
|
return SDEargument; |
508 |
|
} |
509 |
< |
if (vec[2] > .0) /* front surface query? */ |
509 |
> |
if (v1[2] > 0) /* front surface query? */ |
510 |
|
rdf = sd->rf; |
511 |
|
else |
512 |
|
rdf = sd->rb; |
513 |
+ |
tdf = sd->tf; |
514 |
+ |
if (v2 != NULL) /* bidirectional? */ |
515 |
+ |
if (v1[2] > 0 ^ v2[2] > 0) |
516 |
+ |
rdf = NULL; |
517 |
+ |
else |
518 |
+ |
tdf = NULL; |
519 |
|
ec = SDEdata; /* run through components */ |
520 |
|
for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { |
521 |
< |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
522 |
< |
rdf->comp[i].dist); |
521 |
> |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
522 |
> |
qflags, &rdf->comp[i]); |
523 |
|
if (ec) |
524 |
|
return ec; |
525 |
|
} |
526 |
< |
for (i = (sd->tf==NULL) ? 0 : sd->tf->ncomp; i--; ) { |
527 |
< |
ec = (*sd->tf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
528 |
< |
sd->tf->comp[i].dist); |
526 |
> |
for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) { |
527 |
> |
ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
528 |
> |
qflags, &tdf->comp[i]); |
529 |
|
if (ec) |
530 |
|
return ec; |
531 |
|
} |
532 |
< |
return ec; |
532 |
> |
if (ec) { /* all diffuse? */ |
533 |
> |
projSA[0] = M_PI; |
534 |
> |
if (qflags == SDqueryMin+SDqueryMax) |
535 |
> |
projSA[1] = M_PI; |
536 |
> |
} |
537 |
> |
return SDEnone; |
538 |
|
} |
539 |
|
|
540 |
|
/* Return BSDF for the given incident and scattered ray vectors */ |
549 |
|
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL)) |
550 |
|
return SDEargument; |
551 |
|
/* whose side are we on? */ |
552 |
< |
inFront = (inVec[2] > .0); |
553 |
< |
outFront = (outVec[2] > .0); |
552 |
> |
inFront = (inVec[2] > 0); |
553 |
> |
outFront = (outVec[2] > 0); |
554 |
|
/* start with diffuse portion */ |
555 |
|
if (inFront & outFront) { |
556 |
|
*sv = sd->rLambFront; |
567 |
|
i = (sdf != NULL) ? sdf->ncomp : 0; |
568 |
|
while (i-- > 0) { |
569 |
|
nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec, |
570 |
< |
sdf->comp[i].dist); |
570 |
> |
&sdf->comp[i]); |
571 |
|
while (nch-- > 0) { |
572 |
|
c_cmix(&sv->spec, sv->cieY, &sv->spec, |
573 |
|
coef[nch], &sdf->comp[i].cspec[nch]); |
591 |
|
if ((inVec == NULL) | (sd == NULL)) |
592 |
|
return .0; |
593 |
|
/* gather diffuse components */ |
594 |
< |
if (inVec[2] > .0) { |
594 |
> |
if (inVec[2] > 0) { |
595 |
|
hsum = sd->rLambFront.cieY; |
596 |
|
rdf = sd->rf; |
597 |
|
} else /* !inFront */ { |
622 |
|
|
623 |
|
/* Sample BSDF direction based on the given random variable */ |
624 |
|
SDError |
625 |
< |
SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec, |
579 |
< |
double randX, int sflags, const SDData *sd) |
625 |
> |
SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd) |
626 |
|
{ |
627 |
|
SDError ec; |
628 |
+ |
FVECT inVec; |
629 |
|
int inFront; |
630 |
|
SDSpectralDF *rdf; |
631 |
|
double rdiff; |
634 |
|
SDComponent *sdc; |
635 |
|
const SDCDst **cdarr = NULL; |
636 |
|
/* check arguments */ |
637 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) | |
638 |
< |
(randX < .0) | (randX >= 1.)) |
637 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) | |
638 |
> |
(randX < 0) | (randX >= 1.)) |
639 |
|
return SDEargument; |
640 |
|
/* whose side are we on? */ |
641 |
< |
inFront = (inVec[2] > .0); |
641 |
> |
VCOPY(inVec, ioVec); |
642 |
> |
inFront = (inVec[2] > 0); |
643 |
|
/* remember diffuse portions */ |
644 |
|
if (inFront) { |
645 |
|
*sv = sd->rLambFront; |
679 |
|
} |
680 |
|
if (sv->cieY <= 1e-7) { /* anything to sample? */ |
681 |
|
sv->cieY = .0; |
682 |
< |
memset(outVec, 0, 3*sizeof(double)); |
682 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
683 |
|
return SDEnone; |
684 |
|
} |
685 |
|
/* scale random variable */ |
686 |
|
randX *= sv->cieY; |
687 |
|
/* diffuse reflection? */ |
688 |
|
if (randX < rdiff) { |
689 |
< |
SDdiffuseSamp(outVec, inFront, randX/rdiff); |
689 |
> |
SDdiffuseSamp(ioVec, inFront, randX/rdiff); |
690 |
|
goto done; |
691 |
|
} |
692 |
|
randX -= rdiff; |
694 |
|
if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) { |
695 |
|
if (randX < sd->tLamb.cieY) { |
696 |
|
sv->spec = sd->tLamb.spec; |
697 |
< |
SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY); |
697 |
> |
SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY); |
698 |
|
goto done; |
699 |
|
} |
700 |
|
randX -= sd->tLamb.cieY; |
706 |
|
return SDEinternal; |
707 |
|
/* compute sample direction */ |
708 |
|
sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr]; |
709 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]); |
709 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]); |
710 |
|
if (ec) |
711 |
|
return ec; |
712 |
|
/* compute color */ |
713 |
< |
j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
713 |
> |
j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
714 |
|
if (j <= 0) { |
715 |
|
sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error", |
716 |
|
sd->name); |
737 |
|
if ((vMtx == NULL) | (sNrm == NULL) | (uVec == NULL)) |
738 |
|
return SDEargument; |
739 |
|
VCOPY(vMtx[2], sNrm); |
740 |
< |
if (normalize(vMtx[2]) == .0) |
740 |
> |
if (normalize(vMtx[2]) == 0) |
741 |
|
return SDEargument; |
742 |
|
fcross(vMtx[0], uVec, vMtx[2]); |
743 |
< |
if (normalize(vMtx[0]) == .0) |
743 |
> |
if (normalize(vMtx[0]) == 0) |
744 |
|
return SDEargument; |
745 |
|
fcross(vMtx[1], vMtx[2], vMtx[0]); |
746 |
|
return SDEnone; |
760 |
|
mTmp[0][1] = vMtx[2][1]*vMtx[0][2] - vMtx[2][2]*vMtx[0][1]; |
761 |
|
mTmp[0][2] = vMtx[1][2]*vMtx[0][1] - vMtx[1][1]*vMtx[0][2]; |
762 |
|
d = vMtx[0][0]*mTmp[0][0] + vMtx[1][0]*mTmp[0][1] + vMtx[2][0]*mTmp[0][2]; |
763 |
< |
if (d == .0) { |
763 |
> |
if (d == 0) { |
764 |
|
strcpy(SDerrorDetail, "Zero determinant in matrix inversion"); |
765 |
|
return SDEargument; |
766 |
|
} |
787 |
|
if (vMtx == NULL) { /* assume they just want to normalize */ |
788 |
|
if (resVec != inpVec) |
789 |
|
VCOPY(resVec, inpVec); |
790 |
< |
return (normalize(resVec) > .0) ? SDEnone : SDEargument; |
790 |
> |
return (normalize(resVec) > 0) ? SDEnone : SDEargument; |
791 |
|
} |
792 |
|
vTmp[0] = DOT(vMtx[0], inpVec); |
793 |
|
vTmp[1] = DOT(vMtx[1], inpVec); |
794 |
|
vTmp[2] = DOT(vMtx[2], inpVec); |
795 |
< |
if (normalize(vTmp) == .0) |
795 |
> |
if (normalize(vTmp) == 0) |
796 |
|
return SDEargument; |
797 |
|
VCOPY(resVec, vTmp); |
798 |
|
return SDEnone; |
864 |
|
static int |
865 |
|
fequal(double a, double b) |
866 |
|
{ |
867 |
< |
if (b != .0) |
867 |
> |
if (b != 0) |
868 |
|
a = a/b - 1.; |
869 |
|
return((a <= 1e-6) & (a >= -1e-6)); |
870 |
|
} |
1125 |
|
break; |
1126 |
|
} |
1127 |
|
if (i < 0) { |
1128 |
< |
sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis); |
1128 |
> |
sprintf(errmsg, "undefined RowAngleBasis '%s'", rbasis); |
1129 |
|
error(WARNING, errmsg); |
1130 |
|
return; |
1131 |
|
} |
1182 |
|
hemi_total = .0; |
1183 |
|
for (i = dp->ninc; i--; ) { |
1184 |
|
dom = getBSDF_incohm(dp,i); |
1185 |
< |
if (dom <= .0) { |
1185 |
> |
if (dom <= 0) { |
1186 |
|
error(WARNING, "zero/negative incoming solid angle"); |
1187 |
|
continue; |
1188 |
|
} |
1205 |
|
hemi_total = .0; |
1206 |
|
for (o = dp->nout; o--; ) { |
1207 |
|
dom = getBSDF_outohm(dp,o); |
1208 |
< |
if (dom <= .0) { |
1208 |
> |
if (dom <= 0) { |
1209 |
|
error(WARNING, "zero/negative outgoing solid angle"); |
1210 |
|
continue; |
1211 |
|
} |
1229 |
|
hemi_total = .0; |
1230 |
|
for (o = dp->nout; o--; ) { |
1231 |
|
double f = BSDF_value(dp,i,o); |
1232 |
< |
if (f >= .0) |
1232 |
> |
if (f >= 0) |
1233 |
|
hemi_total += f*omega_oarr[o]; |
1234 |
|
else { |
1235 |
|
nneg += (f < -FTINY); |