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.34 by greg, Tue Feb 2 18:02:32 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"
# Line 22 | Line 23 | static const char RCSid[] = "$Id$";
23   #define getc    getc_unlocked
24   #endif
25  
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
26   #define MAXRCARG        512
27  
28   char            *progname;              /* global argv[0] */
29  
30 < int             verbose = 0;            /* verbose mode? */
30 > int             verbose = 0;            /* verbose mode (< 0 no warnings) */
31  
32   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
33   int             nrcargs = 2;
# Line 83 | Line 75 | typedef struct {
75   } POLYTRIS;                     /* triangulated polygon */
76  
77   typedef struct param_s {
78 <        char            hemis[32];      /* hemispherical sampling spec. */
78 >        char            sign;           /* '-' for axis reversal */
79 >        char            hemis[31];      /* hemispherical sampling spec. */
80          int             hsiz;           /* hemisphere basis size */
81          int             nsurfs;         /* number of surfaces */
82          SURF            *slist;         /* list of surfaces */
83          FVECT           vup;            /* up vector (zero if unset) */
84          FVECT           nrm;            /* average normal direction */
85 <        FVECT           udir, vdir;     /* v-up tangent axes */
85 >        FVECT           udir, vdir;     /* tangent axes */
86          char            *outfn;         /* output file name (receiver) */
87          int             (*sample_basis)(struct param_s *p, int, FILE *);
88   } PARAMS;                       /* sender/receiver parameters */
89  
90   PARAMS          curparams;
91   char            curmod[128];
92 + char            newparams[1024];
93  
94   typedef int     SURFSAMP(FVECT, SURF *, double);
95  
# Line 109 | Line 103 | SURFSAMP       *orig_in_surf[4] = {
103   static void
104   clear_params(PARAMS *p, int reset_only)
105   {
112        curmod[0] = '\0';
106          while (p->slist != NULL) {
107                  SURF    *sdel = p->slist;
108                  p->slist = sdel->next;
# Line 124 | Line 117 | clear_params(PARAMS *p, int reset_only)
117                  p->outfn = NULL;
118                  return;
119          }
120 <        memset(p, 0, sizeof(curparams));
120 >        memset(p, 0, sizeof(PARAMS));
121   }
122  
123   /* Get surface type from name */
# Line 144 | Line 137 | surf_type(const char *otype)
137   static char *
138   oconv_command(int ac, char *av[])
139   {
140 <        static char     oconvbuf[2048] = "!oconv -f";
141 <        char            *cp = oconvbuf + 9;
142 <
140 >        static char     oconvbuf[2048] = "!oconv -f ";
141 >        char            *cp = oconvbuf + 10;
142 >        char            *recv = *av++;
143 >        
144 >        if (ac-- <= 0)
145 >                return(NULL);
146          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++ = ' ';
147                  strcpy(cp, *av++);
148                  while (*cp) cp++;
149 +                *cp++ = ' ';
150 +                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
151 +                        goto overrun;
152          }
153 <        *cp = '\0';
153 >                                /* receiver goes last */
154 >        if (matchany(recv, SPECIALS)) {
155 >                *cp++ = QUOTCHAR;
156 >                while (*recv) {
157 >                        if (cp >= oconvbuf+(sizeof(oconvbuf)-3))
158 >                                goto overrun;
159 >                        *cp++ = *recv++;
160 >                }
161 >                *cp++ = QUOTCHAR;
162 >                *cp = '\0';
163 >        } else
164 >                strcpy(cp, recv);
165          return(oconvbuf);
166 + overrun:
167 +        fputs(progname, stderr);
168 +        fputs(": too many file arguments!\n", stderr);
169 +        exit(1);
170   }
171  
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
172   /* Open a pipe to/from a command given as an argument list */
173   static FILE *
174   popen_arglist(char *av[], char *mode)
# Line 222 | Line 180 | popen_arglist(char *av[], char *mode)
180                  fputs(": command line too long in popen_arglist()\n", stderr);
181                  return(NULL);
182          }
183 <        if (verbose)
183 >        if (verbose > 0)
184                  fprintf(stderr, "%s: opening pipe %s: %s\n",
185                                  progname, (*mode=='w') ? "to" : "from", cmd);
186          return(popen(cmd, mode));
# Line 240 | Line 198 | my_exec(char *av[])
198                  fputs(": command line too long in my_exec()\n", stderr);
199                  return(1);
200          }
201 <        if (verbose)
201 >        if (verbose > 0)
202                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
203          return(system(cmd));
204   }
# Line 255 | Line 213 | my_exec(char *av[])
213                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
214                  return(1);
215          }
216 <        if (verbose) {
216 >        if (verbose > 0) {
217                  char    cmd[4096];
218                  if (!convert_commandline(cmd, sizeof(cmd), av))
219                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 309 | Line 267 | nextchar:
267  
268   /* Parse program parameters (directives) */
269   static int
270 < parse_params(char *pargs)
270 > parse_params(PARAMS *p, char *pargs)
271   {
272          char    *cp = pargs;
273          int     nparams = 0;
274 +        int     quot;
275          int     i;
276  
277 <        for ( ; ; )
277 >        for ( ; ; ) {
278                  switch (*cp++) {
279                  case 'h':
280                          if (*cp++ != '=')
281                                  break;
282 <                        curparams.hsiz = 0;
282 >                        if ((*cp == '+') | (*cp == '-'))
283 >                                p->sign = *cp++;
284 >                        else
285 >                                p->sign = '+';
286 >                        p->hsiz = 0;
287                          i = 0;
288                          while (*cp && !isspace(*cp)) {
289                                  if (isdigit(*cp))
290 <                                        curparams.hsiz = 10*curparams.hsiz +
291 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
290 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
291 >                                p->hemis[i++] = *cp++;
292                          }
293                          if (!i)
294                                  break;
295 <                        curparams.hemis[i] = '\0';
296 <                        curparams.hsiz += !curparams.hsiz;
295 >                        p->hemis[i] = '\0';
296 >                        p->hsiz += !p->hsiz;
297                          ++nparams;
298                          continue;
299                  case 'u':
300                          if (*cp++ != '=')
301                                  break;
302 <                        if (!get_direction(curparams.vup, cp))
302 >                        if (!get_direction(p->vup, cp))
303                                  break;
304 +                        while (*cp && !isspace(*cp++))
305 +                                ;
306                          ++nparams;
307                          continue;
308                  case 'o':
309                          if (*cp++ != '=')
310                                  break;
311 +                        quot = 0;
312 +                        if ((*cp == '"') | (*cp == '\''))
313 +                                quot = *cp++;
314                          i = 0;
315 <                        while (*cp && !isspace(*cp++))
316 <                                i++;
315 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
316 >                                i++; cp++;
317 >                        }
318                          if (!i)
319                                  break;
320 <                        *--cp = '\0';
321 <                        curparams.outfn = savqstr(cp-i);
322 <                        *cp++ = ' ';
320 >                        if (!*cp) {
321 >                                if (quot)
322 >                                        break;
323 >                                cp[1] = '\0';
324 >                        }
325 >                        *cp = '\0';
326 >                        p->outfn = savqstr(cp-i);
327 >                        *cp++ = quot ? quot : ' ';
328                          ++nparams;
329                          continue;
330                  case ' ':
# Line 364 | Line 337 | parse_params(char *pargs)
337                  default:
338                          break;
339                  }
340 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
340 >                break;
341 >        }
342 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
343          exit(1);
344          return(-1);     /* pro forma return */
345   }
# Line 402 | Line 377 | finish_receiver(void)
377                  fputs(": undefined normal for hemisphere sampling\n", stderr);
378                  exit(1);
379          }
380 <        if (normalize(curparams.vup) == 0)
380 >        if (normalize(curparams.vup) == 0) {
381                  if (fabs(curparams.nrm[2]) < .7)
382                          curparams.vup[2] = 1;
383                  else
384                          curparams.vup[1] = 1;
385 +        }
386                                          /* determine sample type/bin */
387          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
388 <                binv = "0";             /* uniform sampling -- one bin */
388 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
389 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
390 >                binv = savqstr(sbuf);
391 >                nbins = "1";            /* uniform sampling -- one bin */
392                  uniform = 1;
393          } else if (tolower(curparams.hemis[0]) == 's' &&
394                                  tolower(curparams.hemis[1]) == 'c') {
# Line 420 | Line 399 | finish_receiver(void)
399                          exit(1);
400                  }
401                  calfn = shirchiufn; shirchiufn = NULL;
402 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
402 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
403                                  curparams.hsiz,
404                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
405 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
405 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
406 >                        curparams.sign);
407                  params = savqstr(sbuf);
408                  binv = "scbin";
409                  nbins = "SCdim*SCdim";
410          } else if ((tolower(curparams.hemis[0]) == 'r') |
411                          (tolower(curparams.hemis[0]) == 't')) {
412                  calfn = reinhfn; reinhfn = NULL;
413 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
413 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
414                                  curparams.hsiz,
415                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
416 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
416 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
417 >                        curparams.sign);
418                  params = savqstr(sbuf);
419                  binv = "rbin";
420                  nbins = "Nrbins";
# Line 461 | Line 442 | finish_receiver(void)
442                                  progname, curparams.hemis);
443                  exit(1);
444          }
445 +        if (tolower(curparams.hemis[0]) == 'k') {
446 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
447 +                params = savqstr(sbuf);
448 +        }
449          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
450                  SURF    *sp;
451                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 508 | Line 493 | make_axes(FVECT uva[2], const FVECT nrm)
493   {
494          int     i;
495  
496 <        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) {
496 >        if (!getperpendicular(uva[0], nrm, 1)) {
497                  fputs(progname, stderr);
498                  fputs(": bad surface normal in make_axes!\n", stderr);
499                  exit(1);
500          }
501 <        uva[1][i] = 1.0;
523 <        VCROSS(uva[0], uva[1], nrm);
524 <        normalize(uva[0]);
525 <        VCROSS(uva[1], nrm, uva[0]);
501 >        fcross(uva[1], nrm, uva[0]);
502   }
503  
504   /* Illegal sender surfaces end up here */
# Line 554 | Line 530 | ssamp_ring(FVECT orig, SURF *sp, double x)
530                  sp->priv = (void *)uva;
531          }
532          SDmultiSamp(samp2, 2, x);
533 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
533 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
534          samp2[1] *= 2.*PI;
535          uv[0] = samp2[0]*tcos(samp2[1]);
536          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 583 | ssamp_poly(FVECT orig, SURF *sp, double x)
583                          }
584                          ptp->ntris = 0;
585                          v2l->p = (void *)ptp;
586 <                        if (!polyTriangulate(v2l, add_triangle))
586 >                        if (!polyTriangulate(v2l, add_triangle)) {
587 >                                fprintf(stderr,
588 >                                        "%s: cannot triangulate polygon '%s'\n",
589 >                                                progname, sp->sname);
590                                  return(0);
591 +                        }
592                          for (i = ptp->ntris; i--; ) {
593                                  int     a = ptp->tri[i].vndx[0];
594                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 637 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
637                                          /* special case for lone surface */
638          if (p->nsurfs == 1) {
639                  sp = p->slist;
640 <                if (DOT(sp->snrm, rdir) >= -FTINY)
641 <                        return(0);      /* behind surface! */
640 >                if (DOT(sp->snrm, rdir) >= FTINY) {
641 >                        fprintf(stderr,
642 >                                "%s: internal - sample behind sender '%s'\n",
643 >                                        progname, sp->sname);
644 >                        return(0);
645 >                }
646                  return((*orig_in_surf[sp->styp])(orig, sp, x));
647          }
648          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 656 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
656                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
657                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
658          }
659 <        if (tarea <= FTINY)             /* wrong side of sender? */
659 >        if (tarea <= FTINY) {           /* wrong side of sender? */
660 >                fputs(progname, stderr);
661 >                fputs(": internal - sample behind all sender elements!\n",
662 >                                stderr);
663                  return(0);
664 +        }
665          tarea *= x;                     /* get surface from list */
666          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
667                  tarea -= projsa[i++];
# Line 746 | Line 734 | sample_reinhart(PARAMS *p, int b, FILE *fp)
734   #define T_NALT  7
735          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
736          const int               RowMax = T_NALT*p->hsiz + 1;
737 <        const double            RAH = (.25*PI)/(RowMax-.5);
737 >        const double            RAH = (.5*PI)/(RowMax-.5);
738   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
739          int                     n = sampcnt;
740          int                     row, col;
# Line 771 | Line 759 | sample_reinhart(PARAMS *p, int b, FILE *fp)
759                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
760                  alt = (row+samp3[1])*RAH;
761                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
762 <                duvw[2] = tcos(alt);    /* measured from horizon */
763 <                duvw[0] = tcos(azi)*duvw[2];
764 <                duvw[1] = tsin(azi)*duvw[2];
762 >                duvw[2] = cos(alt);     /* measured from horizon */
763 >                duvw[0] = tsin(azi)*duvw[2];
764 >                duvw[1] = tcos(azi)*duvw[2];
765                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
766                  for (i = 3; i--; )
767                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 824 | Line 812 | sample_klems(PARAMS *p, int b, FILE *fp)
812  
813          while (n--) {                   /* stratified sampling */
814                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
815 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
815 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
816                          return(0);
817                  for (i = 3; i--; )
818 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
819 <                                                duvw[1]*p->vdir[i] +
818 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
819 >                                                duvw[1]*p->vdir[i] -
820                                                  duvw[2]*p->nrm[i] ;
821                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
822                          return(0);
# Line 847 | Line 835 | prepare_sampler(void)
835                  fputs(": no sender surface!\n", stderr);
836                  return(-1);
837          }
838 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
838 >                                        /* misplaced output file spec. */
839 >        if ((curparams.outfn != NULL) & (verbose >= 0))
840                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
841                                  progname, curparams.outfn);
842                                          /* check/set basis hemisphere */
# Line 861 | Line 850 | prepare_sampler(void)
850                  fputs(": undefined normal for sender sampling\n", stderr);
851                  return(-1);
852          }
853 <        if (normalize(curparams.vup) == 0)
853 >        if (normalize(curparams.vup) == 0) {
854                  if (fabs(curparams.nrm[2]) < .7)
855                          curparams.vup[2] = 1;
856                  else
857                          curparams.vup[1] = 1;
858 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
858 >        }
859 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
860          if (normalize(curparams.udir) == 0) {
861                  fputs(progname, stderr);
862                  fputs(": up vector coincides with sender normal\n", stderr);
863                  return(-1);
864          }
865 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
865 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
866 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
867 >                curparams.udir[0] *= -1.;
868 >                curparams.udir[1] *= -1.;
869 >                curparams.udir[2] *= -1.;
870 >        }
871          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
872                  curparams.sample_basis = sample_uniform;
873          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 989 | Line 984 | add_surface(int st, const char *oname, FILE *fp)
984          case ST_SOURCE:
985                  if (snew->nfargs != 4)
986                          goto badcount;
987 <                VCOPY(snew->snrm, snew->farg);
987 >                for (n = 3; n--; )      /* need to reverse "normal" */
988 >                        snew->snrm[n] = -snew->farg[n];
989                  if (normalize(snew->snrm) == 0)
990                          goto badnorm;
991                  snew->area = sin((PI/180./2.)*snew->farg[3]);
992                  snew->area *= PI*snew->area;
993                  break;
994          }
995 <        if (snew->area <= FTINY) {
995 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
996                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
997                                  progname, oname);
998                  free(snew);
# Line 1008 | Line 1004 | add_surface(int st, const char *oname, FILE *fp)
1004          curparams.nsurfs++;
1005          return;
1006   badcount:
1007 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1007 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1008                          progname, oname);
1009          exit(1);
1010   badnorm:
1011 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1011 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1012                          progname, oname);
1013          exit(1);
1014   }
# Line 1044 | Line 1040 | add_recv_object(FILE *fp)
1040                                  finish_receiver();
1041                                  clear_params(&curparams, 1);
1042                          }
1043 +                        parse_params(&curparams, newparams);
1044 +                        newparams[0] = '\0';
1045                          strcpy(curmod, thismod);
1046                  }
1047                  add_surface(st, oname, fp);     /* read & store surface */
1048                  return(1);
1049          }
1050                                          /* else skip arguments */
1051 <        if (!fscanf(fp, "%d", &n)) return;
1051 >        if (!fscanf(fp, "%d", &n)) return(0);
1052          while (n-- > 0) fscanf(fp, "%*s");
1053 <        if (!fscanf(fp, "%d", &n)) return;
1053 >        if (!fscanf(fp, "%d", &n)) return(0);
1054          while (n-- > 0) fscanf(fp, "%*d");
1055 <        if (!fscanf(fp, "%d", &n)) return;
1055 >        if (!fscanf(fp, "%d", &n)) return(0);
1056          while (n-- > 0) fscanf(fp, "%*f");
1057          return(0);
1058   }
# Line 1064 | Line 1062 | static int
1062   add_send_object(FILE *fp)
1063   {
1064          int             st;
1065 <        char            otype[32], oname[128];
1065 >        char            thismod[128], otype[32], oname[128];
1066          int             n;
1067  
1068 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1068 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1069                  return(0);              /* must have hit EOF! */
1070          if (!strcmp(otype, "alias")) {
1071                  fscanf(fp, "%*s");      /* skip alias */
# Line 1080 | Line 1078 | add_send_object(FILE *fp)
1078                          fputs(": cannot use source as a sender!\n", stderr);
1079                          return(-1);
1080                  }
1081 +                if (strcmp(thismod, curmod)) {
1082 +                        if (curmod[0]) {
1083 +                                fputs(progname, stderr);
1084 +                                fputs(": warning - multiple modifiers in sender\n",
1085 +                                                stderr);
1086 +                        }
1087 +                        strcpy(curmod, thismod);
1088 +                }
1089 +                parse_params(&curparams, newparams);
1090 +                newparams[0] = '\0';
1091                  add_surface(st, oname, fp);     /* read & store surface */
1092                  return(0);
1093          }
1094                                          /* else skip arguments */
1095 <        if (!fscanf(fp, "%d", &n)) return;
1095 >        if (!fscanf(fp, "%d", &n)) return(0);
1096          while (n-- > 0) fscanf(fp, "%*s");
1097 <        if (!fscanf(fp, "%d", &n)) return;
1097 >        if (!fscanf(fp, "%d", &n)) return(0);
1098          while (n-- > 0) fscanf(fp, "%*d");
1099 <        if (!fscanf(fp, "%d", &n)) return;
1099 >        if (!fscanf(fp, "%d", &n)) return(0);
1100          while (n-- > 0) fscanf(fp, "%*f");
1101          return(0);
1102   }
# Line 1128 | Line 1136 | load_scene(const char *inspec, int (*ocb)(FILE *))
1136                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1137                                          !strcmp(inpbuf, PARAMSTART)) {
1138                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1139 <                                        parse_params(inpbuf);
1139 >                                        strcat(newparams, inpbuf);
1140                                  continue;
1141                          }
1142 <                        while ((c = getc(fp)) != EOF && c != '\n');
1142 >                        while ((c = getc(fp)) != EOF && c != '\n')
1143                                  ;       /* else skipping comment */
1144                          continue;
1145                  }
# Line 1156 | Line 1164 | main(int argc, char *argv[])
1164   {
1165          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1166          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1167 +        char    *iropt = NULL;
1168          char    *sendfn;
1169          char    sampcntbuf[32], nsbinbuf[32];
1170          FILE    *rcfp;
# Line 1163 | Line 1172 | main(int argc, char *argv[])
1172          int     a, i;
1173                                          /* screen rcontrib options */
1174          progname = argv[0];
1175 <        for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) {
1176 <                int     na = 1;         /* !! Keep consistent !! */
1177 <                switch (argv[a][1]) {
1175 >        for (a = 1; a < argc-2; a++) {
1176 >                int     na;
1177 >                                        /* check for argument expansion */
1178 >                while ((na = expandarg(&argc, &argv, a)) > 0)
1179 >                        ;
1180 >                if (na < 0) {
1181 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
1182 >                                        progname, argv[a]);
1183 >                        return(1);
1184 >                }
1185 >                if (argv[a][0] != '-' || !argv[a][1])
1186 >                        break;
1187 >                na = 1;
1188 >                switch (argv[a][1]) {   /* !! Keep consistent !! */
1189                  case 'v':               /* verbose mode */
1190 <                        verbose = !verbose;
1190 >                        verbose = 1;
1191                          na = 0;
1192                          continue;
1193                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1180 | Line 1200 | main(int argc, char *argv[])
1200                          case 'f':
1201                          case 'd':
1202                          case 'c':
1203 <                                if (!(fmtopt[4] = argv[a][3]))
1204 <                                        fmtopt[4] = argv[a][2];
1205 <                                fmtopt[3] = argv[a][2];
1203 >                                if (!(fmtopt[3] = argv[a][3]))
1204 >                                        fmtopt[3] = argv[a][2];
1205 >                                fmtopt[2] = argv[a][2];
1206                                  na = 0;
1207                                  continue;       /* will pass later */
1208                          default:
# Line 1198 | Line 1218 | main(int argc, char *argv[])
1218                          na = 0;
1219                          continue;
1220                  case 'c':               /* number of samples */
1221 <                        sampcnt = atoi(argv[a+1]);
1221 >                        sampcnt = atoi(argv[++a]);
1222                          if (sampcnt <= 0)
1223                                  goto userr;
1224                          na = 0;         /* we re-add this later */
1225                          continue;
1226 <                case 'V':               /* options without arguments */
1207 <                case 'w':
1208 <                case 'u':
1226 >                case 'I':               /* only for pass-through mode */
1227                  case 'i':
1228 +                        iropt = argv[a];
1229 +                        na = 0;
1230 +                        continue;
1231 +                case 'w':               /* options without arguments */
1232 +                        if (argv[a][2] != '+') verbose = -1;
1233 +                case 'V':
1234 +                case 'u':
1235                  case 'h':
1236                  case 'r':
1237                          break;
# Line 1230 | Line 1255 | main(int argc, char *argv[])
1255                          if (argv[a][2] != 'v') na = 2;
1256                          break;
1257                  case 'a':               /* special case */
1258 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1258 >                        if (argv[a][2] == 'p') {
1259 >                                na = 2; /* photon map [+ bandwidth(s)] */
1260 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1261 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1262 >                        } else
1263 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1264                          break;
1265                  case 'm':               /* special case */
1266                          if (!argv[a][2]) goto userr;
1267                          na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2;
1268                          break;
1239                case '\0':              /* pass-through mode */
1240                        goto done_opts;
1269                  default:                /* anything else is verbotten */
1270                          goto userr;
1271                  }
# Line 1247 | Line 1275 | main(int argc, char *argv[])
1275                  while (--na)            /* + arguments if any */
1276                          rcarg[nrcargs++] = argv[++a];
1277          }
1250 done_opts:
1278          if (a > argc-2)
1279                  goto userr;             /* check at end of options */
1280          sendfn = argv[a++];             /* assign sender & receiver inputs */
1281          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1282                  if (sendfn[1]) goto userr;
1283                  sendfn = NULL;
1284 +                if (iropt) {
1285 +                        CHECKARGC(1);
1286 +                        rcarg[nrcargs++] = iropt;
1287 +                }
1288                  if (xrs) {
1289                          CHECKARGC(2);
1290                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1300 | done_opts:
1300                          rcarg[nrcargs++] = ldopt;
1301                  }
1302                  if (sampcnt <= 0) sampcnt = 1;
1303 <        } else {                        /* else FVECT determines input format */
1304 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1303 >        } else {                        /* else in sampling mode */
1304 >                if (iropt) {
1305 >                        fputs(progname, stderr);
1306 >                        fputs(": -i, -I supported for pass-through only\n", stderr);
1307 >                        return(1);
1308 >                }
1309 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1310                  if (sampcnt <= 0) sampcnt = 10000;
1311          }
1312          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1289 | Line 1325 | done_opts:
1325                  return(my_exec(rcarg)); /* rcontrib does everything */
1326          }
1327          clear_params(&curparams, 0);    /* else load sender surface & params */
1328 +        curmod[0] = '\0';
1329          if (load_scene(sendfn, add_send_object) < 0)
1330                  return(1);
1331          if ((nsbins = prepare_sampler()) <= 0)
# Line 1306 | Line 1343 | done_opts:
1343   #ifdef getc_unlocked
1344          flockfile(rcfp);
1345   #endif
1346 <        if (verbose) {
1346 >        if (verbose > 0) {
1347                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1348                  if (curparams.nsurfs > 1)
1349 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1349 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1350                  else
1351                          fputc('\n', stderr);
1352          }
1353          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1354                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1355                          return(1);
1356 <        return(pclose(rcfp) == 0);      /* all finished! */
1356 >        return(pclose(rcfp) < 0);       /* all finished! */
1357   userr:
1358          if (a < argc-2)
1359                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1360 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1360 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1361                                  progname);
1362          return(1);
1363   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines