--- ray/src/cv/bsdfrbf.c 2014/03/08 18:16:49 2.20 +++ ray/src/cv/bsdfrbf.c 2014/03/21 01:04:42 2.24 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfrbf.c,v 2.20 2014/03/08 18:16:49 greg Exp $"; +static const char RCSid[] = "$Id: bsdfrbf.c,v 2.24 2014/03/21 01:04:42 greg Exp $"; #endif /* * Radial basis function representation for BSDF data. @@ -72,9 +72,7 @@ add_bsdf_data(double theta_out, double phi_out, double ovec[1] = sin((M_PI/180.)*phi_out) * ovec[2]; ovec[2] = sqrt(1. - ovec[2]*ovec[2]); - if (val <= 0) /* truncate to zero */ - val = 0; - else if (!isDSF) + if (!isDSF) val *= ovec[2]; /* convert from BSDF to DSF */ /* update BSDF histogram */ @@ -169,7 +167,7 @@ smooth_region(int x0, int x1, int y0, int y1) } /* Create new lobe based on integrated samples in region */ -static void +static int create_lobe(RBFVAL *rvp, int x0, int x1, int y0, int y1) { double vtot = 0.0; @@ -187,6 +185,8 @@ create_lobe(RBFVAL *rvp, int x0, int x1, int y0, int y progname); exit(1); } + if (vtot <= 0) /* only create positive lobes */ + return(0); /* peak value based on integral */ vtot *= (x1-x0)*(y1-y0)*(2.*M_PI/GRIDRES/GRIDRES)/(double)nv; rad = (RSCA/(double)GRIDRES)*(x1-x0); @@ -194,6 +194,7 @@ create_lobe(RBFVAL *rvp, int x0, int x1, int y0, int y rvp->crad = ANG2R(rad); rvp->gx = (x0+x1)>>1; rvp->gy = (y0+y1)>>1; + return(1); } /* Recursive function to build radial basis function representation */ @@ -235,15 +236,18 @@ build_rbfrep(RBFVAL **arp, int *np, int x0, int x1, in return(-1); } /* create lobes for leaves */ - if (!branched[0]) - create_lobe(*arp+(*np)++, x0, xmid, y0, ymid); - if (!branched[1]) - create_lobe(*arp+(*np)++, xmid, x1, y0, ymid); - if (!branched[2]) - create_lobe(*arp+(*np)++, x0, xmid, ymid, y1); - if (!branched[3]) - create_lobe(*arp+(*np)++, xmid, x1, ymid, y1); - nadded += nleaves; + if (!branched[0] && create_lobe(*arp+*np, x0, xmid, y0, ymid)) { + ++(*np); ++nadded; + } + if (!branched[1] && create_lobe(*arp+*np, xmid, x1, y0, ymid)) { + ++(*np); ++nadded; + } + if (!branched[2] && create_lobe(*arp+*np, x0, xmid, ymid, y1)) { + ++(*np); ++nadded; + } + if (!branched[3] && create_lobe(*arp+*np, xmid, x1, ymid, y1)) { + ++(*np); ++nadded; + } return(nadded); } @@ -258,8 +262,14 @@ make_rbfrep() comp_bsdf_min(); /* create RBF node list */ rbfarr = NULL; nn = 0; - if (build_rbfrep(&rbfarr, &nn, 0, GRIDRES, 0, GRIDRES) <= 0) - goto memerr; + if (build_rbfrep(&rbfarr, &nn, 0, GRIDRES, 0, GRIDRES) <= 0) { + if (nn) + goto memerr; + fprintf(stderr, + "%s: warning - skipping bad incidence (%.1f,%.1f)\n", + progname, theta_in_deg, phi_in_deg); + return(NULL); + } /* (re)allocate RBF array */ newnode = (RBFNODE *)realloc(rbfarr, sizeof(RBFNODE) + sizeof(RBFVAL)*(nn-1)); @@ -286,7 +296,6 @@ make_rbfrep() newnode->vtotal); #endif insert_dsf(newnode); - return(newnode); memerr: fprintf(stderr, "%s: Out of memory in make_rbfrep()\n", progname);