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

Comparing ray/src/cv/pabopto2bsdf.c (file contents):
Revision 2.27 by greg, Fri Oct 3 21:57:06 2014 UTC vs.
Revision 2.29 by greg, Tue Feb 2 00:42:11 2016 UTC

# Line 3 | Line 3 | static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   * Load measured BSDF data in PAB-Opto format.
6 + * Assumes that surface-normal (Z-axis) faces into room unless -t option given.
7   *
8   *      G. Ward
9   */
# Line 25 | Line 26 | typedef struct {
26          double          up_phi;         /* azimuth for "up" direction */
27          int             igp[2];         /* input grid position */
28          int             isDSF;          /* data is DSF (rather than BSDF)? */
29 +        int             nspec;          /* number of spectral samples */
30          long            dstart;         /* data start offset in file */
31   } PGINPUT;
32  
33   PGINPUT         *inpfile;       /* input files sorted by incidence */
34   int             ninpfiles;      /* number of input files */
35  
36 + int             rev_orient = 0; /* shall we reverse surface orientation? */
37 +
38   /* Compare incident angles */
39   static int
40   cmp_indir(const void *p1, const void *p2)
# Line 61 | Line 65 | init_pabopto_inp(const int i, const char *fname)
65          }
66          inpfile[i].fname = fname;
67          inpfile[i].isDSF = -1;
68 +        inpfile[i].nspec = 0;
69          inpfile[i].up_phi = 0;
70          inpfile[i].theta = inpfile[i].phi = -10001.;
71                                  /* read header information */
72          while ((c = getc(fp)) == '#' || c == EOF) {
73 <                char    typ[32];
73 >                char    typ[64];
74                  if (fgets(buf, sizeof(buf), fp) == NULL) {
75                          fputs(fname, stderr);
76                          fputs(": unexpected EOF\n", stderr);
# Line 74 | Line 79 | init_pabopto_inp(const int i, const char *fname)
79                  }
80                  if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1)
81                          continue;
82 +                if (sscanf(buf, "colorimetry: %s", typ) == 1) {
83 +                        if (!strcasecmp(typ, "CIE-XYZ"))
84 +                                inpfile[i].nspec = 3;
85 +                        else if (!strcasecmp(typ, "CIE-Y"))
86 +                                inpfile[i].nspec = 1;
87 +                        continue;
88 +                }
89                  if (sscanf(buf, "format: theta phi %s", typ) == 1) {
90 <                        if (!strcasecmp(typ, "DSF")) {
90 >                        if (!strcasecmp(typ, "DSF"))
91                                  inpfile[i].isDSF = 1;
92 <                                continue;
81 <                        }
82 <                        if (!strcasecmp(typ, "BSDF") ||
92 >                        else if (!strcasecmp(typ, "BSDF") ||
93                                          !strcasecmp(typ, "BRDF") ||
94 <                                        !strcasecmp(typ, "BTDF")) {
94 >                                        !strcasecmp(typ, "BTDF"))
95                                  inpfile[i].isDSF = 0;
96 <                                continue;
87 <                        }
96 >                        continue;
97                  }
98                  if (sscanf(buf, "upphi %lf", &inpfile[i].up_phi) == 1)
99                          continue;
# Line 108 | Line 117 | init_pabopto_inp(const int i, const char *fname)
117                  fputs(": unknown incident angle\n", stderr);
118                  return(0);
119          }
120 +        if (rev_orient) {       /* reverse Z-axis to face outside */
121 +                inpfile[i].theta = 180. - inpfile[i].theta;
122 +                inpfile[i].phi = 360. - inpfile[i].phi;
123 +        }
124                                  /* convert to Y-up orientation */
125          inpfile[i].phi += 90.-inpfile[i].up_phi;
126                                  /* convert angle to grid position */
# Line 124 | Line 137 | static int
137   add_pabopto_inp(const int i)
138   {
139          FILE            *fp = fopen(inpfile[i].fname, "r");
140 <        double          theta_out, phi_out, val;
140 >        double          theta_out, phi_out, val[3];
141          int             n, c;
142          
143          if (fp == NULL || fseek(fp, inpfile[i].dstart, 0) == EOF) {
# Line 140 | Line 153 | add_pabopto_inp(const int i)
153                  fprintf(stderr, "New incident (theta,phi)=(%.1f,%.1f)\n",
154                                          inpfile[i].theta, inpfile[i].phi);
155   #endif
156 +                if (inpfile[i].nspec)
157 +                        set_spectral_samples(inpfile[i].nspec);
158                  new_bsdf_data(inpfile[i].theta, inpfile[i].phi);
159          }
160   #ifdef DEBUG
161          fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname);
162   #endif
163                                          /* read scattering data */
164 <        while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3)
164 >        while (fscanf(fp, "%lf %lf %lf", &theta_out, &phi_out, val) == 3) {
165 >                for (n = 1; n < inpfile[i].nspec; n++)
166 >                        if (fscanf(fp, "%lf", val+n) != 1) {
167 >                                fprintf(stderr, "%s: warning: unexpected EOF\n",
168 >                                                inpfile[i].fname);
169 >                                fclose(fp);
170 >                                return(1);
171 >                        }
172 >                if (rev_orient) {       /* reverse Z-axis to face outside */
173 >                        theta_out = 180. - theta_out;
174 >                        phi_out = 360. - phi_out;
175 >                }
176                  add_bsdf_data(theta_out, phi_out+90.-inpfile[i].up_phi,
177                                  val, inpfile[i].isDSF);
178 +        }
179          n = 0;
180          while ((c = getc(fp)) != EOF)
181                  n += !isspace(c);
# Line 175 | Line 202 | main(int argc, char *argv[])
202          progname = argv[0];                     /* get options */
203          while (argc > 2 && argv[1][0] == '-') {
204                  switch (argv[1][1]) {
205 +                case 't':
206 +                        rev_orient = !rev_orient;
207 +                        break;
208                  case 'n':
209                          nprocs = atoi(argv[2]);
210 +                        argv++; argc--;
211                          break;
212                  default:
213                          goto userr;
214                  }
215 <                argv += 2; argc -= 2;
215 >                argv++; argc--;
216          }
217                                                  /* initialize & sort inputs */
218          ninpfiles = argc - 1;
# Line 203 | Line 234 | main(int argc, char *argv[])
234          save_bsdf_rep(stdout);                  /* write it out */
235          return(0);
236   userr:
237 <        fprintf(stderr, "Usage: %s [-n nproc] meas1.dat meas2.dat .. > bsdf.sir\n",
237 >        fprintf(stderr, "Usage: %s [-t][-n nproc] meas1.dat meas2.dat .. > bsdf.sir\n",
238                                          progname);
239          return(1);
240   }
# Line 240 | Line 271 | main(int argc, char *argv[])
271   #if 1                                           /* produce spheres at meas. */
272          puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n");
273          n = 0;
274 <        for (i = 0; i < GRIDRES; i++)
275 <            for (j = 0; j < GRIDRES; j++)
274 >        for (i = 0; i < grid_res; i++)
275 >            for (j = 0; j < grid_res; j++)
276                  if (dsf_grid[i][j].sum.n > 0) {
277                          ovec_from_pos(dir, i, j);
278                          bsdf = dsf_grid[i][j].sum.v /
# Line 272 | Line 303 | main(int argc, char *argv[])
303   #if 1                                           /* output continuous surface */
304          puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n");
305          fflush(stdout);
306 <        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
306 >        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", grid_res-1, grid_res-1);
307          pfp = popen(buf, "w");
308          if (pfp == NULL) {
309                  fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf);
310                  return(1);
311          }
312 <        for (i = 0; i < GRIDRES; i++)
313 <            for (j = 0; j < GRIDRES; j++) {
312 >        for (i = 0; i < grid_res; i++)
313 >            for (j = 0; j < grid_res; j++) {
314                  ovec_from_pos(dir, i, j);
315                  bsdf = eval_rbfrep(dsf_list, dir);
316                  bsdf = log(bsdf + 1e-5) - min_log;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines