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.32 by greg, Fri Dec 4 22:16:18 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     quot;
333          int     i;
334  
335 <        for ( ; ; )
335 >        for ( ; ; ) {
336                  switch (*cp++) {
337                  case 'h':
338                          if (*cp++ != '=')
339                                  break;
340 <                        curparams.hsiz = 0;
340 >                        if ((*cp == '+') | (*cp == '-'))
341 >                                p->sign = *cp++;
342 >                        else
343 >                                p->sign = '+';
344 >                        p->hsiz = 0;
345                          i = 0;
346                          while (*cp && !isspace(*cp)) {
347                                  if (isdigit(*cp))
348 <                                        curparams.hsiz = 10*curparams.hsiz +
349 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
348 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
349 >                                p->hemis[i++] = *cp++;
350                          }
351                          if (!i)
352                                  break;
353 <                        curparams.hemis[i] = '\0';
354 <                        curparams.hsiz += !curparams.hsiz;
353 >                        p->hemis[i] = '\0';
354 >                        p->hsiz += !p->hsiz;
355                          ++nparams;
356                          continue;
357                  case 'u':
358                          if (*cp++ != '=')
359                                  break;
360 <                        if (!get_direction(curparams.vup, cp))
360 >                        if (!get_direction(p->vup, cp))
361                                  break;
362 +                        while (*cp && !isspace(*cp++))
363 +                                ;
364                          ++nparams;
365                          continue;
366                  case 'o':
367                          if (*cp++ != '=')
368                                  break;
369 +                        quot = 0;
370 +                        if ((*cp == '"') | (*cp == '\''))
371 +                                quot = *cp++;
372                          i = 0;
373 <                        while (*cp && !isspace(*cp++))
374 <                                i++;
373 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
374 >                                i++; cp++;
375 >                        }
376                          if (!i)
377                                  break;
378 <                        *--cp = '\0';
379 <                        curparams.outfn = savqstr(cp-i);
380 <                        *cp++ = ' ';
378 >                        if (!*cp) {
379 >                                if (quot)
380 >                                        break;
381 >                                cp[1] = '\0';
382 >                        }
383 >                        *cp = '\0';
384 >                        p->outfn = savqstr(cp-i);
385 >                        *cp++ = quot ? quot : ' ';
386                          ++nparams;
387                          continue;
388                  case ' ':
# Line 364 | Line 395 | parse_params(char *pargs)
395                  default:
396                          break;
397                  }
398 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
398 >                break;
399 >        }
400 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
401          exit(1);
402          return(-1);     /* pro forma return */
403   }
# Line 402 | Line 435 | finish_receiver(void)
435                  fputs(": undefined normal for hemisphere sampling\n", stderr);
436                  exit(1);
437          }
438 <        if (normalize(curparams.vup) == 0)
438 >        if (normalize(curparams.vup) == 0) {
439                  if (fabs(curparams.nrm[2]) < .7)
440                          curparams.vup[2] = 1;
441                  else
442                          curparams.vup[1] = 1;
443 +        }
444                                          /* determine sample type/bin */
445          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
446 <                binv = "0";             /* uniform sampling -- one bin */
446 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
447 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
448 >                binv = savqstr(sbuf);
449 >                nbins = "1";            /* uniform sampling -- one bin */
450                  uniform = 1;
451          } else if (tolower(curparams.hemis[0]) == 's' &&
452                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 457 | finish_receiver(void)
457                          exit(1);
458                  }
459                  calfn = shirchiufn; shirchiufn = NULL;
460 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
460 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
461                                  curparams.hsiz,
462                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
463 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
463 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
464 >                        curparams.sign);
465                  params = savqstr(sbuf);
466                  binv = "scbin";
467                  nbins = "SCdim*SCdim";
468          } else if ((tolower(curparams.hemis[0]) == 'r') |
469                          (tolower(curparams.hemis[0]) == 't')) {
470                  calfn = reinhfn; reinhfn = NULL;
471 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
471 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
472                                  curparams.hsiz,
473                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
474 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
474 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
475 >                        curparams.sign);
476                  params = savqstr(sbuf);
477                  binv = "rbin";
478                  nbins = "Nrbins";
# Line 461 | Line 500 | finish_receiver(void)
500                                  progname, curparams.hemis);
501                  exit(1);
502          }
503 +        if (tolower(curparams.hemis[0]) == 'k') {
504 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
505 +                params = savqstr(sbuf);
506 +        }
507          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
508                  SURF    *sp;
509                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 551 | make_axes(FVECT uva[2], const FVECT nrm)
551   {
552          int     i;
553  
554 <        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) {
554 >        if (!getperpendicular(uva[0], nrm, 1)) {
555                  fputs(progname, stderr);
556                  fputs(": bad surface normal in make_axes!\n", stderr);
557                  exit(1);
558          }
559 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
559 >        fcross(uva[1], nrm, uva[0]);
560   }
561  
562   /* Illegal sender surfaces end up here */
# Line 554 | Line 588 | ssamp_ring(FVECT orig, SURF *sp, double x)
588                  sp->priv = (void *)uva;
589          }
590          SDmultiSamp(samp2, 2, x);
591 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
591 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
592          samp2[1] *= 2.*PI;
593          uv[0] = samp2[0]*tcos(samp2[1]);
594          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 641 | ssamp_poly(FVECT orig, SURF *sp, double x)
641                          }
642                          ptp->ntris = 0;
643                          v2l->p = (void *)ptp;
644 <                        if (!polyTriangulate(v2l, add_triangle))
644 >                        if (!polyTriangulate(v2l, add_triangle)) {
645 >                                fprintf(stderr,
646 >                                        "%s: cannot triangulate polygon '%s'\n",
647 >                                                progname, sp->sname);
648                                  return(0);
649 +                        }
650                          for (i = ptp->ntris; i--; ) {
651                                  int     a = ptp->tri[i].vndx[0];
652                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 695 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
695                                          /* special case for lone surface */
696          if (p->nsurfs == 1) {
697                  sp = p->slist;
698 <                if (DOT(sp->snrm, rdir) >= -FTINY)
699 <                        return(0);      /* behind surface! */
698 >                if (DOT(sp->snrm, rdir) >= FTINY) {
699 >                        fprintf(stderr,
700 >                                "%s: internal - sample behind sender '%s'\n",
701 >                                        progname, sp->sname);
702 >                        return(0);
703 >                }
704                  return((*orig_in_surf[sp->styp])(orig, sp, x));
705          }
706          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 714 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
714                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
715                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
716          }
717 <        if (tarea <= FTINY)             /* wrong side of sender? */
717 >        if (tarea <= FTINY) {           /* wrong side of sender? */
718 >                fputs(progname, stderr);
719 >                fputs(": internal - sample behind all sender elements!\n",
720 >                                stderr);
721                  return(0);
722 +        }
723          tarea *= x;                     /* get surface from list */
724          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
725                  tarea -= projsa[i++];
# Line 746 | Line 792 | sample_reinhart(PARAMS *p, int b, FILE *fp)
792   #define T_NALT  7
793          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
794          const int               RowMax = T_NALT*p->hsiz + 1;
795 <        const double            RAH = (.25*PI)/(RowMax-.5);
795 >        const double            RAH = (.5*PI)/(RowMax-.5);
796   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
797          int                     n = sampcnt;
798          int                     row, col;
# Line 771 | Line 817 | sample_reinhart(PARAMS *p, int b, FILE *fp)
817                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
818                  alt = (row+samp3[1])*RAH;
819                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
820 <                duvw[2] = tcos(alt);    /* measured from horizon */
821 <                duvw[0] = tcos(azi)*duvw[2];
822 <                duvw[1] = tsin(azi)*duvw[2];
820 >                duvw[2] = cos(alt);     /* measured from horizon */
821 >                duvw[0] = tsin(azi)*duvw[2];
822 >                duvw[1] = tcos(azi)*duvw[2];
823                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
824                  for (i = 3; i--; )
825                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 870 | sample_klems(PARAMS *p, int b, FILE *fp)
870  
871          while (n--) {                   /* stratified sampling */
872                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
873 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
873 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
874                          return(0);
875                  for (i = 3; i--; )
876 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
877 <                                                duvw[1]*p->vdir[i] +
876 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
877 >                                                duvw[1]*p->vdir[i] -
878                                                  duvw[2]*p->nrm[i] ;
879                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
880                          return(0);
# Line 847 | Line 893 | prepare_sampler(void)
893                  fputs(": no sender surface!\n", stderr);
894                  return(-1);
895          }
896 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
896 >                                        /* misplaced output file spec. */
897 >        if ((curparams.outfn != NULL) & (verbose >= 0))
898                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
899                                  progname, curparams.outfn);
900                                          /* check/set basis hemisphere */
# Line 861 | Line 908 | prepare_sampler(void)
908                  fputs(": undefined normal for sender sampling\n", stderr);
909                  return(-1);
910          }
911 <        if (normalize(curparams.vup) == 0)
911 >        if (normalize(curparams.vup) == 0) {
912                  if (fabs(curparams.nrm[2]) < .7)
913                          curparams.vup[2] = 1;
914                  else
915                          curparams.vup[1] = 1;
916 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
916 >        }
917 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
918          if (normalize(curparams.udir) == 0) {
919                  fputs(progname, stderr);
920                  fputs(": up vector coincides with sender normal\n", stderr);
921                  return(-1);
922          }
923 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
923 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
924 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
925 >                curparams.udir[0] *= -1.;
926 >                curparams.udir[1] *= -1.;
927 >                curparams.udir[2] *= -1.;
928 >        }
929          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
930                  curparams.sample_basis = sample_uniform;
931          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 1042 | add_surface(int st, const char *oname, FILE *fp)
1042          case ST_SOURCE:
1043                  if (snew->nfargs != 4)
1044                          goto badcount;
1045 <                VCOPY(snew->snrm, snew->farg);
1045 >                for (n = 3; n--; )      /* need to reverse "normal" */
1046 >                        snew->snrm[n] = -snew->farg[n];
1047                  if (normalize(snew->snrm) == 0)
1048                          goto badnorm;
1049                  snew->area = sin((PI/180./2.)*snew->farg[3]);
1050                  snew->area *= PI*snew->area;
1051                  break;
1052          }
1053 <        if (snew->area <= FTINY) {
1053 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1054                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1055                                  progname, oname);
1056                  free(snew);
# Line 1008 | Line 1062 | add_surface(int st, const char *oname, FILE *fp)
1062          curparams.nsurfs++;
1063          return;
1064   badcount:
1065 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1065 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1066                          progname, oname);
1067          exit(1);
1068   badnorm:
1069 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1069 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1070                          progname, oname);
1071          exit(1);
1072   }
# Line 1044 | Line 1098 | add_recv_object(FILE *fp)
1098                                  finish_receiver();
1099                                  clear_params(&curparams, 1);
1100                          }
1101 +                        parse_params(&curparams, newparams);
1102 +                        newparams[0] = '\0';
1103                          strcpy(curmod, thismod);
1104                  }
1105                  add_surface(st, oname, fp);     /* read & store surface */
1106                  return(1);
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 1064 | Line 1120 | static int
1120   add_send_object(FILE *fp)
1121   {
1122          int             st;
1123 <        char            otype[32], oname[128];
1123 >        char            thismod[128], otype[32], oname[128];
1124          int             n;
1125  
1126 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1126 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1127                  return(0);              /* must have hit EOF! */
1128          if (!strcmp(otype, "alias")) {
1129                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1136 | add_send_object(FILE *fp)
1136                          fputs(": cannot use source as a sender!\n", stderr);
1137                          return(-1);
1138                  }
1139 +                if (strcmp(thismod, curmod)) {
1140 +                        if (curmod[0]) {
1141 +                                fputs(progname, stderr);
1142 +                                fputs(": warning - multiple modifiers in sender\n",
1143 +                                                stderr);
1144 +                        }
1145 +                        strcpy(curmod, thismod);
1146 +                }
1147 +                parse_params(&curparams, newparams);
1148 +                newparams[0] = '\0';
1149                  add_surface(st, oname, fp);     /* read & store surface */
1150                  return(0);
1151          }
1152                                          /* else skip arguments */
1153 <        if (!fscanf(fp, "%d", &n)) return;
1153 >        if (!fscanf(fp, "%d", &n)) return(0);
1154          while (n-- > 0) fscanf(fp, "%*s");
1155 <        if (!fscanf(fp, "%d", &n)) return;
1155 >        if (!fscanf(fp, "%d", &n)) return(0);
1156          while (n-- > 0) fscanf(fp, "%*d");
1157 <        if (!fscanf(fp, "%d", &n)) return;
1157 >        if (!fscanf(fp, "%d", &n)) return(0);
1158          while (n-- > 0) fscanf(fp, "%*f");
1159          return(0);
1160   }
# Line 1128 | Line 1194 | load_scene(const char *inspec, int (*ocb)(FILE *))
1194                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1195                                          !strcmp(inpbuf, PARAMSTART)) {
1196                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1197 <                                        parse_params(inpbuf);
1197 >                                        strcat(newparams, inpbuf);
1198                                  continue;
1199                          }
1200 <                        while ((c = getc(fp)) != EOF && c != '\n');
1200 >                        while ((c = getc(fp)) != EOF && c != '\n')
1201                                  ;       /* else skipping comment */
1202                          continue;
1203                  }
# Line 1156 | Line 1222 | main(int argc, char *argv[])
1222   {
1223          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1224          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1225 +        char    *iropt = NULL;
1226          char    *sendfn;
1227          char    sampcntbuf[32], nsbinbuf[32];
1228          FILE    *rcfp;
# Line 1163 | Line 1230 | main(int argc, char *argv[])
1230          int     a, i;
1231                                          /* screen rcontrib options */
1232          progname = argv[0];
1233 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1234 <                int     na = 1;         /* !! Keep consistent !! */
1235 <                switch (argv[a][1]) {
1233 >        for (a = 1; a < argc-2; a++) {
1234 >                int     na;
1235 >                                        /* check for argument expansion */
1236 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1237 >                        ;
1238 >                if (na < 0) {
1239 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1240 >                                        progname, argv[a]);
1241 >                        return(1);
1242 >                }
1243 >                if (argv[a][0] != '-' || !argv[a][1])
1244 >                        break;
1245 >                na = 1;
1246 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1247                  case 'v':               /* verbose mode */
1248 <                        verbose = !verbose;
1248 >                        verbose = 1;
1249                          na = 0;
1250                          continue;
1251                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1258 | main(int argc, char *argv[])
1258                          case 'f':
1259                          case 'd':
1260                          case 'c':
1261 <                                if (!(fmtopt[4] = argv[a][3]))
1262 <                                        fmtopt[4] = argv[a][2];
1263 <                                fmtopt[3] = argv[a][2];
1261 >                                if (!(fmtopt[3] = argv[a][3]))
1262 >                                        fmtopt[3] = argv[a][2];
1263 >                                fmtopt[2] = argv[a][2];
1264                                  na = 0;
1265                                  continue;       /* will pass later */
1266                          default:
# Line 1198 | Line 1276 | main(int argc, char *argv[])
1276                          na = 0;
1277                          continue;
1278                  case 'c':               /* number of samples */
1279 <                        sampcnt = atoi(argv[a+1]);
1279 >                        sampcnt = atoi(argv[++a]);
1280                          if (sampcnt <= 0)
1281                                  goto userr;
1282                          na = 0;         /* we re-add this later */
1283                          continue;
1284 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1284 >                case 'I':               /* only for pass-through mode */
1285                  case 'i':
1286 +                        iropt = argv[a];
1287 +                        na = 0;
1288 +                        continue;
1289 +                case 'w':               /* options without arguments */
1290 +                        if (argv[a][2] != '+') verbose = -1;
1291 +                case 'V':
1292 +                case 'u':
1293                  case 'h':
1294                  case 'r':
1295                          break;
# Line 1230 | Line 1313 | main(int argc, char *argv[])
1313                          if (argv[a][2] != 'v') na = 2;
1314                          break;
1315                  case 'a':               /* special case */
1316 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1316 >                        if (argv[a][2] == 'p') {
1317 >                                na = 2; /* photon map [+ bandwidth(s)] */
1318 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1319 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1320 >                        } else
1321 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1322                          break;
1323                  case 'm':               /* special case */
1324                          if (!argv[a][2]) goto userr;
1325                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1326                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1327                  default:                /* anything else is verbotten */
1328                          goto userr;
1329                  }
# Line 1247 | Line 1333 | main(int argc, char *argv[])
1333                  while (--na)            /* + arguments if any */
1334                          rcarg[nrcargs++] = argv[++a];
1335          }
1250 done_opts:
1336          if (a > argc-2)
1337                  goto userr;             /* check at end of options */
1338          sendfn = argv[a++];             /* assign sender & receiver inputs */
1339          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1340                  if (sendfn[1]) goto userr;
1341                  sendfn = NULL;
1342 +                if (iropt) {
1343 +                        CHECKARGC(1);
1344 +                        rcarg[nrcargs++] = iropt;
1345 +                }
1346                  if (xrs) {
1347                          CHECKARGC(2);
1348                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1358 | done_opts:
1358                          rcarg[nrcargs++] = ldopt;
1359                  }
1360                  if (sampcnt <= 0) sampcnt = 1;
1361 <        } else {                        /* else FVECT determines input format */
1362 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1361 >        } else {                        /* else in sampling mode */
1362 >                if (iropt) {
1363 >                        fputs(progname, stderr);
1364 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1365 >                        return(1);
1366 >                }
1367 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1368                  if (sampcnt <= 0) sampcnt = 10000;
1369          }
1370          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1383 | done_opts:
1383                  return(my_exec(rcarg)); /* rcontrib does everything */
1384          }
1385          clear_params(&curparams, 0);    /* else load sender surface & params */
1386 +        curmod[0] = '\0';
1387          if (load_scene(sendfn, add_send_object) < 0)
1388                  return(1);
1389          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1401 | done_opts:
1401   #ifdef getc_unlocked
1402          flockfile(rcfp);
1403   #endif
1404 <        if (verbose) {
1404 >        if (verbose > 0) {
1405                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1406                  if (curparams.nsurfs > 1)
1407 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1407 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1408                  else
1409                          fputc('\n', stderr);
1410          }
1411          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1412                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1413                          return(1);
1414 <        return(pclose(rcfp) == 0);      /* all finished! */
1414 >        return(pclose(rcfp) < 0);       /* all finished! */
1415   userr:
1416          if (a < argc-2)
1417                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1418 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1418 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1419                                  progname);
1420          return(1);
1421   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines