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.7 by greg, Mon Oct 21 18:33:15 2013 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                                  /* global argv[0] */
# Line 62 | Line 63 | init_pabopto_inp(const int i, const char *fname)
63          inpfile[i].theta = inpfile[i].phi = -10001.;
64                                  /* read header information */
65          while ((c = getc(fp)) == '#' || c == EOF) {
66 +                char    typ[32];
67                  if (fgets(buf, sizeof(buf), fp) == NULL) {
68                          fputs(fname, stderr);
69                          fputs(": unexpected EOF\n", stderr);
70                          fclose(fp);
71                          return(0);
72                  }
73 <                if (!strcmp(buf, "format: theta phi DSF\n")) {
74 <                        inpfile[i].isDSF = 1;
75 <                        continue;
73 >                if (sscanf(buf, "format: theta phi %s", typ) == 1) {
74 >                        if (!strcasecmp(typ, "DSF")) {
75 >                                inpfile[i].isDSF = 1;
76 >                                continue;
77 >                        }
78 >                        if (!strcasecmp(typ, "BSDF")) {
79 >                                inpfile[i].isDSF = 0;
80 >                                continue;
81 >                        }
82                  }
75                if (!strcmp(buf, "format: theta phi BSDF\n")) {
76                        inpfile[i].isDSF = 0;
77                        continue;
78                }
83                  if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1)
84                          continue;
85                  if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1)
# Line 141 | Line 145 | add_pabopto_inp(const int i)
145          return(1);
146   }
147  
148 + #if 1
149   /* Read in PAB-Opto BSDF files and output RBF interpolant */
150   int
151   main(int argc, char *argv[])
# Line 187 | Line 192 | userr:
192                                          progname);
193          return(1);
194   }
195 + #else
196 + /* Test main produces a Radiance model from the given input file */
197 + int
198 + main(int argc, char *argv[])
199 + {
200 +        PGINPUT pginp;
201 +        char    buf[128];
202 +        FILE    *pfp;
203 +        double  bsdf, min_log;
204 +        FVECT   dir;
205 +        int     i, j, n;
206 +
207 +        if (argc != 2) {
208 +                fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]);
209 +                return(1);
210 +        }
211 +        ninpfiles = 1;
212 +        inpfile = &pginp;
213 +        if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0))
214 +                return(1);
215 +                                                /* reduce data set */
216 +        make_rbfrep();
217 +                                                /* produce spheres at meas. */
218 +        puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n");
219 +        min_log = log(bsdf_min*.5);
220 +        n = 0;
221 +        for (i = 0; i < GRIDRES; i++)
222 +            for (j = 0; j < GRIDRES; j++)
223 +                if (dsf_grid[i][j].nval > 0) {
224 +                        ovec_from_pos(dir, i, j);
225 +                        bsdf = dsf_grid[i][j].vsum/(dsf_grid[i][j].nval*dir[2]);
226 +                        if (bsdf <= bsdf_min*.6)
227 +                                continue;
228 +                        bsdf = log(bsdf) - min_log;
229 +                        ovec_from_pos(dir, i, j);
230 +                        printf("yellow sphere s%04d\n0\n0\n", ++n);
231 +                        printf("4 %.6g %.6g %.6g %.6g\n\n",
232 +                                        dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
233 +                                        .007*bsdf);
234 +                }
235 +                                                /* output continuous surface */
236 +        puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n");
237 +        fflush(stdout);
238 +        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
239 +        pfp = popen(buf, "w");
240 +        if (pfp == NULL) {
241 +                fputs(buf, stderr);
242 +                fputs(": cannot start command\n", stderr);
243 +                return(1);
244 +        }
245 +        for (i = 0; i < GRIDRES; i++)
246 +            for (j = 0; j < GRIDRES; j++) {
247 +                ovec_from_pos(dir, i, j);
248 +                bsdf = eval_rbfrep(dsf_list, dir) / dir[2];
249 +                bsdf = log(bsdf) - min_log;
250 +                fprintf(pfp, "%.8e %.8e %.8e\n",
251 +                                dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf);
252 +            }
253 +        return(pclose(pfp)==0 ? 0 : 1);
254 + }
255 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines