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.7 by greg, Wed Jul 23 22:39:40 2014 UTC vs.
Revision 2.24 by greg, Thu Mar 12 15:36:11 2015 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include <stdlib.h>
12   #include "rtio.h"
13   #include "rtmath.h"
14 + #include "rtprocess.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
17   #include "random.h"
# Line 35 | Line 36 | static const char RCSid[] = "$Id$";
36  
37   char            *progname;              /* global argv[0] */
38  
39 < int             verbose = 0;            /* verbose mode? */
39 > int             verbose = 0;            /* verbose mode (< 0 no warnings) */
40  
41   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
42   int             nrcargs = 2;
# Line 144 | Line 145 | surf_type(const char *otype)
145   static char *
146   oconv_command(int ac, char *av[])
147   {
148 <        static char     oconvbuf[2048] = "!oconv -f";
149 <        char            *cp = oconvbuf + 9;
150 <
148 >        static char     oconvbuf[2048] = "!oconv -f ";
149 >        char            *cp = oconvbuf + 10;
150 >        char            *recv = *av++;
151 >        
152 >        if (ac-- <= 0)
153 >                return(NULL);
154          while (ac-- > 0) {
155 +                strcpy(cp, *av++);
156 +                while (*cp) cp++;
157 +                *cp++ = ' ';
158                  if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) {
159                          fputs(progname, stderr);
160                          fputs(": too many file arguments!\n", stderr);
161                          exit(1);
162                  }
156                *cp++ = ' ';
157                strcpy(cp, *av++);
158                while (*cp) cp++;
163          }
164 <        *cp = '\0';
164 >        strcpy(cp, recv);       /* receiver goes last */
165          return(oconvbuf);
166   }
167  
# Line 222 | Line 226 | popen_arglist(char *av[], char *mode)
226                  fputs(": command line too long in popen_arglist()\n", stderr);
227                  return(NULL);
228          }
229 <        if (verbose)
229 >        if (verbose > 0)
230                  fprintf(stderr, "%s: opening pipe %s: %s\n",
231                                  progname, (*mode=='w') ? "to" : "from", cmd);
232          return(popen(cmd, mode));
# Line 240 | Line 244 | my_exec(char *av[])
244                  fputs(": command line too long in my_exec()\n", stderr);
245                  return(1);
246          }
247 <        if (verbose)
247 >        if (verbose > 0)
248                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
249          return(system(cmd));
250   }
# Line 255 | Line 259 | my_exec(char *av[])
259                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
260                  return(1);
261          }
262 <        if (verbose) {
262 >        if (verbose > 0) {
263                  char    cmd[4096];
264                  if (!convert_commandline(cmd, sizeof(cmd), av))
265                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 315 | Line 319 | parse_params(PARAMS *p, char *pargs)
319          int     nparams = 0;
320          int     i;
321  
322 <        for ( ; ; )
322 >        for ( ; ; ) {
323                  switch (*cp++) {
324                  case 'h':
325                          if (*cp++ != '=')
# Line 338 | Line 342 | parse_params(PARAMS *p, char *pargs)
342                                  break;
343                          if (!get_direction(p->vup, cp))
344                                  break;
345 +                        while (*cp && !isspace(*cp++))
346 +                                ;
347                          ++nparams;
348                          continue;
349                  case 'o':
# Line 363 | Line 369 | parse_params(PARAMS *p, char *pargs)
369                  default:
370                          break;
371                  }
372 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
372 >                break;
373 >        }
374 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
375          exit(1);
376          return(-1);     /* pro forma return */
377   }
# Line 401 | Line 409 | finish_receiver(void)
409                  fputs(": undefined normal for hemisphere sampling\n", stderr);
410                  exit(1);
411          }
412 <        if (normalize(curparams.vup) == 0)
412 >        if (normalize(curparams.vup) == 0) {
413                  if (fabs(curparams.nrm[2]) < .7)
414                          curparams.vup[2] = 1;
415                  else
416                          curparams.vup[1] = 1;
417 +        }
418                                          /* determine sample type/bin */
419          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
420 <                binv = "0";             /* uniform sampling -- one bin */
420 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
421 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
422 >                binv = savqstr(sbuf);
423 >                nbins = "1";            /* uniform sampling -- one bin */
424                  uniform = 1;
425          } else if (tolower(curparams.hemis[0]) == 's' &&
426                                  tolower(curparams.hemis[1]) == 'c') {
# Line 419 | Line 431 | finish_receiver(void)
431                          exit(1);
432                  }
433                  calfn = shirchiufn; shirchiufn = NULL;
434 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
434 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
435                                  curparams.hsiz,
436                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
437                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 429 | Line 441 | finish_receiver(void)
441          } else if ((tolower(curparams.hemis[0]) == 'r') |
442                          (tolower(curparams.hemis[0]) == 't')) {
443                  calfn = reinhfn; reinhfn = NULL;
444 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
444 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
445                                  curparams.hsiz,
446                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
447                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 507 | Line 519 | make_axes(FVECT uva[2], const FVECT nrm)
519   {
520          int     i;
521  
522 <        uva[1][0] = 0.5 - frandom();
511 <        uva[1][1] = 0.5 - frandom();
512 <        uva[1][2] = 0.5 - frandom();
513 <        for (i = 3; i--; )
514 <                if ((-0.6 < nrm[i]) & (nrm[i] < 0.6))
515 <                        break;
516 <        if (i < 0) {
522 >        if (!getperpendicular(uva[0], nrm)) {
523                  fputs(progname, stderr);
524                  fputs(": bad surface normal in make_axes!\n", stderr);
525                  exit(1);
526          }
527 <        uva[1][i] = 1.0;
522 <        VCROSS(uva[0], uva[1], nrm);
523 <        normalize(uva[0]);
524 <        VCROSS(uva[1], nrm, uva[0]);
527 >        fcross(uva[1], nrm, uva[0]);
528   }
529  
530   /* Illegal sender surfaces end up here */
# Line 783 | Line 786 | sample_reinhart(PARAMS *p, int b, FILE *fp)
786                  alt = (row+samp3[1])*RAH;
787                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
788                  duvw[2] = cos(alt);     /* measured from horizon */
789 <                duvw[0] = tcos(azi)*duvw[2];
790 <                duvw[1] = tsin(azi)*duvw[2];
789 >                duvw[0] = tsin(azi)*duvw[2];
790 >                duvw[1] = tcos(azi)*duvw[2];
791                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
792                  for (i = 3; i--; )
793                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 835 | Line 838 | sample_klems(PARAMS *p, int b, FILE *fp)
838  
839          while (n--) {                   /* stratified sampling */
840                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
841 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
841 >                if (!bi_getvec(duvw, b+samp2[1], kbasis[bi]))
842                          return(0);
843                  for (i = 3; i--; )
844                          orig_dir[1][i] = duvw[0]*p->udir[i] +
# Line 858 | Line 861 | prepare_sampler(void)
861                  fputs(": no sender surface!\n", stderr);
862                  return(-1);
863          }
864 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
864 >                                        /* misplaced output file spec. */
865 >        if ((curparams.outfn != NULL) & (verbose >= 0))
866                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
867                                  progname, curparams.outfn);
868                                          /* check/set basis hemisphere */
# Line 872 | Line 876 | prepare_sampler(void)
876                  fputs(": undefined normal for sender sampling\n", stderr);
877                  return(-1);
878          }
879 <        if (normalize(curparams.vup) == 0)
879 >        if (normalize(curparams.vup) == 0) {
880                  if (fabs(curparams.nrm[2]) < .7)
881                          curparams.vup[2] = 1;
882                  else
883                          curparams.vup[1] = 1;
884 +        }
885          VCROSS(curparams.udir, curparams.vup, curparams.nrm);
886          if (normalize(curparams.udir) == 0) {
887                  fputs(progname, stderr);
# Line 1000 | Line 1005 | add_surface(int st, const char *oname, FILE *fp)
1005          case ST_SOURCE:
1006                  if (snew->nfargs != 4)
1007                          goto badcount;
1008 <                VCOPY(snew->snrm, snew->farg);
1008 >                for (n = 3; n--; )      /* need to reverse "normal" */
1009 >                        snew->snrm[n] = -snew->farg[n];
1010                  if (normalize(snew->snrm) == 0)
1011                          goto badnorm;
1012                  snew->area = sin((PI/180./2.)*snew->farg[3]);
1013                  snew->area *= PI*snew->area;
1014                  break;
1015          }
1016 <        if (snew->area <= FTINY) {
1016 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1017                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1018                                  progname, oname);
1019                  free(snew);
# Line 1063 | Line 1069 | add_recv_object(FILE *fp)
1069                  return(1);
1070          }
1071                                          /* else skip arguments */
1072 <        if (!fscanf(fp, "%d", &n)) return;
1072 >        if (!fscanf(fp, "%d", &n)) return(0);
1073          while (n-- > 0) fscanf(fp, "%*s");
1074 <        if (!fscanf(fp, "%d", &n)) return;
1074 >        if (!fscanf(fp, "%d", &n)) return(0);
1075          while (n-- > 0) fscanf(fp, "%*d");
1076 <        if (!fscanf(fp, "%d", &n)) return;
1076 >        if (!fscanf(fp, "%d", &n)) return(0);
1077          while (n-- > 0) fscanf(fp, "%*f");
1078          return(0);
1079   }
# Line 1077 | Line 1083 | static int
1083   add_send_object(FILE *fp)
1084   {
1085          int             st;
1086 <        char            otype[32], oname[128];
1086 >        char            thismod[128], otype[32], oname[128];
1087          int             n;
1088  
1089 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1089 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 2)
1090                  return(0);              /* must have hit EOF! */
1091          if (!strcmp(otype, "alias")) {
1092                  fscanf(fp, "%*s");      /* skip alias */
# Line 1093 | Line 1099 | add_send_object(FILE *fp)
1099                          fputs(": cannot use source as a sender!\n", stderr);
1100                          return(-1);
1101                  }
1102 +                if (strcmp(thismod, curmod)) {
1103 +                        if (curmod[0]) {
1104 +                                fputs(progname, stderr);
1105 +                                fputs(": warning - multiple modifiers in sender\n",
1106 +                                                stderr);
1107 +                        }
1108 +                        strcpy(curmod, thismod);
1109 +                }
1110                  parse_params(&curparams, newparams);
1111                  newparams[0] = '\0';
1112                  add_surface(st, oname, fp);     /* read & store surface */
1113                  return(0);
1114          }
1115                                          /* else skip arguments */
1116 <        if (!fscanf(fp, "%d", &n)) return;
1116 >        if (!fscanf(fp, "%d", &n)) return(0);
1117          while (n-- > 0) fscanf(fp, "%*s");
1118 <        if (!fscanf(fp, "%d", &n)) return;
1118 >        if (!fscanf(fp, "%d", &n)) return(0);
1119          while (n-- > 0) fscanf(fp, "%*d");
1120 <        if (!fscanf(fp, "%d", &n)) return;
1120 >        if (!fscanf(fp, "%d", &n)) return(0);
1121          while (n-- > 0) fscanf(fp, "%*f");
1122          return(0);
1123   }
# Line 1146 | Line 1160 | load_scene(const char *inspec, int (*ocb)(FILE *))
1160                                          strcat(newparams, inpbuf);
1161                                  continue;
1162                          }
1163 <                        while ((c = getc(fp)) != EOF && c != '\n');
1163 >                        while ((c = getc(fp)) != EOF && c != '\n')
1164                                  ;       /* else skipping comment */
1165                          continue;
1166                  }
# Line 1171 | Line 1185 | main(int argc, char *argv[])
1185   {
1186          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1187          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1188 +        char    *iropt = NULL;
1189          char    *sendfn;
1190          char    sampcntbuf[32], nsbinbuf[32];
1191          FILE    *rcfp;
# Line 1178 | Line 1193 | main(int argc, char *argv[])
1193          int     a, i;
1194                                          /* screen rcontrib options */
1195          progname = argv[0];
1196 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1197 <                int     na = 1;         /* !! Keep consistent !! */
1198 <                switch (argv[a][1]) {
1196 >        for (a = 1; a < argc-2; a++) {
1197 >                int     na;
1198 >                                        /* check for argument expansion */
1199 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1200 >                        ;
1201 >                if (na < 0) {
1202 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1203 >                                        progname, argv[a]);
1204 >                        return(1);
1205 >                }
1206 >                if (argv[a][0] != '-' || !argv[a][1])
1207 >                        break;
1208 >                na = 1;
1209 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1210                  case 'v':               /* verbose mode */
1211 <                        verbose = !verbose;
1211 >                        verbose = 1;
1212                          na = 0;
1213                          continue;
1214                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1218 | Line 1244 | main(int argc, char *argv[])
1244                                  goto userr;
1245                          na = 0;         /* we re-add this later */
1246                          continue;
1247 <                case 'V':               /* options without arguments */
1222 <                case 'w':
1223 <                case 'u':
1247 >                case 'I':               /* only for pass-through mode */
1248                  case 'i':
1249 +                        iropt = argv[a];
1250 +                        na = 0;
1251 +                        continue;
1252 +                case 'w':               /* options without arguments */
1253 +                        if (argv[a][2] != '+') verbose = -1;
1254 +                case 'V':
1255 +                case 'u':
1256                  case 'h':
1257                  case 'r':
1258                          break;
# Line 1251 | Line 1282 | main(int argc, char *argv[])
1282                          if (!argv[a][2]) goto userr;
1283                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1284                          break;
1254                case '\0':              /* pass-through mode */
1255                        goto done_opts;
1285                  default:                /* anything else is verbotten */
1286                          goto userr;
1287                  }
# Line 1262 | Line 1291 | main(int argc, char *argv[])
1291                  while (--na)            /* + arguments if any */
1292                          rcarg[nrcargs++] = argv[++a];
1293          }
1265 done_opts:
1294          if (a > argc-2)
1295                  goto userr;             /* check at end of options */
1296          sendfn = argv[a++];             /* assign sender & receiver inputs */
1297          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1298                  if (sendfn[1]) goto userr;
1299                  sendfn = NULL;
1300 +                if (iropt) {
1301 +                        CHECKARGC(1);
1302 +                        rcarg[nrcargs++] = iropt;
1303 +                }
1304                  if (xrs) {
1305                          CHECKARGC(2);
1306                          rcarg[nrcargs++] = "-x";
# Line 1284 | Line 1316 | done_opts:
1316                          rcarg[nrcargs++] = ldopt;
1317                  }
1318                  if (sampcnt <= 0) sampcnt = 1;
1319 <        } else {                        /* else FVECT determines input format */
1319 >        } else {                        /* else in sampling mode */
1320 >                if (iropt) {
1321 >                        fputs(progname, stderr);
1322 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1323 >                        return(1);
1324 >                }
1325                  fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1326                  if (sampcnt <= 0) sampcnt = 10000;
1327          }
# Line 1304 | Line 1341 | done_opts:
1341                  return(my_exec(rcarg)); /* rcontrib does everything */
1342          }
1343          clear_params(&curparams, 0);    /* else load sender surface & params */
1344 +        curmod[0] = '\0';
1345          if (load_scene(sendfn, add_send_object) < 0)
1346                  return(1);
1347          if ((nsbins = prepare_sampler()) <= 0)
# Line 1321 | Line 1359 | done_opts:
1359   #ifdef getc_unlocked
1360          flockfile(rcfp);
1361   #endif
1362 <        if (verbose) {
1362 >        if (verbose > 0) {
1363                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1364                  if (curparams.nsurfs > 1)
1365                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
# Line 1331 | Line 1369 | done_opts:
1369          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1370                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1371                          return(1);
1372 <        return(pclose(rcfp) == 0);      /* all finished! */
1372 >        return(pclose(rcfp) < 0);       /* all finished! */
1373   userr:
1374          if (a < argc-2)
1375                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1376 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1376 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1377                                  progname);
1378          return(1);
1379   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines