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

Comparing ray/src/cv/bsdfmesh.c (file contents):
Revision 2.5 by greg, Thu Nov 8 23:32:30 2012 UTC vs.
Revision 2.9 by greg, Fri Jun 28 23:18:51 2013 UTC

# Line 119 | Line 119 | run_subprocess(void)
119                  if (pid < 0) {
120                          fprintf(stderr, "%s: cannot fork subprocess\n",
121                                          progname);
122 +                        await_children(nchild);
123                          exit(1);
124                  }
125                  ++nchild;                       /* subprocess started */
# Line 172 | Line 173 | price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, co
173              FVECT               vfrom;
174              ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy);
175              for (j = to_rbf->nrbf; j--; ) {
176 <                pricerow(pm,i)[j] = acos(DOT(vfrom, vto[j])) +
176 >                double          dprod = DOT(vfrom, vto[j]);
177 >                pricerow(pm,i)[j] = ((dprod >= 1.) ? .0 : acos(dprod)) +
178                                  fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang);
179                  psortrow(pm,i)[j] = j;
180              }
# Line 271 | Line 273 | migration_step(MIGRATION *mig, double *src_rem, double
273          return(best.amt);
274   }
275  
274 #ifdef DEBUG
275 static char *
276 thetaphi(const FVECT v)
277 {
278        static char     buf[128];
279        double          theta, phi;
280
281        theta = 180./M_PI*acos(v[2]);
282        phi = 180./M_PI*atan2(v[1],v[0]);
283        sprintf(buf, "(%.0f,%.0f)", theta, phi);
284
285        return(buf);
286 }
287 #endif
288
276   /* Compute and insert migration along directed edge (may fork child) */
277   static MIGRATION *
278   create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
# Line 295 | Line 282 | create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
282          MIGRATION       *newmig;
283          double          *src_rem, *dst_rem;
284          double          total_rem = 1., move_amt;
285 <        int             i;
285 >        int             i, j;
286                                                  /* check if exists already */
287          for (newmig = from_rbf->ejl; newmig != NULL;
288                          newmig = nextedge(from_rbf,newmig))
289                  if (newmig->rbfv[1] == to_rbf)
290                          return(NULL);
291                                                  /* else allocate */
292 + #ifdef DEBUG
293 +        fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ",
294 +                        get_theta180(from_rbf->invec),
295 +                        get_phi360(from_rbf->invec));
296 +        fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n",
297 +                        get_theta180(to_rbf->invec),
298 +                        get_phi360(to_rbf->invec),
299 +                        from_rbf->nrbf, to_rbf->nrbf);
300 + #endif
301          newmig = new_migration(from_rbf, to_rbf);
302          if (run_subprocess())
303                  return(newmig);                 /* child continues */
# Line 313 | Line 309 | create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
309                                  progname);
310                  exit(1);
311          }
316 #ifdef DEBUG
317        fprintf(stderr, "Building path from (theta,phi) %s ",
318                        thetaphi(from_rbf->invec));
319        fprintf(stderr, "to %s with %d x %d matrix\n",
320                        thetaphi(to_rbf->invec),
321                        from_rbf->nrbf, to_rbf->nrbf);
322 #endif
312                                                  /* starting quantities */
313          memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf);
314          for (i = from_rbf->nrbf; i--; )
315                  src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal;
316 <        for (i = to_rbf->nrbf; i--; )
317 <                dst_rem[i] = rbf_volume(&to_rbf->rbfa[i]) / to_rbf->vtotal;
316 >        for (j = to_rbf->nrbf; j--; )
317 >                dst_rem[j] = rbf_volume(&to_rbf->rbfa[j]) / to_rbf->vtotal;
318 >
319          do {                                    /* move a bit at a time */
320                  move_amt = migration_step(newmig, src_rem, dst_rem, &pmtx);
321                  total_rem -= move_amt;
332 #ifdef DEBUG
333                if (!nchild)
334                        fprintf(stderr, "\r%.9f remaining...", total_rem);
335 #endif
322          } while ((total_rem > end_thresh) & (move_amt > 0));
323 < #ifdef DEBUG
338 <        if (!nchild) fputs("done.\n", stderr);
339 <        else fprintf(stderr, "finished with %.9f remaining\n", total_rem);
340 < #endif
323 >
324          for (i = from_rbf->nrbf; i--; ) {       /* normalize final matrix */
325 <            float       nf = rbf_volume(&from_rbf->rbfa[i]);
343 <            int         j;
325 >            double      nf = rbf_volume(&from_rbf->rbfa[i]);
326              if (nf <= FTINY) continue;
327              nf = from_rbf->vtotal / nf;
328              for (j = to_rbf->nrbf; j--; )
329 <                mtx_coef(newmig,i,j) *= nf;
329 >                mtx_coef(newmig,i,j) *= nf;     /* row now sums to 1.0 */
330          }
331          end_subprocess();                       /* exit here if subprocess */
332          free_routes(&pmtx);                     /* free working arrays */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines