--- ray/src/cv/bsdfrep.c 2014/08/21 10:33:48 2.25 +++ ray/src/cv/bsdfrep.c 2015/05/28 15:46:28 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfrep.c,v 2.25 2014/08/21 10:33:48 greg Exp $"; +static const char RCSid[] = "$Id: bsdfrep.c,v 2.28 2015/05/28 15:46:28 greg Exp $"; #endif /* * Support BSDF representation as radial basis functions. @@ -34,8 +34,8 @@ unsigned long bsdf_hist[HISTLEN]; /* BSDF value for boundary regions */ double bsdf_min = 0; -float bsdf_spec_peak = 0; -int bsdf_spec_crad = 0; +double bsdf_spec_peak = 0; +double bsdf_spec_rad = 0; /* processed incident DSF measurements */ RBFNODE *dsf_list = NULL; @@ -50,14 +50,6 @@ double theta_in_deg, phi_in_deg; int new_input_direction(double new_theta, double new_phi) { - if (!input_orient) /* check input orientation */ - input_orient = 1 - 2*(new_theta > 90.); - else if (input_orient > 0 ^ new_theta < 90.) { - fprintf(stderr, - "%s: Cannot handle input angles on both sides of surface\n", - progname); - return(0); - } /* normalize angle ranges */ while (new_theta < -180.) new_theta += 360.; @@ -67,12 +59,21 @@ new_input_direction(double new_theta, double new_phi) new_theta = -new_theta; new_phi += 180.; } - if ((theta_in_deg = new_theta) < 1.0) - return(1); /* don't rely on phi near normal */ while (new_phi < 0) new_phi += 360.; while (new_phi >= 360.) new_phi -= 360.; + /* check input orientation */ + if (!input_orient) + input_orient = 1 - 2*(new_theta > 90.); + else if (input_orient > 0 ^ new_theta < 90.) { + fprintf(stderr, + "%s: Cannot handle input angles on both sides of surface\n", + progname); + return(0); + } + if ((theta_in_deg = new_theta) < 1.0) + return(1); /* don't rely on phi near normal */ if (single_plane_incident > 0) /* check input coverage */ single_plane_incident = (round(new_phi) == round(phi_in_deg)); else if (single_plane_incident < 0) @@ -290,7 +291,7 @@ eval_rbfrep(const RBFNODE *rp, const FVECT outvec) ovec_from_pos(odir, rbfp->gx, rbfp->gy); res += rbfp->peak * exp((DOT(odir,outvec) - 1.) / rad2); } - res /= output_orient*outvec[2]; + res /= COSF(outvec[2]); if (res < bsdf_min) /* never return less than bsdf_min */ return(bsdf_min); return(res); @@ -406,7 +407,7 @@ def_rbf_spec(const FVECT invec) if (input_orient > 0 ^ invec[2] > 0) /* wrong side? */ return(NULL); - if ((bsdf_spec_peak <= bsdf_min) | (bsdf_spec_crad <= 0)) + if ((bsdf_spec_peak <= bsdf_min) | (bsdf_spec_rad <= 0)) return(NULL); /* nothing set */ rbf = (RBFNODE *)malloc(sizeof(RBFNODE)); if (rbf == NULL) @@ -421,7 +422,7 @@ def_rbf_spec(const FVECT invec) VCOPY(rbf->invec, invec); rbf->nrbf = 1; rbf->rbfa[0].peak = bsdf_spec_peak * output_orient*ovec[2]; - rbf->rbfa[0].crad = bsdf_spec_crad; + rbf->rbfa[0].crad = ANG2R(bsdf_spec_rad); rbf->rbfa[0].gx = pos[0]; rbf->rbfa[0].gy = pos[1]; rbf->vtotal = rbf_volume(rbf->rbfa); @@ -536,7 +537,7 @@ clear_bsdf_rep(void) grid_res = GRIDRES; bsdf_min = 0; bsdf_spec_peak = 0; - bsdf_spec_crad = 0; + bsdf_spec_rad = 0; } /* Write our BSDF mesh interpolant out to the given binary stream */ @@ -555,9 +556,8 @@ save_bsdf_rep(FILE *ofp) fprintf(ofp, "IO_SIDES= %d %d\n", input_orient, output_orient); fprintf(ofp, "GRIDRES=%d\n", grid_res); fprintf(ofp, "BSDFMIN=%g\n", bsdf_min); - if ((bsdf_spec_peak > bsdf_min) & (bsdf_spec_crad > 0)) - fprintf(ofp, "BSDFSPEC= %f %f\n", bsdf_spec_peak, - R2ANG(bsdf_spec_crad)); + if ((bsdf_spec_peak > bsdf_min) & (bsdf_spec_rad > 0)) + fprintf(ofp, "BSDFSPEC= %f %f\n", bsdf_spec_peak, bsdf_spec_rad); fputformat(BSDFREP_FMT, ofp); fputc('\n', ofp); /* write each DSF */ @@ -636,9 +636,7 @@ headline(char *s, void *p) return(0); } if (!strncmp(s, "BSDFSPEC=", 9)) { - float bsdf_spec_rad = 0; - sscanf(s+9, "%f %f", &bsdf_spec_peak, &bsdf_spec_rad); - bsdf_spec_crad = ANG2R(bsdf_spec_rad); + sscanf(s+9, "%lf %lf", &bsdf_spec_peak, &bsdf_spec_rad); return(0); } if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT))