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); |
84 |
|
|
85 |
|
/* Load geometric dimensions and description (if any) */ |
86 |
|
static SDError |
87 |
< |
SDloadGeometry(SDData *dp, ezxml_t wdb) |
87 |
> |
SDloadGeometry(SDData *sd, ezxml_t wdb) |
88 |
|
{ |
89 |
|
ezxml_t geom; |
90 |
|
double cfact; |
91 |
|
const char *fmt, *mgfstr; |
92 |
|
|
93 |
< |
sprintf(SDerrorDetail, "Negative size in \"%s\"", dp->name); |
94 |
< |
dp->dim[0] = dp->dim[1] = dp->dim[2] = .0; |
93 |
> |
if (wdb == NULL) /* no geometry section? */ |
94 |
> |
return SDEnone; |
95 |
> |
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
96 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
97 |
< |
dp->dim[0] = atof(ezxml_txt(geom)) * |
97 |
> |
sd->dim[0] = atof(ezxml_txt(geom)) * |
98 |
|
to_meters(ezxml_attr(geom, "unit")); |
99 |
|
if ((geom = ezxml_child(wdb, "Height")) != NULL) |
100 |
< |
dp->dim[1] = atof(ezxml_txt(geom)) * |
100 |
> |
sd->dim[1] = atof(ezxml_txt(geom)) * |
101 |
|
to_meters(ezxml_attr(geom, "unit")); |
102 |
|
if ((geom = ezxml_child(wdb, "Thickness")) != NULL) |
103 |
< |
dp->dim[2] = atof(ezxml_txt(geom)) * |
103 |
> |
sd->dim[2] = atof(ezxml_txt(geom)) * |
104 |
|
to_meters(ezxml_attr(geom, "unit")); |
105 |
< |
if ((dp->dim[0] < .0) | (dp->dim[1] < .0) | (dp->dim[2] < .0)) |
105 |
> |
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
106 |
> |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
107 |
|
return SDEdata; |
108 |
+ |
} |
109 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
110 |
|
(mgfstr = ezxml_txt(geom)) == NULL) |
111 |
|
return SDEnone; |
112 |
+ |
while (isspace(*mgfstr)) |
113 |
+ |
++mgfstr; |
114 |
+ |
if (!*mgfstr) |
115 |
+ |
return SDEnone; |
116 |
|
if ((fmt = ezxml_attr(geom, "format")) != NULL && |
117 |
|
strcasecmp(fmt, "MGF")) { |
118 |
|
sprintf(SDerrorDetail, |
119 |
|
"Unrecognized geometry format '%s' in \"%s\"", |
120 |
< |
fmt, dp->name); |
120 |
> |
fmt, sd->name); |
121 |
|
return SDEsupport; |
122 |
|
} |
123 |
|
cfact = to_meters(ezxml_attr(geom, "unit")); |
124 |
< |
dp->mgf = (char *)malloc(strlen(mgfstr)+32); |
125 |
< |
if (dp->mgf == NULL) { |
124 |
> |
sd->mgf = (char *)malloc(strlen(mgfstr)+32); |
125 |
> |
if (sd->mgf == NULL) { |
126 |
|
strcpy(SDerrorDetail, "Out of memory in SDloadGeometry"); |
127 |
|
return SDEmemory; |
128 |
|
} |
129 |
|
if (cfact < 0.99 || cfact > 1.01) |
130 |
< |
sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr); |
130 |
> |
sprintf(sd->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr); |
131 |
|
else |
132 |
< |
strcpy(dp->mgf, mgfstr); |
132 |
> |
strcpy(sd->mgf, mgfstr); |
133 |
|
return SDEnone; |
134 |
|
} |
135 |
|
|
122 |
– |
|
136 |
|
/* Load a BSDF struct from the given file (free first and keep name) */ |
137 |
|
SDError |
138 |
|
SDloadFile(SDData *sd, const char *fname) |
139 |
|
{ |
140 |
|
SDError lastErr; |
141 |
< |
ezxml_t fl; |
141 |
> |
ezxml_t fl, wtl; |
142 |
|
|
143 |
|
if ((sd == NULL) | (fname == NULL || !*fname)) |
144 |
|
return SDEargument; |
155 |
|
ezxml_free(fl); |
156 |
|
return SDEformat; |
157 |
|
} |
158 |
+ |
if (strcmp(ezxml_name(fl), "WindowElement")) { |
159 |
+ |
sprintf(SDerrorDetail, |
160 |
+ |
"BSDF \"%s\": top level node not 'WindowElement'", |
161 |
+ |
sd->name); |
162 |
+ |
ezxml_free(fl); |
163 |
+ |
return SDEformat; |
164 |
+ |
} |
165 |
+ |
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
166 |
+ |
if (wtl == NULL) { |
167 |
+ |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'", |
168 |
+ |
sd->name); |
169 |
+ |
ezxml_free(fl); |
170 |
+ |
return SDEformat; |
171 |
+ |
} |
172 |
|
/* load geometry if present */ |
173 |
< |
if ((lastErr = SDloadGeometry(sd, fl))) |
173 |
> |
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
174 |
> |
if (lastErr) |
175 |
|
return lastErr; |
176 |
|
/* try loading variable resolution data */ |
177 |
< |
lastErr = SDloadTre(sd, fl); |
177 |
> |
lastErr = SDloadTre(sd, wtl); |
178 |
|
/* check our result */ |
179 |
< |
switch (lastErr) { |
180 |
< |
case SDEformat: |
181 |
< |
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 |
< |
} |
179 |
> |
if (lastErr == SDEsupport) /* try matrix BSDF if not tree data */ |
180 |
> |
lastErr = SDloadMtx(sd, wtl); |
181 |
> |
|
182 |
|
/* done with XML file */ |
183 |
|
ezxml_free(fl); |
184 |
< |
/* return success or failure */ |
185 |
< |
return lastErr; |
184 |
> |
|
185 |
> |
if (lastErr) { /* was there a load error? */ |
186 |
> |
SDfreeBSDF(sd); |
187 |
> |
return lastErr; |
188 |
> |
} |
189 |
> |
/* remove any insignificant components */ |
190 |
> |
if (sd->rf != NULL && sd->rf->maxHemi <= .001) { |
191 |
> |
SDfreeSpectralDF(sd->rf); sd->rf = NULL; |
192 |
> |
} |
193 |
> |
if (sd->rb != NULL && sd->rb->maxHemi <= .001) { |
194 |
> |
SDfreeSpectralDF(sd->rb); sd->rb = NULL; |
195 |
> |
} |
196 |
> |
if (sd->tf != NULL && sd->tf->maxHemi <= .001) { |
197 |
> |
SDfreeSpectralDF(sd->tf); sd->tf = NULL; |
198 |
> |
} |
199 |
> |
/* return success */ |
200 |
> |
return SDEnone; |
201 |
|
} |
202 |
|
|
203 |
|
/* Allocate new spectral distribution function */ |
256 |
|
|
257 |
|
/* Shorten file path to useable BSDF name, removing suffix */ |
258 |
|
void |
259 |
< |
SDclipName(char res[SDnameLn], const char *fname) |
259 |
> |
SDclipName(char *res, const char *fname) |
260 |
|
{ |
261 |
|
const char *cp, *dot = NULL; |
262 |
|
|
274 |
|
|
275 |
|
/* Initialize an unused BSDF struct (simply clears to zeroes) */ |
276 |
|
void |
277 |
< |
SDclearBSDF(SDData *sd) |
277 |
> |
SDclearBSDF(SDData *sd, const char *fname) |
278 |
|
{ |
279 |
< |
if (sd != NULL) |
280 |
< |
memset(sd, 0, sizeof(SDData)); |
279 |
> |
if (sd == NULL) |
280 |
> |
return; |
281 |
> |
memset(sd, 0, sizeof(SDData)); |
282 |
> |
if (fname == NULL) |
283 |
> |
return; |
284 |
> |
SDclipName(sd->name, fname); |
285 |
|
} |
286 |
|
|
287 |
|
/* Free data associated with BSDF struct */ |
307 |
|
sd->tf = NULL; |
308 |
|
} |
309 |
|
sd->rLambFront.cieY = .0; |
310 |
< |
sd->rLambFront.spec.clock = 0; |
310 |
> |
sd->rLambFront.spec.flags = 0; |
311 |
|
sd->rLambBack.cieY = .0; |
312 |
< |
sd->rLambBack.spec.clock = 0; |
312 |
> |
sd->rLambBack.spec.flags = 0; |
313 |
|
sd->tLamb.cieY = .0; |
314 |
< |
sd->tLamb.spec.clock = 0; |
314 |
> |
sd->tLamb.spec.flags = 0; |
315 |
|
} |
316 |
|
|
317 |
|
/* Find writeable BSDF by name, or allocate new cache entry if absent */ |
339 |
|
sdl->next = SDcacheList; |
340 |
|
SDcacheList = sdl; |
341 |
|
|
342 |
< |
sdl->refcnt++; |
342 |
> |
sdl->refcnt = 1; |
343 |
|
return &sdl->bsdf; |
344 |
|
} |
345 |
|
|
383 |
|
for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next) |
384 |
|
if (&sdl->bsdf == sd) |
385 |
|
break; |
386 |
< |
if (sdl == NULL || --sdl->refcnt) |
386 |
> |
if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0))) |
387 |
|
return; /* missing or still in use */ |
388 |
|
/* keep unreferenced data? */ |
389 |
|
if (SDisLoaded(sd) && SDretainSet) { |
406 |
|
|
407 |
|
/* Sample an individual BSDF component */ |
408 |
|
SDError |
409 |
< |
SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec, |
369 |
< |
double randX, SDComponent *sdc) |
409 |
> |
SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc) |
410 |
|
{ |
411 |
|
float coef[SDmaxCh]; |
412 |
|
SDError ec; |
413 |
+ |
FVECT inVec; |
414 |
|
const SDCDst *cd; |
415 |
|
double d; |
416 |
|
int n; |
417 |
|
/* check arguments */ |
418 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL)) |
418 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL)) |
419 |
|
return SDEargument; |
420 |
|
/* get cumulative distribution */ |
421 |
+ |
VCOPY(inVec, ioVec); |
422 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
423 |
|
if (cd == NULL) |
424 |
|
return SDEmemory; |
425 |
|
if (cd->cTotal <= 1e-7) { /* anything to sample? */ |
426 |
|
sv->spec = c_dfcolor; |
427 |
|
sv->cieY = .0; |
428 |
< |
memset(outVec, 0, 3*sizeof(double)); |
428 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
429 |
|
return SDEnone; |
430 |
|
} |
431 |
|
sv->cieY = cd->cTotal; |
432 |
|
/* compute sample direction */ |
433 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX, cd); |
433 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
434 |
|
if (ec) |
435 |
|
return ec; |
436 |
|
/* get BSDF color */ |
437 |
< |
n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
437 |
> |
n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
438 |
|
if (n <= 0) { |
439 |
|
strcpy(SDerrorDetail, "BSDF sample value error"); |
440 |
|
return SDEinternal; |
461 |
|
bitmask_t ndx, coord[MS_MAXDIM]; |
462 |
|
|
463 |
|
while (n > MS_MAXDIM) /* punt for higher dimensions */ |
464 |
< |
t[--n] = drand48(); |
464 |
> |
t[--n] = rand()*(1./(RAND_MAX+.5)); |
465 |
|
nBits = (8*sizeof(bitmask_t) - 1) / n; |
466 |
|
ndx = randX * (double)((bitmask_t)1 << (nBits*n)); |
467 |
|
/* get coordinate on Hilbert curve */ |
469 |
|
/* convert back to [0,1) range */ |
470 |
|
scale = 1. / (double)((bitmask_t)1 << nBits); |
471 |
|
while (n--) |
472 |
< |
t[n] = scale * ((double)coord[n] + drand48()); |
472 |
> |
t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5))); |
473 |
|
} |
474 |
|
|
475 |
|
#undef MS_MAXDIM |
482 |
|
SDmultiSamp(outVec, 2, randX); |
483 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
484 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
485 |
< |
if (outVec[2] > .0) /* a bit of paranoia */ |
485 |
> |
if (outVec[2] > 0) /* a bit of paranoia */ |
486 |
|
outVec[2] = sqrt(outVec[2]); |
487 |
|
if (!outFront) /* going out back? */ |
488 |
|
outVec[2] = -outVec[2]; |
490 |
|
|
491 |
|
/* Query projected solid angle coverage for non-diffuse BSDF direction */ |
492 |
|
SDError |
493 |
< |
SDsizeBSDF(double *projSA, const FVECT vec, int qflags, const SDData *sd) |
493 |
> |
SDsizeBSDF(double *projSA, const FVECT v1, const RREAL *v2, |
494 |
> |
int qflags, const SDData *sd) |
495 |
|
{ |
496 |
< |
SDSpectralDF *rdf; |
496 |
> |
SDSpectralDF *rdf, *tdf; |
497 |
|
SDError ec; |
498 |
|
int i; |
499 |
|
/* check arguments */ |
500 |
< |
if ((projSA == NULL) | (vec == NULL) | (sd == NULL)) |
500 |
> |
if ((projSA == NULL) | (v1 == NULL) | (sd == NULL)) |
501 |
|
return SDEargument; |
502 |
|
/* initialize extrema */ |
503 |
< |
switch (qflags & SDqueryMin+SDqueryMax) { |
503 |
> |
switch (qflags) { |
504 |
|
case SDqueryMax: |
505 |
|
projSA[0] = .0; |
506 |
|
break; |
513 |
|
case 0: |
514 |
|
return SDEargument; |
515 |
|
} |
516 |
< |
if (vec[2] > .0) /* front surface query? */ |
516 |
> |
if (v1[2] > 0) /* front surface query? */ |
517 |
|
rdf = sd->rf; |
518 |
|
else |
519 |
|
rdf = sd->rb; |
520 |
+ |
tdf = sd->tf; |
521 |
+ |
if (v2 != NULL) /* bidirectional? */ |
522 |
+ |
if (v1[2] > 0 ^ v2[2] > 0) |
523 |
+ |
rdf = NULL; |
524 |
+ |
else |
525 |
+ |
tdf = NULL; |
526 |
|
ec = SDEdata; /* run through components */ |
527 |
|
for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { |
528 |
< |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
529 |
< |
rdf->comp[i].dist); |
528 |
> |
ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
529 |
> |
qflags, &rdf->comp[i]); |
530 |
|
if (ec) |
531 |
|
return ec; |
532 |
|
} |
533 |
< |
for (i = (sd->tf==NULL) ? 0 : sd->tf->ncomp; i--; ) { |
534 |
< |
ec = (*sd->tf->comp[i].func->queryProjSA)(projSA, vec, qflags, |
535 |
< |
sd->tf->comp[i].dist); |
533 |
> |
for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) { |
534 |
> |
ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
535 |
> |
qflags, &tdf->comp[i]); |
536 |
|
if (ec) |
537 |
|
return ec; |
538 |
|
} |
539 |
< |
return ec; |
539 |
> |
if (ec) { /* all diffuse? */ |
540 |
> |
projSA[0] = M_PI; |
541 |
> |
if (qflags == SDqueryMin+SDqueryMax) |
542 |
> |
projSA[1] = M_PI; |
543 |
> |
} |
544 |
> |
return SDEnone; |
545 |
|
} |
546 |
|
|
547 |
|
/* Return BSDF for the given incident and scattered ray vectors */ |
556 |
|
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL)) |
557 |
|
return SDEargument; |
558 |
|
/* whose side are we on? */ |
559 |
< |
inFront = (inVec[2] > .0); |
560 |
< |
outFront = (outVec[2] > .0); |
559 |
> |
inFront = (inVec[2] > 0); |
560 |
> |
outFront = (outVec[2] > 0); |
561 |
|
/* start with diffuse portion */ |
562 |
|
if (inFront & outFront) { |
563 |
|
*sv = sd->rLambFront; |
574 |
|
i = (sdf != NULL) ? sdf->ncomp : 0; |
575 |
|
while (i-- > 0) { |
576 |
|
nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec, |
577 |
< |
sdf->comp[i].dist); |
577 |
> |
&sdf->comp[i]); |
578 |
|
while (nch-- > 0) { |
579 |
|
c_cmix(&sv->spec, sv->cieY, &sv->spec, |
580 |
|
coef[nch], &sdf->comp[i].cspec[nch]); |
598 |
|
if ((inVec == NULL) | (sd == NULL)) |
599 |
|
return .0; |
600 |
|
/* gather diffuse components */ |
601 |
< |
if (inVec[2] > .0) { |
601 |
> |
if (inVec[2] > 0) { |
602 |
|
hsum = sd->rLambFront.cieY; |
603 |
|
rdf = sd->rf; |
604 |
|
} else /* !inFront */ { |
629 |
|
|
630 |
|
/* Sample BSDF direction based on the given random variable */ |
631 |
|
SDError |
632 |
< |
SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec, |
579 |
< |
double randX, int sflags, const SDData *sd) |
632 |
> |
SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd) |
633 |
|
{ |
634 |
|
SDError ec; |
635 |
+ |
FVECT inVec; |
636 |
|
int inFront; |
637 |
|
SDSpectralDF *rdf; |
638 |
|
double rdiff; |
641 |
|
SDComponent *sdc; |
642 |
|
const SDCDst **cdarr = NULL; |
643 |
|
/* check arguments */ |
644 |
< |
if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) | |
645 |
< |
(randX < .0) | (randX >= 1.)) |
644 |
> |
if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) | |
645 |
> |
(randX < 0) | (randX >= 1.)) |
646 |
|
return SDEargument; |
647 |
|
/* whose side are we on? */ |
648 |
< |
inFront = (inVec[2] > .0); |
648 |
> |
VCOPY(inVec, ioVec); |
649 |
> |
inFront = (inVec[2] > 0); |
650 |
|
/* remember diffuse portions */ |
651 |
|
if (inFront) { |
652 |
|
*sv = sd->rLambFront; |
686 |
|
} |
687 |
|
if (sv->cieY <= 1e-7) { /* anything to sample? */ |
688 |
|
sv->cieY = .0; |
689 |
< |
memset(outVec, 0, 3*sizeof(double)); |
689 |
> |
memset(ioVec, 0, 3*sizeof(double)); |
690 |
|
return SDEnone; |
691 |
|
} |
692 |
|
/* scale random variable */ |
693 |
|
randX *= sv->cieY; |
694 |
|
/* diffuse reflection? */ |
695 |
|
if (randX < rdiff) { |
696 |
< |
SDdiffuseSamp(outVec, inFront, randX/rdiff); |
696 |
> |
SDdiffuseSamp(ioVec, inFront, randX/rdiff); |
697 |
|
goto done; |
698 |
|
} |
699 |
|
randX -= rdiff; |
701 |
|
if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) { |
702 |
|
if (randX < sd->tLamb.cieY) { |
703 |
|
sv->spec = sd->tLamb.spec; |
704 |
< |
SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY); |
704 |
> |
SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY); |
705 |
|
goto done; |
706 |
|
} |
707 |
|
randX -= sd->tLamb.cieY; |
713 |
|
return SDEinternal; |
714 |
|
/* compute sample direction */ |
715 |
|
sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr]; |
716 |
< |
ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]); |
716 |
> |
ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]); |
717 |
|
if (ec) |
718 |
|
return ec; |
719 |
|
/* compute color */ |
720 |
< |
j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist); |
720 |
> |
j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); |
721 |
|
if (j <= 0) { |
722 |
|
sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error", |
723 |
|
sd->name); |
744 |
|
if ((vMtx == NULL) | (sNrm == NULL) | (uVec == NULL)) |
745 |
|
return SDEargument; |
746 |
|
VCOPY(vMtx[2], sNrm); |
747 |
< |
if (normalize(vMtx[2]) == .0) |
747 |
> |
if (normalize(vMtx[2]) == 0) |
748 |
|
return SDEargument; |
749 |
|
fcross(vMtx[0], uVec, vMtx[2]); |
750 |
< |
if (normalize(vMtx[0]) == .0) |
750 |
> |
if (normalize(vMtx[0]) == 0) |
751 |
|
return SDEargument; |
752 |
|
fcross(vMtx[1], vMtx[2], vMtx[0]); |
753 |
|
return SDEnone; |
767 |
|
mTmp[0][1] = vMtx[2][1]*vMtx[0][2] - vMtx[2][2]*vMtx[0][1]; |
768 |
|
mTmp[0][2] = vMtx[1][2]*vMtx[0][1] - vMtx[1][1]*vMtx[0][2]; |
769 |
|
d = vMtx[0][0]*mTmp[0][0] + vMtx[1][0]*mTmp[0][1] + vMtx[2][0]*mTmp[0][2]; |
770 |
< |
if (d == .0) { |
770 |
> |
if (d == 0) { |
771 |
|
strcpy(SDerrorDetail, "Zero determinant in matrix inversion"); |
772 |
|
return SDEargument; |
773 |
|
} |
794 |
|
if (vMtx == NULL) { /* assume they just want to normalize */ |
795 |
|
if (resVec != inpVec) |
796 |
|
VCOPY(resVec, inpVec); |
797 |
< |
return (normalize(resVec) > .0) ? SDEnone : SDEargument; |
797 |
> |
return (normalize(resVec) > 0) ? SDEnone : SDEargument; |
798 |
|
} |
799 |
|
vTmp[0] = DOT(vMtx[0], inpVec); |
800 |
|
vTmp[1] = DOT(vMtx[1], inpVec); |
801 |
|
vTmp[2] = DOT(vMtx[2], inpVec); |
802 |
< |
if (normalize(vTmp) == .0) |
802 |
> |
if (normalize(vTmp) == 0) |
803 |
|
return SDEargument; |
804 |
|
VCOPY(resVec, vTmp); |
805 |
|
return SDEnone; |
814 |
|
|
815 |
|
#include "standard.h" |
816 |
|
#include "paths.h" |
762 |
– |
#include <ctype.h> |
817 |
|
|
818 |
|
#define MAXLATS 46 /* maximum number of latitudes */ |
819 |
|
|
870 |
|
static int |
871 |
|
fequal(double a, double b) |
872 |
|
{ |
873 |
< |
if (b != .0) |
873 |
> |
if (b != 0) |
874 |
|
a = a/b - 1.; |
875 |
|
return((a <= 1e-6) & (a >= -1e-6)); |
876 |
|
} |
1131 |
|
break; |
1132 |
|
} |
1133 |
|
if (i < 0) { |
1134 |
< |
sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis); |
1134 |
> |
sprintf(errmsg, "undefined RowAngleBasis '%s'", rbasis); |
1135 |
|
error(WARNING, errmsg); |
1136 |
|
return; |
1137 |
|
} |
1188 |
|
hemi_total = .0; |
1189 |
|
for (i = dp->ninc; i--; ) { |
1190 |
|
dom = getBSDF_incohm(dp,i); |
1191 |
< |
if (dom <= .0) { |
1191 |
> |
if (dom <= 0) { |
1192 |
|
error(WARNING, "zero/negative incoming solid angle"); |
1193 |
|
continue; |
1194 |
|
} |
1211 |
|
hemi_total = .0; |
1212 |
|
for (o = dp->nout; o--; ) { |
1213 |
|
dom = getBSDF_outohm(dp,o); |
1214 |
< |
if (dom <= .0) { |
1214 |
> |
if (dom <= 0) { |
1215 |
|
error(WARNING, "zero/negative outgoing solid angle"); |
1216 |
|
continue; |
1217 |
|
} |
1235 |
|
hemi_total = .0; |
1236 |
|
for (o = dp->nout; o--; ) { |
1237 |
|
double f = BSDF_value(dp,i,o); |
1238 |
< |
if (f >= .0) |
1238 |
> |
if (f >= 0) |
1239 |
|
hemi_total += f*omega_oarr[o]; |
1240 |
|
else { |
1241 |
|
nneg += (f < -FTINY); |