--- ray/src/common/testBSDF.c 2017/02/02 04:46:38 1.9 +++ ray/src/common/testBSDF.c 2019/12/28 18:05:14 1.15 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: testBSDF.c,v 1.9 2017/02/02 04:46:38 greg Exp $"; +static const char RCSid[] = "$Id: testBSDF.c,v 1.15 2019/12/28 18:05:14 greg Exp $"; #endif /* * Simple test program to demonstrate BSDF operation. @@ -8,7 +8,6 @@ static const char RCSid[] = "$Id: testBSDF.c,v 1.9 201 */ #define _USE_MATH_DEFINES -#include #include #include #include @@ -24,10 +23,10 @@ Usage(const char *prog) printf(" i\t\t\t\t Report general information (metadata)\n"); printf(" c\t\t\t\t Report diffuse and specular components\n"); printf(" q theta_i phi_i theta_o phi_o\t Query BSDF for given path (CIE-XYZ)\n"); - printf(" s[r|t][s|d] N theta phi\t\t\t Generate N ray directions & colors at given incidence\n"); - printf(" h[s|d] theta phi\t\t\t Report hemispherical scatteromg at given incidence\n"); - printf(" r[s|d] theta phi\t\t\t Report hemispherical reflection at given incidence\n"); - printf(" t[s|d] theta phi\t\t\t Report hemispherical transmission at given incidence\n"); + printf(" s[r|t][s|d] N theta phi\t Generate N ray directions & colors at given incidence\n"); + printf(" h[s|d] theta phi\t\t Report hemispherical scattering at given incidence\n"); + printf(" r[s|d] theta phi\t\t Report hemispherical reflection at given incidence\n"); + printf(" t[s|d] theta phi\t\t Report hemispherical transmission at given incidence\n"); printf(" a theta phi [t2 p2]\t\t Report resolution (in proj. steradians) for given direction(s)\n"); printf(" ^D\t\t\t\t Quit program\n"); } @@ -47,6 +46,10 @@ vec_from_deg(FVECT v, double theta, double phi) static void printXYZ(const char *intro, const SDValue *vp) { + if (vp->cieY <= 1e-9) { + printf("%s0 0 0\n", intro); + return; + } printf("%s%.3e %.3e %.3e\n", intro, vp->spec.cx/vp->spec.cy*vp->cieY, vp->cieY, @@ -104,8 +107,12 @@ main(int argc, char *argv[]) printf("Manufacturer: '%s'\n", bsdf->makr); printf("Width, Height, Thickness (m): %.4e, %.4e, %.4e\n", bsdf->dim[0], bsdf->dim[1], bsdf->dim[2]); - printf("Has geometry: %s\n", bsdf->mgf ? "yes" : "no"); - continue; + if (bsdf->mgf) + printf("Has geometry: %lu bytes\n", + (unsigned long)strlen(bsdf->mgf)); + else + printf("Has geometry: no\n"); + break; case 'C': /* report constant values */ if (!bsdf) goto noBSDFerr; @@ -126,7 +133,7 @@ main(int argc, char *argv[]) printXYZ("Diffuse Front Reflectance: ", &bsdf->rLambFront); printXYZ("Diffuse Back Reflectance: ", &bsdf->rLambBack); printXYZ("Diffuse Transmittance: ", &bsdf->tLamb); - continue; + break; case 'Q': /* query BSDF value */ if (!bsdf) goto noBSDFerr; @@ -136,7 +143,7 @@ main(int argc, char *argv[]) vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); if (!SDreportError(SDevalBSDF(&val, vout, vin, bsdf), stderr)) printXYZ("", &val); - continue; + break; case 'S': /* sample BSDF */ if (!bsdf) goto noBSDFerr; @@ -164,7 +171,7 @@ main(int argc, char *argv[]) printf("%.8f %.8f %.8f ", vout[0], vout[1], vout[2]); printXYZ("", &val); } - continue; + break; case 'H': /* hemispherical values */ case 'R': case 'T': @@ -182,7 +189,7 @@ main(int argc, char *argv[]) sflags &= ~SDsampSp; vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf)); - continue; + break; case 'A': /* resolution in proj. steradians */ if (!bsdf) goto noBSDFerr; @@ -191,16 +198,19 @@ main(int argc, char *argv[]) vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); if (*sskip2(cp,4)) { vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); - if (SDreportError(SDsizeBSDF(proja, vin, vout, + if (SDreportError(SDsizeBSDF(proja, vout, vin, SDqueryMin+SDqueryMax, bsdf), stderr)) continue; } else if (SDreportError(SDsizeBSDF(proja, vin, NULL, SDqueryMin+SDqueryMax, bsdf), stderr)) continue; printf("%.4e %.4e\n", proja[0], proja[1]); - continue; + break; + default: + Usage(argv[0]); + break; } - Usage(argv[0]); + fflush(stdout); /* in case we're on remote */ continue; noBSDFerr: fprintf(stderr, "%s: First, use 'L' command to load BSDF\n", argv[0]);