--- ray/src/common/testBSDF.c 2015/06/05 17:55:18 1.1 +++ ray/src/common/testBSDF.c 2017/05/15 22:15:40 1.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: testBSDF.c,v 1.1 2015/06/05 17:55:18 greg Exp $"; +static const char RCSid[] = "$Id: testBSDF.c,v 1.12 2017/05/15 22:15:40 greg Exp $"; #endif /* * Simple test program to demonstrate BSDF operation. @@ -20,12 +20,14 @@ Usage(const char *prog) { printf("Usage: %s [bsdf_directory]\n", prog); printf("Input commands:\n"); - printf(" l bsdf.xml\t\t\t Load (make active) given BSDF input file\n"); - printf(" q theta_i phi_i theta_o phi_o\t Query BSDF for given path\n"); - printf(" s N theta phi\t\t\t Generate N ray directions at given incidence\n"); - printf(" h theta phi\t\t\t Report hemispherical total at given incidence\n"); - printf(" r theta phi\t\t\t Report hemispherical reflection at given incidence\n"); - printf(" t theta phi\t\t\t Report hemispherical transmission at given incidence\n"); + printf(" L bsdf.xml\t\t\t Load (make active) given BSDF input file\n"); + 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 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"); } @@ -42,10 +44,24 @@ vec_from_deg(FVECT v, double theta, double phi) v[2] = cos(theta); } +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, + (1.-vp->spec.cx-vp->spec.cy)/ + vp->spec.cy*vp->cieY); +} + int main(int argc, char *argv[]) { - const char *directory = ""; + const char *directory = NULL; char inp[512], path[512]; const SDData *bsdf = NULL; @@ -56,88 +72,130 @@ main(int argc, char *argv[]) if (argc == 2) directory = argv[1]; - SDretainSet = SDretainBSDFs; /* keep BSDFs loaded */ + SDretainSet = SDretainBSDFs; /* keep BSDFs in memory */ /* loop on command */ - while (fgets(inp, sizeof(inp), stdin) != NULL) { + while (fgets(inp, sizeof(inp), stdin)) { int sflags = SDsampAll; char *cp = inp; char *cp2; FVECT vin, vout; double proja[2]; - int n; + int n, i; SDValue val; while (isspace(*cp)) cp++; - switch (*cp) { - case 'l': + switch (toupper(*cp)) { case 'L': /* load/activate BSDF input */ cp2 = cp = sskip2(cp, 1); if (!*cp) break; while (*cp) cp++; while (isspace(*--cp)) *cp = '\0'; - if (directory[0]) + if (directory) sprintf(path, "%s/%s", directory, cp2); else strcpy(path, cp2); + if (bsdf) + SDfreeCache(bsdf); bsdf = SDcacheFile(path); continue; - case 'q': + case 'I': /* report general info. */ + if (!bsdf) + goto noBSDFerr; + printf("Material: '%s'\n", bsdf->matn); + 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; + case 'C': /* report constant values */ + if (!bsdf) + goto noBSDFerr; + if (bsdf->rf) + printf("Peak front hemispherical reflectance: %.3e\n", + bsdf->rLambFront.cieY + + bsdf->rf->maxHemi); + if (bsdf->rb) + printf("Peak back hemispherical reflectance: %.3e\n", + bsdf->rLambBack.cieY + + bsdf->rb->maxHemi); + if (bsdf->tf) + printf("Peak front hemispherical transmittance: %.3e\n", + bsdf->tLamb.cieY + bsdf->tf->maxHemi); + if (bsdf->tb) + printf("Peak back hemispherical transmittance: %.3e\n", + bsdf->tLamb.cieY + bsdf->tb->maxHemi); + printXYZ("Diffuse Front Reflectance: ", &bsdf->rLambFront); + printXYZ("Diffuse Back Reflectance: ", &bsdf->rLambBack); + printXYZ("Diffuse Transmittance: ", &bsdf->tLamb); + continue; case 'Q': /* query BSDF value */ - if (bsdf == NULL) + if (!bsdf) goto noBSDFerr; if (!*sskip2(cp,4)) break; vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); if (!SDreportError(SDevalBSDF(&val, vout, vin, bsdf), stderr)) - printf("%.3e\n", val.cieY); + printXYZ("", &val); continue; - case 's': case 'S': /* sample BSDF */ - if (bsdf == NULL) + if (!bsdf) goto noBSDFerr; if (!*sskip2(cp,3)) break; - n = atoi(sskip2(cp,1)); + if (toupper(cp[1]) == 'R') { + sflags &= ~SDsampT; + ++cp; + } else if (toupper(cp[1]) == 'T') { + sflags &= ~SDsampR; + ++cp; + } + if (toupper(cp[1]) == 'S') + sflags &= ~SDsampDf; + else if (toupper(cp[1]) == 'D') + sflags &= ~SDsampSp; + i = n = atoi(sskip2(cp,1)); vec_from_deg(vin, atof(sskip2(cp,2)), atof(sskip2(cp,3))); - while (n-- > 0) { - if (SDreportError(SDsampBSDF(&val, vin, - rand()*(1./(RAND_MAX+.5)), + while (i-- > 0) { + VCOPY(vout, vin); + if (SDreportError(SDsampBSDF(&val, vout, + (i+rand()*(1./(RAND_MAX+.5)))/(double)n, sflags, bsdf), stderr)) break; - printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]); + printf("%.8f %.8f %.8f ", vout[0], vout[1], vout[2]); + printXYZ("", &val); } continue; - case 'h': - case 'H': /* hemispherical totals */ - case 'r': + case 'H': /* hemispherical values */ case 'R': - case 't': case 'T': - if (bsdf == NULL) + if (!bsdf) goto noBSDFerr; if (!*sskip2(cp,2)) break; - if (tolower(*cp) == 'r') - sflags ^= SDsampT; - else if (tolower(*cp) == 't') - sflags ^= SDsampR; + if (toupper(cp[0]) == 'R') + sflags &= ~SDsampT; + else if (toupper(cp[0]) == 'T') + sflags &= ~SDsampR; + if (toupper(cp[1]) == 'S') + sflags &= ~SDsampDf; + else if (toupper(cp[1]) == 'D') + sflags &= ~SDsampSp; vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf)); continue; - case 'a': - case 'A': /* resolution in degrees */ - if (bsdf == NULL) + case 'A': /* resolution in proj. steradians */ + if (!bsdf) goto noBSDFerr; if (!*sskip2(cp,2)) break; 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, @@ -149,7 +207,7 @@ main(int argc, char *argv[]) Usage(argv[0]); continue; noBSDFerr: - fprintf(stderr, "%s: need to use 'l' command to load BSDF\n", argv[0]); + fprintf(stderr, "%s: First, use 'L' command to load BSDF\n", argv[0]); } return 0; }