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.27 by greg, Wed Apr 1 01:38:36 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 83 | Line 84 | typedef struct {
84   } POLYTRIS;                     /* triangulated polygon */
85  
86   typedef struct param_s {
87 <        char            hemis[32];      /* hemispherical sampling spec. */
87 >        char            sign;           /* '-' for axis reversal */
88 >        char            hemis[31];      /* hemispherical sampling spec. */
89          int             hsiz;           /* hemisphere basis size */
90          int             nsurfs;         /* number of surfaces */
91          SURF            *slist;         /* list of surfaces */
92          FVECT           vup;            /* up vector (zero if unset) */
93          FVECT           nrm;            /* average normal direction */
94 <        FVECT           udir, vdir;     /* v-up tangent axes */
94 >        FVECT           udir, vdir;     /* tangent axes */
95          char            *outfn;         /* output file name (receiver) */
96          int             (*sample_basis)(struct param_s *p, int, FILE *);
97   } PARAMS;                       /* sender/receiver parameters */
98  
99   PARAMS          curparams;
100   char            curmod[128];
101 + char            newparams[1024];
102  
103   typedef int     SURFSAMP(FVECT, SURF *, double);
104  
# Line 109 | Line 112 | SURFSAMP       *orig_in_surf[4] = {
112   static void
113   clear_params(PARAMS *p, int reset_only)
114   {
112        curmod[0] = '\0';
115          while (p->slist != NULL) {
116                  SURF    *sdel = p->slist;
117                  p->slist = sdel->next;
# Line 124 | Line 126 | clear_params(PARAMS *p, int reset_only)
126                  p->outfn = NULL;
127                  return;
128          }
129 <        memset(p, 0, sizeof(curparams));
129 >        memset(p, 0, sizeof(PARAMS));
130   }
131  
132   /* Get surface type from name */
# Line 144 | Line 146 | surf_type(const char *otype)
146   static char *
147   oconv_command(int ac, char *av[])
148   {
149 <        static char     oconvbuf[2048] = "!oconv -f";
150 <        char            *cp = oconvbuf + 9;
151 <
149 >        static char     oconvbuf[2048] = "!oconv -f ";
150 >        char            *cp = oconvbuf + 10;
151 >        char            *recv = *av++;
152 >        
153 >        if (ac-- <= 0)
154 >                return(NULL);
155          while (ac-- > 0) {
156 +                strcpy(cp, *av++);
157 +                while (*cp) cp++;
158 +                *cp++ = ' ';
159                  if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) {
160                          fputs(progname, stderr);
161                          fputs(": too many file arguments!\n", stderr);
162                          exit(1);
163                  }
156                *cp++ = ' ';
157                strcpy(cp, *av++);
158                while (*cp) cp++;
164          }
165 <        *cp = '\0';
165 >        strcpy(cp, recv);       /* receiver goes last */
166          return(oconvbuf);
167   }
168  
# Line 222 | Line 227 | popen_arglist(char *av[], char *mode)
227                  fputs(": command line too long in popen_arglist()\n", stderr);
228                  return(NULL);
229          }
230 <        if (verbose)
230 >        if (verbose > 0)
231                  fprintf(stderr, "%s: opening pipe %s: %s\n",
232                                  progname, (*mode=='w') ? "to" : "from", cmd);
233          return(popen(cmd, mode));
# Line 240 | Line 245 | my_exec(char *av[])
245                  fputs(": command line too long in my_exec()\n", stderr);
246                  return(1);
247          }
248 <        if (verbose)
248 >        if (verbose > 0)
249                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
250          return(system(cmd));
251   }
# Line 255 | Line 260 | my_exec(char *av[])
260                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
261                  return(1);
262          }
263 <        if (verbose) {
263 >        if (verbose > 0) {
264                  char    cmd[4096];
265                  if (!convert_commandline(cmd, sizeof(cmd), av))
266                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 309 | Line 314 | nextchar:
314  
315   /* Parse program parameters (directives) */
316   static int
317 < parse_params(char *pargs)
317 > parse_params(PARAMS *p, char *pargs)
318   {
319          char    *cp = pargs;
320          int     nparams = 0;
321          int     i;
322  
323 <        for ( ; ; )
323 >        for ( ; ; ) {
324                  switch (*cp++) {
325                  case 'h':
326                          if (*cp++ != '=')
327                                  break;
328 <                        curparams.hsiz = 0;
328 >                        if ((*cp == '+') | (*cp == '-'))
329 >                                p->sign = *cp++;
330 >                        else
331 >                                p->sign = '+';
332 >                        p->hsiz = 0;
333                          i = 0;
334                          while (*cp && !isspace(*cp)) {
335                                  if (isdigit(*cp))
336 <                                        curparams.hsiz = 10*curparams.hsiz +
337 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
336 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
337 >                                p->hemis[i++] = *cp++;
338                          }
339                          if (!i)
340                                  break;
341 <                        curparams.hemis[i] = '\0';
342 <                        curparams.hsiz += !curparams.hsiz;
341 >                        p->hemis[i] = '\0';
342 >                        p->hsiz += !p->hsiz;
343                          ++nparams;
344                          continue;
345                  case 'u':
346                          if (*cp++ != '=')
347                                  break;
348 <                        if (!get_direction(curparams.vup, cp))
348 >                        if (!get_direction(p->vup, cp))
349                                  break;
350 +                        while (*cp && !isspace(*cp++))
351 +                                ;
352                          ++nparams;
353                          continue;
354                  case 'o':
# Line 350 | Line 360 | parse_params(char *pargs)
360                          if (!i)
361                                  break;
362                          *--cp = '\0';
363 <                        curparams.outfn = savqstr(cp-i);
363 >                        p->outfn = savqstr(cp-i);
364                          *cp++ = ' ';
365                          ++nparams;
366                          continue;
# Line 364 | Line 374 | parse_params(char *pargs)
374                  default:
375                          break;
376                  }
377 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
377 >                break;
378 >        }
379 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
380          exit(1);
381          return(-1);     /* pro forma return */
382   }
# Line 402 | Line 414 | finish_receiver(void)
414                  fputs(": undefined normal for hemisphere sampling\n", stderr);
415                  exit(1);
416          }
417 <        if (normalize(curparams.vup) == 0)
417 >        if (normalize(curparams.vup) == 0) {
418                  if (fabs(curparams.nrm[2]) < .7)
419                          curparams.vup[2] = 1;
420                  else
421                          curparams.vup[1] = 1;
422 +        }
423                                          /* determine sample type/bin */
424          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
425 <                binv = "0";             /* uniform sampling -- one bin */
425 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
426 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
427 >                binv = savqstr(sbuf);
428 >                nbins = "1";            /* uniform sampling -- one bin */
429                  uniform = 1;
430          } else if (tolower(curparams.hemis[0]) == 's' &&
431                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 436 | finish_receiver(void)
436                          exit(1);
437                  }
438                  calfn = shirchiufn; shirchiufn = NULL;
439 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
439 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
440                                  curparams.hsiz,
441                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
442 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
442 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
443 >                        curparams.sign);
444                  params = savqstr(sbuf);
445                  binv = "scbin";
446                  nbins = "SCdim*SCdim";
447          } else if ((tolower(curparams.hemis[0]) == 'r') |
448                          (tolower(curparams.hemis[0]) == 't')) {
449                  calfn = reinhfn; reinhfn = NULL;
450 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
450 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
451                                  curparams.hsiz,
452                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
453 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
453 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
454 >                        curparams.sign);
455                  params = savqstr(sbuf);
456                  binv = "rbin";
457                  nbins = "Nrbins";
# Line 461 | Line 479 | finish_receiver(void)
479                                  progname, curparams.hemis);
480                  exit(1);
481          }
482 +        if (tolower(curparams.hemis[0]) == 'k') {
483 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
484 +                params = savqstr(sbuf);
485 +        }
486          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
487                  SURF    *sp;
488                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 530 | make_axes(FVECT uva[2], const FVECT nrm)
530   {
531          int     i;
532  
533 <        uva[1][0] = 0.5 - frandom();
512 <        uva[1][1] = 0.5 - frandom();
513 <        uva[1][2] = 0.5 - frandom();
514 <        for (i = 3; i--; )
515 <                if ((-0.6 < nrm[i]) & (nrm[i] < 0.6))
516 <                        break;
517 <        if (i < 0) {
533 >        if (!getperpendicular(uva[0], nrm)) {
534                  fputs(progname, stderr);
535                  fputs(": bad surface normal in make_axes!\n", stderr);
536                  exit(1);
537          }
538 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
538 >        fcross(uva[1], nrm, uva[0]);
539   }
540  
541   /* Illegal sender surfaces end up here */
# Line 554 | Line 567 | ssamp_ring(FVECT orig, SURF *sp, double x)
567                  sp->priv = (void *)uva;
568          }
569          SDmultiSamp(samp2, 2, x);
570 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
570 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
571          samp2[1] *= 2.*PI;
572          uv[0] = samp2[0]*tcos(samp2[1]);
573          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 620 | ssamp_poly(FVECT orig, SURF *sp, double x)
620                          }
621                          ptp->ntris = 0;
622                          v2l->p = (void *)ptp;
623 <                        if (!polyTriangulate(v2l, add_triangle))
623 >                        if (!polyTriangulate(v2l, add_triangle)) {
624 >                                fprintf(stderr,
625 >                                        "%s: cannot triangulate polygon '%s'\n",
626 >                                                progname, sp->sname);
627                                  return(0);
628 +                        }
629                          for (i = ptp->ntris; i--; ) {
630                                  int     a = ptp->tri[i].vndx[0];
631                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 674 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
674                                          /* special case for lone surface */
675          if (p->nsurfs == 1) {
676                  sp = p->slist;
677 <                if (DOT(sp->snrm, rdir) >= -FTINY)
678 <                        return(0);      /* behind surface! */
677 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
678 >                        fprintf(stderr,
679 >                                "%s: internal - sample behind sender '%s'\n",
680 >                                        progname, sp->sname);
681 >                        return(0);
682 >                }
683                  return((*orig_in_surf[sp->styp])(orig, sp, x));
684          }
685          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 693 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
693                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
694                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
695          }
696 <        if (tarea <= FTINY)             /* wrong side of sender? */
696 >        if (tarea <= FTINY) {           /* wrong side of sender? */
697 >                fputs(progname, stderr);
698 >                fputs(": internal - sample behind all sender elements!\n",
699 >                                stderr);
700                  return(0);
701 +        }
702          tarea *= x;                     /* get surface from list */
703          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
704                  tarea -= projsa[i++];
# Line 746 | Line 771 | sample_reinhart(PARAMS *p, int b, FILE *fp)
771   #define T_NALT  7
772          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
773          const int               RowMax = T_NALT*p->hsiz + 1;
774 <        const double            RAH = (.25*PI)/(RowMax-.5);
774 >        const double            RAH = (.5*PI)/(RowMax-.5);
775   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
776          int                     n = sampcnt;
777          int                     row, col;
# Line 771 | Line 796 | sample_reinhart(PARAMS *p, int b, FILE *fp)
796                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
797                  alt = (row+samp3[1])*RAH;
798                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
799 <                duvw[2] = tcos(alt);    /* measured from horizon */
800 <                duvw[0] = tcos(azi)*duvw[2];
801 <                duvw[1] = tsin(azi)*duvw[2];
799 >                duvw[2] = cos(alt);     /* measured from horizon */
800 >                duvw[0] = tsin(azi)*duvw[2];
801 >                duvw[1] = tcos(azi)*duvw[2];
802                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
803                  for (i = 3; i--; )
804                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 849 | sample_klems(PARAMS *p, int b, FILE *fp)
849  
850          while (n--) {                   /* stratified sampling */
851                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
852 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
852 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
853                          return(0);
854                  for (i = 3; i--; )
855 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
856 <                                                duvw[1]*p->vdir[i] +
855 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
856 >                                                duvw[1]*p->vdir[i] -
857                                                  duvw[2]*p->nrm[i] ;
858                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
859                          return(0);
# Line 847 | Line 872 | prepare_sampler(void)
872                  fputs(": no sender surface!\n", stderr);
873                  return(-1);
874          }
875 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
875 >                                        /* misplaced output file spec. */
876 >        if ((curparams.outfn != NULL) & (verbose >= 0))
877                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
878                                  progname, curparams.outfn);
879                                          /* check/set basis hemisphere */
# Line 861 | Line 887 | prepare_sampler(void)
887                  fputs(": undefined normal for sender sampling\n", stderr);
888                  return(-1);
889          }
890 <        if (normalize(curparams.vup) == 0)
890 >        if (normalize(curparams.vup) == 0) {
891                  if (fabs(curparams.nrm[2]) < .7)
892                          curparams.vup[2] = 1;
893                  else
894                          curparams.vup[1] = 1;
895 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
895 >        }
896 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
897          if (normalize(curparams.udir) == 0) {
898                  fputs(progname, stderr);
899                  fputs(": up vector coincides with sender normal\n", stderr);
900                  return(-1);
901          }
902 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
902 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
903 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
904 >                curparams.udir[0] *= -1.;
905 >                curparams.udir[1] *= -1.;
906 >                curparams.udir[2] *= -1.;
907 >        }
908          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
909                  curparams.sample_basis = sample_uniform;
910          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 1021 | add_surface(int st, const char *oname, FILE *fp)
1021          case ST_SOURCE:
1022                  if (snew->nfargs != 4)
1023                          goto badcount;
1024 <                VCOPY(snew->snrm, snew->farg);
1024 >                for (n = 3; n--; )      /* need to reverse "normal" */
1025 >                        snew->snrm[n] = -snew->farg[n];
1026                  if (normalize(snew->snrm) == 0)
1027                          goto badnorm;
1028                  snew->area = sin((PI/180./2.)*snew->farg[3]);
1029                  snew->area *= PI*snew->area;
1030                  break;
1031          }
1032 <        if (snew->area <= FTINY) {
1032 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1033                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1034                                  progname, oname);
1035                  free(snew);
# Line 1008 | Line 1041 | add_surface(int st, const char *oname, FILE *fp)
1041          curparams.nsurfs++;
1042          return;
1043   badcount:
1044 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1044 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1045                          progname, oname);
1046          exit(1);
1047   badnorm:
1048 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1048 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1049                          progname, oname);
1050          exit(1);
1051   }
# Line 1044 | Line 1077 | add_recv_object(FILE *fp)
1077                                  finish_receiver();
1078                                  clear_params(&curparams, 1);
1079                          }
1080 +                        parse_params(&curparams, newparams);
1081 +                        newparams[0] = '\0';
1082                          strcpy(curmod, thismod);
1083                  }
1084                  add_surface(st, oname, fp);     /* read & store surface */
1085                  return(1);
1086          }
1087                                          /* else skip arguments */
1088 <        if (!fscanf(fp, "%d", &n)) return;
1088 >        if (!fscanf(fp, "%d", &n)) return(0);
1089          while (n-- > 0) fscanf(fp, "%*s");
1090 <        if (!fscanf(fp, "%d", &n)) return;
1090 >        if (!fscanf(fp, "%d", &n)) return(0);
1091          while (n-- > 0) fscanf(fp, "%*d");
1092 <        if (!fscanf(fp, "%d", &n)) return;
1092 >        if (!fscanf(fp, "%d", &n)) return(0);
1093          while (n-- > 0) fscanf(fp, "%*f");
1094          return(0);
1095   }
# Line 1064 | Line 1099 | static int
1099   add_send_object(FILE *fp)
1100   {
1101          int             st;
1102 <        char            otype[32], oname[128];
1102 >        char            thismod[128], otype[32], oname[128];
1103          int             n;
1104  
1105 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1105 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1106                  return(0);              /* must have hit EOF! */
1107          if (!strcmp(otype, "alias")) {
1108                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1115 | add_send_object(FILE *fp)
1115                          fputs(": cannot use source as a sender!\n", stderr);
1116                          return(-1);
1117                  }
1118 +                if (strcmp(thismod, curmod)) {
1119 +                        if (curmod[0]) {
1120 +                                fputs(progname, stderr);
1121 +                                fputs(": warning - multiple modifiers in sender\n",
1122 +                                                stderr);
1123 +                        }
1124 +                        strcpy(curmod, thismod);
1125 +                }
1126 +                parse_params(&curparams, newparams);
1127 +                newparams[0] = '\0';
1128                  add_surface(st, oname, fp);     /* read & store surface */
1129                  return(0);
1130          }
1131                                          /* else skip arguments */
1132 <        if (!fscanf(fp, "%d", &n)) return;
1132 >        if (!fscanf(fp, "%d", &n)) return(0);
1133          while (n-- > 0) fscanf(fp, "%*s");
1134 <        if (!fscanf(fp, "%d", &n)) return;
1134 >        if (!fscanf(fp, "%d", &n)) return(0);
1135          while (n-- > 0) fscanf(fp, "%*d");
1136 <        if (!fscanf(fp, "%d", &n)) return;
1136 >        if (!fscanf(fp, "%d", &n)) return(0);
1137          while (n-- > 0) fscanf(fp, "%*f");
1138          return(0);
1139   }
# Line 1128 | Line 1173 | load_scene(const char *inspec, int (*ocb)(FILE *))
1173                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1174                                          !strcmp(inpbuf, PARAMSTART)) {
1175                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1176 <                                        parse_params(inpbuf);
1176 >                                        strcat(newparams, inpbuf);
1177                                  continue;
1178                          }
1179 <                        while ((c = getc(fp)) != EOF && c != '\n');
1179 >                        while ((c = getc(fp)) != EOF && c != '\n')
1180                                  ;       /* else skipping comment */
1181                          continue;
1182                  }
# Line 1156 | Line 1201 | main(int argc, char *argv[])
1201   {
1202          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1203          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1204 +        char    *iropt = NULL;
1205          char    *sendfn;
1206          char    sampcntbuf[32], nsbinbuf[32];
1207          FILE    *rcfp;
# Line 1163 | Line 1209 | main(int argc, char *argv[])
1209          int     a, i;
1210                                          /* screen rcontrib options */
1211          progname = argv[0];
1212 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1213 <                int     na = 1;         /* !! Keep consistent !! */
1214 <                switch (argv[a][1]) {
1212 >        for (a = 1; a < argc-2; a++) {
1213 >                int     na;
1214 >                                        /* check for argument expansion */
1215 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1216 >                        ;
1217 >                if (na < 0) {
1218 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1219 >                                        progname, argv[a]);
1220 >                        return(1);
1221 >                }
1222 >                if (argv[a][0] != '-' || !argv[a][1])
1223 >                        break;
1224 >                na = 1;
1225 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1226                  case 'v':               /* verbose mode */
1227 <                        verbose = !verbose;
1227 >                        verbose = 1;
1228                          na = 0;
1229                          continue;
1230                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1237 | main(int argc, char *argv[])
1237                          case 'f':
1238                          case 'd':
1239                          case 'c':
1240 <                                if (!(fmtopt[4] = argv[a][3]))
1241 <                                        fmtopt[4] = argv[a][2];
1242 <                                fmtopt[3] = argv[a][2];
1240 >                                if (!(fmtopt[3] = argv[a][3]))
1241 >                                        fmtopt[3] = argv[a][2];
1242 >                                fmtopt[2] = argv[a][2];
1243                                  na = 0;
1244                                  continue;       /* will pass later */
1245                          default:
# Line 1198 | Line 1255 | main(int argc, char *argv[])
1255                          na = 0;
1256                          continue;
1257                  case 'c':               /* number of samples */
1258 <                        sampcnt = atoi(argv[a+1]);
1258 >                        sampcnt = atoi(argv[++a]);
1259                          if (sampcnt <= 0)
1260                                  goto userr;
1261                          na = 0;         /* we re-add this later */
1262                          continue;
1263 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1263 >                case 'I':               /* only for pass-through mode */
1264                  case 'i':
1265 +                        iropt = argv[a];
1266 +                        na = 0;
1267 +                        continue;
1268 +                case 'w':               /* options without arguments */
1269 +                        if (argv[a][2] != '+') verbose = -1;
1270 +                case 'V':
1271 +                case 'u':
1272                  case 'h':
1273                  case 'r':
1274                          break;
# Line 1236 | Line 1298 | main(int argc, char *argv[])
1298                          if (!argv[a][2]) goto userr;
1299                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1300                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1301                  default:                /* anything else is verbotten */
1302                          goto userr;
1303                  }
# Line 1247 | Line 1307 | main(int argc, char *argv[])
1307                  while (--na)            /* + arguments if any */
1308                          rcarg[nrcargs++] = argv[++a];
1309          }
1250 done_opts:
1310          if (a > argc-2)
1311                  goto userr;             /* check at end of options */
1312          sendfn = argv[a++];             /* assign sender & receiver inputs */
1313          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1314                  if (sendfn[1]) goto userr;
1315                  sendfn = NULL;
1316 +                if (iropt) {
1317 +                        CHECKARGC(1);
1318 +                        rcarg[nrcargs++] = iropt;
1319 +                }
1320                  if (xrs) {
1321                          CHECKARGC(2);
1322                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1332 | done_opts:
1332                          rcarg[nrcargs++] = ldopt;
1333                  }
1334                  if (sampcnt <= 0) sampcnt = 1;
1335 <        } else {                        /* else FVECT determines input format */
1336 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1335 >        } else {                        /* else in sampling mode */
1336 >                if (iropt) {
1337 >                        fputs(progname, stderr);
1338 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1339 >                        return(1);
1340 >                }
1341 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1342                  if (sampcnt <= 0) sampcnt = 10000;
1343          }
1344          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1357 | done_opts:
1357                  return(my_exec(rcarg)); /* rcontrib does everything */
1358          }
1359          clear_params(&curparams, 0);    /* else load sender surface & params */
1360 +        curmod[0] = '\0';
1361          if (load_scene(sendfn, add_send_object) < 0)
1362                  return(1);
1363          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1375 | done_opts:
1375   #ifdef getc_unlocked
1376          flockfile(rcfp);
1377   #endif
1378 <        if (verbose) {
1378 >        if (verbose > 0) {
1379                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1380                  if (curparams.nsurfs > 1)
1381 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1381 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1382                  else
1383                          fputc('\n', stderr);
1384          }
1385          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1386                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1387                          return(1);
1388 <        return(pclose(rcfp) == 0);      /* all finished! */
1388 >        return(pclose(rcfp) < 0);       /* all finished! */
1389   userr:
1390          if (a < argc-2)
1391                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1392 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1392 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1393                                  progname);
1394          return(1);
1395   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines