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 |
|
} |
418 |
|
int i; |
419 |
|
/* allocate BSDF component */ |
420 |
|
sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection")); |
421 |
+ |
if (!sdata) |
422 |
+ |
return RC_FAIL; |
423 |
|
/* |
424 |
|
* Remember that front and back are reversed from WINDOW 6 orientations |
425 |
|
* Favor their "Front" (incoming light) since that's more often valid |
509 |
|
df->comp[0].dist = dp; |
510 |
|
df->comp[0].func = &SDhandleMtx; |
511 |
|
/* read BSDF data */ |
512 |
< |
sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData")); |
512 |
> |
sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData")); |
513 |
|
if (!sdata || !*sdata) { |
514 |
|
sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'", |
515 |
|
sd->name); |
523 |
|
sd->name); |
524 |
|
return RC_FORMERR; |
525 |
|
} |
526 |
< |
while (*sdnext && isspace(*sdnext)) |
526 |
> |
while (isspace(*sdnext)) |
527 |
|
sdnext++; |
528 |
|
if (*sdnext == ',') sdnext++; |
529 |
|
if (rowinc) { |
548 |
|
for (i = n; --i; ) |
549 |
|
if (sm->bsdf[i] < minv) |
550 |
|
minv = sm->bsdf[i]; |
551 |
+ |
|
552 |
+ |
if (minv <= FTINY) |
553 |
+ |
return .0; |
554 |
+ |
|
555 |
|
for (i = n; i--; ) |
556 |
|
sm->bsdf[i] -= minv; |
557 |
|
|
577 |
|
c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]); |
578 |
|
dv->cieY += ymin; |
579 |
|
} |
580 |
< |
df->maxHemi -= dv->cieY; /* adjust minimum hemispherical */ |
580 |
> |
df->maxHemi -= dv->cieY; /* adjust maximum hemispherical */ |
581 |
|
/* make sure everything is set */ |
582 |
|
c_ccvt(&dv->spec, C_CSXY+C_CSSPEC); |
583 |
|
} |
586 |
|
SDError |
587 |
|
SDloadMtx(SDData *sd, ezxml_t wtl) |
588 |
|
{ |
589 |
< |
ezxml_t wld, wdb; |
590 |
< |
int rowIn; |
591 |
< |
struct BSDF_data *dp; |
592 |
< |
char *txt; |
593 |
< |
int rval; |
588 |
< |
|
589 |
> |
ezxml_t wld, wdb; |
590 |
> |
int rowIn; |
591 |
> |
char *txt; |
592 |
> |
int rval; |
593 |
> |
/* basic checks and data ordering */ |
594 |
|
txt = ezxml_txt(ezxml_child(ezxml_child(wtl, |
595 |
|
"DataDefinition"), "IncidentDataStructure")); |
596 |
|
if (txt == NULL || !*txt) { |
609 |
|
sd->name); |
610 |
|
return SDEsupport; |
611 |
|
} |
612 |
< |
/* get angle basis */ |
612 |
> |
/* get angle basis */ |
613 |
|
rval = load_angle_basis(ezxml_child(ezxml_child(wtl, |
614 |
|
"DataDefinition"), "AngleBasis")); |
615 |
|
if (rval < 0) |
616 |
|
return convert_errcode(rval); |
617 |
< |
/* load BSDF components */ |
617 |
> |
/* load BSDF components */ |
618 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |
619 |
|
wld != NULL; wld = wld->next) { |
620 |
|
if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")), |
625 |
|
if ((rval = load_bsdf_data(sd, wdb, rowIn)) < 0) |
626 |
|
return convert_errcode(rval); |
627 |
|
} |
628 |
< |
/* separate diffuse components */ |
628 |
> |
/* separate diffuse components */ |
629 |
|
extract_diffuse(&sd->rLambFront, sd->rf); |
630 |
|
extract_diffuse(&sd->rLambBack, sd->rb); |
631 |
|
extract_diffuse(&sd->tLamb, sd->tf); |
632 |
< |
/* return success */ |
632 |
> |
/* return success */ |
633 |
|
return SDEnone; |
634 |
|
} |
635 |
|
|
636 |
|
/* Get Matrix BSDF value */ |
637 |
|
static int |
638 |
|
SDgetMtxBSDF(float coef[SDmaxCh], const FVECT outVec, |
639 |
< |
const FVECT inVec, const void *dist) |
639 |
> |
const FVECT inVec, SDComponent *sdc) |
640 |
|
{ |
641 |
< |
const SDMat *dp = (const SDMat *)dist; |
641 |
> |
const SDMat *dp; |
642 |
|
int i_ndx, o_ndx; |
643 |
+ |
/* check arguments */ |
644 |
+ |
if ((coef == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL) |
645 |
+ |
|| (dp = (SDMat *)sdc->dist) == NULL) |
646 |
+ |
return 0; |
647 |
|
/* get angle indices */ |
648 |
|
i_ndx = mBSDF_incndx(dp, inVec); |
649 |
|
o_ndx = mBSDF_outndx(dp, outVec); |
658 |
|
return 1; /* XXX monochrome for now */ |
659 |
|
} |
660 |
|
|
661 |
< |
/* Query solid angle for vector */ |
661 |
> |
/* Query solid angle for vector(s) */ |
662 |
|
static SDError |
663 |
|
SDqueryMtxProjSA(double *psa, const FVECT v1, const RREAL *v2, |
664 |
< |
int qflags, const void *dist) |
664 |
> |
int qflags, SDComponent *sdc) |
665 |
|
{ |
666 |
< |
const SDMat *dp = (const SDMat *)dist; |
666 |
> |
const SDMat *dp; |
667 |
|
double inc_psa, out_psa; |
668 |
|
/* check arguments */ |
669 |
< |
if ((psa == NULL) | (v1 == NULL) | (dp == NULL)) |
669 |
> |
if ((psa == NULL) | (v1 == NULL) | (sdc == NULL) || |
670 |
> |
(dp = (SDMat *)sdc->dist) == NULL) |
671 |
|
return SDEargument; |
672 |
|
if (v2 == NULL) |
673 |
|
v2 = v1; |
674 |
|
/* get projected solid angles */ |
675 |
|
out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v1)); |
676 |
|
inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v2)); |
677 |
+ |
if ((v1 != v2) & (out_psa <= 0) & (inc_psa <= 0)) { |
678 |
+ |
inc_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v2)); |
679 |
+ |
out_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v1)); |
680 |
+ |
} |
681 |
|
|
682 |
|
switch (qflags) { /* record based on flag settings */ |
669 |
– |
case SDqueryVal: |
670 |
– |
psa[0] = .0; |
671 |
– |
/* fall through */ |
683 |
|
case SDqueryMax: |
684 |
|
if (inc_psa > psa[0]) |
685 |
|
psa[0] = inc_psa; |
687 |
|
psa[0] = out_psa; |
688 |
|
break; |
689 |
|
case SDqueryMin+SDqueryMax: |
690 |
< |
if (inc_psa > psa[0]) |
690 |
> |
if (inc_psa > psa[1]) |
691 |
|
psa[1] = inc_psa; |
692 |
< |
if (out_psa > psa[0]) |
692 |
> |
if (out_psa > psa[1]) |
693 |
|
psa[1] = out_psa; |
694 |
|
/* fall through */ |
695 |
+ |
case SDqueryVal: |
696 |
+ |
if (qflags == SDqueryVal) |
697 |
+ |
psa[0] = M_PI; |
698 |
+ |
/* fall through */ |
699 |
|
case SDqueryMin: |
700 |
|
if ((inc_psa > 0) & (inc_psa < psa[0])) |
701 |
|
psa[0] = inc_psa; |
742 |
|
static const SDCDst * |
743 |
|
SDgetMtxCDist(const FVECT inVec, SDComponent *sdc) |
744 |
|
{ |
745 |
< |
SDMat *dp = (SDMat *)sdc->dist; |
745 |
> |
SDMat *dp; |
746 |
|
int reverse; |
747 |
|
SDMatCDst myCD; |
748 |
|
SDMatCDst *cd, *cdlast; |
749 |
|
/* check arguments */ |
750 |
< |
if ((inVec == NULL) | (dp == NULL)) |
750 |
> |
if ((inVec == NULL) | (sdc == NULL) || |
751 |
> |
(dp = (SDMat *)sdc->dist) == NULL) |
752 |
|
return NULL; |
753 |
|
memset(&myCD, 0, sizeof(myCD)); |
754 |
|
myCD.indx = mBSDF_incndx(dp, inVec); |
767 |
|
reverse = 1; |
768 |
|
} |
769 |
|
cdlast = NULL; /* check for it in cache list */ |
770 |
< |
for (cd = (SDMatCDst *)sdc->cdList; |
771 |
< |
cd != NULL; cd = (SDMatCDst *)cd->next) { |
770 |
> |
for (cd = (SDMatCDst *)sdc->cdList; cd != NULL; |
771 |
> |
cdlast = cd, cd = (SDMatCDst *)cd->next) |
772 |
|
if (cd->indx == myCD.indx && (cd->calen == myCD.calen) & |
773 |
|
(cd->ob_priv == myCD.ob_priv) & |
774 |
|
(cd->ob_vec == myCD.ob_vec)) |
775 |
|
break; |
760 |
– |
cdlast = cd; |
761 |
– |
} |
776 |
|
if (cd == NULL) { /* need to allocate new entry */ |
777 |
|
cd = (SDMatCDst *)malloc(sizeof(SDMatCDst) + |
778 |
< |
myCD.calen*sizeof(myCD.carr[0])); |
778 |
> |
sizeof(myCD.carr[0])*myCD.calen); |
779 |
|
if (cd == NULL) |
780 |
|
return NULL; |
781 |
|
*cd = myCD; /* compute cumulative distribution */ |
795 |
|
|
796 |
|
/* Sample cumulative distribution */ |
797 |
|
static SDError |
798 |
< |
SDsampMtxCDist(FVECT outVec, double randX, const SDCDst *cdp) |
798 |
> |
SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst *cdp) |
799 |
|
{ |
800 |
|
const unsigned maxval = ~0; |
801 |
|
const SDMatCDst *mcd = (const SDMatCDst *)cdp; |
802 |
|
const unsigned target = randX*maxval; |
803 |
|
int i, iupper, ilower; |
804 |
|
/* check arguments */ |
805 |
< |
if ((outVec == NULL) | (mcd == NULL)) |
805 |
> |
if ((ioVec == NULL) | (mcd == NULL)) |
806 |
|
return SDEargument; |
807 |
|
/* binary search to find index */ |
808 |
|
ilower = 0; iupper = mcd->calen; |
815 |
|
randX = (randX*maxval - mcd->carr[ilower]) / |
816 |
|
(double)(mcd->carr[iupper] - mcd->carr[ilower]); |
817 |
|
/* convert index to vector */ |
818 |
< |
if ((*mcd->ob_vec)(outVec, i+randX, mcd->ob_priv)) |
818 |
> |
if ((*mcd->ob_vec)(ioVec, i+randX, mcd->ob_priv)) |
819 |
|
return SDEnone; |
820 |
< |
strcpy(SDerrorDetail, "BSDF sampling fault"); |
820 |
> |
strcpy(SDerrorDetail, "Matrix BSDF sampling fault"); |
821 |
|
return SDEinternal; |
822 |
|
} |
823 |
|
|