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.1 by greg, Fri Oct 19 04:14:29 2012 UTC vs.
Revision 2.2 by greg, Tue Nov 13 04:23:38 2012 UTC

# Line 193 | Line 193 | make_rbfrep(void)
193          double  lastVar, thisVar = 100.;
194          int     nn;
195          RBFNODE *newnode;
196 +        RBFVAL  *itera;
197          int     i, j;
198                                  /* compute RBF radii */
199          compute_radii();
# Line 204 | Line 205 | make_rbfrep(void)
205                  nn += dsf_grid[i][j].nval;
206                                  /* allocate RBF array */
207          newnode = (RBFNODE *)malloc(sizeof(RBFNODE) + sizeof(RBFVAL)*(nn-1));
208 <        if (newnode == NULL) {
209 <                fprintf(stderr, "%s: Out of memory in make_rbfrep()\n", progname);
209 <                exit(1);
210 <        }
208 >        if (newnode == NULL)
209 >                goto memerr;
210          newnode->ord = -1;
211          newnode->next = NULL;
212          newnode->ejl = NULL;
# Line 228 | Line 227 | make_rbfrep(void)
227                          ++nn;
228                  }
229                                  /* iterate to improve interpolation accuracy */
230 +        itera = (RBFVAL *)malloc(sizeof(RBFVAL)*newnode->nrbf);
231 +        if (itera == NULL)
232 +                goto memerr;
233 +        memcpy(itera, newnode->rbfa, sizeof(RBFVAL)*newnode->nrbf);
234          do {
235                  double  dsum = 0, dsum2 = 0;
236                  nn = 0;
# Line 237 | Line 240 | make_rbfrep(void)
240                                  FVECT   odir;
241                                  double  corr;
242                                  ovec_from_pos(odir, i, j);
243 <                                newnode->rbfa[nn++].peak *= corr =
243 >                                itera[nn++].peak *= corr =
244                                          dsf_grid[i][j].vsum /
245                                                  eval_rbfrep(newnode, odir);
246 <                                dsum += corr - 1.;
247 <                                dsum2 += (corr-1.)*(corr-1.);
246 >                                dsum += 1. - corr;
247 >                                dsum2 += (1.-corr)*(1.-corr);
248                          }
249 +                memcpy(newnode->rbfa, itera, sizeof(RBFVAL)*newnode->nrbf);
250                  lastVar = thisVar;
251                  thisVar = dsum2/(double)nn;
252   #ifdef DEBUG
# Line 252 | Line 256 | make_rbfrep(void)
256   #endif
257          } while (--niter > 0 && lastVar-thisVar > 0.02*lastVar);
258  
259 +        free(itera);
260          nn = 0;                 /* compute sum for normalization */
261          while (nn < newnode->nrbf)
262                  newnode->vtotal += rbf_volume(&newnode->rbfa[nn++]);
# Line 259 | Line 264 | make_rbfrep(void)
264          insert_dsf(newnode);
265  
266          return(newnode);
267 + memerr:
268 +        fprintf(stderr, "%s: Out of memory in make_rbfrep()\n", progname);
269 +        exit(1);
270   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines