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.4 by greg, Sun Jun 30 14:46:29 2013 UTC vs.
Revision 2.18 by greg, Wed Mar 19 00:19:11 2014 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include <stdlib.h>
12   #include <string.h>
13   #include <ctype.h>
14 + #include <math.h>
15   #include "platform.h"
16   #include "bsdfrep.h"
17 + #include "resolu.h"
18                                  /* global argv[0] */
19   char                    *progname;
20  
# Line 23 | Line 25 | typedef struct {
25          long            dstart;         /* data start offset in file */
26   } PGINPUT;
27  
28 + double          angle_eps = 0;  /* epsilon for angle comparisons */
29 +
30   PGINPUT         *inpfile;       /* input files sorted by incidence */
31   int             ninpfiles;      /* number of input files */
32  
# Line 33 | Line 37 | cmp_inang(const void *p1, const void *p2)
37          const PGINPUT   *inp1 = (const PGINPUT *)p1;
38          const PGINPUT   *inp2 = (const PGINPUT *)p2;
39          
40 <        if (inp1->theta > inp2->theta+FTINY)
40 >        if (inp1->theta > inp2->theta+angle_eps)
41                  return(1);
42 <        if (inp1->theta < inp2->theta-FTINY)
42 >        if (inp1->theta < inp2->theta-angle_eps)
43                  return(-1);
44 <        if (inp1->phi > inp2->phi+FTINY)
44 >        if (inp1->phi > inp2->phi+angle_eps)
45                  return(1);
46 <        if (inp1->phi < inp2->phi-FTINY)
46 >        if (inp1->phi < inp2->phi-angle_eps)
47                  return(-1);
48          return(0);
49   }
# Line 62 | Line 66 | init_pabopto_inp(const int i, const char *fname)
66          inpfile[i].theta = inpfile[i].phi = -10001.;
67                                  /* read header information */
68          while ((c = getc(fp)) == '#' || c == EOF) {
69 +                char    typ[32];
70                  if (fgets(buf, sizeof(buf), fp) == NULL) {
71                          fputs(fname, stderr);
72                          fputs(": unexpected EOF\n", stderr);
73                          fclose(fp);
74                          return(0);
75                  }
76 <                if (!strcmp(buf, "format: theta phi DSF\n")) {
72 <                        inpfile[i].isDSF = 1;
76 >                if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1)
77                          continue;
78 +                if (sscanf(buf, "format: theta phi %s", typ) == 1) {
79 +                        if (!strcasecmp(typ, "DSF")) {
80 +                                inpfile[i].isDSF = 1;
81 +                                continue;
82 +                        }
83 +                        if (!strcasecmp(typ, "BSDF")) {
84 +                                inpfile[i].isDSF = 0;
85 +                                continue;
86 +                        }
87                  }
75                if (!strcmp(buf, "format: theta phi BSDF\n")) {
76                        inpfile[i].isDSF = 0;
77                        continue;
78                }
88                  if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1)
89                          continue;
90                  if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1)
# Line 115 | Line 124 | add_pabopto_inp(const int i)
124                  return(0);
125          }
126                                          /* prepare input grid */
127 +        angle_eps = 180./2./GRIDRES;
128          if (!i || cmp_inang(&inpfile[i-1], &inpfile[i])) {
129                  if (i)                  /* need to process previous incidence */
130                          make_rbfrep();
# Line 141 | Line 151 | add_pabopto_inp(const int i)
151          return(1);
152   }
153  
154 + #ifndef TEST_MAIN
155   /* Read in PAB-Opto BSDF files and output RBF interpolant */
156   int
157   main(int argc, char *argv[])
# Line 173 | Line 184 | main(int argc, char *argv[])
184          for (i = 0; i < ninpfiles; i++)
185                  if (!init_pabopto_inp(i, argv[i+1]))
186                          return(1);
187 +        angle_eps = 0;
188          qsort(inpfile, ninpfiles, sizeof(PGINPUT), &cmp_inang);
189                                                  /* compile measurements */
190          for (i = 0; i < ninpfiles; i++)
# Line 187 | Line 199 | userr:
199                                          progname);
200          return(1);
201   }
202 + #else
203 + /* Test main produces a Radiance model from the given input file */
204 + int
205 + main(int argc, char *argv[])
206 + {
207 +        PGINPUT pginp;
208 +        char    buf[128];
209 +        FILE    *pfp;
210 +        double  bsdf, min_log;
211 +        FVECT   dir;
212 +        int     i, j, n;
213 +
214 +        if (argc != 2) {
215 +                fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]);
216 +                return(1);
217 +        }
218 +        ninpfiles = 1;
219 +        inpfile = &pginp;
220 +        if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0))
221 +                return(1);
222 +                                                /* reduce data set */
223 +        make_rbfrep();
224 + #ifdef DEBUG
225 +        fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min);
226 + #endif
227 +        min_log = log(bsdf_min*.5 + 1e-5);
228 + #if 1                                           /* produce spheres at meas. */
229 +        puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n");
230 +        n = 0;
231 +        for (i = 0; i < GRIDRES; i++)
232 +            for (j = 0; j < GRIDRES; j++)
233 +                if (dsf_grid[i][j].sum.n > 0) {
234 +                        ovec_from_pos(dir, i, j);
235 +                        bsdf = dsf_grid[i][j].sum.v /
236 +                                (dsf_grid[i][j].sum.n*output_orient*dir[2]);
237 +                        if (bsdf <= bsdf_min*.6)
238 +                                continue;
239 +                        bsdf = log(bsdf + 1e-5) - min_log;
240 +                        ovec_from_pos(dir, i, j);
241 +                        printf("yellow sphere s%04d\n0\n0\n", ++n);
242 +                        printf("4 %.6g %.6g %.6g %.6g\n\n",
243 +                                        dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
244 +                                        .007*bsdf);
245 +                }
246 + #endif
247 + #if 1                                           /* spheres at RBF peaks */
248 +        puts("void plastic red\n0\n0\n5 .8 .01 .01 .04 .08\n");
249 +        for (n = 0; n < dsf_list->nrbf; n++) {
250 +                RBFVAL  *rbf = &dsf_list->rbfa[n];
251 +                ovec_from_pos(dir, rbf->gx, rbf->gy);
252 +                bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]);
253 +                bsdf = log(bsdf + 1e-5) - min_log;
254 +                printf("red sphere p%04d\n0\n0\n", ++n);
255 +                printf("4 %.6g %.6g %.6g %.6g\n\n",
256 +                                dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
257 +                                .011*bsdf);
258 +        }
259 + #endif
260 + #if 1                                           /* output continuous surface */
261 +        puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n");
262 +        fflush(stdout);
263 +        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
264 +        pfp = popen(buf, "w");
265 +        if (pfp == NULL) {
266 +                fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf);
267 +                return(1);
268 +        }
269 +        for (i = 0; i < GRIDRES; i++)
270 +            for (j = 0; j < GRIDRES; j++) {
271 +                ovec_from_pos(dir, i, j);
272 +                bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]);
273 +                bsdf = log(bsdf + 1e-5) - min_log;
274 +                fprintf(pfp, "%.8e %.8e %.8e\n",
275 +                                dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf);
276 +            }
277 +        if (pclose(pfp) != 0)
278 +                return(1);
279 + #endif
280 +        return(0);
281 + }
282 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines