--- ray/src/cv/bsdfquery.c 2016/01/30 17:34:17 2.6 +++ ray/src/cv/bsdfquery.c 2017/04/13 00:14:36 2.9 @@ -1,10 +1,11 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfquery.c,v 2.6 2016/01/30 17:34:17 greg Exp $"; +static const char RCSid[] = "$Id: bsdfquery.c,v 2.9 2017/04/13 00:14:36 greg Exp $"; #endif /* * Query values from the given BSDF (scattering interpolant or XML repres.) * Input query is incident and exiting vectors directed away from surface. * We normalize. Output is a BSDF value for the vector pair. + * A zero length in or out vector is ignored, causing output to be flushed. * It is wise to sort the input directions to keep identical ones together * when using a scattering interpolant representation. */ @@ -14,6 +15,7 @@ static const char RCSid[] = "$Id: bsdfquery.c,v 2.6 20 #include #include #include "rtmath.h" +#include "rtio.h" #include "bsdfrep.h" char *progname; @@ -24,7 +26,7 @@ readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt) { double dvec[6]; float fvec[6]; - +tryagain: switch (fmt) { case 'a': if (fscanf(fp, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 || @@ -32,21 +34,21 @@ readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt) return(0); break; case 'd': - if (fread(dvec, sizeof(double), 6, fp) != 6) + if (getbinary(dvec, sizeof(double), 6, fp) != 6) return(0); VCOPY(idir, dvec); VCOPY(odir, dvec+3); break; case 'f': - if (fread(fvec, sizeof(float), 6, fp) != 6) + if (getbinary(fvec, sizeof(float), 6, fp) != 6) return(0); VCOPY(idir, fvec); VCOPY(odir, fvec+3); break; } if ((normalize(idir) == 0) | (normalize(odir) == 0)) { - fprintf(stderr, "%s: zero input vector!\n", progname); - return(0); + fflush(stdout); /* desired side-effect? */ + goto tryagain; } return(1); } @@ -134,8 +136,6 @@ main(int argc, char *argv[]) if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr)) return(1); } - if (repXYZ) /* ensure we have CIE (x,y) */ - c_ccvt(&sval.spec, C_CSXY); switch (outfmt) { /* write to stdout */ case 'a': @@ -154,9 +154,9 @@ main(int argc, char *argv[]) cieXYZ[1] = sval.cieY; cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) / sval.spec.cy * sval.cieY; - fwrite(cieXYZ, sizeof(double), 3, stdout); + putbinary(cieXYZ, sizeof(double), 3, stdout); } else - fwrite(&sval.cieY, sizeof(double), 1, stdout); + putbinary(&sval.cieY, sizeof(double), 1, stdout); break; case 'f': if (repXYZ) { @@ -165,10 +165,10 @@ main(int argc, char *argv[]) cieXYZ[1] = sval.cieY; cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) / sval.spec.cy * sval.cieY; - fwrite(cieXYZ, sizeof(float), 3, stdout); + putbinary(cieXYZ, sizeof(float), 3, stdout); } else { float cieY = sval.cieY; - fwrite(&cieY, sizeof(float), 1, stdout); + putbinary(&cieY, sizeof(float), 1, stdout); } break; }