81 |
|
static int |
82 |
|
fequal(double a, double b) |
83 |
|
{ |
84 |
< |
if (b != .0) |
84 |
> |
if (b != 0) |
85 |
|
a = a/b - 1.; |
86 |
|
return (a <= 1e-6) & (a >= -1e-6); |
87 |
|
} |
88 |
|
|
89 |
< |
/* returns the name of the given tag */ |
89 |
> |
/* Returns the name of the given tag */ |
90 |
|
#ifdef ezxml_name |
91 |
|
#undef ezxml_name |
92 |
|
static char * |
98 |
|
} |
99 |
|
#endif |
100 |
|
|
101 |
< |
/* returns the given tag's character content or empty string if none */ |
101 |
> |
/* Returns the given tag's character content or empty string if none */ |
102 |
|
#ifdef ezxml_txt |
103 |
|
#undef ezxml_txt |
104 |
|
static char * |
159 |
|
|
160 |
|
/* get vector for this angle basis index (front exiting) */ |
161 |
|
static int |
162 |
< |
fo_getvec(FVECT v, int ndx, double randX, void *p) |
162 |
> |
fo_getvec(FVECT v, double ndxr, void *p) |
163 |
|
{ |
164 |
< |
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
164 |
> |
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
165 |
> |
int ndx = (int)ndxr; |
166 |
> |
double randX = ndxr - ndx; |
167 |
|
double rx[2]; |
168 |
|
int li; |
169 |
|
double pol, azi, d; |
170 |
|
|
171 |
< |
if ((ndx < 0) | (ndx >= ab->nangles)) |
171 |
> |
if ((ndxr < 0) | (ndx >= ab->nangles)) |
172 |
|
return RC_FAIL; |
173 |
|
for (li = 0; ndx >= ab->lat[li].nphis; li++) |
174 |
|
ndx -= ab->lat[li].nphis; |
187 |
|
static int |
188 |
|
fo_getndx(const FVECT v, void *p) |
189 |
|
{ |
190 |
< |
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
190 |
> |
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
191 |
|
int li, ndx; |
192 |
|
double pol, azi, d; |
193 |
|
|
194 |
|
if (v == NULL) |
195 |
|
return -1; |
196 |
< |
if ((v[2] < .0) | (v[2] > 1.0)) |
196 |
> |
if ((v[2] < 0) | (v[2] > 1.)) |
197 |
|
return -1; |
198 |
|
pol = 180.0/M_PI*acos(v[2]); |
199 |
|
azi = 180.0/M_PI*atan2(v[1], v[0]); |
239 |
|
|
240 |
|
/* get vector for this angle basis index (back incident) */ |
241 |
|
static int |
242 |
< |
bi_getvec(FVECT v, int ndx, double randX, void *p) |
242 |
> |
bi_getvec(FVECT v, double ndxr, void *p) |
243 |
|
{ |
244 |
< |
if (!fo_getvec(v, ndx, randX, p)) |
244 |
> |
if (!fo_getvec(v, ndxr, p)) |
245 |
|
return RC_FAIL; |
246 |
|
|
247 |
|
v[0] = -v[0]; |
266 |
|
|
267 |
|
/* get vector for this angle basis index (back exiting) */ |
268 |
|
static int |
269 |
< |
bo_getvec(FVECT v, int ndx, double randX, void *p) |
269 |
> |
bo_getvec(FVECT v, double ndxr, void *p) |
270 |
|
{ |
271 |
< |
if (!fo_getvec(v, ndx, randX, p)) |
271 |
> |
if (!fo_getvec(v, ndxr, p)) |
272 |
|
return RC_FAIL; |
273 |
|
|
274 |
|
v[2] = -v[2]; |
291 |
|
|
292 |
|
/* get vector for this angle basis index (front incident) */ |
293 |
|
static int |
294 |
< |
fi_getvec(FVECT v, int ndx, double randX, void *p) |
294 |
> |
fi_getvec(FVECT v, double ndxr, void *p) |
295 |
|
{ |
296 |
< |
if (!fo_getvec(v, ndx, randX, p)) |
296 |
> |
if (!fo_getvec(v, ndxr, p)) |
297 |
|
return RC_FAIL; |
298 |
|
|
299 |
|
v[0] = -v[0]; |
352 |
|
"ThetaBounds"), "LowerTheta"))), |
353 |
|
abase_list[nabases].lat[i].tmin)) { |
354 |
|
sprintf(SDerrorDetail, "Theta values disagree in '%s'", |
355 |
< |
abname); |
355 |
> |
abname); |
356 |
|
return RC_DATERR; |
357 |
|
} |
358 |
|
abase_list[nabases].nangles += |
362 |
|
(abase_list[nabases].lat[i].nphis == 1 && |
363 |
|
abase_list[nabases].lat[i].tmin > FTINY)) { |
364 |
|
sprintf(SDerrorDetail, "Illegal phi count in '%s'", |
365 |
< |
abname); |
365 |
> |
abname); |
366 |
|
return RC_DATERR; |
367 |
|
} |
368 |
|
} |
420 |
|
sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection")); |
421 |
|
/* |
422 |
|
* Remember that front and back are reversed from WINDOW 6 orientations |
423 |
+ |
* Favor their "Front" (incoming light) since that's more often valid |
424 |
|
*/ |
425 |
< |
if ((tfront = !strcasecmp(sdata, "Transmission Back")) || |
426 |
< |
(sd->tf == NULL && |
427 |
< |
!strcasecmp(sdata, "Transmission Front"))) { |
425 |
> |
tfront = !strcasecmp(sdata, "Transmission Back"); |
426 |
> |
if (!strcasecmp(sdata, "Transmission Front") || |
427 |
> |
tfront & (sd->tf == NULL)) { |
428 |
|
if (sd->tf != NULL) |
429 |
|
SDfreeSpectralDF(sd->tf); |
430 |
|
if ((sd->tf = SDnewSpectralDF(1)) == NULL) |
507 |
|
df->comp[0].dist = dp; |
508 |
|
df->comp[0].func = &SDhandleMtx; |
509 |
|
/* read BSDF data */ |
510 |
< |
sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData")); |
510 |
> |
sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData")); |
511 |
|
if (!sdata || !*sdata) { |
512 |
|
sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'", |
513 |
|
sd->name); |
631 |
|
/* Get Matrix BSDF value */ |
632 |
|
static int |
633 |
|
SDgetMtxBSDF(float coef[SDmaxCh], const FVECT outVec, |
634 |
< |
const FVECT inVec, const void *dist) |
634 |
> |
const FVECT inVec, SDComponent *sdc) |
635 |
|
{ |
636 |
< |
const SDMat *dp = (const SDMat *)dist; |
636 |
> |
const SDMat *dp; |
637 |
|
int i_ndx, o_ndx; |
638 |
+ |
/* check arguments */ |
639 |
+ |
if ((coef == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL) |
640 |
+ |
|| (dp = (SDMat *)sdc->dist) == NULL) |
641 |
+ |
return 0; |
642 |
|
/* get angle indices */ |
643 |
|
i_ndx = mBSDF_incndx(dp, inVec); |
644 |
|
o_ndx = mBSDF_outndx(dp, outVec); |
653 |
|
return 1; /* XXX monochrome for now */ |
654 |
|
} |
655 |
|
|
656 |
< |
/* Query solid angle for vector */ |
656 |
> |
/* Query solid angle for vector(s) */ |
657 |
|
static SDError |
658 |
< |
SDqueryMtxProjSA(double *psa, const FVECT vec, int qflags, const void *dist) |
658 |
> |
SDqueryMtxProjSA(double *psa, const FVECT v1, const RREAL *v2, |
659 |
> |
int qflags, SDComponent *sdc) |
660 |
|
{ |
661 |
< |
const SDMat *dp = (const SDMat *)dist; |
661 |
> |
const SDMat *dp; |
662 |
|
double inc_psa, out_psa; |
663 |
|
/* check arguments */ |
664 |
< |
if ((psa == NULL) | (vec == NULL) | (dp == NULL)) |
664 |
> |
if ((psa == NULL) | (v1 == NULL) | (sdc == NULL) || |
665 |
> |
(dp = (SDMat *)sdc->dist) == NULL) |
666 |
|
return SDEargument; |
667 |
+ |
if (v2 == NULL) |
668 |
+ |
v2 = v1; |
669 |
|
/* get projected solid angles */ |
670 |
< |
inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, vec)); |
671 |
< |
out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, vec)); |
670 |
> |
out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v1)); |
671 |
> |
inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v2)); |
672 |
> |
if ((v1 != v2) & (out_psa <= 0) & (inc_psa <= 0)) { |
673 |
> |
inc_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v2)); |
674 |
> |
out_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v1)); |
675 |
> |
} |
676 |
|
|
677 |
|
switch (qflags) { /* record based on flag settings */ |
663 |
– |
case SDqueryVal: |
664 |
– |
psa[0] = .0; |
665 |
– |
/* fall through */ |
678 |
|
case SDqueryMax: |
679 |
|
if (inc_psa > psa[0]) |
680 |
|
psa[0] = inc_psa; |
682 |
|
psa[0] = out_psa; |
683 |
|
break; |
684 |
|
case SDqueryMin+SDqueryMax: |
685 |
< |
if (inc_psa > psa[0]) |
685 |
> |
if (inc_psa > psa[1]) |
686 |
|
psa[1] = inc_psa; |
687 |
< |
if (out_psa > psa[0]) |
687 |
> |
if (out_psa > psa[1]) |
688 |
|
psa[1] = out_psa; |
689 |
|
/* fall through */ |
690 |
|
case SDqueryMin: |
691 |
< |
if ((inc_psa > .0) & (inc_psa < psa[0])) |
691 |
> |
case SDqueryVal: |
692 |
> |
if (qflags == SDqueryVal) |
693 |
> |
psa[0] = M_PI; |
694 |
> |
if ((inc_psa > 0) & (inc_psa < psa[0])) |
695 |
|
psa[0] = inc_psa; |
696 |
< |
if ((out_psa > .0) & (out_psa < psa[0])) |
696 |
> |
if ((out_psa > 0) & (out_psa < psa[0])) |
697 |
|
psa[0] = out_psa; |
698 |
|
break; |
699 |
|
} |
700 |
|
/* make sure it's legal */ |
701 |
< |
return (psa[0] <= .0) ? SDEinternal : SDEnone; |
701 |
> |
return (psa[0] <= 0) ? SDEinternal : SDEnone; |
702 |
|
} |
703 |
|
|
704 |
|
/* Compute new cumulative distribution from BSDF */ |
736 |
|
static const SDCDst * |
737 |
|
SDgetMtxCDist(const FVECT inVec, SDComponent *sdc) |
738 |
|
{ |
739 |
< |
SDMat *dp = (SDMat *)sdc->dist; |
739 |
> |
SDMat *dp; |
740 |
|
int reverse; |
741 |
|
SDMatCDst myCD; |
742 |
|
SDMatCDst *cd, *cdlast; |
743 |
|
/* check arguments */ |
744 |
< |
if ((inVec == NULL) | (dp == NULL)) |
744 |
> |
if ((inVec == NULL) | (sdc == NULL) || |
745 |
> |
(dp = (SDMat *)sdc->dist) == NULL) |
746 |
|
return NULL; |
747 |
|
memset(&myCD, 0, sizeof(myCD)); |
748 |
|
myCD.indx = mBSDF_incndx(dp, inVec); |
791 |
|
|
792 |
|
/* Sample cumulative distribution */ |
793 |
|
static SDError |
794 |
< |
SDsampMtxCDist(FVECT outVec, double randX, const SDCDst *cdp) |
794 |
> |
SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst *cdp) |
795 |
|
{ |
796 |
|
const unsigned maxval = ~0; |
797 |
|
const SDMatCDst *mcd = (const SDMatCDst *)cdp; |
798 |
|
const unsigned target = randX*maxval; |
799 |
|
int i, iupper, ilower; |
800 |
|
/* check arguments */ |
801 |
< |
if ((outVec == NULL) | (mcd == NULL)) |
801 |
> |
if ((ioVec == NULL) | (mcd == NULL)) |
802 |
|
return SDEargument; |
803 |
|
/* binary search to find index */ |
804 |
|
ilower = 0; iupper = mcd->calen; |
811 |
|
randX = (randX*maxval - mcd->carr[ilower]) / |
812 |
|
(double)(mcd->carr[iupper] - mcd->carr[ilower]); |
813 |
|
/* convert index to vector */ |
814 |
< |
if ((*mcd->ob_vec)(outVec, i, randX, mcd->ob_priv)) |
814 |
> |
if ((*mcd->ob_vec)(ioVec, i+randX, mcd->ob_priv)) |
815 |
|
return SDEnone; |
816 |
< |
strcpy(SDerrorDetail, "BSDF sampling fault"); |
816 |
> |
strcpy(SDerrorDetail, "Matrix BSDF sampling fault"); |
817 |
|
return SDEinternal; |
818 |
|
} |
819 |
|
|