--- ray/src/cv/bsdf2ttree.c 2016/02/02 22:34:00 2.34 +++ ray/src/cv/bsdf2ttree.c 2017/02/17 22:31:49 2.40 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.34 2016/02/02 22:34:00 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.40 2017/02/17 22:31:49 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with tensor tree. @@ -27,7 +27,7 @@ static int samp_order = 6; const double ssamp_thresh = 0.35; /* number of super-samples */ #ifndef NSSAMP -#define NSSAMP 100 +#define NSSAMP 64 #endif /* limit on number of RBF lobes */ static int lobe_lim = 15000; @@ -38,7 +38,7 @@ static int do_prog = 79; static char *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"}; static int wbsdfac = 2; -/* Add argument to wrapBSDF, allocating space if isstatic */ +/* Add argument to wrapBSDF, allocating space if !isstatic */ static void add_wbsdf(const char *arg, int isstatic) { @@ -185,8 +185,7 @@ eval_isotropic(char *funame) fputs("{\n", uvfp[1]); } } - /* need to assign Dx, Dy, Dz? */ - if (funame != NULL) + if (funame != NULL) /* need to assign Dx, Dy, Dz? */ assignD = (fundefined(funame) < 6); /* run through directions */ for (ix = 0; ix < sqres/2; ix++) { @@ -207,7 +206,6 @@ eval_isotropic(char *funame) eval_rbfcol(&sdv, rbf, iovec+3); bsdf = sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { - c_ccvt(&sdv.spec, C_CSXY); uv[0] = uv[1] = 1. / (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); uv[0] *= 4.*sdv.spec.cx; @@ -251,14 +249,14 @@ eval_isotropic(char *funame) #endif } if (pctcull >= 0) - fwrite(&bsdf, sizeof(bsdf), 1, ofp); + putbinary(&bsdf, sizeof(bsdf), 1, ofp); else fprintf(ofp, "\t%.3e\n", bsdf); if (rbf_colorimetry == RBCtristimulus) { if (pctcull >= 0) { - fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); - fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); + putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); + putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); } else { fprintf(uvfp[0], "\t%.3e\n", uv[0]); fprintf(uvfp[1], "\t%.3e\n", uv[1]); @@ -271,6 +269,7 @@ eval_isotropic(char *funame) free(rbf); prog_show((ix+1.)*(2./sqres)); } + prog_done(); if (pctcull >= 0) { /* finish output */ if (pclose(ofp)) { fprintf(stderr, "%s: error running rttree_reduce on Y\n", @@ -306,7 +305,6 @@ eval_isotropic(char *funame) } } } - prog_done(); } /* Interpolate and output anisotropic BSDF data */ @@ -322,9 +320,11 @@ eval_anisotropic(char *funame) float bsdf, uv[2]; if (pctcull >= 0) { + const char *avgopt = (input_orient>0 ^ output_orient>0) + ? "" : " -a"; sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", - (input_orient>0 ^ output_orient>0) ? "" : " -a", - pctcull, samp_order, create_component_file(0)); + avgopt, pctcull, samp_order, + create_component_file(0)); ofp = popen(cmd, "w"); if (ofp == NULL) { fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n", @@ -338,12 +338,12 @@ eval_anisotropic(char *funame) if (rbf_colorimetry == RBCtristimulus) { double uvcull = 100. - (100.-pctcull)*.25; sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", - (input_orient>0 ^ output_orient>0) ? "" : " -a", - uvcull, samp_order, create_component_file(1)); + avgopt, uvcull, samp_order, + create_component_file(1)); uvfp[0] = popen(cmd, "w"); sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", - (input_orient>0 ^ output_orient>0) ? "" : " -a", - uvcull, samp_order, create_component_file(2)); + avgopt, uvcull, samp_order, + create_component_file(2)); uvfp[1] = popen(cmd, "w"); if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { fprintf(stderr, "%s: cannot open pipes to uv output\n", @@ -375,8 +375,7 @@ eval_anisotropic(char *funame) fputs("{\n", uvfp[1]); } } - /* need to assign Dx, Dy, Dz? */ - if (funame != NULL) + if (funame != NULL) /* need to assign Dx, Dy, Dz? */ assignD = (fundefined(funame) < 6); /* run through directions */ for (ix = 0; ix < sqres; ix++) @@ -398,7 +397,6 @@ eval_anisotropic(char *funame) eval_rbfcol(&sdv, rbf, iovec+3); bsdf = sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { - c_ccvt(&sdv.spec, C_CSXY); uv[0] = uv[1] = 1. / (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); uv[0] *= 4.*sdv.spec.cx; @@ -443,14 +441,14 @@ eval_anisotropic(char *funame) #endif } if (pctcull >= 0) - fwrite(&bsdf, sizeof(bsdf), 1, ofp); + putbinary(&bsdf, sizeof(bsdf), 1, ofp); else fprintf(ofp, "\t%.3e\n", bsdf); if (rbf_colorimetry == RBCtristimulus) { if (pctcull >= 0) { - fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); - fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); + putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); + putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); } else { fprintf(uvfp[0], "\t%.3e\n", uv[0]); fprintf(uvfp[1], "\t%.3e\n", uv[1]); @@ -463,6 +461,7 @@ eval_anisotropic(char *funame) free(rbf); prog_show((ix*sqres+iy+1.)/(sqres*sqres)); } + prog_done(); if (pctcull >= 0) { /* finish output */ if (pclose(ofp)) { fprintf(stderr, "%s: error running rttree_reduce on Y\n", @@ -492,10 +491,9 @@ eval_anisotropic(char *funame) } } } - prog_done(); } -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) /* Execute wrapBSDF command (may never return) */ static int wrap_up(void)