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.31 by greg, Tue Mar 19 20:27:33 2019 UTC vs.
Revision 2.37 by greg, Mon Feb 15 23:20:22 2021 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   */
10  
11   #define _USE_MATH_DEFINES
12 #include <stdio.h>
12   #include <stdlib.h>
14 #include <string.h>
13   #include <ctype.h>
14   #include <math.h>
15 + #include "rtio.h"
16   #include "platform.h"
17   #include "bsdfrep.h"
19 #include "resolu.h"
18                                  /* global argv[0] */
19   char                    *progname;
20  
# Line 31 | Line 29 | typedef struct {
29   } PGINPUT;
30  
31   PGINPUT         *inpfile;       /* input files sorted by incidence */
34 int             ninpfiles;      /* number of input files */
32  
33   int             rev_orient = 0; /* shall we reverse surface orientation? */
34  
# Line 49 | Line 46 | cmp_indir(const void *p1, const void *p2)
46          return(inp1->igp[0] - inp2->igp[0]);
47   }
48  
49 + /* Assign grid position from theta and phi */
50 + static void
51 + set_grid_pos(PGINPUT *pip)
52 + {
53 +        FVECT   dv;
54 +
55 +        if (pip->theta <= FTINY) {
56 +                pip->igp[0] = pip->igp[1] = grid_res/2 - 1;
57 +                return;
58 +        }
59 +        dv[2] = sin(M_PI/180.*pip->theta);
60 +        dv[0] = cos(M_PI/180.*pip->phi)*dv[2];
61 +        dv[1] = sin(M_PI/180.*pip->phi)*dv[2];
62 +        dv[2] = sqrt(1. - dv[2]*dv[2]);
63 +        pos_from_vec(pip->igp, dv);
64 + }
65 +
66   /* Prepare a PAB-Opto input file by reading its header */
67   static int
68   init_pabopto_inp(const int i, const char *fname)
69   {
70          FILE    *fp = fopen(fname, "r");
57        FVECT   dv;
71          char    buf[2048];
72          int     c;
73          
# Line 124 | Line 137 | init_pabopto_inp(const int i, const char *fname)
137                                  /* convert to Y-up orientation */
138          inpfile[i].phi += 90.-inpfile[i].up_phi;
139                                  /* convert angle to grid position */
140 <        dv[2] = sin(M_PI/180.*inpfile[i].theta);
128 <        dv[0] = cos(M_PI/180.*inpfile[i].phi)*dv[2];
129 <        dv[1] = sin(M_PI/180.*inpfile[i].phi)*dv[2];
130 <        dv[2] = sqrt(1. - dv[2]*dv[2]);
131 <        if (inpfile[i].theta <= FTINY)
132 <                inpfile[i].igp[0] = inpfile[i].igp[1] = grid_res/2 - 1;
133 <        else
134 <                pos_from_vec(inpfile[i].igp, dv);
140 >        set_grid_pos(&inpfile[i]);
141          return(1);
142   }
143  
# Line 176 | Line 182 | add_pabopto_inp(const int i)
182                          theta_out = 180. - theta_out;
183                          phi_out = 360. - phi_out;
184                  }
185 <                add_bsdf_data(theta_out, phi_out+90.-inpfile[i].up_phi,
186 <                                val, inpfile[i].isDSF);
185 >                phi_out += 90.-inpfile[i].up_phi;
186 >                add_bsdf_data(theta_out, phi_out, val, inpfile[i].isDSF);
187          }
188          n = 0;
189          while ((c = getc(fp)) != EOF)
# Line 191 | Line 197 | add_pabopto_inp(const int i)
197   }
198  
199   #ifndef TEST_MAIN
200 +
201 + #define SYM_ILL         '?'             /* illegal symmetry value */
202 + #define SYM_ISO         'I'             /* isotropic */
203 + #define SYM_QUAD        'Q'             /* quadrilateral symmetry */
204 + #define SYM_BILAT       'B'             /* bilateral symmetry */
205 + #define SYM_ANISO       'A'             /* anisotropic */
206 + #define SYM_UP          'U'             /* "up-down" (180°) symmetry */
207 +
208 + static const char       quadrant_rep[16][16] = {
209 +                                "in-plane","0-90","90-180","0-180",
210 +                                "180-270","0-90+180-270","90-270",
211 +                                "0-270","270-360","270-90",
212 +                                "90-180+270-360","270-180","180-360",
213 +                                "180-90","90-360","0-360"
214 +                        };
215 + static const char       quadrant_sym[16] = {
216 +                                SYM_ISO, SYM_QUAD, SYM_QUAD, SYM_BILAT,
217 +                                SYM_QUAD, SYM_ILL, SYM_BILAT, SYM_ILL,
218 +                                SYM_QUAD, SYM_BILAT, SYM_ILL, SYM_ILL,
219 +                                SYM_BILAT, SYM_ILL, SYM_ILL, SYM_ANISO
220 +                        };
221 +
222   /* Read in PAB-Opto BSDF files and output RBF interpolant */
223   int
224   main(int argc, char *argv[])
225   {
226          extern int      nprocs;
227 <        int             i;
227 >        const char      *symmetry = "0";
228 >        int             ninpfiles, totinc;
229 >        int             a, i;
230                                                  /* start header */
231          SET_FILE_BINARY(stdout);
232          newheader("RADIANCE", stdout);
233          printargs(argc, argv, stdout);
234          fputnow(stdout);
235          progname = argv[0];                     /* get options */
236 <        while (argc > 2 && argv[1][0] == '-') {
237 <                switch (argv[1][1]) {
236 >        for (a = 1; a < argc && argv[a][0] == '-'; a++)
237 >                switch (argv[a][1]) {
238                  case 't':
239                          rev_orient = !rev_orient;
240                          break;
241                  case 'n':
242 <                        nprocs = atoi(argv[2]);
213 <                        argv++; argc--;
242 >                        nprocs = atoi(argv[++a]);
243                          break;
244 +                case 's':
245 +                        symmetry = argv[++a];
246 +                        break;
247                  default:
248                          goto userr;
249                  }
250 <                argv++; argc--;
219 <        }
220 <                                                /* initialize & sort inputs */
221 <        ninpfiles = argc - 1;
250 >        totinc = ninpfiles = argc - a;          /* initialize & sort inputs */
251          if (ninpfiles < 2)
252                  goto userr;
253 <        inpfile = (PGINPUT *)malloc(sizeof(PGINPUT)*ninpfiles);
253 >        if (toupper(symmetry[0]) == SYM_UP)     /* special case for "up" symmetry */
254 >                totinc += ninpfiles;
255 >        inpfile = (PGINPUT *)malloc(sizeof(PGINPUT)*totinc);
256          if (inpfile == NULL)
257                  return(1);
258          for (i = 0; i < ninpfiles; i++)
259 <                if (!init_pabopto_inp(i, argv[i+1]))
259 >                if (!init_pabopto_inp(i, argv[a+i]))
260                          return(1);
261 +
262 +        for (i = ninpfiles; i < totinc; i++) {  /* copy for "up" symmetry */
263 +                inpfile[i] = inpfile[i-ninpfiles];
264 +                inpfile[i].phi += 180.;         /* invert duplicate data */
265 +                inpfile[i].up_phi -= 180.;
266 +                set_grid_pos(&inpfile[i]);      /* grid location for sorting */
267 +        }
268          qsort(inpfile, ninpfiles, sizeof(PGINPUT), cmp_indir);
269                                                  /* compile measurements */
270 <        for (i = 0; i < ninpfiles; i++)
270 >        for (i = 0; i < totinc; i++)
271                  if (!add_pabopto_inp(i))
272                          return(1);
273          make_rbfrep();                          /* process last data set */
274 +                                                /* check input symmetry */
275 +        switch (toupper(symmetry[0])) {
276 +        case '0':                               /* unspecified symmetry */
277 +                if (quadrant_sym[inp_coverage] != SYM_ILL)
278 +                        break;                  /* anything legal goes */
279 +                fprintf(stderr, "%s: unsupported phi coverage (%s)\n",
280 +                                progname, quadrant_rep[inp_coverage]);
281 +                return(1);
282 +        case SYM_UP:                            /* faux "up" symmetry */
283 +                if (quadrant_sym[inp_coverage] == SYM_ANISO)
284 +                        break;
285 +                /* fall through */
286 +        case SYM_ISO:                           /* usual symmetry types */
287 +        case SYM_QUAD:
288 +        case SYM_BILAT:
289 +        case SYM_ANISO:
290 +                if (quadrant_sym[inp_coverage] == toupper(symmetry[0]))
291 +                        break;                  /* matches spec */
292 +                fprintf(stderr,
293 +                "%s: phi coverage (%s) does not match requested '%s' symmetry\n",
294 +                                progname, quadrant_rep[inp_coverage], symmetry);
295 +                return(1);
296 +        default:
297 +                fprintf(stderr,
298 +  "%s: -s option must be Isotropic, Quadrilateral, Bilateral, Up, or Anisotropic\n",
299 +                                progname);
300 +                return(1);
301 +        }
302 + #ifdef DEBUG
303 +        fprintf(stderr, "Input phi coverage (%s) has '%c' symmetry\n",
304 +                                quadrant_rep[inp_coverage],
305 +                                quadrant_sym[inp_coverage]);
306 + #endif
307          build_mesh();                           /* create interpolation */
308          save_bsdf_rep(stdout);                  /* write it out */
309          return(0);
310   userr:
311 <        fprintf(stderr, "Usage: %s [-t][-n nproc] meas1.dat meas2.dat .. > bsdf.sir\n",
311 >        fprintf(stderr, "Usage: %s [-t][-n nproc][-s symmetry] meas1.dat meas2.dat .. > bsdf.sir\n",
312                                          progname);
313          return(1);
314   }
315 < #else
315 >
316 > #else           /* TEST_MAIN */
317 >
318   /* Test main produces a Radiance model from the given input file */
319   int
320   main(int argc, char *argv[])
# Line 258 | Line 331 | main(int argc, char *argv[])
331                  fprintf(stderr, "Usage: %s input.dat > output.rad\n", progname);
332                  return(1);
333          }
261        ninpfiles = 1;
334          inpfile = &pginp;
335          if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0))
336                  return(1);
# Line 269 | Line 341 | main(int argc, char *argv[])
341          }
342   #ifdef DEBUG
343          fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min);
272        fprintf(stderr, "Integrated hemispherical value = %.4f\n", dsf_list->vtotal);
344   #endif
345          min_log = log(bsdf_min*.5 + 1e-5);
346   #if 1                                           /* produce spheres at meas. */
# Line 326 | Line 397 | main(int argc, char *argv[])
397   #endif
398          return(0);
399   }
400 < #endif
400 >
401 > #endif          /* TEST_MAIN */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines