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.5 by greg, Tue Jul 22 23:21:56 2014 UTC vs.
Revision 2.15 by greg, Fri Aug 15 19:59:56 2014 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 96 | Line 97 | typedef struct param_s {
97  
98   PARAMS          curparams;
99   char            curmod[128];
100 + char            newparams[1024];
101  
102   typedef int     SURFSAMP(FVECT, SURF *, double);
103  
# Line 109 | Line 111 | SURFSAMP       *orig_in_surf[4] = {
111   static void
112   clear_params(PARAMS *p, int reset_only)
113   {
112        curmod[0] = '\0';
114          while (p->slist != NULL) {
115                  SURF    *sdel = p->slist;
116                  p->slist = sdel->next;
# Line 124 | Line 125 | clear_params(PARAMS *p, int reset_only)
125                  p->outfn = NULL;
126                  return;
127          }
128 <        memset(p, 0, sizeof(curparams));
128 >        memset(p, 0, sizeof(PARAMS));
129   }
130  
131   /* Get surface type from name */
# 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 309 | Line 313 | nextchar:
313  
314   /* Parse program parameters (directives) */
315   static int
316 < parse_params(char *pargs)
316 > parse_params(PARAMS *p, char *pargs)
317   {
318          char    *cp = pargs;
319          int     nparams = 0;
320          int     i;
321  
322 <        for ( ; ; )
322 >        for ( ; ; ) {
323                  switch (*cp++) {
324                  case 'h':
325                          if (*cp++ != '=')
326                                  break;
327 <                        curparams.hsiz = 0;
327 >                        p->hsiz = 0;
328                          i = 0;
329                          while (*cp && !isspace(*cp)) {
330                                  if (isdigit(*cp))
331 <                                        curparams.hsiz = 10*curparams.hsiz +
332 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
331 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
332 >                                p->hemis[i++] = *cp++;
333                          }
334                          if (!i)
335                                  break;
336 <                        curparams.hemis[i] = '\0';
337 <                        curparams.hsiz += !curparams.hsiz;
336 >                        p->hemis[i] = '\0';
337 >                        p->hsiz += !p->hsiz;
338                          ++nparams;
339                          continue;
340                  case 'u':
341                          if (*cp++ != '=')
342                                  break;
343 <                        if (!get_direction(curparams.vup, cp))
343 >                        if (!get_direction(p->vup, cp))
344                                  break;
345 +                        while (*cp && !isspace(*cp++))
346 +                                ;
347                          ++nparams;
348                          continue;
349                  case 'o':
# Line 350 | Line 355 | parse_params(char *pargs)
355                          if (!i)
356                                  break;
357                          *--cp = '\0';
358 <                        curparams.outfn = savqstr(cp-i);
358 >                        p->outfn = savqstr(cp-i);
359                          *cp++ = ' ';
360                          ++nparams;
361                          continue;
362                  case ' ':
363                  case '\t':
364                  case '\r':
360                case '\n':
365                          continue;
366 +                case '\n':
367                  case '\0':
368                          return(nparams);
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 402 | 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 */
# Line 420 | Line 428 | finish_receiver(void)
428                          exit(1);
429                  }
430                  calfn = shirchiufn; shirchiufn = NULL;
431 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
431 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
432                                  curparams.hsiz,
433                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
434                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 430 | Line 438 | finish_receiver(void)
438          } else if ((tolower(curparams.hemis[0]) == 'r') |
439                          (tolower(curparams.hemis[0]) == 't')) {
440                  calfn = reinhfn; reinhfn = NULL;
441 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
441 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
442                                  curparams.hsiz,
443                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
444                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 554 | Line 562 | ssamp_ring(FVECT orig, SURF *sp, double x)
562                  sp->priv = (void *)uva;
563          }
564          SDmultiSamp(samp2, 2, x);
565 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
565 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
566          samp2[1] *= 2.*PI;
567          uv[0] = samp2[0]*tcos(samp2[1]);
568          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 615 | ssamp_poly(FVECT orig, SURF *sp, double x)
615                          }
616                          ptp->ntris = 0;
617                          v2l->p = (void *)ptp;
618 <                        if (!polyTriangulate(v2l, add_triangle))
618 >                        if (!polyTriangulate(v2l, add_triangle)) {
619 >                                fprintf(stderr,
620 >                                        "%s: cannot triangulate polygon '%s'\n",
621 >                                                progname, sp->sname);
622                                  return(0);
623 +                        }
624                          for (i = ptp->ntris; i--; ) {
625                                  int     a = ptp->tri[i].vndx[0];
626                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 669 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
669                                          /* special case for lone surface */
670          if (p->nsurfs == 1) {
671                  sp = p->slist;
672 <                if (DOT(sp->snrm, rdir) >= -FTINY)
673 <                        return(0);      /* behind surface! */
672 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
673 >                        fprintf(stderr,
674 >                                "%s: internal - sample behind sender '%s'\n",
675 >                                        progname, sp->sname);
676 >                        return(0);
677 >                }
678                  return((*orig_in_surf[sp->styp])(orig, sp, x));
679          }
680          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 688 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
688                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
689                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
690          }
691 <        if (tarea <= FTINY)             /* wrong side of sender? */
691 >        if (tarea <= FTINY) {           /* wrong side of sender? */
692 >                fputs(progname, stderr);
693 >                fputs(": internal - sample behind all sender elements!\n",
694 >                                stderr);
695                  return(0);
696 +        }
697          tarea *= x;                     /* get surface from list */
698          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
699                  tarea -= projsa[i++];
# Line 746 | Line 766 | sample_reinhart(PARAMS *p, int b, FILE *fp)
766   #define T_NALT  7
767          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
768          const int               RowMax = T_NALT*p->hsiz + 1;
769 <        const double            RAH = (.25*PI)/(RowMax-.5);
769 >        const double            RAH = (.5*PI)/(RowMax-.5);
770   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
771          int                     n = sampcnt;
772          int                     row, col;
# Line 771 | Line 791 | sample_reinhart(PARAMS *p, int b, FILE *fp)
791                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
792                  alt = (row+samp3[1])*RAH;
793                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
794 <                duvw[2] = tcos(alt);    /* measured from horizon */
794 >                duvw[2] = cos(alt);     /* measured from horizon */
795                  duvw[0] = tcos(azi)*duvw[2];
796                  duvw[1] = tsin(azi)*duvw[2];
797                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
# Line 861 | Line 881 | prepare_sampler(void)
881                  fputs(": undefined normal for sender sampling\n", stderr);
882                  return(-1);
883          }
884 <        if (normalize(curparams.vup) == 0)
884 >        if (normalize(curparams.vup) == 0) {
885                  if (fabs(curparams.nrm[2]) < .7)
886                          curparams.vup[2] = 1;
887                  else
888                          curparams.vup[1] = 1;
889 +        }
890          VCROSS(curparams.udir, curparams.vup, curparams.nrm);
891          if (normalize(curparams.udir) == 0) {
892                  fputs(progname, stderr);
# Line 989 | Line 1010 | add_surface(int st, const char *oname, FILE *fp)
1010          case ST_SOURCE:
1011                  if (snew->nfargs != 4)
1012                          goto badcount;
1013 <                VCOPY(snew->snrm, snew->farg);
1013 >                for (n = 3; n--; )      /* need to reverse "normal" */
1014 >                        snew->snrm[n] = -snew->farg[n];
1015                  if (normalize(snew->snrm) == 0)
1016                          goto badnorm;
1017                  snew->area = sin((PI/180./2.)*snew->farg[3]);
# Line 1008 | Line 1030 | add_surface(int st, const char *oname, FILE *fp)
1030          curparams.nsurfs++;
1031          return;
1032   badcount:
1033 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1033 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1034                          progname, oname);
1035          exit(1);
1036   badnorm:
1037 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1037 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1038                          progname, oname);
1039          exit(1);
1040   }
# Line 1044 | Line 1066 | add_recv_object(FILE *fp)
1066                                  finish_receiver();
1067                                  clear_params(&curparams, 1);
1068                          }
1069 +                        parse_params(&curparams, newparams);
1070 +                        newparams[0] = '\0';
1071                          strcpy(curmod, thismod);
1072                  }
1073                  add_surface(st, oname, fp);     /* read & store surface */
1074                  return(1);
1075          }
1076                                          /* else skip arguments */
1077 <        if (!fscanf(fp, "%d", &n)) return;
1077 >        if (!fscanf(fp, "%d", &n)) return(0);
1078          while (n-- > 0) fscanf(fp, "%*s");
1079 <        if (!fscanf(fp, "%d", &n)) return;
1079 >        if (!fscanf(fp, "%d", &n)) return(0);
1080          while (n-- > 0) fscanf(fp, "%*d");
1081 <        if (!fscanf(fp, "%d", &n)) return;
1081 >        if (!fscanf(fp, "%d", &n)) return(0);
1082          while (n-- > 0) fscanf(fp, "%*f");
1083          return(0);
1084   }
# Line 1080 | Line 1104 | add_send_object(FILE *fp)
1104                          fputs(": cannot use source as a sender!\n", stderr);
1105                          return(-1);
1106                  }
1107 +                parse_params(&curparams, newparams);
1108 +                newparams[0] = '\0';
1109                  add_surface(st, oname, fp);     /* read & store surface */
1110                  return(0);
1111          }
1112                                          /* else skip arguments */
1113 <        if (!fscanf(fp, "%d", &n)) return;
1113 >        if (!fscanf(fp, "%d", &n)) return(0);
1114          while (n-- > 0) fscanf(fp, "%*s");
1115 <        if (!fscanf(fp, "%d", &n)) return;
1115 >        if (!fscanf(fp, "%d", &n)) return(0);
1116          while (n-- > 0) fscanf(fp, "%*d");
1117 <        if (!fscanf(fp, "%d", &n)) return;
1117 >        if (!fscanf(fp, "%d", &n)) return(0);
1118          while (n-- > 0) fscanf(fp, "%*f");
1119          return(0);
1120   }
# Line 1128 | Line 1154 | load_scene(const char *inspec, int (*ocb)(FILE *))
1154                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1155                                          !strcmp(inpbuf, PARAMSTART)) {
1156                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1157 <                                        parse_params(inpbuf);
1157 >                                        strcat(newparams, inpbuf);
1158                                  continue;
1159                          }
1160 <                        while ((c = getc(fp)) != EOF && c != '\n');
1160 >                        while ((c = getc(fp)) != EOF && c != '\n')
1161                                  ;       /* else skipping comment */
1162                          continue;
1163                  }
# Line 1156 | Line 1182 | main(int argc, char *argv[])
1182   {
1183          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1184          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1185 +        char    *iropt = NULL;
1186          char    *sendfn;
1187          char    sampcntbuf[32], nsbinbuf[32];
1188          FILE    *rcfp;
# Line 1163 | Line 1190 | main(int argc, char *argv[])
1190          int     a, i;
1191                                          /* screen rcontrib options */
1192          progname = argv[0];
1193 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1194 <                int     na = 1;         /* !! Keep consistent !! */
1195 <                switch (argv[a][1]) {
1193 >        for (a = 1; a < argc-2; a++) {
1194 >                int     na;
1195 >                                        /* check for argument expansion */
1196 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1197 >                        ;
1198 >                if (na < 0) {
1199 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1200 >                                        progname, argv[a]);
1201 >                        return(1);
1202 >                }
1203 >                if (argv[a][0] != '-' || !argv[a][1])
1204 >                        break;
1205 >                na = 1;
1206 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1207                  case 'v':               /* verbose mode */
1208                          verbose = !verbose;
1209                          na = 0;
# Line 1180 | Line 1218 | main(int argc, char *argv[])
1218                          case 'f':
1219                          case 'd':
1220                          case 'c':
1221 <                                if (!(fmtopt[4] = argv[a][3]))
1222 <                                        fmtopt[4] = argv[a][2];
1223 <                                fmtopt[3] = argv[a][2];
1221 >                                if (!(fmtopt[3] = argv[a][3]))
1222 >                                        fmtopt[3] = argv[a][2];
1223 >                                fmtopt[2] = argv[a][2];
1224                                  na = 0;
1225                                  continue;       /* will pass later */
1226                          default:
# Line 1198 | Line 1236 | main(int argc, char *argv[])
1236                          na = 0;
1237                          continue;
1238                  case 'c':               /* number of samples */
1239 <                        sampcnt = atoi(argv[a+1]);
1239 >                        sampcnt = atoi(argv[++a]);
1240                          if (sampcnt <= 0)
1241                                  goto userr;
1242                          na = 0;         /* we re-add this later */
1243                          continue;
1244 +                case 'I':               /* only for pass-through mode */
1245 +                case 'i':
1246 +                        iropt = argv[a];
1247 +                        na = 0;
1248 +                        continue;
1249                  case 'V':               /* options without arguments */
1250                  case 'w':
1251                  case 'u':
1209                case 'i':
1252                  case 'h':
1253                  case 'r':
1254                          break;
# Line 1236 | Line 1278 | main(int argc, char *argv[])
1278                          if (!argv[a][2]) goto userr;
1279                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1280                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1281                  default:                /* anything else is verbotten */
1282                          goto userr;
1283                  }
# Line 1247 | Line 1287 | main(int argc, char *argv[])
1287                  while (--na)            /* + arguments if any */
1288                          rcarg[nrcargs++] = argv[++a];
1289          }
1250 done_opts:
1290          if (a > argc-2)
1291                  goto userr;             /* check at end of options */
1292          sendfn = argv[a++];             /* assign sender & receiver inputs */
1293          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1294                  if (sendfn[1]) goto userr;
1295                  sendfn = NULL;
1296 +                if (iropt) {
1297 +                        CHECKARGC(1);
1298 +                        rcarg[nrcargs++] = iropt;
1299 +                }
1300                  if (xrs) {
1301                          CHECKARGC(2);
1302                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1312 | done_opts:
1312                          rcarg[nrcargs++] = ldopt;
1313                  }
1314                  if (sampcnt <= 0) sampcnt = 1;
1315 <        } else {                        /* else FVECT determines input format */
1316 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1315 >        } else {                        /* else in sampling mode */
1316 >                if (iropt) {
1317 >                        fputs(progname, stderr);
1318 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1319 >                        return(1);
1320 >                }
1321 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1322                  if (sampcnt <= 0) sampcnt = 10000;
1323          }
1324          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1309 | Line 1357 | done_opts:
1357          if (verbose) {
1358                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1359                  if (curparams.nsurfs > 1)
1360 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1360 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1361                  else
1362                          fputc('\n', stderr);
1363          }
# Line 1320 | Line 1368 | done_opts:
1368   userr:
1369          if (a < argc-2)
1370                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1371 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1371 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1372                                  progname);
1373          return(1);
1374   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines