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.28 by greg, Fri Jan 29 16:21:56 2016 UTC vs.
Revision 2.36 by greg, Fri Jul 19 17:37:56 2019 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   */
10  
11   #define _USE_MATH_DEFINES
11 #include <stdio.h>
12   #include <stdlib.h>
13 #include <string.h>
13   #include <ctype.h>
14   #include <math.h>
15 + #include "rtio.h"
16   #include "platform.h"
17   #include "bsdfrep.h"
18 #include "resolu.h"
18                                  /* global argv[0] */
19   char                    *progname;
20  
# Line 32 | Line 31 | typedef struct {
31   PGINPUT         *inpfile;       /* input files sorted by incidence */
32   int             ninpfiles;      /* number of input files */
33  
34 + int             rev_orient = 0; /* shall we reverse surface orientation? */
35 +
36   /* Compare incident angles */
37   static int
38   cmp_indir(const void *p1, const void *p2)
# Line 114 | Line 115 | init_pabopto_inp(const int i, const char *fname)
115                  fputs(": unknown incident angle\n", stderr);
116                  return(0);
117          }
118 +        if (rev_orient) {       /* reverse Z-axis to face outside */
119 +                inpfile[i].theta = 180. - inpfile[i].theta;
120 +                inpfile[i].phi = 360. - inpfile[i].phi;
121 +        }
122                                  /* convert to Y-up orientation */
123          inpfile[i].phi += 90.-inpfile[i].up_phi;
124                                  /* convert angle to grid position */
# Line 121 | Line 126 | init_pabopto_inp(const int i, const char *fname)
126          dv[0] = cos(M_PI/180.*inpfile[i].phi)*dv[2];
127          dv[1] = sin(M_PI/180.*inpfile[i].phi)*dv[2];
128          dv[2] = sqrt(1. - dv[2]*dv[2]);
129 <        pos_from_vec(inpfile[i].igp, dv);
129 >        if (inpfile[i].theta <= FTINY)
130 >                inpfile[i].igp[0] = inpfile[i].igp[1] = grid_res/2 - 1;
131 >        else
132 >                pos_from_vec(inpfile[i].igp, dv);
133          return(1);
134   }
135  
# Line 162 | Line 170 | add_pabopto_inp(const int i)
170                                  fclose(fp);
171                                  return(1);
172                          }
173 +                if (rev_orient) {       /* reverse Z-axis to face outside */
174 +                        theta_out = 180. - theta_out;
175 +                        phi_out = 360. - phi_out;
176 +                }
177                  add_bsdf_data(theta_out, phi_out+90.-inpfile[i].up_phi,
178                                  val, inpfile[i].isDSF);
179          }
# Line 177 | Line 189 | add_pabopto_inp(const int i)
189   }
190  
191   #ifndef TEST_MAIN
192 +
193 + #define SYM_ILL         '?'             /* illegal symmetry value */
194 + #define SYM_ISO         'I'             /* isotropic */
195 + #define SYM_QUAD        'Q'             /* quadrilateral symmetry */
196 + #define SYM_BILAT       'B'             /* bilateral symmetry */
197 + #define SYM_ANISO       'A'             /* anisotropic */
198 +
199 + static const char       quadrant_rep[16][16] = {
200 +                                "in-plane","0-90","90-180","0-180",
201 +                                "180-270","0-90+180-270","90-270",
202 +                                "0-270","270-360","270-90",
203 +                                "90-180+270-360","270-180","180-360",
204 +                                "180-90","90-360","0-360"
205 +                        };
206 + static const char       quadrant_sym[16] = {
207 +                                SYM_ISO, SYM_QUAD, SYM_QUAD, SYM_BILAT,
208 +                                SYM_QUAD, SYM_ILL, SYM_BILAT, SYM_ILL,
209 +                                SYM_QUAD, SYM_BILAT, SYM_ILL, SYM_ILL,
210 +                                SYM_BILAT, SYM_ILL, SYM_ILL, SYM_ANISO
211 +                        };
212 +
213   /* Read in PAB-Opto BSDF files and output RBF interpolant */
214   int
215   main(int argc, char *argv[])
216   {
217          extern int      nprocs;
218 +        const char      *symmetry = "U";
219          int             i;
220                                                  /* start header */
221          SET_FILE_BINARY(stdout);
# Line 191 | Line 225 | main(int argc, char *argv[])
225          progname = argv[0];                     /* get options */
226          while (argc > 2 && argv[1][0] == '-') {
227                  switch (argv[1][1]) {
228 +                case 't':
229 +                        rev_orient = !rev_orient;
230 +                        break;
231                  case 'n':
232                          nprocs = atoi(argv[2]);
233 +                        argv++; argc--;
234                          break;
235 +                case 's':
236 +                        symmetry = argv[2];
237 +                        argv++; argc--;
238 +                        break;
239                  default:
240                          goto userr;
241                  }
242 <                argv += 2; argc -= 2;
242 >                argv++; argc--;
243          }
244                                                  /* initialize & sort inputs */
245          ninpfiles = argc - 1;
# Line 215 | Line 257 | main(int argc, char *argv[])
257                  if (!add_pabopto_inp(i))
258                          return(1);
259          make_rbfrep();                          /* process last data set */
260 +                                                /* check input symmetry */
261 +        switch (toupper(symmetry[0])) {
262 +        case 'U':                               /* unspecified symmetry */
263 +                if (quadrant_sym[inp_coverage] != SYM_ILL)
264 +                        break;                  /* anything legal goes */
265 +                fprintf(stderr, "%s: unsupported phi coverage (%s)\n",
266 +                                progname, quadrant_rep[inp_coverage]);
267 +                return(1);
268 +        case SYM_ISO:                           /* legal symmetry types */
269 +        case SYM_QUAD:
270 +        case SYM_BILAT:
271 +        case SYM_ANISO:
272 +                if (quadrant_sym[inp_coverage] == toupper(symmetry[0]))
273 +                        break;                  /* matches spec */
274 +                fprintf(stderr,
275 +                "%s: phi coverage (%s) does not match requested '%s' symmetry\n",
276 +                                progname, quadrant_rep[inp_coverage], symmetry);
277 +                return(1);
278 +        default:
279 +                fprintf(stderr,
280 +  "%s: -s option must be Isotropic, Quadrilateral, Bilateral, or Anisotropic\n",
281 +                                progname);
282 +                return(1);
283 +        }
284 + #ifdef DEBUG
285 +        fprintf(stderr, "Input phi coverage (%s) has '%c' symmetry\n",
286 +                                quadrant_rep[inp_coverage],
287 +                                quadrant_sym[inp_coverage]);
288 + #endif
289          build_mesh();                           /* create interpolation */
290          save_bsdf_rep(stdout);                  /* write it out */
291          return(0);
292   userr:
293 <        fprintf(stderr, "Usage: %s [-n nproc] meas1.dat meas2.dat .. > bsdf.sir\n",
293 >        fprintf(stderr, "Usage: %s [-t][-n nproc][-s symmetry] meas1.dat meas2.dat .. > bsdf.sir\n",
294                                          progname);
295          return(1);
296   }
297 < #else
297 >
298 > #else           /* TEST_MAIN */
299 >
300   /* Test main produces a Radiance model from the given input file */
301   int
302   main(int argc, char *argv[])
# Line 307 | Line 380 | main(int argc, char *argv[])
380   #endif
381          return(0);
382   }
383 < #endif
383 >
384 > #endif          /* TEST_MAIN */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines