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

Comparing ray/src/common/interp2d.c (file contents):
Revision 2.4 by greg, Mon Feb 11 22:56:22 2013 UTC vs.
Revision 2.9 by greg, Tue Feb 12 18:41:39 2013 UTC

# Line 17 | Line 17 | static const char RCSid[] = "$Id$";
17   * each of NI2DIR surrounding directions.  To speed this
18   * calculation, we sort the data into half-planes and apply
19   * simple tests to see which neighbor is closest in each
20 < * direction.  Once we have our approximate neighborhood
20 > * angular slice.  Once we have our approximate neighborhood
21   * for a sample, we can use it in a modified Gaussian weighting
22   * with allowing local anisotropy.  Harmonic weighting is added
23   * to reduce the influence of distant neighbors.  This yields a
# Line 71 | Line 71 | interp2_realloc(INTERP2 *ip, int nsamps)
71                  interp2_free(ip);
72                  return(NULL);
73          }
74 <        if (nsamps == ip->ns);
74 >        if (nsamps == ip->ns)
75                  return(ip);
76          if (ip->da != NULL) {   /* will need to recompute distribution */
77                  free(ip->da);
# Line 84 | Line 84 | interp2_realloc(INTERP2 *ip, int nsamps)
84          return(ip);
85   }
86  
87 + /* Set minimum distance under which samples will start to merge */
88 + void
89 + interp2_spacing(INTERP2 *ip, double mind)
90 + {
91 +        if (mind <= 0)
92 +                return;
93 +        if ((.998*ip->dmin <= mind) & (mind <= 1.002*ip->dmin))
94 +                return;
95 +        if (ip->da != NULL) {   /* will need to recompute distribution */
96 +                free(ip->da);
97 +                ip->da = NULL;
98 +        }
99 +        ip->dmin = mind;
100 + }
101 +
102 + /* Modify smoothing parameter by the given factor */
103 + void
104 + interp2_smooth(INTERP2 *ip, double sf)
105 + {
106 +        if ((ip->smf *= sf) < NI2DSMF)
107 +                ip->smf = NI2DSMF;
108 + }
109 +
110   /* private call-back to sort position index */
111   static int
112   cmp_spos(const void *p1, const void *p2)
# Line 215 | Line 238 | interp2_analyze(INTERP2 *ip)
238   static double
239   get_wt(const INTERP2 *ip, const int i, double x, double y)
240   {
241 <        double  dir, rd, d2;
241 >        double  dir, rd, r2, d2;
242          int     ri;
243                                  /* get relative direction */
244          x -= ip->spt[i][0];
# Line 228 | Line 251 | get_wt(const INTERP2 *ip, const int i, double x, doubl
251          rd -= (double)ri;
252          rd = (1.-rd)*ip->da[i][ri] + rd*ip->da[i][(ri+1)%NI2DIR];
253          rd = ip->smf * DECODE_DIA(ip, rd);
254 +        r2 = 2.*rd*rd;
255          d2 = x*x + y*y;
256 +        if (d2 > 21.*r2)        /* result would be < 1e-9 */
257 +                return(.0);
258                                  /* Gaussian times harmonic weighting */
259 <        return( exp(d2/(-2.*rd*rd)) * ip->dmin/(ip->dmin + sqrt(d2)) );
259 >        return( exp(-d2/r2) * ip->dmin/(ip->dmin + sqrt(d2)) );
260   }
261  
262   /* Assign full set of normalized weights to interpolate the given position */
# Line 277 | Line 303 | interp2_topsamp(float wt[], int si[], const int n, INT
303                                          /* identify top n weights */
304          for (i = ip->ns; i--; ) {
305                  const double    wti = get_wt(ip, i, x, y);
306 +                if (wti <= 1e-9)
307 +                        continue;
308                  for (j = nn; j > 0; j--) {
309                          if (wt[j-1] >= wti)
310                                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines