ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.c
(Generate patch)

Comparing ray/src/cv/bsdfrep.c (file contents):
Revision 2.5 by greg, Wed Nov 7 03:04:23 2012 UTC vs.
Revision 2.13 by greg, Sun Mar 24 17:22:23 2013 UTC

# Line 26 | Line 26 | int                    single_plane_incident = -1;
26   int                     input_orient = 0;
27   int                     output_orient = 0;
28  
29 +                                /* BSDF histogram */
30 + int                     bsdf_hist[HISTLEN];
31 +
32 +                                /* BSDF value for boundary regions */
33 + double                  bsdf_min = 0;
34 +
35                                  /* processed incident DSF measurements */
36   RBFNODE                 *dsf_list = NULL;
37  
# Line 56 | Line 62 | new_input_direction(double new_theta, double new_phi)
62                  new_theta = -new_theta;
63                  new_phi += 180.;
64          }
65 +        if ((theta_in_deg = new_theta) < 1.0)
66 +                return(1);              /* don't rely on phi near normal */
67          while (new_phi < 0)
68                  new_phi += 360.;
69          while (new_phi >= 360.)
# Line 64 | Line 72 | new_input_direction(double new_theta, double new_phi)
72                  single_plane_incident = (round(new_phi) == round(phi_in_deg));
73          else if (single_plane_incident < 0)
74                  single_plane_incident = 1;
67        theta_in_deg = new_theta;       /* assume it's OK */
75          phi_in_deg = new_phi;
76          if ((1. < new_phi) & (new_phi < 89.))
77                  inp_coverage |= INP_QUAD1;
# Line 81 | Line 88 | new_input_direction(double new_theta, double new_phi)
88   int
89   use_symmetry(FVECT vec)
90   {
91 <        double  phi = get_phi360(vec);
91 >        const double    phi = get_phi360(vec);
92  
93          switch (inp_coverage) {
94          case INP_QUAD1|INP_QUAD2|INP_QUAD3|INP_QUAD4:
# Line 177 | Line 184 | rev_rbf_symmetry(RBFNODE *rbf, int sym)
184                          rbf->rbfa[n].gy = grid_res-1 - rbf->rbfa[n].gy;
185   }
186  
187 + /* Rotate RBF to correspond to given incident vector */
188 + void
189 + rotate_rbf(RBFNODE *rbf, const FVECT invec)
190 + {
191 +        static const FVECT      vnorm = {.0, .0, 1.};
192 +        const double            phi = atan2(invec[1],invec[0]) -
193 +                                        atan2(rbf->invec[1],rbf->invec[0]);
194 +        FVECT                   outvec;
195 +        int                     pos[2];
196 +        int                     n;
197 +
198 +        for (n = ((-.01 > phi) | (phi > .01))*rbf->nrbf; n-- > 0; ) {
199 +                ovec_from_pos(outvec, rbf->rbfa[n].gx, rbf->rbfa[n].gy);
200 +                spinvector(outvec, outvec, vnorm, phi);
201 +                pos_from_vec(pos, outvec);
202 +                rbf->rbfa[n].gx = pos[0];
203 +                rbf->rbfa[n].gy = pos[1];
204 +        }
205 +        VCOPY(rbf->invec, invec);
206 + }
207 +
208   /* Compute volume associated with Gaussian lobe */
209   double
210   rbf_volume(const RBFVAL *rbfp)
# Line 193 | Line 221 | ovec_from_pos(FVECT vec, int xpos, int ypos)
221          double  uv[2];
222          double  r2;
223          
224 <        SDsquare2disk(uv, (1./grid_res)*(xpos+.5), (1./grid_res)*(ypos+.5));
224 >        SDsquare2disk(uv, (xpos+.5)/grid_res, (ypos+.5)/grid_res);
225                                  /* uniform hemispherical projection */
226          r2 = uv[0]*uv[0] + uv[1]*uv[1];
227          vec[0] = vec[1] = sqrt(2. - r2);
# Line 219 | Line 247 | pos_from_vec(int pos[2], const FVECT vec)
247   double
248   eval_rbfrep(const RBFNODE *rp, const FVECT outvec)
249   {
250 <        double          res = .0;
250 >        double          minval = bsdf_min*output_orient*outvec[2];
251 >        double          res = 0;
252          const RBFVAL    *rbfp;
253          FVECT           odir;
254          double          sig2;
255          int             n;
256 <
257 <        if (rp == NULL)
258 <                return(.0);
256 >                                /* use minimum if no information avail. */
257 >        if (rp == NULL) {
258 >                if (outvec[2] > 0 ^ output_orient > 0)
259 >                        return(.0);
260 >                return(minval);
261 >        }
262          rbfp = rp->rbfa;
263          for (n = rp->nrbf; n--; rbfp++) {
264                  ovec_from_pos(odir, rbfp->gx, rbfp->gy);
# Line 235 | Line 267 | eval_rbfrep(const RBFNODE *rp, const FVECT outvec)
267                  if (sig2 > -19.)
268                          res += rbfp->peak * exp(sig2);
269          }
270 +        if (res < minval)       /* never return less than minval */
271 +                return(minval);
272          return(res);
273   }
274  
# Line 368 | Line 402 | save_bsdf_rep(FILE *ofp)
402          fprintf(ofp, "SYMMETRY=%d\n", !single_plane_incident * inp_coverage);
403          fprintf(ofp, "IO_SIDES= %d %d\n", input_orient, output_orient);
404          fprintf(ofp, "GRIDRES=%d\n", grid_res);
405 +        fprintf(ofp, "BSDFMIN=%g\n", bsdf_min);
406          fputformat(BSDFREP_FMT, ofp);
407          fputc('\n', ofp);
408                                          /* write each DSF */
# Line 433 | Line 468 | headline(char *s, void *p)
468                  sscanf(s+8, "%d", &grid_res);
469                  return(0);
470          }
471 +        if (!strncmp(s, "BSDFMIN=", 8)) {
472 +                sscanf(s+8, "%lf", &bsdf_min);
473 +                return(0);
474 +        }
475          if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT))
476                  return(-1);
477          return(0);
# Line 463 | Line 502 | load_bsdf_rep(FILE *ifp)
502                  rbfh.invec[0] = getflt(ifp);
503                  rbfh.invec[1] = getflt(ifp);
504                  rbfh.invec[2] = getflt(ifp);
505 +                if (normalize(rbfh.invec) == 0) {
506 +                        fprintf(stderr, "%s: zero incident vector\n", progname);
507 +                        return(0);
508 +                }
509                  rbfh.vtotal = getflt(ifp);
510                  rbfh.nrbf = getint(4, ifp);
511                  newrbf = (RBFNODE *)malloc(sizeof(RBFNODE) +
512                                          sizeof(RBFVAL)*(rbfh.nrbf-1));
513                  if (newrbf == NULL)
514                          goto memerr;
515 <                memcpy(newrbf, &rbfh, sizeof(RBFNODE));
515 >                memcpy(newrbf, &rbfh, sizeof(RBFNODE)-sizeof(RBFVAL));
516                  for (i = 0; i < rbfh.nrbf; i++) {
517                          newrbf->rbfa[i].peak = getflt(ifp);
518                          newrbf->rbfa[i].crad = getint(2, ifp) & 0xffff;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines