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.33 by greg, Tue Feb 2 01:43:24 2016 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 185 | Line 201 | convert_commandline(char *cmd, const int len, char *av
201  
202          for (cp = cmd; *av != NULL; av++) {
203                  const int       n = strlen(*av);
204 <                if (cp+n >= cmd+(len-3)) {
189 <                        fputs(progname, stderr);
204 >                if (cp+n >= cmd+(len-3))
205                          return(NULL);
206 <                }
192 <                if ((match = matchany(*av, SPECIALS))) {
206 >                if (matchany(*av, SPECIALS)) {
207                          const int       quote =
208   #ifdef ALTQUOT
209 <                                (match == QUOTCHAR) ? ALTQUOT :
209 >                                strchr(*av, QUOTCHAR) ? ALTQUOT :
210   #endif
211                                          QUOTCHAR;
212                          *cp++ = quote;
# Line 222 | Line 236 | popen_arglist(char *av[], char *mode)
236                  fputs(": command line too long in popen_arglist()\n", stderr);
237                  return(NULL);
238          }
239 <        if (verbose)
239 >        if (verbose > 0)
240                  fprintf(stderr, "%s: opening pipe %s: %s\n",
241                                  progname, (*mode=='w') ? "to" : "from", cmd);
242          return(popen(cmd, mode));
# Line 240 | Line 254 | my_exec(char *av[])
254                  fputs(": command line too long in my_exec()\n", stderr);
255                  return(1);
256          }
257 <        if (verbose)
257 >        if (verbose > 0)
258                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
259          return(system(cmd));
260   }
# Line 255 | Line 269 | my_exec(char *av[])
269                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
270                  return(1);
271          }
272 <        if (verbose) {
272 >        if (verbose > 0) {
273                  char    cmd[4096];
274                  if (!convert_commandline(cmd, sizeof(cmd), av))
275                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 309 | Line 323 | nextchar:
323  
324   /* Parse program parameters (directives) */
325   static int
326 < parse_params(char *pargs)
326 > parse_params(PARAMS *p, char *pargs)
327   {
328          char    *cp = pargs;
329          int     nparams = 0;
330 +        int     quot;
331          int     i;
332  
333 <        for ( ; ; )
333 >        for ( ; ; ) {
334                  switch (*cp++) {
335                  case 'h':
336                          if (*cp++ != '=')
337                                  break;
338 <                        curparams.hsiz = 0;
338 >                        if ((*cp == '+') | (*cp == '-'))
339 >                                p->sign = *cp++;
340 >                        else
341 >                                p->sign = '+';
342 >                        p->hsiz = 0;
343                          i = 0;
344                          while (*cp && !isspace(*cp)) {
345                                  if (isdigit(*cp))
346 <                                        curparams.hsiz = 10*curparams.hsiz +
347 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
346 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
347 >                                p->hemis[i++] = *cp++;
348                          }
349                          if (!i)
350                                  break;
351 <                        curparams.hemis[i] = '\0';
352 <                        curparams.hsiz += !curparams.hsiz;
351 >                        p->hemis[i] = '\0';
352 >                        p->hsiz += !p->hsiz;
353                          ++nparams;
354                          continue;
355                  case 'u':
356                          if (*cp++ != '=')
357                                  break;
358 <                        if (!get_direction(curparams.vup, cp))
358 >                        if (!get_direction(p->vup, cp))
359                                  break;
360 +                        while (*cp && !isspace(*cp++))
361 +                                ;
362                          ++nparams;
363                          continue;
364                  case 'o':
365                          if (*cp++ != '=')
366                                  break;
367 +                        quot = 0;
368 +                        if ((*cp == '"') | (*cp == '\''))
369 +                                quot = *cp++;
370                          i = 0;
371 <                        while (*cp && !isspace(*cp++))
372 <                                i++;
371 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
372 >                                i++; cp++;
373 >                        }
374                          if (!i)
375                                  break;
376 <                        *--cp = '\0';
377 <                        curparams.outfn = savqstr(cp-i);
378 <                        *cp++ = ' ';
376 >                        if (!*cp) {
377 >                                if (quot)
378 >                                        break;
379 >                                cp[1] = '\0';
380 >                        }
381 >                        *cp = '\0';
382 >                        p->outfn = savqstr(cp-i);
383 >                        *cp++ = quot ? quot : ' ';
384                          ++nparams;
385                          continue;
386                  case ' ':
# Line 364 | Line 393 | parse_params(char *pargs)
393                  default:
394                          break;
395                  }
396 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
396 >                break;
397 >        }
398 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
399          exit(1);
400          return(-1);     /* pro forma return */
401   }
# Line 402 | Line 433 | finish_receiver(void)
433                  fputs(": undefined normal for hemisphere sampling\n", stderr);
434                  exit(1);
435          }
436 <        if (normalize(curparams.vup) == 0)
436 >        if (normalize(curparams.vup) == 0) {
437                  if (fabs(curparams.nrm[2]) < .7)
438                          curparams.vup[2] = 1;
439                  else
440                          curparams.vup[1] = 1;
441 +        }
442                                          /* determine sample type/bin */
443          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
444 <                binv = "0";             /* uniform sampling -- one bin */
444 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
445 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
446 >                binv = savqstr(sbuf);
447 >                nbins = "1";            /* uniform sampling -- one bin */
448                  uniform = 1;
449          } else if (tolower(curparams.hemis[0]) == 's' &&
450                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 455 | finish_receiver(void)
455                          exit(1);
456                  }
457                  calfn = shirchiufn; shirchiufn = NULL;
458 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
458 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
459                                  curparams.hsiz,
460                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
461 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
461 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
462 >                        curparams.sign);
463                  params = savqstr(sbuf);
464                  binv = "scbin";
465                  nbins = "SCdim*SCdim";
466          } else if ((tolower(curparams.hemis[0]) == 'r') |
467                          (tolower(curparams.hemis[0]) == 't')) {
468                  calfn = reinhfn; reinhfn = NULL;
469 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
469 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
470                                  curparams.hsiz,
471                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
472 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
472 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
473 >                        curparams.sign);
474                  params = savqstr(sbuf);
475                  binv = "rbin";
476                  nbins = "Nrbins";
# Line 461 | Line 498 | finish_receiver(void)
498                                  progname, curparams.hemis);
499                  exit(1);
500          }
501 +        if (tolower(curparams.hemis[0]) == 'k') {
502 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
503 +                params = savqstr(sbuf);
504 +        }
505          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
506                  SURF    *sp;
507                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 549 | make_axes(FVECT uva[2], const FVECT nrm)
549   {
550          int     i;
551  
552 <        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) {
552 >        if (!getperpendicular(uva[0], nrm, 1)) {
553                  fputs(progname, stderr);
554                  fputs(": bad surface normal in make_axes!\n", stderr);
555                  exit(1);
556          }
557 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
557 >        fcross(uva[1], nrm, uva[0]);
558   }
559  
560   /* Illegal sender surfaces end up here */
# Line 554 | Line 586 | ssamp_ring(FVECT orig, SURF *sp, double x)
586                  sp->priv = (void *)uva;
587          }
588          SDmultiSamp(samp2, 2, x);
589 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
589 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
590          samp2[1] *= 2.*PI;
591          uv[0] = samp2[0]*tcos(samp2[1]);
592          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 639 | ssamp_poly(FVECT orig, SURF *sp, double x)
639                          }
640                          ptp->ntris = 0;
641                          v2l->p = (void *)ptp;
642 <                        if (!polyTriangulate(v2l, add_triangle))
642 >                        if (!polyTriangulate(v2l, add_triangle)) {
643 >                                fprintf(stderr,
644 >                                        "%s: cannot triangulate polygon '%s'\n",
645 >                                                progname, sp->sname);
646                                  return(0);
647 +                        }
648                          for (i = ptp->ntris; i--; ) {
649                                  int     a = ptp->tri[i].vndx[0];
650                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 693 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
693                                          /* special case for lone surface */
694          if (p->nsurfs == 1) {
695                  sp = p->slist;
696 <                if (DOT(sp->snrm, rdir) >= -FTINY)
697 <                        return(0);      /* behind surface! */
696 >                if (DOT(sp->snrm, rdir) >= FTINY) {
697 >                        fprintf(stderr,
698 >                                "%s: internal - sample behind sender '%s'\n",
699 >                                        progname, sp->sname);
700 >                        return(0);
701 >                }
702                  return((*orig_in_surf[sp->styp])(orig, sp, x));
703          }
704          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 712 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
712                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
713                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
714          }
715 <        if (tarea <= FTINY)             /* wrong side of sender? */
715 >        if (tarea <= FTINY) {           /* wrong side of sender? */
716 >                fputs(progname, stderr);
717 >                fputs(": internal - sample behind all sender elements!\n",
718 >                                stderr);
719                  return(0);
720 +        }
721          tarea *= x;                     /* get surface from list */
722          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
723                  tarea -= projsa[i++];
# Line 746 | Line 790 | sample_reinhart(PARAMS *p, int b, FILE *fp)
790   #define T_NALT  7
791          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
792          const int               RowMax = T_NALT*p->hsiz + 1;
793 <        const double            RAH = (.25*PI)/(RowMax-.5);
793 >        const double            RAH = (.5*PI)/(RowMax-.5);
794   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
795          int                     n = sampcnt;
796          int                     row, col;
# Line 771 | Line 815 | sample_reinhart(PARAMS *p, int b, FILE *fp)
815                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
816                  alt = (row+samp3[1])*RAH;
817                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
818 <                duvw[2] = tcos(alt);    /* measured from horizon */
819 <                duvw[0] = tcos(azi)*duvw[2];
820 <                duvw[1] = tsin(azi)*duvw[2];
818 >                duvw[2] = cos(alt);     /* measured from horizon */
819 >                duvw[0] = tsin(azi)*duvw[2];
820 >                duvw[1] = tcos(azi)*duvw[2];
821                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
822                  for (i = 3; i--; )
823                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 868 | sample_klems(PARAMS *p, int b, FILE *fp)
868  
869          while (n--) {                   /* stratified sampling */
870                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
871 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
871 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
872                          return(0);
873                  for (i = 3; i--; )
874 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
875 <                                                duvw[1]*p->vdir[i] +
874 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
875 >                                                duvw[1]*p->vdir[i] -
876                                                  duvw[2]*p->nrm[i] ;
877                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
878                          return(0);
# Line 847 | Line 891 | prepare_sampler(void)
891                  fputs(": no sender surface!\n", stderr);
892                  return(-1);
893          }
894 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
894 >                                        /* misplaced output file spec. */
895 >        if ((curparams.outfn != NULL) & (verbose >= 0))
896                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
897                                  progname, curparams.outfn);
898                                          /* check/set basis hemisphere */
# Line 861 | Line 906 | prepare_sampler(void)
906                  fputs(": undefined normal for sender sampling\n", stderr);
907                  return(-1);
908          }
909 <        if (normalize(curparams.vup) == 0)
909 >        if (normalize(curparams.vup) == 0) {
910                  if (fabs(curparams.nrm[2]) < .7)
911                          curparams.vup[2] = 1;
912                  else
913                          curparams.vup[1] = 1;
914 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
914 >        }
915 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
916          if (normalize(curparams.udir) == 0) {
917                  fputs(progname, stderr);
918                  fputs(": up vector coincides with sender normal\n", stderr);
919                  return(-1);
920          }
921 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
921 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
922 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
923 >                curparams.udir[0] *= -1.;
924 >                curparams.udir[1] *= -1.;
925 >                curparams.udir[2] *= -1.;
926 >        }
927          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
928                  curparams.sample_basis = sample_uniform;
929          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 1040 | add_surface(int st, const char *oname, FILE *fp)
1040          case ST_SOURCE:
1041                  if (snew->nfargs != 4)
1042                          goto badcount;
1043 <                VCOPY(snew->snrm, snew->farg);
1043 >                for (n = 3; n--; )      /* need to reverse "normal" */
1044 >                        snew->snrm[n] = -snew->farg[n];
1045                  if (normalize(snew->snrm) == 0)
1046                          goto badnorm;
1047                  snew->area = sin((PI/180./2.)*snew->farg[3]);
1048                  snew->area *= PI*snew->area;
1049                  break;
1050          }
1051 <        if (snew->area <= FTINY) {
1051 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1052                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1053                                  progname, oname);
1054                  free(snew);
# Line 1008 | Line 1060 | add_surface(int st, const char *oname, FILE *fp)
1060          curparams.nsurfs++;
1061          return;
1062   badcount:
1063 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1063 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1064                          progname, oname);
1065          exit(1);
1066   badnorm:
1067 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1067 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1068                          progname, oname);
1069          exit(1);
1070   }
# Line 1044 | Line 1096 | add_recv_object(FILE *fp)
1096                                  finish_receiver();
1097                                  clear_params(&curparams, 1);
1098                          }
1099 +                        parse_params(&curparams, newparams);
1100 +                        newparams[0] = '\0';
1101                          strcpy(curmod, thismod);
1102                  }
1103                  add_surface(st, oname, fp);     /* read & store surface */
1104                  return(1);
1105          }
1106                                          /* else skip arguments */
1107 <        if (!fscanf(fp, "%d", &n)) return;
1107 >        if (!fscanf(fp, "%d", &n)) return(0);
1108          while (n-- > 0) fscanf(fp, "%*s");
1109 <        if (!fscanf(fp, "%d", &n)) return;
1109 >        if (!fscanf(fp, "%d", &n)) return(0);
1110          while (n-- > 0) fscanf(fp, "%*d");
1111 <        if (!fscanf(fp, "%d", &n)) return;
1111 >        if (!fscanf(fp, "%d", &n)) return(0);
1112          while (n-- > 0) fscanf(fp, "%*f");
1113          return(0);
1114   }
# Line 1064 | Line 1118 | static int
1118   add_send_object(FILE *fp)
1119   {
1120          int             st;
1121 <        char            otype[32], oname[128];
1121 >        char            thismod[128], otype[32], oname[128];
1122          int             n;
1123  
1124 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1124 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1125                  return(0);              /* must have hit EOF! */
1126          if (!strcmp(otype, "alias")) {
1127                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1134 | add_send_object(FILE *fp)
1134                          fputs(": cannot use source as a sender!\n", stderr);
1135                          return(-1);
1136                  }
1137 +                if (strcmp(thismod, curmod)) {
1138 +                        if (curmod[0]) {
1139 +                                fputs(progname, stderr);
1140 +                                fputs(": warning - multiple modifiers in sender\n",
1141 +                                                stderr);
1142 +                        }
1143 +                        strcpy(curmod, thismod);
1144 +                }
1145 +                parse_params(&curparams, newparams);
1146 +                newparams[0] = '\0';
1147                  add_surface(st, oname, fp);     /* read & store surface */
1148                  return(0);
1149          }
1150                                          /* else skip arguments */
1151 <        if (!fscanf(fp, "%d", &n)) return;
1151 >        if (!fscanf(fp, "%d", &n)) return(0);
1152          while (n-- > 0) fscanf(fp, "%*s");
1153 <        if (!fscanf(fp, "%d", &n)) return;
1153 >        if (!fscanf(fp, "%d", &n)) return(0);
1154          while (n-- > 0) fscanf(fp, "%*d");
1155 <        if (!fscanf(fp, "%d", &n)) return;
1155 >        if (!fscanf(fp, "%d", &n)) return(0);
1156          while (n-- > 0) fscanf(fp, "%*f");
1157          return(0);
1158   }
# Line 1128 | Line 1192 | load_scene(const char *inspec, int (*ocb)(FILE *))
1192                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1193                                          !strcmp(inpbuf, PARAMSTART)) {
1194                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1195 <                                        parse_params(inpbuf);
1195 >                                        strcat(newparams, inpbuf);
1196                                  continue;
1197                          }
1198 <                        while ((c = getc(fp)) != EOF && c != '\n');
1198 >                        while ((c = getc(fp)) != EOF && c != '\n')
1199                                  ;       /* else skipping comment */
1200                          continue;
1201                  }
# Line 1156 | Line 1220 | main(int argc, char *argv[])
1220   {
1221          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1222          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1223 +        char    *iropt = NULL;
1224          char    *sendfn;
1225          char    sampcntbuf[32], nsbinbuf[32];
1226          FILE    *rcfp;
# Line 1163 | Line 1228 | main(int argc, char *argv[])
1228          int     a, i;
1229                                          /* screen rcontrib options */
1230          progname = argv[0];
1231 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1232 <                int     na = 1;         /* !! Keep consistent !! */
1233 <                switch (argv[a][1]) {
1231 >        for (a = 1; a < argc-2; a++) {
1232 >                int     na;
1233 >                                        /* check for argument expansion */
1234 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1235 >                        ;
1236 >                if (na < 0) {
1237 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1238 >                                        progname, argv[a]);
1239 >                        return(1);
1240 >                }
1241 >                if (argv[a][0] != '-' || !argv[a][1])
1242 >                        break;
1243 >                na = 1;
1244 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1245                  case 'v':               /* verbose mode */
1246 <                        verbose = !verbose;
1246 >                        verbose = 1;
1247                          na = 0;
1248                          continue;
1249                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1256 | main(int argc, char *argv[])
1256                          case 'f':
1257                          case 'd':
1258                          case 'c':
1259 <                                if (!(fmtopt[4] = argv[a][3]))
1260 <                                        fmtopt[4] = argv[a][2];
1261 <                                fmtopt[3] = argv[a][2];
1259 >                                if (!(fmtopt[3] = argv[a][3]))
1260 >                                        fmtopt[3] = argv[a][2];
1261 >                                fmtopt[2] = argv[a][2];
1262                                  na = 0;
1263                                  continue;       /* will pass later */
1264                          default:
# Line 1198 | Line 1274 | main(int argc, char *argv[])
1274                          na = 0;
1275                          continue;
1276                  case 'c':               /* number of samples */
1277 <                        sampcnt = atoi(argv[a+1]);
1277 >                        sampcnt = atoi(argv[++a]);
1278                          if (sampcnt <= 0)
1279                                  goto userr;
1280                          na = 0;         /* we re-add this later */
1281                          continue;
1282 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1282 >                case 'I':               /* only for pass-through mode */
1283                  case 'i':
1284 +                        iropt = argv[a];
1285 +                        na = 0;
1286 +                        continue;
1287 +                case 'w':               /* options without arguments */
1288 +                        if (argv[a][2] != '+') verbose = -1;
1289 +                case 'V':
1290 +                case 'u':
1291                  case 'h':
1292                  case 'r':
1293                          break;
# Line 1230 | Line 1311 | main(int argc, char *argv[])
1311                          if (argv[a][2] != 'v') na = 2;
1312                          break;
1313                  case 'a':               /* special case */
1314 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1314 >                        if (argv[a][2] == 'p') {
1315 >                                na = 2; /* photon map [+ bandwidth(s)] */
1316 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1317 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1318 >                        } else
1319 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1320                          break;
1321                  case 'm':               /* special case */
1322                          if (!argv[a][2]) goto userr;
1323                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1324                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1325                  default:                /* anything else is verbotten */
1326                          goto userr;
1327                  }
# Line 1247 | Line 1331 | main(int argc, char *argv[])
1331                  while (--na)            /* + arguments if any */
1332                          rcarg[nrcargs++] = argv[++a];
1333          }
1250 done_opts:
1334          if (a > argc-2)
1335                  goto userr;             /* check at end of options */
1336          sendfn = argv[a++];             /* assign sender & receiver inputs */
1337          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1338                  if (sendfn[1]) goto userr;
1339                  sendfn = NULL;
1340 +                if (iropt) {
1341 +                        CHECKARGC(1);
1342 +                        rcarg[nrcargs++] = iropt;
1343 +                }
1344                  if (xrs) {
1345                          CHECKARGC(2);
1346                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1356 | done_opts:
1356                          rcarg[nrcargs++] = ldopt;
1357                  }
1358                  if (sampcnt <= 0) sampcnt = 1;
1359 <        } else {                        /* else FVECT determines input format */
1360 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1359 >        } else {                        /* else in sampling mode */
1360 >                if (iropt) {
1361 >                        fputs(progname, stderr);
1362 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1363 >                        return(1);
1364 >                }
1365 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1366                  if (sampcnt <= 0) sampcnt = 10000;
1367          }
1368          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1381 | done_opts:
1381                  return(my_exec(rcarg)); /* rcontrib does everything */
1382          }
1383          clear_params(&curparams, 0);    /* else load sender surface & params */
1384 +        curmod[0] = '\0';
1385          if (load_scene(sendfn, add_send_object) < 0)
1386                  return(1);
1387          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1399 | done_opts:
1399   #ifdef getc_unlocked
1400          flockfile(rcfp);
1401   #endif
1402 <        if (verbose) {
1402 >        if (verbose > 0) {
1403                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1404                  if (curparams.nsurfs > 1)
1405 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1405 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1406                  else
1407                          fputc('\n', stderr);
1408          }
1409          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1410                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1411                          return(1);
1412 <        return(pclose(rcfp) == 0);      /* all finished! */
1412 >        return(pclose(rcfp) < 0);       /* all finished! */
1413   userr:
1414          if (a < argc-2)
1415                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1416 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1416 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1417                                  progname);
1418          return(1);
1419   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines