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.2 by greg, Sat Oct 20 07:02:00 2012 UTC vs.
Revision 2.5 by greg, Wed Nov 7 03:04:23 2012 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include "rtio.h"
15   #include "resolu.h"
16   #include "bsdfrep.h"
17 <                                /* which quadrants are represented */
17 >                                /* active grid resolution */
18 > int                     grid_res = GRIDRES;
19 >
20 >                                /* coverage/symmetry using INP_QUAD? flags */
21   int                     inp_coverage = 0;
22                                  /* all incident angles in-plane so far? */
23   int                     single_plane_incident = -1;
# Line 168 | Line 171 | rev_rbf_symmetry(RBFNODE *rbf, int sym)
171          rev_symmetry(rbf->invec, sym);
172          if (sym & MIRROR_X)
173                  for (n = rbf->nrbf; n-- > 0; )
174 <                        rbf->rbfa[n].gx = GRIDRES-1 - rbf->rbfa[n].gx;
174 >                        rbf->rbfa[n].gx = grid_res-1 - rbf->rbfa[n].gx;
175          if (sym & MIRROR_Y)
176                  for (n = rbf->nrbf; n-- > 0; )
177 <                        rbf->rbfa[n].gy = GRIDRES-1 - rbf->rbfa[n].gy;
177 >                        rbf->rbfa[n].gy = grid_res-1 - rbf->rbfa[n].gy;
178   }
179  
180   /* Compute volume associated with Gaussian lobe */
# Line 190 | Line 193 | ovec_from_pos(FVECT vec, int xpos, int ypos)
193          double  uv[2];
194          double  r2;
195          
196 <        SDsquare2disk(uv, (1./GRIDRES)*(xpos+.5), (1./GRIDRES)*(ypos+.5));
196 >        SDsquare2disk(uv, (1./grid_res)*(xpos+.5), (1./grid_res)*(ypos+.5));
197                                  /* uniform hemispherical projection */
198          r2 = uv[0]*uv[0] + uv[1]*uv[1];
199          vec[0] = vec[1] = sqrt(2. - r2);
# Line 208 | Line 211 | pos_from_vec(int pos[2], const FVECT vec)
211  
212          SDdisk2square(sq, vec[0]*norm, vec[1]*norm);
213  
214 <        pos[0] = (int)(sq[0]*GRIDRES);
215 <        pos[1] = (int)(sq[1]*GRIDRES);
214 >        pos[0] = (int)(sq[0]*grid_res);
215 >        pos[1] = (int)(sq[1]*grid_res);
216   }
217  
218   /* Evaluate RBF for DSF at the given normalized outgoing direction */
# Line 281 | Line 284 | get_dsf(int ord)
284          RBFNODE         *rbf;
285  
286          for (rbf = dsf_list; rbf != NULL; rbf = rbf->next)
287 <                if (rbf->ord == ord);
287 >                if (rbf->ord == ord)
288                          return(rbf);
289          return(NULL);
290   }
# Line 312 | Line 315 | is_rev_tri(const FVECT v1, const FVECT v2, const FVECT
315   int
316   get_triangles(RBFNODE *rbfv[2], const MIGRATION *mig)
317   {
318 <        const MIGRATION *ej, *ej2;
318 >        const MIGRATION *ej1, *ej2;
319          RBFNODE         *tv;
320  
321          rbfv[0] = rbfv[1] = NULL;
322          if (mig == NULL)
323                  return(0);
324 <        for (ej = mig->rbfv[0]->ejl; ej != NULL;
325 <                                ej = nextedge(mig->rbfv[0],ej)) {
326 <                if (ej == mig)
324 >        for (ej1 = mig->rbfv[0]->ejl; ej1 != NULL;
325 >                                ej1 = nextedge(mig->rbfv[0],ej1)) {
326 >                if (ej1 == mig)
327                          continue;
328 <                tv = opp_rbf(mig->rbfv[0],ej);
328 >                tv = opp_rbf(mig->rbfv[0],ej1);
329                  for (ej2 = tv->ejl; ej2 != NULL; ej2 = nextedge(tv,ej2))
330                          if (opp_rbf(tv,ej2) == mig->rbfv[1]) {
331                                  rbfv[is_rev_tri(mig->rbfv[0]->invec,
# Line 334 | Line 337 | get_triangles(RBFNODE *rbfv[2], const MIGRATION *mig)
337          return((rbfv[0] != NULL) + (rbfv[1] != NULL));
338   }
339  
340 + /* Clear our BSDF representation and free memory */
341 + void
342 + clear_bsdf_rep(void)
343 + {
344 +        while (mig_list != NULL) {
345 +                MIGRATION       *mig = mig_list;
346 +                mig_list = mig->next;
347 +                free(mig);
348 +        }
349 +        while (dsf_list != NULL) {
350 +                RBFNODE         *rbf = dsf_list;
351 +                dsf_list = rbf->next;
352 +                free(rbf);
353 +        }
354 +        inp_coverage = 0;
355 +        single_plane_incident = -1;
356 +        input_orient = output_orient = 0;
357 +        grid_res = GRIDRES;
358 + }
359 +
360   /* Write our BSDF mesh interpolant out to the given binary stream */
361   void
362   save_bsdf_rep(FILE *ofp)
# Line 344 | Line 367 | save_bsdf_rep(FILE *ofp)
367                                          /* finish header */
368          fprintf(ofp, "SYMMETRY=%d\n", !single_plane_incident * inp_coverage);
369          fprintf(ofp, "IO_SIDES= %d %d\n", input_orient, output_orient);
370 +        fprintf(ofp, "GRIDRES=%d\n", grid_res);
371          fputformat(BSDFREP_FMT, ofp);
372          fputc('\n', ofp);
373                                          /* write each DSF */
# Line 370 | Line 394 | save_bsdf_rep(FILE *ofp)
394                                          /* write out as sparse data */
395                  n = mtx_nrows(mig) * mtx_ncols(mig);
396                  for (i = 0; i < n; i++) {
397 <                        if (zerocnt >= 0xff) {
398 <                                putint(zerocnt, 1, ofp); zerocnt = 0;
397 >                        if (zerocnt == 0xff) {
398 >                                putint(0xff, 1, ofp); zerocnt = 0;
399                          }
400                          if (mig->mtx[i] != 0) {
401                                  putint(zerocnt, 1, ofp); zerocnt = 0;
# Line 405 | Line 429 | headline(char *s, void *p)
429                  sscanf(s+9, "%d %d", &input_orient, &output_orient);
430                  return(0);
431          }
432 +        if (!strncmp(s, "GRIDRES=", 8)) {
433 +                sscanf(s+8, "%d", &grid_res);
434 +                return(0);
435 +        }
436          if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT))
437                  return(-1);
438          return(0);
# Line 417 | Line 445 | load_bsdf_rep(FILE *ifp)
445          RBFNODE         rbfh;
446          int             from_ord, to_ord;
447          int             i;
448 < #ifdef DEBUG
449 <        if ((dsf_list != NULL) | (mig_list != NULL)) {
450 <                fprintf(stderr,
423 <                "%s: attempt to load BSDF interpolant over existing\n",
424 <                                progname);
448 >
449 >        clear_bsdf_rep();
450 >        if (ifp == NULL)
451                  return(0);
426        }
427 #endif
428        input_orient = output_orient = 0;
429        single_plane_incident = -1;
452          if (getheader(ifp, headline, NULL) < 0 || single_plane_incident < 0 |
453                          !input_orient | !output_orient) {
454                  fprintf(stderr, "%s: missing/bad format for BSDF interpolant\n",
# Line 441 | Line 463 | load_bsdf_rep(FILE *ifp)
463                  rbfh.invec[0] = getflt(ifp);
464                  rbfh.invec[1] = getflt(ifp);
465                  rbfh.invec[2] = getflt(ifp);
466 +                rbfh.vtotal = getflt(ifp);
467                  rbfh.nrbf = getint(4, ifp);
445                if (!new_input_vector(rbfh.invec))
446                        return(0);
468                  newrbf = (RBFNODE *)malloc(sizeof(RBFNODE) +
469                                          sizeof(RBFVAL)*(rbfh.nrbf-1));
470                  if (newrbf == NULL)
# Line 487 | Line 508 | load_bsdf_rep(FILE *ifp)
508                  memset(newmig->mtx, 0, sizeof(float)*n);
509                  for (i = 0; ; ) {       /* read sparse data */
510                          int     zc = getint(1, ifp) & 0xff;
490                        if (zc == 0xff) {
491                                i += 0xff;
492                                continue;
493                        }
511                          if ((i += zc) >= n)
512                                  break;
513 +                        if (zc == 0xff)
514 +                                continue;
515                          newmig->mtx[i++] = getflt(ifp);
516                  }
517                  if (feof(ifp))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines