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.30 by greg, Wed Jul 22 04:23:27 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 140 | Line 142 | surf_type(const char *otype)
142          return(ST_NONE);
143   }
144  
143 /* Add arguments to oconv command */
144 static char *
145 oconv_command(int ac, char *av[])
146 {
147        static char     oconvbuf[2048] = "!oconv -f";
148        char            *cp = oconvbuf + 9;
149
150        while (ac-- > 0) {
151                if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) {
152                        fputs(progname, stderr);
153                        fputs(": too many file arguments!\n", stderr);
154                        exit(1);
155                }
156                *cp++ = ' ';
157                strcpy(cp, *av++);
158                while (*cp) cp++;
159        }
160        *cp = '\0';
161        return(oconvbuf);
162 }
163
145   /* Check if any of the characters in str2 are found in str1 */
146   static int
147   matchany(const char *str1, const char *str2)
# Line 175 | Line 156 | matchany(const char *str1, const char *str2)
156          return(0);
157   }
158  
159 + /* Add arguments to oconv command */
160 + static char *
161 + oconv_command(int ac, char *av[])
162 + {
163 +        static char     oconvbuf[2048] = "!oconv -f ";
164 +        char            *cp = oconvbuf + 10;
165 +        char            *recv = *av++;
166 +        
167 +        if (ac-- <= 0)
168 +                return(NULL);
169 +        while (ac-- > 0) {
170 +                strcpy(cp, *av++);
171 +                while (*cp) cp++;
172 +                *cp++ = ' ';
173 +                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
174 +                        goto overrun;
175 +        }
176 +                                /* receiver goes last */
177 +        if (matchany(recv, SPECIALS)) {
178 +                *cp++ = QUOTCHAR;
179 +                while (*recv) {
180 +                        if (cp >= oconvbuf+(sizeof(oconvbuf)-3))
181 +                                goto overrun;
182 +                        *cp++ = *recv++;
183 +                }
184 +                *cp++ = QUOTCHAR;
185 +                *cp = '\0';
186 +        } else
187 +                strcpy(cp, recv);
188 +        return(oconvbuf);
189 + overrun:
190 +        fputs(progname, stderr);
191 +        fputs(": too many file arguments!\n", stderr);
192 +        exit(1);
193 + }
194  
195   /* Convert a set of arguments into a command line for pipe() or system() */
196   static char *
# Line 189 | Line 205 | convert_commandline(char *cmd, const int len, char *av
205                          fputs(progname, stderr);
206                          return(NULL);
207                  }
208 <                if ((match = matchany(*av, SPECIALS))) {
208 >                if (matchany(*av, SPECIALS)) {
209                          const int       quote =
210   #ifdef ALTQUOT
211 <                                (match == QUOTCHAR) ? ALTQUOT :
211 >                                strchr(*av, QUOTCHAR) ? ALTQUOT :
212   #endif
213                                          QUOTCHAR;
214                          *cp++ = quote;
# Line 222 | Line 238 | popen_arglist(char *av[], char *mode)
238                  fputs(": command line too long in popen_arglist()\n", stderr);
239                  return(NULL);
240          }
241 <        if (verbose)
241 >        if (verbose > 0)
242                  fprintf(stderr, "%s: opening pipe %s: %s\n",
243                                  progname, (*mode=='w') ? "to" : "from", cmd);
244          return(popen(cmd, mode));
# Line 240 | Line 256 | my_exec(char *av[])
256                  fputs(": command line too long in my_exec()\n", stderr);
257                  return(1);
258          }
259 <        if (verbose)
259 >        if (verbose > 0)
260                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
261          return(system(cmd));
262   }
# Line 255 | Line 271 | my_exec(char *av[])
271                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
272                  return(1);
273          }
274 <        if (verbose) {
274 >        if (verbose > 0) {
275                  char    cmd[4096];
276                  if (!convert_commandline(cmd, sizeof(cmd), av))
277                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 309 | Line 325 | nextchar:
325  
326   /* Parse program parameters (directives) */
327   static int
328 < parse_params(char *pargs)
328 > parse_params(PARAMS *p, char *pargs)
329   {
330          char    *cp = pargs;
331          int     nparams = 0;
332          int     i;
333  
334 <        for ( ; ; )
334 >        for ( ; ; ) {
335                  switch (*cp++) {
336                  case 'h':
337                          if (*cp++ != '=')
338                                  break;
339 <                        curparams.hsiz = 0;
339 >                        if ((*cp == '+') | (*cp == '-'))
340 >                                p->sign = *cp++;
341 >                        else
342 >                                p->sign = '+';
343 >                        p->hsiz = 0;
344                          i = 0;
345                          while (*cp && !isspace(*cp)) {
346                                  if (isdigit(*cp))
347 <                                        curparams.hsiz = 10*curparams.hsiz +
348 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
347 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
348 >                                p->hemis[i++] = *cp++;
349                          }
350                          if (!i)
351                                  break;
352 <                        curparams.hemis[i] = '\0';
353 <                        curparams.hsiz += !curparams.hsiz;
352 >                        p->hemis[i] = '\0';
353 >                        p->hsiz += !p->hsiz;
354                          ++nparams;
355                          continue;
356                  case 'u':
357                          if (*cp++ != '=')
358                                  break;
359 <                        if (!get_direction(curparams.vup, cp))
359 >                        if (!get_direction(p->vup, cp))
360                                  break;
361 +                        while (*cp && !isspace(*cp++))
362 +                                ;
363                          ++nparams;
364                          continue;
365                  case 'o':
# Line 350 | Line 371 | parse_params(char *pargs)
371                          if (!i)
372                                  break;
373                          *--cp = '\0';
374 <                        curparams.outfn = savqstr(cp-i);
374 >                        p->outfn = savqstr(cp-i);
375                          *cp++ = ' ';
376                          ++nparams;
377                          continue;
# Line 364 | Line 385 | parse_params(char *pargs)
385                  default:
386                          break;
387                  }
388 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
388 >                break;
389 >        }
390 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
391          exit(1);
392          return(-1);     /* pro forma return */
393   }
# Line 402 | Line 425 | finish_receiver(void)
425                  fputs(": undefined normal for hemisphere sampling\n", stderr);
426                  exit(1);
427          }
428 <        if (normalize(curparams.vup) == 0)
428 >        if (normalize(curparams.vup) == 0) {
429                  if (fabs(curparams.nrm[2]) < .7)
430                          curparams.vup[2] = 1;
431                  else
432                          curparams.vup[1] = 1;
433 +        }
434                                          /* determine sample type/bin */
435          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
436 <                binv = "0";             /* uniform sampling -- one bin */
436 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
437 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
438 >                binv = savqstr(sbuf);
439 >                nbins = "1";            /* uniform sampling -- one bin */
440                  uniform = 1;
441          } else if (tolower(curparams.hemis[0]) == 's' &&
442                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 447 | finish_receiver(void)
447                          exit(1);
448                  }
449                  calfn = shirchiufn; shirchiufn = NULL;
450 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
450 >                sprintf(sbuf, "SCdim=%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 = "scbin";
457                  nbins = "SCdim*SCdim";
458          } else if ((tolower(curparams.hemis[0]) == 'r') |
459                          (tolower(curparams.hemis[0]) == 't')) {
460                  calfn = reinhfn; reinhfn = NULL;
461 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
461 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
462                                  curparams.hsiz,
463                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
464 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
464 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
465 >                        curparams.sign);
466                  params = savqstr(sbuf);
467                  binv = "rbin";
468                  nbins = "Nrbins";
# Line 461 | Line 490 | finish_receiver(void)
490                                  progname, curparams.hemis);
491                  exit(1);
492          }
493 +        if (tolower(curparams.hemis[0]) == 'k') {
494 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
495 +                params = savqstr(sbuf);
496 +        }
497          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
498                  SURF    *sp;
499                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 541 | make_axes(FVECT uva[2], const FVECT nrm)
541   {
542          int     i;
543  
544 <        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) {
544 >        if (!getperpendicular(uva[0], nrm, 1)) {
545                  fputs(progname, stderr);
546                  fputs(": bad surface normal in make_axes!\n", stderr);
547                  exit(1);
548          }
549 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
549 >        fcross(uva[1], nrm, uva[0]);
550   }
551  
552   /* Illegal sender surfaces end up here */
# Line 554 | Line 578 | ssamp_ring(FVECT orig, SURF *sp, double x)
578                  sp->priv = (void *)uva;
579          }
580          SDmultiSamp(samp2, 2, x);
581 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
581 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
582          samp2[1] *= 2.*PI;
583          uv[0] = samp2[0]*tcos(samp2[1]);
584          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 631 | ssamp_poly(FVECT orig, SURF *sp, double x)
631                          }
632                          ptp->ntris = 0;
633                          v2l->p = (void *)ptp;
634 <                        if (!polyTriangulate(v2l, add_triangle))
634 >                        if (!polyTriangulate(v2l, add_triangle)) {
635 >                                fprintf(stderr,
636 >                                        "%s: cannot triangulate polygon '%s'\n",
637 >                                                progname, sp->sname);
638                                  return(0);
639 +                        }
640                          for (i = ptp->ntris; i--; ) {
641                                  int     a = ptp->tri[i].vndx[0];
642                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 685 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
685                                          /* special case for lone surface */
686          if (p->nsurfs == 1) {
687                  sp = p->slist;
688 <                if (DOT(sp->snrm, rdir) >= -FTINY)
689 <                        return(0);      /* behind surface! */
688 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
689 >                        fprintf(stderr,
690 >                                "%s: internal - sample behind sender '%s'\n",
691 >                                        progname, sp->sname);
692 >                        return(0);
693 >                }
694                  return((*orig_in_surf[sp->styp])(orig, sp, x));
695          }
696          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 704 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
704                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
705                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
706          }
707 <        if (tarea <= FTINY)             /* wrong side of sender? */
707 >        if (tarea <= FTINY) {           /* wrong side of sender? */
708 >                fputs(progname, stderr);
709 >                fputs(": internal - sample behind all sender elements!\n",
710 >                                stderr);
711                  return(0);
712 +        }
713          tarea *= x;                     /* get surface from list */
714          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
715                  tarea -= projsa[i++];
# Line 746 | Line 782 | sample_reinhart(PARAMS *p, int b, FILE *fp)
782   #define T_NALT  7
783          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
784          const int               RowMax = T_NALT*p->hsiz + 1;
785 <        const double            RAH = (.25*PI)/(RowMax-.5);
785 >        const double            RAH = (.5*PI)/(RowMax-.5);
786   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
787          int                     n = sampcnt;
788          int                     row, col;
# Line 771 | Line 807 | sample_reinhart(PARAMS *p, int b, FILE *fp)
807                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
808                  alt = (row+samp3[1])*RAH;
809                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
810 <                duvw[2] = tcos(alt);    /* measured from horizon */
811 <                duvw[0] = tcos(azi)*duvw[2];
812 <                duvw[1] = tsin(azi)*duvw[2];
810 >                duvw[2] = cos(alt);     /* measured from horizon */
811 >                duvw[0] = tsin(azi)*duvw[2];
812 >                duvw[1] = tcos(azi)*duvw[2];
813                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
814                  for (i = 3; i--; )
815                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 860 | sample_klems(PARAMS *p, int b, FILE *fp)
860  
861          while (n--) {                   /* stratified sampling */
862                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
863 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
863 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
864                          return(0);
865                  for (i = 3; i--; )
866 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
867 <                                                duvw[1]*p->vdir[i] +
866 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
867 >                                                duvw[1]*p->vdir[i] -
868                                                  duvw[2]*p->nrm[i] ;
869                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
870                          return(0);
# Line 847 | Line 883 | prepare_sampler(void)
883                  fputs(": no sender surface!\n", stderr);
884                  return(-1);
885          }
886 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
886 >                                        /* misplaced output file spec. */
887 >        if ((curparams.outfn != NULL) & (verbose >= 0))
888                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
889                                  progname, curparams.outfn);
890                                          /* check/set basis hemisphere */
# Line 861 | Line 898 | prepare_sampler(void)
898                  fputs(": undefined normal for sender sampling\n", stderr);
899                  return(-1);
900          }
901 <        if (normalize(curparams.vup) == 0)
901 >        if (normalize(curparams.vup) == 0) {
902                  if (fabs(curparams.nrm[2]) < .7)
903                          curparams.vup[2] = 1;
904                  else
905                          curparams.vup[1] = 1;
906 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
906 >        }
907 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
908          if (normalize(curparams.udir) == 0) {
909                  fputs(progname, stderr);
910                  fputs(": up vector coincides with sender normal\n", stderr);
911                  return(-1);
912          }
913 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
913 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
914 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
915 >                curparams.udir[0] *= -1.;
916 >                curparams.udir[1] *= -1.;
917 >                curparams.udir[2] *= -1.;
918 >        }
919          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
920                  curparams.sample_basis = sample_uniform;
921          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 1032 | add_surface(int st, const char *oname, FILE *fp)
1032          case ST_SOURCE:
1033                  if (snew->nfargs != 4)
1034                          goto badcount;
1035 <                VCOPY(snew->snrm, snew->farg);
1035 >                for (n = 3; n--; )      /* need to reverse "normal" */
1036 >                        snew->snrm[n] = -snew->farg[n];
1037                  if (normalize(snew->snrm) == 0)
1038                          goto badnorm;
1039                  snew->area = sin((PI/180./2.)*snew->farg[3]);
1040                  snew->area *= PI*snew->area;
1041                  break;
1042          }
1043 <        if (snew->area <= FTINY) {
1043 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1044                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1045                                  progname, oname);
1046                  free(snew);
# Line 1008 | Line 1052 | add_surface(int st, const char *oname, FILE *fp)
1052          curparams.nsurfs++;
1053          return;
1054   badcount:
1055 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1055 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1056                          progname, oname);
1057          exit(1);
1058   badnorm:
1059 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1059 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1060                          progname, oname);
1061          exit(1);
1062   }
# Line 1044 | Line 1088 | add_recv_object(FILE *fp)
1088                                  finish_receiver();
1089                                  clear_params(&curparams, 1);
1090                          }
1091 +                        parse_params(&curparams, newparams);
1092 +                        newparams[0] = '\0';
1093                          strcpy(curmod, thismod);
1094                  }
1095                  add_surface(st, oname, fp);     /* read & store surface */
1096                  return(1);
1097          }
1098                                          /* else skip arguments */
1099 <        if (!fscanf(fp, "%d", &n)) return;
1099 >        if (!fscanf(fp, "%d", &n)) return(0);
1100          while (n-- > 0) fscanf(fp, "%*s");
1101 <        if (!fscanf(fp, "%d", &n)) return;
1101 >        if (!fscanf(fp, "%d", &n)) return(0);
1102          while (n-- > 0) fscanf(fp, "%*d");
1103 <        if (!fscanf(fp, "%d", &n)) return;
1103 >        if (!fscanf(fp, "%d", &n)) return(0);
1104          while (n-- > 0) fscanf(fp, "%*f");
1105          return(0);
1106   }
# Line 1064 | Line 1110 | static int
1110   add_send_object(FILE *fp)
1111   {
1112          int             st;
1113 <        char            otype[32], oname[128];
1113 >        char            thismod[128], otype[32], oname[128];
1114          int             n;
1115  
1116 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1116 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1117                  return(0);              /* must have hit EOF! */
1118          if (!strcmp(otype, "alias")) {
1119                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1126 | add_send_object(FILE *fp)
1126                          fputs(": cannot use source as a sender!\n", stderr);
1127                          return(-1);
1128                  }
1129 +                if (strcmp(thismod, curmod)) {
1130 +                        if (curmod[0]) {
1131 +                                fputs(progname, stderr);
1132 +                                fputs(": warning - multiple modifiers in sender\n",
1133 +                                                stderr);
1134 +                        }
1135 +                        strcpy(curmod, thismod);
1136 +                }
1137 +                parse_params(&curparams, newparams);
1138 +                newparams[0] = '\0';
1139                  add_surface(st, oname, fp);     /* read & store surface */
1140                  return(0);
1141          }
1142                                          /* else skip arguments */
1143 <        if (!fscanf(fp, "%d", &n)) return;
1143 >        if (!fscanf(fp, "%d", &n)) return(0);
1144          while (n-- > 0) fscanf(fp, "%*s");
1145 <        if (!fscanf(fp, "%d", &n)) return;
1145 >        if (!fscanf(fp, "%d", &n)) return(0);
1146          while (n-- > 0) fscanf(fp, "%*d");
1147 <        if (!fscanf(fp, "%d", &n)) return;
1147 >        if (!fscanf(fp, "%d", &n)) return(0);
1148          while (n-- > 0) fscanf(fp, "%*f");
1149          return(0);
1150   }
# Line 1128 | Line 1184 | load_scene(const char *inspec, int (*ocb)(FILE *))
1184                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1185                                          !strcmp(inpbuf, PARAMSTART)) {
1186                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1187 <                                        parse_params(inpbuf);
1187 >                                        strcat(newparams, inpbuf);
1188                                  continue;
1189                          }
1190 <                        while ((c = getc(fp)) != EOF && c != '\n');
1190 >                        while ((c = getc(fp)) != EOF && c != '\n')
1191                                  ;       /* else skipping comment */
1192                          continue;
1193                  }
# Line 1156 | Line 1212 | main(int argc, char *argv[])
1212   {
1213          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1214          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1215 +        char    *iropt = NULL;
1216          char    *sendfn;
1217          char    sampcntbuf[32], nsbinbuf[32];
1218          FILE    *rcfp;
# Line 1163 | Line 1220 | main(int argc, char *argv[])
1220          int     a, i;
1221                                          /* screen rcontrib options */
1222          progname = argv[0];
1223 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1224 <                int     na = 1;         /* !! Keep consistent !! */
1225 <                switch (argv[a][1]) {
1223 >        for (a = 1; a < argc-2; a++) {
1224 >                int     na;
1225 >                                        /* check for argument expansion */
1226 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1227 >                        ;
1228 >                if (na < 0) {
1229 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1230 >                                        progname, argv[a]);
1231 >                        return(1);
1232 >                }
1233 >                if (argv[a][0] != '-' || !argv[a][1])
1234 >                        break;
1235 >                na = 1;
1236 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1237                  case 'v':               /* verbose mode */
1238 <                        verbose = !verbose;
1238 >                        verbose = 1;
1239                          na = 0;
1240                          continue;
1241                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1248 | main(int argc, char *argv[])
1248                          case 'f':
1249                          case 'd':
1250                          case 'c':
1251 <                                if (!(fmtopt[4] = argv[a][3]))
1252 <                                        fmtopt[4] = argv[a][2];
1253 <                                fmtopt[3] = argv[a][2];
1251 >                                if (!(fmtopt[3] = argv[a][3]))
1252 >                                        fmtopt[3] = argv[a][2];
1253 >                                fmtopt[2] = argv[a][2];
1254                                  na = 0;
1255                                  continue;       /* will pass later */
1256                          default:
# Line 1198 | Line 1266 | main(int argc, char *argv[])
1266                          na = 0;
1267                          continue;
1268                  case 'c':               /* number of samples */
1269 <                        sampcnt = atoi(argv[a+1]);
1269 >                        sampcnt = atoi(argv[++a]);
1270                          if (sampcnt <= 0)
1271                                  goto userr;
1272                          na = 0;         /* we re-add this later */
1273                          continue;
1274 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1274 >                case 'I':               /* only for pass-through mode */
1275                  case 'i':
1276 +                        iropt = argv[a];
1277 +                        na = 0;
1278 +                        continue;
1279 +                case 'w':               /* options without arguments */
1280 +                        if (argv[a][2] != '+') verbose = -1;
1281 +                case 'V':
1282 +                case 'u':
1283                  case 'h':
1284                  case 'r':
1285                          break;
# Line 1230 | Line 1303 | main(int argc, char *argv[])
1303                          if (argv[a][2] != 'v') na = 2;
1304                          break;
1305                  case 'a':               /* special case */
1306 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1306 >                        if (argv[a][2] == 'p') {
1307 >                                na = 2; /* photon map [+ bandwidth(s)] */
1308 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1309 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1310 >                        } else
1311 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1312                          break;
1313                  case 'm':               /* special case */
1314                          if (!argv[a][2]) goto userr;
1315                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1316                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1317                  default:                /* anything else is verbotten */
1318                          goto userr;
1319                  }
# Line 1247 | Line 1323 | main(int argc, char *argv[])
1323                  while (--na)            /* + arguments if any */
1324                          rcarg[nrcargs++] = argv[++a];
1325          }
1250 done_opts:
1326          if (a > argc-2)
1327                  goto userr;             /* check at end of options */
1328          sendfn = argv[a++];             /* assign sender & receiver inputs */
1329          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1330                  if (sendfn[1]) goto userr;
1331                  sendfn = NULL;
1332 +                if (iropt) {
1333 +                        CHECKARGC(1);
1334 +                        rcarg[nrcargs++] = iropt;
1335 +                }
1336                  if (xrs) {
1337                          CHECKARGC(2);
1338                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1348 | done_opts:
1348                          rcarg[nrcargs++] = ldopt;
1349                  }
1350                  if (sampcnt <= 0) sampcnt = 1;
1351 <        } else {                        /* else FVECT determines input format */
1352 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1351 >        } else {                        /* else in sampling mode */
1352 >                if (iropt) {
1353 >                        fputs(progname, stderr);
1354 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1355 >                        return(1);
1356 >                }
1357 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1358                  if (sampcnt <= 0) sampcnt = 10000;
1359          }
1360          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1373 | done_opts:
1373                  return(my_exec(rcarg)); /* rcontrib does everything */
1374          }
1375          clear_params(&curparams, 0);    /* else load sender surface & params */
1376 +        curmod[0] = '\0';
1377          if (load_scene(sendfn, add_send_object) < 0)
1378                  return(1);
1379          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1391 | done_opts:
1391   #ifdef getc_unlocked
1392          flockfile(rcfp);
1393   #endif
1394 <        if (verbose) {
1394 >        if (verbose > 0) {
1395                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1396                  if (curparams.nsurfs > 1)
1397 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1397 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1398                  else
1399                          fputc('\n', stderr);
1400          }
1401          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1402                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1403                          return(1);
1404 <        return(pclose(rcfp) == 0);      /* all finished! */
1404 >        return(pclose(rcfp) < 0);       /* all finished! */
1405   userr:
1406          if (a < argc-2)
1407                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1408 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1408 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1409                                  progname);
1410          return(1);
1411   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines