--- ray/src/common/testBSDF.c 2015/06/05 18:58:37 1.2 +++ ray/src/common/testBSDF.c 2017/02/02 00:27:55 1.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: testBSDF.c,v 1.2 2015/06/05 18:58:37 greg Exp $"; +static const char RCSid[] = "$Id: testBSDF.c,v 1.6 2017/02/02 00:27:55 greg Exp $"; #endif /* * Simple test program to demonstrate BSDF operation. @@ -20,8 +20,10 @@ 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(" 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 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"); @@ -42,10 +44,20 @@ vec_from_deg(FVECT v, double theta, double phi) v[2] = cos(theta); } +static void +printXYZ(const char *intro, const SDValue *vp) +{ + 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,7 +68,7 @@ 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) { @@ -70,23 +82,51 @@ main(int argc, char *argv[]) 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 != NULL) + if (bsdf) SDfreeCache(bsdf); bsdf = SDcacheFile(path); continue; - case 'q': + case 'I': /* report general info. */ + if (bsdf == NULL) + goto noBSDFerr; + printf("Material: '%s'\n", bsdf->matn); + printf("Manufacturer: '%s'\n", bsdf->makr); + printf("Has geometry: %s\n", bsdf->mgf!=NULL ? "yes" : "no"); + printf("Width, Height, Thickness (m): %.4e, %.4e, %.4e\n", + bsdf->dim[0], bsdf->dim[1], bsdf->dim[2]); + continue; + case 'C': /* report constant values */ + if (bsdf == NULL) + goto noBSDFerr; + if (bsdf->rf != NULL) + printf("Peak front hemispherical reflectance: %.3e\n", + bsdf->rLambFront.cieY + + bsdf->rf->maxHemi); + if (bsdf->rb != NULL) + printf("Peak back hemispherical reflectance: %.3e\n", + bsdf->rLambBack.cieY + + bsdf->rb->maxHemi); + if (bsdf->tf != NULL) + printf("Peak front hemispherical transmittance: %.3e\n", + bsdf->tLamb.cieY + bsdf->tf->maxHemi); + if (bsdf->tb != NULL) + 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) goto noBSDFerr; @@ -95,9 +135,8 @@ main(int argc, char *argv[]) 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) goto noBSDFerr; @@ -113,25 +152,21 @@ main(int argc, char *argv[]) printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]); } continue; - case 'h': case 'H': /* hemispherical totals */ - case 'r': case 'R': - case 't': case 'T': if (bsdf == NULL) goto noBSDFerr; if (!*sskip2(cp,2)) break; if (tolower(*cp) == 'r') - sflags ^= SDsampT; + sflags &= ~SDsampT; else if (tolower(*cp) == 't') - sflags ^= SDsampR; + sflags &= ~SDsampR; 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 */ + case 'A': /* resolution in proj. steradians */ if (bsdf == NULL) goto noBSDFerr; if (!*sskip2(cp,2)) @@ -151,7 +186,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; }