ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rfluxmtx.c
(Generate patch)

Comparing ray/src/util/rfluxmtx.c (file contents):
Revision 2.3 by greg, Tue Jul 22 02:12:48 2014 UTC vs.
Revision 2.6 by greg, Wed Jul 23 00:40:17 2014 UTC

# Line 53 | Line 53 | char           *kfullfn = "klems_full.cal";
53   char            *khalffn = "klems_half.cal";
54   char            *kquarterfn = "klems_quarter.cal";
55  
56 < #define PARAMSTART      "@rfluxmtx"     /* string indicating parameters */
56 >                                        /* string indicating parameters */
57 > const char      PARAMSTART[] = "@rfluxmtx";
58  
59                                  /* surface type IDs */
60   #define ST_NONE         0
# Line 66 | Line 67 | typedef struct surf_s {
67          void            *priv;          /* private data (malloc'ed) */
68          char            sname[32];      /* surface name */
69          FVECT           snrm;           /* surface normal */
70 <        double          area;           /* surface area (or solid angle) */
70 >        double          area;           /* surface area / proj. solid angle */
71          short           styp;           /* surface type */
72          short           nfargs;         /* number of real arguments */
73          double          farg[1];        /* real values (extends struct) */
# Line 95 | Line 96 | typedef struct param_s {
96  
97   PARAMS          curparams;
98   char            curmod[128];
99 + char            newparams[1024];
100  
101   typedef int     SURFSAMP(FVECT, SURF *, double);
102  
# Line 108 | Line 110 | SURFSAMP       *orig_in_surf[4] = {
110   static void
111   clear_params(PARAMS *p, int reset_only)
112   {
111        curmod[0] = '\0';
113          while (p->slist != NULL) {
114                  SURF    *sdel = p->slist;
115                  p->slist = sdel->next;
# Line 123 | Line 124 | clear_params(PARAMS *p, int reset_only)
124                  p->outfn = NULL;
125                  return;
126          }
127 <        memset(p, 0, sizeof(curparams));
127 >        memset(p, 0, sizeof(PARAMS));
128   }
129  
130   /* Get surface type from name */
# Line 308 | Line 309 | nextchar:
309  
310   /* Parse program parameters (directives) */
311   static int
312 < parse_params(char *pargs)
312 > parse_params(PARAMS *p, char *pargs)
313   {
314          char    *cp = pargs;
315          int     nparams = 0;
# Line 319 | Line 320 | parse_params(char *pargs)
320                  case 'h':
321                          if (*cp++ != '=')
322                                  break;
323 <                        curparams.hsiz = 0;
323 >                        p->hsiz = 0;
324                          i = 0;
325                          while (*cp && !isspace(*cp)) {
326                                  if (isdigit(*cp))
327 <                                        curparams.hsiz = 10*curparams.hsiz +
328 <                                                                *cp - '0';
328 <                                curparams.hemis[i++] = *cp++;
327 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
328 >                                p->hemis[i++] = *cp++;
329                          }
330                          if (!i)
331                                  break;
332 <                        curparams.hemis[i] = '\0';
333 <                        curparams.hsiz += !curparams.hsiz;
332 >                        p->hemis[i] = '\0';
333 >                        p->hsiz += !p->hsiz;
334                          ++nparams;
335                          continue;
336                  case 'u':
337                          if (*cp++ != '=')
338                                  break;
339 <                        if (!get_direction(curparams.vup, cp))
339 >                        if (!get_direction(p->vup, cp))
340                                  break;
341                          ++nparams;
342                          continue;
# Line 349 | Line 349 | parse_params(char *pargs)
349                          if (!i)
350                                  break;
351                          *--cp = '\0';
352 <                        curparams.outfn = savqstr(cp-i);
352 >                        p->outfn = savqstr(cp-i);
353                          *cp++ = ' ';
354                          ++nparams;
355                          continue;
# Line 372 | Line 372 | parse_params(char *pargs)
372   static void
373   finish_receiver(void)
374   {
375 +        char    sbuf[256];
376 +        int     uniform = 0;
377          char    *calfn = NULL;
378          char    *params = NULL;
379          char    *binv = NULL;
380          char    *binf = NULL;
381          char    *nbins = NULL;
380        char    sbuf[256];
382  
383          if (!curmod[0]) {
384                  fputs(progname, stderr);
# Line 389 | Line 390 | finish_receiver(void)
390                  rcarg[nrcargs++] = "-o";
391                  rcarg[nrcargs++] = curparams.outfn;
392          }
393 <                                        /* add bin specification */
393 >                                        /* check arguments */
394          if (!curparams.hemis[0]) {
395                  fputs(progname, stderr);
396                  fputs(": missing hemisphere sampling type!\n", stderr);
# Line 405 | Line 406 | finish_receiver(void)
406                          curparams.vup[2] = 1;
407                  else
408                          curparams.vup[1] = 1;
409 +                                        /* determine sample type/bin */
410          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
411                  binv = "0";             /* uniform sampling -- one bin */
412 +                uniform = 1;
413          } else if (tolower(curparams.hemis[0]) == 's' &&
414                                  tolower(curparams.hemis[1]) == 'c') {
415                                          /* assign parameters */
# Line 457 | Line 460 | finish_receiver(void)
460                                  progname, curparams.hemis);
461                  exit(1);
462          }
463 +        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
464 +                SURF    *sp;
465 +                for (sp = curparams.slist; sp != NULL; sp = sp->next)
466 +                        if (fabs(sp->area - PI) > 1e-3) {
467 +                                fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
468 +                                                progname, sp->sname);
469 +                                exit(1);
470 +                        }
471 +        }
472          if (calfn != NULL) {            /* add cal file if needed */
473                  CHECKARGC(2);
474                  rcarg[nrcargs++] = "-f";
# Line 541 | Line 553 | ssamp_ring(FVECT orig, SURF *sp, double x)
553                  sp->priv = (void *)uva;
554          }
555          SDmultiSamp(samp2, 2, x);
556 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
556 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
557          samp2[1] *= 2.*PI;
558          uv[0] = samp2[0]*tcos(samp2[1]);
559          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 979 | Line 991 | add_surface(int st, const char *oname, FILE *fp)
991                  VCOPY(snew->snrm, snew->farg);
992                  if (normalize(snew->snrm) == 0)
993                          goto badnorm;
994 <                snew->area = 2.*PI*(1. - cos((PI/180./2.)*snew->farg[3]));
994 >                snew->area = sin((PI/180./2.)*snew->farg[3]);
995 >                snew->area *= PI*snew->area;
996                  break;
997          }
998          if (snew->area <= FTINY) {
# Line 1030 | Line 1043 | add_recv_object(FILE *fp)
1043                                  finish_receiver();
1044                                  clear_params(&curparams, 1);
1045                          }
1046 +                        parse_params(&curparams, newparams);
1047 +                        newparams[0] = '\0';
1048                          strcpy(curmod, thismod);
1049                  }
1050                  add_surface(st, oname, fp);     /* read & store surface */
# Line 1066 | Line 1081 | add_send_object(FILE *fp)
1081                          fputs(": cannot use source as a sender!\n", stderr);
1082                          return(-1);
1083                  }
1084 +                parse_params(&curparams, newparams);
1085 +                newparams[0] = '\0';
1086                  add_surface(st, oname, fp);     /* read & store surface */
1087                  return(0);
1088          }
# Line 1109 | Line 1126 | load_scene(const char *inspec, int (*ocb)(FILE *))
1126                          continue;
1127                  }
1128                  if (c == '#') {         /* parameters/comment */
1129 <                        if (fscanf(fp, "%s", inpbuf) == 1 &&
1129 >                        if ((c = getc(fp)) == EOF || ungetc(c,fp) == EOF)
1130 >                                break;
1131 >                        if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1132                                          !strcmp(inpbuf, PARAMSTART)) {
1133                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1134 <                                        parse_params(inpbuf);
1134 >                                        strcat(newparams, inpbuf);
1135                                  continue;
1136                          }
1137                          while ((c = getc(fp)) != EOF && c != '\n');
# Line 1139 | Line 1158 | int
1158   main(int argc, char *argv[])
1159   {
1160          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1161 +        char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1162          char    *sendfn;
1163          char    sampcntbuf[32], nsbinbuf[32];
1164          FILE    *rcfp;
# Line 1163 | Line 1183 | main(int argc, char *argv[])
1183                          case 'f':
1184                          case 'd':
1185                          case 'c':
1186 <                                if (!(fmtopt[4] = argv[a][3]))
1187 <                                        fmtopt[4] = argv[a][2];
1188 <                                fmtopt[3] = argv[a][2];
1186 >                                if (!(fmtopt[3] = argv[a][3]))
1187 >                                        fmtopt[3] = argv[a][2];
1188 >                                fmtopt[2] = argv[a][2];
1189                                  na = 0;
1190                                  continue;       /* will pass later */
1191                          default:
1192                                  goto userr;
1193                          }
1194                          break;
1195 +                case 'x':               /* x-resolution */
1196 +                        xrs = argv[++a];
1197 +                        na = 0;
1198 +                        continue;
1199 +                case 'y':               /* y-resolution */
1200 +                        yrs = argv[++a];
1201 +                        na = 0;
1202 +                        continue;
1203                  case 'c':               /* number of samples */
1204 <                        sampcnt = atoi(argv[a+1]);
1204 >                        sampcnt = atoi(argv[++a]);
1205                          if (sampcnt <= 0)
1206                                  goto userr;
1207                          na = 0;         /* we re-add this later */
# Line 1183 | Line 1211 | main(int argc, char *argv[])
1211                  case 'u':
1212                  case 'i':
1213                  case 'h':
1214 +                case 'r':
1215                          break;
1216                  case 'n':               /* options with 1 argument */
1217                  case 's':
# Line 1193 | Line 1222 | main(int argc, char *argv[])
1222                          if (argv[a][2] != 'v') goto userr;
1223                          break;
1224                  case 'l':               /* special case */
1225 <                        if (argv[a][2] == 'd') goto userr;
1225 >                        if (argv[a][2] == 'd') {
1226 >                                ldopt = argv[a];
1227 >                                na = 0;
1228 >                                continue;
1229 >                        }
1230                          na = 2;
1231                          break;
1232                  case 'd':               /* special case */
# Line 1224 | Line 1257 | done_opts:
1257          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1258                  if (sendfn[1]) goto userr;
1259                  sendfn = NULL;
1260 +                if (xrs) {
1261 +                        CHECKARGC(2);
1262 +                        rcarg[nrcargs++] = "-x";
1263 +                        rcarg[nrcargs++] = xrs;
1264 +                }
1265 +                if (yrs) {
1266 +                        CHECKARGC(2);
1267 +                        rcarg[nrcargs++] = "-y";
1268 +                        rcarg[nrcargs++] = yrs;
1269 +                }
1270 +                if (ldopt) {
1271 +                        CHECKARGC(1);
1272 +                        rcarg[nrcargs++] = ldopt;
1273 +                }
1274                  if (sampcnt <= 0) sampcnt = 1;
1275          } else {                        /* else FVECT determines input format */
1276 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1276 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1277                  if (sampcnt <= 0) sampcnt = 10000;
1278          }
1279          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1276 | Line 1323 | done_opts:
1323   userr:
1324          if (a < argc-2)
1325                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1326 <        fprintf(stderr, "Usage: %s [rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1326 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1327                                  progname);
1328          return(1);
1329   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines