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.6 by greg, Wed Jul 23 00:40:17 2014 UTC vs.
Revision 2.14 by greg, Wed Aug 6 02:38:24 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 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 401 | Line 405 | finish_receiver(void)
405                  fputs(": undefined normal for hemisphere sampling\n", stderr);
406                  exit(1);
407          }
408 <        if (normalize(curparams.vup) == 0)
408 >        if (normalize(curparams.vup) == 0) {
409                  if (fabs(curparams.nrm[2]) < .7)
410                          curparams.vup[2] = 1;
411                  else
412                          curparams.vup[1] = 1;
413 +        }
414                                          /* determine sample type/bin */
415          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
416                  binv = "0";             /* uniform sampling -- one bin */
# Line 419 | Line 424 | finish_receiver(void)
424                          exit(1);
425                  }
426                  calfn = shirchiufn; shirchiufn = NULL;
427 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
427 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
428                                  curparams.hsiz,
429                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
430                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 429 | Line 434 | finish_receiver(void)
434          } else if ((tolower(curparams.hemis[0]) == 'r') |
435                          (tolower(curparams.hemis[0]) == 't')) {
436                  calfn = reinhfn; reinhfn = NULL;
437 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
437 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
438                                  curparams.hsiz,
439                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
440                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 606 | Line 611 | ssamp_poly(FVECT orig, SURF *sp, double x)
611                          }
612                          ptp->ntris = 0;
613                          v2l->p = (void *)ptp;
614 <                        if (!polyTriangulate(v2l, add_triangle))
614 >                        if (!polyTriangulate(v2l, add_triangle)) {
615 >                                fprintf(stderr,
616 >                                        "%s: cannot triangulate polygon '%s'\n",
617 >                                                progname, sp->sname);
618                                  return(0);
619 +                        }
620                          for (i = ptp->ntris; i--; ) {
621                                  int     a = ptp->tri[i].vndx[0];
622                                  int     b = ptp->tri[i].vndx[1];
# Line 656 | Line 665 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
665                                          /* special case for lone surface */
666          if (p->nsurfs == 1) {
667                  sp = p->slist;
668 <                if (DOT(sp->snrm, rdir) >= -FTINY)
669 <                        return(0);      /* behind surface! */
668 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
669 >                        fprintf(stderr,
670 >                                "%s: internal - sample behind sender '%s'\n",
671 >                                        progname, sp->sname);
672 >                        return(0);
673 >                }
674                  return((*orig_in_surf[sp->styp])(orig, sp, x));
675          }
676          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 671 | Line 684 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
684                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
685                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
686          }
687 <        if (tarea <= FTINY)             /* wrong side of sender? */
687 >        if (tarea <= FTINY) {           /* wrong side of sender? */
688 >                fputs(progname, stderr);
689 >                fputs(": internal - sample behind all sender elements!\n",
690 >                                stderr);
691                  return(0);
692 +        }
693          tarea *= x;                     /* get surface from list */
694          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
695                  tarea -= projsa[i++];
# Line 745 | Line 762 | sample_reinhart(PARAMS *p, int b, FILE *fp)
762   #define T_NALT  7
763          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
764          const int               RowMax = T_NALT*p->hsiz + 1;
765 <        const double            RAH = (.25*PI)/(RowMax-.5);
765 >        const double            RAH = (.5*PI)/(RowMax-.5);
766   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
767          int                     n = sampcnt;
768          int                     row, col;
# Line 770 | Line 787 | sample_reinhart(PARAMS *p, int b, FILE *fp)
787                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
788                  alt = (row+samp3[1])*RAH;
789                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
790 <                duvw[2] = tcos(alt);    /* measured from horizon */
790 >                duvw[2] = cos(alt);     /* measured from horizon */
791                  duvw[0] = tcos(azi)*duvw[2];
792                  duvw[1] = tsin(azi)*duvw[2];
793                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
# Line 860 | Line 877 | prepare_sampler(void)
877                  fputs(": undefined normal for sender sampling\n", stderr);
878                  return(-1);
879          }
880 <        if (normalize(curparams.vup) == 0)
880 >        if (normalize(curparams.vup) == 0) {
881                  if (fabs(curparams.nrm[2]) < .7)
882                          curparams.vup[2] = 1;
883                  else
884                          curparams.vup[1] = 1;
885 +        }
886          VCROSS(curparams.udir, curparams.vup, curparams.nrm);
887          if (normalize(curparams.udir) == 0) {
888                  fputs(progname, stderr);
# Line 988 | Line 1006 | add_surface(int st, const char *oname, FILE *fp)
1006          case ST_SOURCE:
1007                  if (snew->nfargs != 4)
1008                          goto badcount;
1009 <                VCOPY(snew->snrm, snew->farg);
1009 >                for (n = 3; n--; )      /* need to reverse "normal" */
1010 >                        snew->snrm[n] = -snew->farg[n];
1011                  if (normalize(snew->snrm) == 0)
1012                          goto badnorm;
1013                  snew->area = sin((PI/180./2.)*snew->farg[3]);
# Line 1007 | Line 1026 | add_surface(int st, const char *oname, FILE *fp)
1026          curparams.nsurfs++;
1027          return;
1028   badcount:
1029 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1029 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1030                          progname, oname);
1031          exit(1);
1032   badnorm:
1033 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1033 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1034                          progname, oname);
1035          exit(1);
1036   }
# Line 1051 | Line 1070 | add_recv_object(FILE *fp)
1070                  return(1);
1071          }
1072                                          /* else skip arguments */
1073 <        if (!fscanf(fp, "%d", &n)) return;
1073 >        if (!fscanf(fp, "%d", &n)) return(0);
1074          while (n-- > 0) fscanf(fp, "%*s");
1075 <        if (!fscanf(fp, "%d", &n)) return;
1075 >        if (!fscanf(fp, "%d", &n)) return(0);
1076          while (n-- > 0) fscanf(fp, "%*d");
1077 <        if (!fscanf(fp, "%d", &n)) return;
1077 >        if (!fscanf(fp, "%d", &n)) return(0);
1078          while (n-- > 0) fscanf(fp, "%*f");
1079          return(0);
1080   }
# Line 1087 | Line 1106 | add_send_object(FILE *fp)
1106                  return(0);
1107          }
1108                                          /* else skip arguments */
1109 <        if (!fscanf(fp, "%d", &n)) return;
1109 >        if (!fscanf(fp, "%d", &n)) return(0);
1110          while (n-- > 0) fscanf(fp, "%*s");
1111 <        if (!fscanf(fp, "%d", &n)) return;
1111 >        if (!fscanf(fp, "%d", &n)) return(0);
1112          while (n-- > 0) fscanf(fp, "%*d");
1113 <        if (!fscanf(fp, "%d", &n)) return;
1113 >        if (!fscanf(fp, "%d", &n)) return(0);
1114          while (n-- > 0) fscanf(fp, "%*f");
1115          return(0);
1116   }
# Line 1134 | Line 1153 | load_scene(const char *inspec, int (*ocb)(FILE *))
1153                                          strcat(newparams, inpbuf);
1154                                  continue;
1155                          }
1156 <                        while ((c = getc(fp)) != EOF && c != '\n');
1156 >                        while ((c = getc(fp)) != EOF && c != '\n')
1157                                  ;       /* else skipping comment */
1158                          continue;
1159                  }
# Line 1159 | Line 1178 | main(int argc, char *argv[])
1178   {
1179          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1180          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1181 +        char    *iropt = NULL;
1182          char    *sendfn;
1183          char    sampcntbuf[32], nsbinbuf[32];
1184          FILE    *rcfp;
# Line 1166 | Line 1186 | main(int argc, char *argv[])
1186          int     a, i;
1187                                          /* screen rcontrib options */
1188          progname = argv[0];
1189 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1190 <                int     na = 1;         /* !! Keep consistent !! */
1191 <                switch (argv[a][1]) {
1189 >        for (a = 1; a < argc-2; a++) {
1190 >                int     na;
1191 >                                        /* check for argument expansion */
1192 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1193 >                        ;
1194 >                if (na < 0) {
1195 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1196 >                                        progname, argv[a]);
1197 >                        return(1);
1198 >                }
1199 >                if (argv[a][0] != '-' || !argv[a][1])
1200 >                        break;
1201 >                na = 1;
1202 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1203                  case 'v':               /* verbose mode */
1204                          verbose = !verbose;
1205                          na = 0;
# Line 1206 | Line 1237 | main(int argc, char *argv[])
1237                                  goto userr;
1238                          na = 0;         /* we re-add this later */
1239                          continue;
1240 +                case 'I':               /* only for pass-through mode */
1241 +                case 'i':
1242 +                        iropt = argv[a];
1243 +                        na = 0;
1244 +                        continue;
1245                  case 'V':               /* options without arguments */
1246                  case 'w':
1247                  case 'u':
1212                case 'i':
1248                  case 'h':
1249                  case 'r':
1250                          break;
# Line 1239 | Line 1274 | main(int argc, char *argv[])
1274                          if (!argv[a][2]) goto userr;
1275                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1276                          break;
1242                case '\0':              /* pass-through mode */
1243                        goto done_opts;
1277                  default:                /* anything else is verbotten */
1278                          goto userr;
1279                  }
# Line 1250 | Line 1283 | main(int argc, char *argv[])
1283                  while (--na)            /* + arguments if any */
1284                          rcarg[nrcargs++] = argv[++a];
1285          }
1253 done_opts:
1286          if (a > argc-2)
1287                  goto userr;             /* check at end of options */
1288          sendfn = argv[a++];             /* assign sender & receiver inputs */
1289          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1290                  if (sendfn[1]) goto userr;
1291                  sendfn = NULL;
1292 +                if (iropt) {
1293 +                        CHECKARGC(1);
1294 +                        rcarg[nrcargs++] = iropt;
1295 +                }
1296                  if (xrs) {
1297                          CHECKARGC(2);
1298                          rcarg[nrcargs++] = "-x";
# Line 1272 | Line 1308 | done_opts:
1308                          rcarg[nrcargs++] = ldopt;
1309                  }
1310                  if (sampcnt <= 0) sampcnt = 1;
1311 <        } else {                        /* else FVECT determines input format */
1311 >        } else {                        /* else in sampling mode */
1312 >                if (iropt) {
1313 >                        fputs(progname, stderr);
1314 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1315 >                        return(1);
1316 >                }
1317                  fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1318                  if (sampcnt <= 0) sampcnt = 10000;
1319          }
# Line 1312 | Line 1353 | done_opts:
1353          if (verbose) {
1354                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1355                  if (curparams.nsurfs > 1)
1356 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1356 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1357                  else
1358                          fputc('\n', stderr);
1359          }
# Line 1323 | Line 1364 | done_opts:
1364   userr:
1365          if (a < argc-2)
1366                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1367 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1367 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1368                                  progname);
1369          return(1);
1370   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines