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.29 by greg, Tue Feb 2 00:42:11 2016 UTC vs.
Revision 2.39 by greg, Thu Feb 25 02:13:15 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 <        pos_from_vec(inpfile[i].igp, dv);
140 >        set_grid_pos(&inpfile[i]);
141          return(1);
142   }
143  
# Line 173 | 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 188 | 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;
228 <                                                /* start header */
229 <        SET_FILE_BINARY(stdout);
230 <        newheader("RADIANCE", stdout);
200 <        printargs(argc, argv, stdout);
201 <        fputnow(stdout);
227 >        const char      *symmetry = "0";
228 >        int             ninpfiles, totinc;
229 >        int             a, i;
230 >
231          progname = argv[0];                     /* get options */
232 <        while (argc > 2 && argv[1][0] == '-') {
233 <                switch (argv[1][1]) {
232 >        for (a = 1; a < argc && argv[a][0] == '-'; a++)
233 >                switch (argv[a][1]) {
234                  case 't':
235                          rev_orient = !rev_orient;
236                          break;
237                  case 'n':
238 <                        nprocs = atoi(argv[2]);
210 <                        argv++; argc--;
238 >                        nprocs = atoi(argv[++a]);
239                          break;
240 +                case 's':
241 +                        symmetry = argv[++a];
242 +                        break;
243                  default:
244                          goto userr;
245                  }
246 <                argv++; argc--;
216 <        }
217 <                                                /* initialize & sort inputs */
218 <        ninpfiles = argc - 1;
246 >        totinc = ninpfiles = argc - a;          /* initialize & sort inputs */
247          if (ninpfiles < 2)
248                  goto userr;
249 <        inpfile = (PGINPUT *)malloc(sizeof(PGINPUT)*ninpfiles);
249 >        if (toupper(symmetry[0]) == SYM_UP)     /* special case for "up" symmetry */
250 >                totinc += ninpfiles;
251 >        inpfile = (PGINPUT *)malloc(sizeof(PGINPUT)*totinc);
252          if (inpfile == NULL)
253                  return(1);
254          for (i = 0; i < ninpfiles; i++)
255 <                if (!init_pabopto_inp(i, argv[i+1]))
255 >                if (!init_pabopto_inp(i, argv[a+i]))
256                          return(1);
257 <        qsort(inpfile, ninpfiles, sizeof(PGINPUT), cmp_indir);
257 >
258 >        for (i = ninpfiles; i < totinc; i++) {  /* copy for "up" symmetry */
259 >                inpfile[i] = inpfile[i-ninpfiles];
260 >                inpfile[i].phi += 180.;         /* invert duplicate data */
261 >                inpfile[i].up_phi -= 180.;
262 >                set_grid_pos(&inpfile[i]);      /* grid location for sorting */
263 >        }
264 >        qsort(inpfile, totinc, sizeof(PGINPUT), cmp_indir);
265                                                  /* compile measurements */
266 <        for (i = 0; i < ninpfiles; i++)
266 >        for (i = 0; i < totinc; i++)
267                  if (!add_pabopto_inp(i))
268                          return(1);
269          make_rbfrep();                          /* process last data set */
270 +                                                /* check input symmetry */
271 +        switch (toupper(symmetry[0])) {
272 +        case '0':                               /* unspecified symmetry */
273 +                if (quadrant_sym[inp_coverage] != SYM_ILL)
274 +                        break;                  /* anything legal goes */
275 +                fprintf(stderr, "%s: unsupported phi coverage (%s)\n",
276 +                                progname, quadrant_rep[inp_coverage]);
277 +                return(1);
278 +        case SYM_UP:                            /* faux "up" symmetry */
279 +                if (quadrant_sym[inp_coverage] == SYM_ANISO)
280 +                        break;
281 +                /* fall through */
282 +        case SYM_ISO:                           /* usual symmetry types */
283 +        case SYM_QUAD:
284 +        case SYM_BILAT:
285 +        case SYM_ANISO:
286 +                if (quadrant_sym[inp_coverage] == toupper(symmetry[0]))
287 +                        break;                  /* matches spec */
288 +                fprintf(stderr,
289 +                "%s: phi coverage (%s) does not match requested '%s' symmetry\n",
290 +                                progname, quadrant_rep[inp_coverage], symmetry);
291 +                return(1);
292 +        default:
293 +                fprintf(stderr,
294 +  "%s: -s option must be Isotropic, Quadrilateral, Bilateral, Up, or Anisotropic\n",
295 +                                progname);
296 +                return(1);
297 +        }
298 + #ifdef DEBUG
299 +        fprintf(stderr, "Input phi coverage (%s) has '%c' symmetry\n",
300 +                                quadrant_rep[inp_coverage],
301 +                                quadrant_sym[inp_coverage]);
302 + #endif
303          build_mesh();                           /* create interpolation */
304 <        save_bsdf_rep(stdout);                  /* write it out */
304 >        SET_FILE_BINARY(stdout);                /* start header */
305 >        newheader("RADIANCE", stdout);
306 >        printargs(argc, argv, stdout);
307 >        fputnow(stdout);
308 >        save_bsdf_rep(stdout);                  /* complete header + data */
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 255 | Line 331 | main(int argc, char *argv[])
331                  fprintf(stderr, "Usage: %s input.dat > output.rad\n", progname);
332                  return(1);
333          }
258        ninpfiles = 1;
334          inpfile = &pginp;
335          if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0))
336                  return(1);
# Line 322 | 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