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.35 by greg, Fri Mar 4 00:21:21 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 "paths.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
17   #include "random.h"
18   #include "triangulate.h"
19   #include "platform.h"
20  
20 #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
21 #undef getc
22 #define getc    getc_unlocked
23 #endif
24
25 #ifdef _WIN32
26 #define SPECIALS        " \t\"$*?"
27 #define QUOTCHAR        '"'
28 #else
29 #define SPECIALS        " \t\n'\"()${}*?[];|&"
30 #define QUOTCHAR        '\''
31 #define ALTQUOT         '"'
32 #endif
33
21   #define MAXRCARG        512
22  
23   char            *progname;              /* global argv[0] */
24  
25 < int             verbose = 0;            /* verbose mode? */
25 > int             verbose = 0;            /* verbose mode (< 0 no warnings) */
26  
27   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
28   int             nrcargs = 2;
# Line 83 | Line 70 | typedef struct {
70   } POLYTRIS;                     /* triangulated polygon */
71  
72   typedef struct param_s {
73 <        char            hemis[32];      /* hemispherical sampling spec. */
73 >        char            sign;           /* '-' for axis reversal */
74 >        char            hemis[31];      /* hemispherical sampling spec. */
75          int             hsiz;           /* hemisphere basis size */
76          int             nsurfs;         /* number of surfaces */
77          SURF            *slist;         /* list of surfaces */
78          FVECT           vup;            /* up vector (zero if unset) */
79          FVECT           nrm;            /* average normal direction */
80 <        FVECT           udir, vdir;     /* v-up tangent axes */
80 >        FVECT           udir, vdir;     /* tangent axes */
81          char            *outfn;         /* output file name (receiver) */
82          int             (*sample_basis)(struct param_s *p, int, FILE *);
83   } PARAMS;                       /* sender/receiver parameters */
84  
85   PARAMS          curparams;
86   char            curmod[128];
87 + char            newparams[1024];
88  
89   typedef int     SURFSAMP(FVECT, SURF *, double);
90  
# Line 109 | Line 98 | SURFSAMP       *orig_in_surf[4] = {
98   static void
99   clear_params(PARAMS *p, int reset_only)
100   {
112        curmod[0] = '\0';
101          while (p->slist != NULL) {
102                  SURF    *sdel = p->slist;
103                  p->slist = sdel->next;
# Line 124 | Line 112 | clear_params(PARAMS *p, int reset_only)
112                  p->outfn = NULL;
113                  return;
114          }
115 <        memset(p, 0, sizeof(curparams));
115 >        memset(p, 0, sizeof(PARAMS));
116   }
117  
118   /* Get surface type from name */
# Line 144 | Line 132 | surf_type(const char *otype)
132   static char *
133   oconv_command(int ac, char *av[])
134   {
135 <        static char     oconvbuf[2048] = "!oconv -f";
136 <        char            *cp = oconvbuf + 9;
137 <
135 >        static char     oconvbuf[2048] = "!oconv -f ";
136 >        char            *cp = oconvbuf + 10;
137 >        char            *recv = *av++;
138 >        
139 >        if (ac-- <= 0)
140 >                return(NULL);
141          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++ = ' ';
142                  strcpy(cp, *av++);
143                  while (*cp) cp++;
144 +                *cp++ = ' ';
145 +                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
146 +                        goto overrun;
147          }
148 <        *cp = '\0';
148 >                                /* receiver goes last */
149 >        if (matchany(recv, SPECIALS)) {
150 >                *cp++ = QUOTCHAR;
151 >                while (*recv) {
152 >                        if (cp >= oconvbuf+(sizeof(oconvbuf)-3))
153 >                                goto overrun;
154 >                        *cp++ = *recv++;
155 >                }
156 >                *cp++ = QUOTCHAR;
157 >                *cp = '\0';
158 >        } else
159 >                strcpy(cp, recv);
160          return(oconvbuf);
161 + overrun:
162 +        fputs(progname, stderr);
163 +        fputs(": too many file arguments!\n", stderr);
164 +        exit(1);
165   }
166  
164 /* Check if any of the characters in str2 are found in str1 */
165 static int
166 matchany(const char *str1, const char *str2)
167 {
168        while (*str1) {
169                const char      *cp = str2;
170                while (*cp)
171                        if (*cp++ == *str1)
172                                return(*str1);
173                ++str1;
174        }
175        return(0);
176 }
177
178
179 /* Convert a set of arguments into a command line for pipe() or system() */
180 static char *
181 convert_commandline(char *cmd, const int len, char *av[])
182 {
183        int     match;
184        char    *cp;
185
186        for (cp = cmd; *av != NULL; av++) {
187                const int       n = strlen(*av);
188                if (cp+n >= cmd+(len-3)) {
189                        fputs(progname, stderr);
190                        return(NULL);
191                }
192                if ((match = matchany(*av, SPECIALS))) {
193                        const int       quote =
194 #ifdef ALTQUOT
195                                (match == QUOTCHAR) ? ALTQUOT :
196 #endif
197                                        QUOTCHAR;
198                        *cp++ = quote;
199                        strcpy(cp, *av);
200                        cp += n;
201                        *cp++ = quote;
202                } else {
203                        strcpy(cp, *av);
204                        cp += n;
205                }
206                *cp++ = ' ';
207        }
208        if (cp <= cmd)
209                return(NULL);
210        *--cp = '\0';
211        return(cmd);
212 }
213
167   /* Open a pipe to/from a command given as an argument list */
168   static FILE *
169   popen_arglist(char *av[], char *mode)
# Line 222 | Line 175 | popen_arglist(char *av[], char *mode)
175                  fputs(": command line too long in popen_arglist()\n", stderr);
176                  return(NULL);
177          }
178 <        if (verbose)
178 >        if (verbose > 0)
179                  fprintf(stderr, "%s: opening pipe %s: %s\n",
180                                  progname, (*mode=='w') ? "to" : "from", cmd);
181          return(popen(cmd, mode));
# Line 240 | Line 193 | my_exec(char *av[])
193                  fputs(": command line too long in my_exec()\n", stderr);
194                  return(1);
195          }
196 <        if (verbose)
196 >        if (verbose > 0)
197                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
198          return(system(cmd));
199   }
# Line 255 | Line 208 | my_exec(char *av[])
208                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
209                  return(1);
210          }
211 <        if (verbose) {
211 >        if (verbose > 0) {
212                  char    cmd[4096];
213                  if (!convert_commandline(cmd, sizeof(cmd), av))
214                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 309 | Line 262 | nextchar:
262  
263   /* Parse program parameters (directives) */
264   static int
265 < parse_params(char *pargs)
265 > parse_params(PARAMS *p, char *pargs)
266   {
267          char    *cp = pargs;
268          int     nparams = 0;
269 +        int     quot;
270          int     i;
271  
272 <        for ( ; ; )
272 >        for ( ; ; ) {
273                  switch (*cp++) {
274                  case 'h':
275                          if (*cp++ != '=')
276                                  break;
277 <                        curparams.hsiz = 0;
277 >                        if ((*cp == '+') | (*cp == '-'))
278 >                                p->sign = *cp++;
279 >                        else
280 >                                p->sign = '+';
281 >                        p->hsiz = 0;
282                          i = 0;
283                          while (*cp && !isspace(*cp)) {
284                                  if (isdigit(*cp))
285 <                                        curparams.hsiz = 10*curparams.hsiz +
286 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
285 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
286 >                                p->hemis[i++] = *cp++;
287                          }
288                          if (!i)
289                                  break;
290 <                        curparams.hemis[i] = '\0';
291 <                        curparams.hsiz += !curparams.hsiz;
290 >                        p->hemis[i] = '\0';
291 >                        p->hsiz += !p->hsiz;
292                          ++nparams;
293                          continue;
294                  case 'u':
295                          if (*cp++ != '=')
296                                  break;
297 <                        if (!get_direction(curparams.vup, cp))
297 >                        if (!get_direction(p->vup, cp))
298                                  break;
299 +                        while (*cp && !isspace(*cp++))
300 +                                ;
301                          ++nparams;
302                          continue;
303                  case 'o':
304                          if (*cp++ != '=')
305                                  break;
306 +                        quot = 0;
307 +                        if ((*cp == '"') | (*cp == '\''))
308 +                                quot = *cp++;
309                          i = 0;
310 <                        while (*cp && !isspace(*cp++))
311 <                                i++;
310 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
311 >                                i++; cp++;
312 >                        }
313                          if (!i)
314                                  break;
315 <                        *--cp = '\0';
316 <                        curparams.outfn = savqstr(cp-i);
317 <                        *cp++ = ' ';
315 >                        if (!*cp) {
316 >                                if (quot)
317 >                                        break;
318 >                                cp[1] = '\0';
319 >                        }
320 >                        *cp = '\0';
321 >                        p->outfn = savqstr(cp-i);
322 >                        *cp++ = quot ? quot : ' ';
323                          ++nparams;
324                          continue;
325                  case ' ':
# Line 364 | Line 332 | parse_params(char *pargs)
332                  default:
333                          break;
334                  }
335 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
335 >                break;
336 >        }
337 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
338          exit(1);
339          return(-1);     /* pro forma return */
340   }
# Line 402 | Line 372 | finish_receiver(void)
372                  fputs(": undefined normal for hemisphere sampling\n", stderr);
373                  exit(1);
374          }
375 <        if (normalize(curparams.vup) == 0)
375 >        if (normalize(curparams.vup) == 0) {
376                  if (fabs(curparams.nrm[2]) < .7)
377                          curparams.vup[2] = 1;
378                  else
379                          curparams.vup[1] = 1;
380 +        }
381                                          /* determine sample type/bin */
382          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
383 <                binv = "0";             /* uniform sampling -- one bin */
383 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
384 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
385 >                binv = savqstr(sbuf);
386 >                nbins = "1";            /* uniform sampling -- one bin */
387                  uniform = 1;
388          } else if (tolower(curparams.hemis[0]) == 's' &&
389                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 394 | finish_receiver(void)
394                          exit(1);
395                  }
396                  calfn = shirchiufn; shirchiufn = NULL;
397 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
397 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
398                                  curparams.hsiz,
399                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
400 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
400 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
401 >                        curparams.sign);
402                  params = savqstr(sbuf);
403                  binv = "scbin";
404                  nbins = "SCdim*SCdim";
405          } else if ((tolower(curparams.hemis[0]) == 'r') |
406                          (tolower(curparams.hemis[0]) == 't')) {
407                  calfn = reinhfn; reinhfn = NULL;
408 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
408 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
409                                  curparams.hsiz,
410                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
411 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
411 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
412 >                        curparams.sign);
413                  params = savqstr(sbuf);
414                  binv = "rbin";
415                  nbins = "Nrbins";
# Line 461 | Line 437 | finish_receiver(void)
437                                  progname, curparams.hemis);
438                  exit(1);
439          }
440 +        if (tolower(curparams.hemis[0]) == 'k') {
441 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
442 +                params = savqstr(sbuf);
443 +        }
444          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
445                  SURF    *sp;
446                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 488 | make_axes(FVECT uva[2], const FVECT nrm)
488   {
489          int     i;
490  
491 <        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) {
491 >        if (!getperpendicular(uva[0], nrm, 1)) {
492                  fputs(progname, stderr);
493                  fputs(": bad surface normal in make_axes!\n", stderr);
494                  exit(1);
495          }
496 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
496 >        fcross(uva[1], nrm, uva[0]);
497   }
498  
499   /* Illegal sender surfaces end up here */
# Line 554 | Line 525 | ssamp_ring(FVECT orig, SURF *sp, double x)
525                  sp->priv = (void *)uva;
526          }
527          SDmultiSamp(samp2, 2, x);
528 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
528 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
529          samp2[1] *= 2.*PI;
530          uv[0] = samp2[0]*tcos(samp2[1]);
531          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 578 | ssamp_poly(FVECT orig, SURF *sp, double x)
578                          }
579                          ptp->ntris = 0;
580                          v2l->p = (void *)ptp;
581 <                        if (!polyTriangulate(v2l, add_triangle))
581 >                        if (!polyTriangulate(v2l, add_triangle)) {
582 >                                fprintf(stderr,
583 >                                        "%s: cannot triangulate polygon '%s'\n",
584 >                                                progname, sp->sname);
585                                  return(0);
586 +                        }
587                          for (i = ptp->ntris; i--; ) {
588                                  int     a = ptp->tri[i].vndx[0];
589                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 632 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
632                                          /* special case for lone surface */
633          if (p->nsurfs == 1) {
634                  sp = p->slist;
635 <                if (DOT(sp->snrm, rdir) >= -FTINY)
636 <                        return(0);      /* behind surface! */
635 >                if (DOT(sp->snrm, rdir) >= FTINY) {
636 >                        fprintf(stderr,
637 >                                "%s: internal - sample behind sender '%s'\n",
638 >                                        progname, sp->sname);
639 >                        return(0);
640 >                }
641                  return((*orig_in_surf[sp->styp])(orig, sp, x));
642          }
643          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 651 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
651                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
652                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
653          }
654 <        if (tarea <= FTINY)             /* wrong side of sender? */
654 >        if (tarea <= FTINY) {           /* wrong side of sender? */
655 >                fputs(progname, stderr);
656 >                fputs(": internal - sample behind all sender elements!\n",
657 >                                stderr);
658                  return(0);
659 +        }
660          tarea *= x;                     /* get surface from list */
661          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
662                  tarea -= projsa[i++];
# Line 746 | Line 729 | sample_reinhart(PARAMS *p, int b, FILE *fp)
729   #define T_NALT  7
730          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
731          const int               RowMax = T_NALT*p->hsiz + 1;
732 <        const double            RAH = (.25*PI)/(RowMax-.5);
732 >        const double            RAH = (.5*PI)/(RowMax-.5);
733   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
734          int                     n = sampcnt;
735          int                     row, col;
# Line 771 | Line 754 | sample_reinhart(PARAMS *p, int b, FILE *fp)
754                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
755                  alt = (row+samp3[1])*RAH;
756                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
757 <                duvw[2] = tcos(alt);    /* measured from horizon */
758 <                duvw[0] = tcos(azi)*duvw[2];
759 <                duvw[1] = tsin(azi)*duvw[2];
757 >                duvw[2] = cos(alt);     /* measured from horizon */
758 >                duvw[0] = tsin(azi)*duvw[2];
759 >                duvw[1] = tcos(azi)*duvw[2];
760                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
761                  for (i = 3; i--; )
762                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 807 | sample_klems(PARAMS *p, int b, FILE *fp)
807  
808          while (n--) {                   /* stratified sampling */
809                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
810 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
810 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
811                          return(0);
812                  for (i = 3; i--; )
813 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
814 <                                                duvw[1]*p->vdir[i] +
813 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
814 >                                                duvw[1]*p->vdir[i] -
815                                                  duvw[2]*p->nrm[i] ;
816                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
817                          return(0);
# Line 847 | Line 830 | prepare_sampler(void)
830                  fputs(": no sender surface!\n", stderr);
831                  return(-1);
832          }
833 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
833 >                                        /* misplaced output file spec. */
834 >        if ((curparams.outfn != NULL) & (verbose >= 0))
835                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
836                                  progname, curparams.outfn);
837                                          /* check/set basis hemisphere */
# Line 861 | Line 845 | prepare_sampler(void)
845                  fputs(": undefined normal for sender sampling\n", stderr);
846                  return(-1);
847          }
848 <        if (normalize(curparams.vup) == 0)
848 >        if (normalize(curparams.vup) == 0) {
849                  if (fabs(curparams.nrm[2]) < .7)
850                          curparams.vup[2] = 1;
851                  else
852                          curparams.vup[1] = 1;
853 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
853 >        }
854 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
855          if (normalize(curparams.udir) == 0) {
856                  fputs(progname, stderr);
857                  fputs(": up vector coincides with sender normal\n", stderr);
858                  return(-1);
859          }
860 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
860 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
861 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
862 >                curparams.udir[0] *= -1.;
863 >                curparams.udir[1] *= -1.;
864 >                curparams.udir[2] *= -1.;
865 >        }
866          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
867                  curparams.sample_basis = sample_uniform;
868          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 979 | add_surface(int st, const char *oname, FILE *fp)
979          case ST_SOURCE:
980                  if (snew->nfargs != 4)
981                          goto badcount;
982 <                VCOPY(snew->snrm, snew->farg);
982 >                for (n = 3; n--; )      /* need to reverse "normal" */
983 >                        snew->snrm[n] = -snew->farg[n];
984                  if (normalize(snew->snrm) == 0)
985                          goto badnorm;
986                  snew->area = sin((PI/180./2.)*snew->farg[3]);
987                  snew->area *= PI*snew->area;
988                  break;
989          }
990 <        if (snew->area <= FTINY) {
990 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
991                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
992                                  progname, oname);
993                  free(snew);
# Line 1008 | Line 999 | add_surface(int st, const char *oname, FILE *fp)
999          curparams.nsurfs++;
1000          return;
1001   badcount:
1002 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1002 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1003                          progname, oname);
1004          exit(1);
1005   badnorm:
1006 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1006 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1007                          progname, oname);
1008          exit(1);
1009   }
# Line 1044 | Line 1035 | add_recv_object(FILE *fp)
1035                                  finish_receiver();
1036                                  clear_params(&curparams, 1);
1037                          }
1038 +                        parse_params(&curparams, newparams);
1039 +                        newparams[0] = '\0';
1040                          strcpy(curmod, thismod);
1041                  }
1042                  add_surface(st, oname, fp);     /* read & store surface */
1043                  return(1);
1044          }
1045                                          /* else skip arguments */
1046 <        if (!fscanf(fp, "%d", &n)) return;
1046 >        if (!fscanf(fp, "%d", &n)) return(0);
1047          while (n-- > 0) fscanf(fp, "%*s");
1048 <        if (!fscanf(fp, "%d", &n)) return;
1048 >        if (!fscanf(fp, "%d", &n)) return(0);
1049          while (n-- > 0) fscanf(fp, "%*d");
1050 <        if (!fscanf(fp, "%d", &n)) return;
1050 >        if (!fscanf(fp, "%d", &n)) return(0);
1051          while (n-- > 0) fscanf(fp, "%*f");
1052          return(0);
1053   }
# Line 1064 | Line 1057 | static int
1057   add_send_object(FILE *fp)
1058   {
1059          int             st;
1060 <        char            otype[32], oname[128];
1060 >        char            thismod[128], otype[32], oname[128];
1061          int             n;
1062  
1063 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1063 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1064                  return(0);              /* must have hit EOF! */
1065          if (!strcmp(otype, "alias")) {
1066                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1073 | add_send_object(FILE *fp)
1073                          fputs(": cannot use source as a sender!\n", stderr);
1074                          return(-1);
1075                  }
1076 +                if (strcmp(thismod, curmod)) {
1077 +                        if (curmod[0]) {
1078 +                                fputs(progname, stderr);
1079 +                                fputs(": warning - multiple modifiers in sender\n",
1080 +                                                stderr);
1081 +                        }
1082 +                        strcpy(curmod, thismod);
1083 +                }
1084 +                parse_params(&curparams, newparams);
1085 +                newparams[0] = '\0';
1086                  add_surface(st, oname, fp);     /* read & store surface */
1087                  return(0);
1088          }
1089                                          /* else skip arguments */
1090 <        if (!fscanf(fp, "%d", &n)) return;
1090 >        if (!fscanf(fp, "%d", &n)) return(0);
1091          while (n-- > 0) fscanf(fp, "%*s");
1092 <        if (!fscanf(fp, "%d", &n)) return;
1092 >        if (!fscanf(fp, "%d", &n)) return(0);
1093          while (n-- > 0) fscanf(fp, "%*d");
1094 <        if (!fscanf(fp, "%d", &n)) return;
1094 >        if (!fscanf(fp, "%d", &n)) return(0);
1095          while (n-- > 0) fscanf(fp, "%*f");
1096          return(0);
1097   }
# Line 1128 | Line 1131 | load_scene(const char *inspec, int (*ocb)(FILE *))
1131                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1132                                          !strcmp(inpbuf, PARAMSTART)) {
1133                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1134 <                                        parse_params(inpbuf);
1134 >                                        strcat(newparams, inpbuf);
1135                                  continue;
1136                          }
1137 <                        while ((c = getc(fp)) != EOF && c != '\n');
1137 >                        while ((c = getc(fp)) != EOF && c != '\n')
1138                                  ;       /* else skipping comment */
1139                          continue;
1140                  }
# Line 1156 | Line 1159 | main(int argc, char *argv[])
1159   {
1160          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1161          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1162 +        char    *iropt = NULL;
1163          char    *sendfn;
1164          char    sampcntbuf[32], nsbinbuf[32];
1165          FILE    *rcfp;
# Line 1163 | Line 1167 | main(int argc, char *argv[])
1167          int     a, i;
1168                                          /* screen rcontrib options */
1169          progname = argv[0];
1170 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1171 <                int     na = 1;         /* !! Keep consistent !! */
1172 <                switch (argv[a][1]) {
1170 >        for (a = 1; a < argc-2; a++) {
1171 >                int     na;
1172 >                                        /* check for argument expansion */
1173 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1174 >                        ;
1175 >                if (na < 0) {
1176 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1177 >                                        progname, argv[a]);
1178 >                        return(1);
1179 >                }
1180 >                if (argv[a][0] != '-' || !argv[a][1])
1181 >                        break;
1182 >                na = 1;
1183 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1184                  case 'v':               /* verbose mode */
1185 <                        verbose = !verbose;
1185 >                        verbose = 1;
1186                          na = 0;
1187                          continue;
1188                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1195 | main(int argc, char *argv[])
1195                          case 'f':
1196                          case 'd':
1197                          case 'c':
1198 <                                if (!(fmtopt[4] = argv[a][3]))
1199 <                                        fmtopt[4] = argv[a][2];
1200 <                                fmtopt[3] = argv[a][2];
1198 >                                if (!(fmtopt[3] = argv[a][3]))
1199 >                                        fmtopt[3] = argv[a][2];
1200 >                                fmtopt[2] = argv[a][2];
1201                                  na = 0;
1202                                  continue;       /* will pass later */
1203                          default:
# Line 1198 | Line 1213 | main(int argc, char *argv[])
1213                          na = 0;
1214                          continue;
1215                  case 'c':               /* number of samples */
1216 <                        sampcnt = atoi(argv[a+1]);
1216 >                        sampcnt = atoi(argv[++a]);
1217                          if (sampcnt <= 0)
1218                                  goto userr;
1219                          na = 0;         /* we re-add this later */
1220                          continue;
1221 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1221 >                case 'I':               /* only for pass-through mode */
1222                  case 'i':
1223 +                        iropt = argv[a];
1224 +                        na = 0;
1225 +                        continue;
1226 +                case 'w':               /* options without arguments */
1227 +                        if (argv[a][2] != '+') verbose = -1;
1228 +                case 'V':
1229 +                case 'u':
1230                  case 'h':
1231                  case 'r':
1232                          break;
# Line 1230 | Line 1250 | main(int argc, char *argv[])
1250                          if (argv[a][2] != 'v') na = 2;
1251                          break;
1252                  case 'a':               /* special case */
1253 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1253 >                        if (argv[a][2] == 'p') {
1254 >                                na = 2; /* photon map [+ bandwidth(s)] */
1255 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1256 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1257 >                        } else
1258 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1259                          break;
1260                  case 'm':               /* special case */
1261                          if (!argv[a][2]) goto userr;
1262                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1263                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1264                  default:                /* anything else is verbotten */
1265                          goto userr;
1266                  }
# Line 1247 | Line 1270 | main(int argc, char *argv[])
1270                  while (--na)            /* + arguments if any */
1271                          rcarg[nrcargs++] = argv[++a];
1272          }
1250 done_opts:
1273          if (a > argc-2)
1274                  goto userr;             /* check at end of options */
1275          sendfn = argv[a++];             /* assign sender & receiver inputs */
1276          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1277                  if (sendfn[1]) goto userr;
1278                  sendfn = NULL;
1279 +                if (iropt) {
1280 +                        CHECKARGC(1);
1281 +                        rcarg[nrcargs++] = iropt;
1282 +                }
1283                  if (xrs) {
1284                          CHECKARGC(2);
1285                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1295 | done_opts:
1295                          rcarg[nrcargs++] = ldopt;
1296                  }
1297                  if (sampcnt <= 0) sampcnt = 1;
1298 <        } else {                        /* else FVECT determines input format */
1299 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1298 >        } else {                        /* else in sampling mode */
1299 >                if (iropt) {
1300 >                        fputs(progname, stderr);
1301 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1302 >                        return(1);
1303 >                }
1304 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1305                  if (sampcnt <= 0) sampcnt = 10000;
1306          }
1307          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1320 | done_opts:
1320                  return(my_exec(rcarg)); /* rcontrib does everything */
1321          }
1322          clear_params(&curparams, 0);    /* else load sender surface & params */
1323 +        curmod[0] = '\0';
1324          if (load_scene(sendfn, add_send_object) < 0)
1325                  return(1);
1326          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1338 | done_opts:
1338   #ifdef getc_unlocked
1339          flockfile(rcfp);
1340   #endif
1341 <        if (verbose) {
1341 >        if (verbose > 0) {
1342                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1343                  if (curparams.nsurfs > 1)
1344 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1344 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1345                  else
1346                          fputc('\n', stderr);
1347          }
1348          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1349                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1350                          return(1);
1351 <        return(pclose(rcfp) == 0);      /* all finished! */
1351 >        return(pclose(rcfp) < 0);       /* all finished! */
1352   userr:
1353          if (a < argc-2)
1354                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1355 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1355 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1356                                  progname);
1357          return(1);
1358   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines