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

Comparing ray/src/cv/bsdfrbf.c (file contents):
Revision 2.12 by greg, Mon Oct 21 18:33:15 2013 UTC vs.
Revision 2.15 by greg, Fri Nov 8 23:32:54 2013 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *      G. Ward
8   */
9  
10 + /****************************************************************
11 + 1) Collect samples into a grid using the Shirley-Chiu
12 +        angular mapping from a hemisphere to a square.
13 +
14 + 2) Compute an adaptive quadtree by subdividing the grid so that
15 +        each leaf node has at least one sample up to as many
16 +        samples as fit nicely on a plane to within a certain
17 +        MSE tolerance.
18 +
19 + 3) Place one Gaussian lobe at each leaf node in the quadtree,
20 +        sizing it to have a radius equal to the leaf size and
21 +        a volume equal to the energy in that node.
22 + *****************************************************************/
23 +
24   #define _USE_MATH_DEFINES
25   #include <stdio.h>
26   #include <stdlib.h>
# Line 122 | Line 136 | smooth_region(int x0, int x1, int y0, int y1)
136              for (y = y0; y < y1; y++)
137                  if ((n = dsf_grid[x][y].nval) > 0) {
138                          double  z = dsf_grid[x][y].vsum;
139 <                        rMtx[0][0] += n*x*x;
140 <                        rMtx[0][1] += n*x*y;
141 <                        rMtx[0][2] += n*x;
142 <                        rMtx[1][1] += n*y*y;
143 <                        rMtx[1][2] += n*y;
144 <                        rMtx[2][2] += n;
139 >                        rMtx[0][0] += x*x*(double)n;
140 >                        rMtx[0][1] += x*y*(double)n;
141 >                        rMtx[0][2] += x*(double)n;
142 >                        rMtx[1][1] += y*y*(double)n;
143 >                        rMtx[1][2] += y*(double)n;
144 >                        rMtx[2][2] += (double)n;
145                          xvec[0] += x*z;
146                          xvec[1] += y*z;
147                          xvec[2] += z;
148                  }
149          rMtx[1][0] = rMtx[0][1];
150 +        rMtx[2][0] = rMtx[0][2];
151          rMtx[2][1] = rMtx[1][2];
152          nvs = rMtx[2][2];
153          if (SDinvXform(rMtx, rMtx) != SDEnone)
# Line 149 | Line 164 | smooth_region(int x0, int x1, int y0, int y1)
164                  }
165          if (sqerr <= nvs*SMOOTH_MSE)    /* below absolute MSE threshold? */
166                  return(1);
167 <                                        /* below relative MSE threshold? */
167 >                                        /* OR below relative MSE threshold? */
168          return(sqerr*nvs <= xvec[2]*xvec[2]*SMOOTH_MSER);
169   }
170  
# Line 209 | Line 224 | build_rbfrep(RBFVAL **arp, int *np, int x0, int x1, in
224          if (!nleaves)                   /* nothing but branches? */
225                  return(nadded);
226                                          /* combine 4 leaves into 1? */
227 <        if (nleaves == 4 && x1-x0 < MAX_RAD && smooth_region(x0, x1, y0, y1))
227 >        if ((nleaves == 4) & (x1-x0 <= MAX_RAD) &&
228 >                        smooth_region(x0, x1, y0, y1))
229                  return(0);
230                                          /* need more array space? */
231          if ((*np+nleaves-1)>>RBFALLOCB != (*np-1)>>RBFALLOCB) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines