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.1 by greg, Sat Jul 19 01:19:49 2014 UTC vs.
Revision 2.13 by greg, Wed Aug 6 00:59:53 2014 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 23 | Line 24 | static const char RCSid[] = "$Id$";
24   #endif
25  
26   #ifdef _WIN32
27 < #define SPECIALS        " \t$*?"
27 > #define SPECIALS        " \t\"$*?"
28   #define QUOTCHAR        '"'
29   #else
30 < #define SPECIALS        " \t\n'\"()${}*?[]"
30 > #define SPECIALS        " \t\n'\"()${}*?[];|&"
31   #define QUOTCHAR        '\''
32   #define ALTQUOT         '"'
33   #endif
# Line 45 | Line 46 | const char     overflowerr[] = "%s: too many arguments!\n"
46   #define CHECKARGC(n)    if (nrcargs >= MAXRCARG-(n)) \
47          { fprintf(stderr, overflowerr, progname); exit(1); }
48  
49 < int             sampcnt = 0;            /* sample count (unset) */
49 > int             sampcnt = 0;            /* sample count (0==unset) */
50  
51 < char            *reinhfn = "reinhart.cal";
52 < char            *shirchufn = "disk2square.cal";
51 > char            *reinhfn = "reinhartb.cal";
52 > char            *shirchiufn = "disk2square.cal";
53   char            *kfullfn = "klems_full.cal";
54   char            *khalffn = "klems_half.cal";
55   char            *kquarterfn = "klems_quarter.cal";
56  
57 < #define PARAMSTART      "@rfluxmtx"     /* string indicating parameters */
57 >                                        /* string indicating parameters */
58 > const char      PARAMSTART[] = "@rfluxmtx";
59  
60                                  /* surface type IDs */
61   #define ST_NONE         0
# Line 66 | Line 68 | typedef struct surf_s {
68          void            *priv;          /* private data (malloc'ed) */
69          char            sname[32];      /* surface name */
70          FVECT           snrm;           /* surface normal */
71 <        double          area;           /* surface area (or solid angle) */
71 >        double          area;           /* surface area / proj. solid angle */
72          short           styp;           /* surface type */
73 <        short           nfargs;         /* number of arguments */
74 <        double          farg[1];        /* arguments (extends struct) */
73 >        short           nfargs;         /* number of real arguments */
74 >        double          farg[1];        /* real values (extends struct) */
75   } SURF;                         /* surface structure */
76  
77   typedef struct {
# Line 95 | Line 97 | typedef struct param_s {
97  
98   PARAMS          curparams;
99   char            curmod[128];
100 + char            newparams[1024];
101  
102   typedef int     SURFSAMP(FVECT, SURF *, double);
103  
# Line 108 | Line 111 | SURFSAMP       *orig_in_surf[4] = {
111   static void
112   clear_params(PARAMS *p, int reset_only)
113   {
111        curmod[0] = '\0';
114          while (p->slist != NULL) {
115                  SURF    *sdel = p->slist;
116                  p->slist = sdel->next;
# Line 123 | Line 125 | clear_params(PARAMS *p, int reset_only)
125                  p->outfn = NULL;
126                  return;
127          }
128 <        memset(p, 0, sizeof(curparams));
128 >        memset(p, 0, sizeof(PARAMS));
129   }
130  
131   /* Get surface type from name */
# Line 143 | Line 145 | surf_type(const char *otype)
145   static char *
146   oconv_command(int ac, char *av[])
147   {
148 <        static char     oconvbuf[2048] = "!oconv -f";
149 <        char            *cp = oconvbuf + 9;
150 <
148 >        static char     oconvbuf[2048] = "!oconv -f ";
149 >        char            *cp = oconvbuf + 10;
150 >        char            *recv = *av++;
151 >        
152 >        if (ac-- <= 0)
153 >                return(NULL);
154          while (ac-- > 0) {
155 +                strcpy(cp, *av++);
156 +                while (*cp) cp++;
157 +                *cp++ = ' ';
158                  if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) {
159                          fputs(progname, stderr);
160                          fputs(": too many file arguments!\n", stderr);
161                          exit(1);
162                  }
155                *cp++ = ' ';
156                strcpy(cp, *av++);
157                while (*cp) cp++;
163          }
164 <        *cp = '\0';
164 >        strcpy(cp, recv);       /* receiver goes last */
165          return(oconvbuf);
166   }
167  
# Line 308 | Line 313 | nextchar:
313  
314   /* Parse program parameters (directives) */
315   static int
316 < parse_params(char *pargs)
316 > parse_params(PARAMS *p, char *pargs)
317   {
318          char    *cp = pargs;
319          int     nparams = 0;
# Line 319 | Line 324 | parse_params(char *pargs)
324                  case 'h':
325                          if (*cp++ != '=')
326                                  break;
327 <                        curparams.hsiz = 0;
327 >                        p->hsiz = 0;
328                          i = 0;
329                          while (*cp && !isspace(*cp)) {
330                                  if (isdigit(*cp))
331 <                                        curparams.hsiz = 10*curparams.hsiz +
332 <                                                                *cp - '0';
328 <                                curparams.hemis[i++] = *cp++;
331 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
332 >                                p->hemis[i++] = *cp++;
333                          }
334                          if (!i)
335                                  break;
336 <                        curparams.hemis[i] = '\0';
337 <                        curparams.hsiz += !curparams.hsiz;
336 >                        p->hemis[i] = '\0';
337 >                        p->hsiz += !p->hsiz;
338                          ++nparams;
339                          continue;
340                  case 'u':
341                          if (*cp++ != '=')
342                                  break;
343 <                        if (!get_direction(curparams.vup, cp))
343 >                        if (!get_direction(p->vup, cp))
344                                  break;
345                          ++nparams;
346                          continue;
# Line 349 | Line 353 | parse_params(char *pargs)
353                          if (!i)
354                                  break;
355                          *--cp = '\0';
356 <                        curparams.outfn = savqstr(cp-i);
356 >                        p->outfn = savqstr(cp-i);
357                          *cp++ = ' ';
358                          ++nparams;
359                          continue;
# Line 372 | Line 376 | parse_params(char *pargs)
376   static void
377   finish_receiver(void)
378   {
379 <        char    binbuf[128];
379 >        char    sbuf[256];
380 >        int     uniform = 0;
381 >        char    *calfn = NULL;
382 >        char    *params = NULL;
383 >        char    *binv = NULL;
384 >        char    *binf = NULL;
385 >        char    *nbins = NULL;
386  
387          if (!curmod[0]) {
388                  fputs(progname, stderr);
# Line 384 | Line 394 | finish_receiver(void)
394                  rcarg[nrcargs++] = "-o";
395                  rcarg[nrcargs++] = curparams.outfn;
396          }
397 <                                        /* add bin specification */
397 >                                        /* check arguments */
398          if (!curparams.hemis[0]) {
399                  fputs(progname, stderr);
400                  fputs(": missing hemisphere sampling type!\n", stderr);
# Line 395 | Line 405 | finish_receiver(void)
405                  fputs(": undefined normal for hemisphere sampling\n", stderr);
406                  exit(1);
407          }
408 <        if (normalize(curparams.vup) == 0)
408 >        if (normalize(curparams.vup) == 0) {
409                  if (fabs(curparams.nrm[2]) < .7)
410                          curparams.vup[2] = 1;
411                  else
412                          curparams.vup[1] = 1;
413 +        }
414 +                                        /* determine sample type/bin */
415          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
416 <                CHECKARGC(2);
417 <                rcarg[nrcargs++] = "-b";
406 <                rcarg[nrcargs++] = "0";
416 >                binv = "0";             /* uniform sampling -- one bin */
417 >                uniform = 1;
418          } else if (tolower(curparams.hemis[0]) == 's' &&
419                                  tolower(curparams.hemis[1]) == 'c') {
420 <                if (shirchufn != NULL) {
410 <                        CHECKARGC(2);
411 <                        rcarg[nrcargs++] = "-f";
412 <                        rcarg[nrcargs++] = shirchufn;
413 <                        shirchufn = NULL;
414 <                }
415 < fputs("Shirley-Chiu unimplemented...\n",stderr); exit(1);
420 >                                        /* assign parameters */
421                  if (curparams.hsiz <= 1) {
422                          fputs(progname, stderr);
423                          fputs(": missing size for Shirley-Chiu sampling!\n", stderr);
424                          exit(1);
425                  }
426 +                calfn = shirchiufn; shirchiufn = NULL;
427 +                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
428 +                                curparams.hsiz,
429 +                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
430 +                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
431 +                params = savqstr(sbuf);
432 +                binv = "scbin";
433 +                nbins = "SCdim*SCdim";
434          } else if ((tolower(curparams.hemis[0]) == 'r') |
435                          (tolower(curparams.hemis[0]) == 't')) {
436 <                if (reinhfn != NULL) {
437 <                        CHECKARGC(2);
438 <                        rcarg[nrcargs++] = "-f";
439 <                        rcarg[nrcargs++] = reinhfn;
440 <                        reinhfn = NULL;
441 <                }
442 < fputs("Reinhart/Tregenza unimplemented...\n",stderr); exit(1);
436 >                calfn = reinhfn; reinhfn = NULL;
437 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
438 >                                curparams.hsiz,
439 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
440 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
441 >                params = savqstr(sbuf);
442 >                binv = "rbin";
443 >                nbins = "Nrbins";
444          } else if (tolower(curparams.hemis[0]) == 'k' &&
445                          !curparams.hemis[1] |
446                          (tolower(curparams.hemis[1]) == 'f') |
447                          (curparams.hemis[1] == '1')) {
448 <                if (kfullfn != NULL) {
449 <                        CHECKARGC(2);
450 <                        rcarg[nrcargs++] = "-f";
437 <                        rcarg[nrcargs++] = kfullfn;
438 <                        kfullfn = NULL;
439 <                }
440 <                CHECKARGC(4);
441 <                sprintf(binbuf, "kbin(%g,%g,%g,%g,%g,%g)",
442 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
443 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
444 <                rcarg[nrcargs++] = "-b";
445 <                rcarg[nrcargs++] = savqstr(binbuf);
446 <                rcarg[nrcargs++] = "-bn";
447 <                rcarg[nrcargs++] = "Nkbins";
448 >                calfn = kfullfn; kfullfn = NULL;
449 >                binf = "kbin";
450 >                nbins = "Nkbins";
451          } else if (tolower(curparams.hemis[0]) == 'k' &&
452                          (tolower(curparams.hemis[1]) == 'h') |
453                          (curparams.hemis[1] == '2')) {
454 <                if (khalffn != NULL) {
455 <                        CHECKARGC(2);
456 <                        rcarg[nrcargs++] = "-f";
454 <                        rcarg[nrcargs++] = khalffn;
455 <                        khalffn = NULL;
456 <                }
457 <                CHECKARGC(4);
458 <                sprintf(binbuf, "khbin(%g,%g,%g,%g,%g,%g)",
459 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
460 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
461 <                rcarg[nrcargs++] = "-b";
462 <                rcarg[nrcargs++] = savqstr(binbuf);
463 <                rcarg[nrcargs++] = "-bn";
464 <                rcarg[nrcargs++] = "Nkhbins";
454 >                calfn = khalffn; khalffn = NULL;
455 >                binf = "khbin";
456 >                nbins = "Nkhbins";
457          } else if (tolower(curparams.hemis[0]) == 'k' &&
458                          (tolower(curparams.hemis[1]) == 'q') |
459                          (curparams.hemis[1] == '4')) {
460 <                if (kquarterfn != NULL) {
461 <                        CHECKARGC(2);
462 <                        rcarg[nrcargs++] = "-f";
471 <                        rcarg[nrcargs++] = kquarterfn;
472 <                        kquarterfn = NULL;
473 <                }
474 <                CHECKARGC(4);
475 <                sprintf(binbuf, "kqbin(%g,%g,%g,%g,%g,%g)",
476 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
477 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
478 <                rcarg[nrcargs++] = "-b";
479 <                rcarg[nrcargs++] = savqstr(binbuf);
480 <                rcarg[nrcargs++] = "-bn";
481 <                rcarg[nrcargs++] = "Nkqbins";
460 >                calfn = kquarterfn; kquarterfn = NULL;
461 >                binf = "kqbin";
462 >                nbins = "Nkqbins";
463          } else {
464                  fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n",
465                                  progname, curparams.hemis);
466                  exit(1);
467          }
468 <        CHECKARGC(2);                   /* modifier argument goes last */
468 >        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
469 >                SURF    *sp;
470 >                for (sp = curparams.slist; sp != NULL; sp = sp->next)
471 >                        if (fabs(sp->area - PI) > 1e-3) {
472 >                                fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
473 >                                                progname, sp->sname);
474 >                                exit(1);
475 >                        }
476 >        }
477 >        if (calfn != NULL) {            /* add cal file if needed */
478 >                CHECKARGC(2);
479 >                rcarg[nrcargs++] = "-f";
480 >                rcarg[nrcargs++] = calfn;
481 >        }
482 >        if (params != NULL) {           /* parameters _after_ cal file */
483 >                CHECKARGC(2);
484 >                rcarg[nrcargs++] = "-p";
485 >                rcarg[nrcargs++] = params;
486 >        }
487 >        if (nbins != NULL) {            /* add #bins if set */
488 >                CHECKARGC(2);
489 >                rcarg[nrcargs++] = "-bn";
490 >                rcarg[nrcargs++] = nbins;
491 >        }
492 >        if (binv != NULL) {
493 >                CHECKARGC(2);           /* assign bin variable */
494 >                rcarg[nrcargs++] = "-b";
495 >                rcarg[nrcargs++] = binv;
496 >        } else if (binf != NULL) {
497 >                CHECKARGC(2);           /* assign bin function */
498 >                rcarg[nrcargs++] = "-b";
499 >                sprintf(sbuf, "%s(%g,%g,%g,%g,%g,%g)", binf,
500 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
501 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
502 >                rcarg[nrcargs++] = savqstr(sbuf);
503 >        }
504 >        CHECKARGC(2);                           /* modifier argument goes last */
505          rcarg[nrcargs++] = "-m";
506          rcarg[nrcargs++] = savqstr(curmod);
507   }
# Line 541 | Line 558 | ssamp_ring(FVECT orig, SURF *sp, double x)
558                  sp->priv = (void *)uva;
559          }
560          SDmultiSamp(samp2, 2, x);
561 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
561 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
562          samp2[1] *= 2.*PI;
563          uv[0] = samp2[0]*tcos(samp2[1]);
564          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 594 | Line 611 | ssamp_poly(FVECT orig, SURF *sp, double x)
611                          }
612                          ptp->ntris = 0;
613                          v2l->p = (void *)ptp;
614 <                        if (!polyTriangulate(v2l, add_triangle))
614 >                        if (!polyTriangulate(v2l, add_triangle)) {
615 >                                fprintf(stderr,
616 >                                        "%s: cannot triangulate polygon '%s'\n",
617 >                                                progname, sp->sname);
618                                  return(0);
619 +                        }
620                          for (i = ptp->ntris; i--; ) {
621                                  int     a = ptp->tri[i].vndx[0];
622                                  int     b = ptp->tri[i].vndx[1];
# Line 644 | Line 665 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
665                                          /* special case for lone surface */
666          if (p->nsurfs == 1) {
667                  sp = p->slist;
668 <                if (DOT(sp->snrm, rdir) >= -FTINY)
669 <                        return(0);      /* behind surface! */
668 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
669 >                        fprintf(stderr,
670 >                                "%s: internal - sample behind sender '%s'\n",
671 >                                        progname, sp->sname);
672 >                        return(0);
673 >                }
674                  return((*orig_in_surf[sp->styp])(orig, sp, x));
675          }
676          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 659 | Line 684 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
684                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
685                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
686          }
687 <        if (tarea <= FTINY)             /* wrong side of sender? */
687 >        if (tarea <= FTINY) {           /* wrong side of sender? */
688 >                fputs(progname, stderr);
689 >                fputs(": internal - sample behind all sender elements!\n",
690 >                                stderr);
691                  return(0);
692 +        }
693          tarea *= x;                     /* get surface from list */
694          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
695                  tarea -= projsa[i++];
# Line 733 | Line 762 | sample_reinhart(PARAMS *p, int b, FILE *fp)
762   #define T_NALT  7
763          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
764          const int               RowMax = T_NALT*p->hsiz + 1;
765 <        const double            RAH = (.25*PI)/(RowMax-.5);
765 >        const double            RAH = (.5*PI)/(RowMax-.5);
766   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
767          int                     n = sampcnt;
768          int                     row, col;
# Line 758 | Line 787 | sample_reinhart(PARAMS *p, int b, FILE *fp)
787                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
788                  alt = (row+samp3[1])*RAH;
789                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
790 <                duvw[2] = tcos(alt);    /* measured from horizon */
790 >                duvw[2] = cos(alt);     /* measured from horizon */
791                  duvw[0] = tcos(azi)*duvw[2];
792                  duvw[1] = tsin(azi)*duvw[2];
793                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
# Line 848 | Line 877 | prepare_sampler(void)
877                  fputs(": undefined normal for sender sampling\n", stderr);
878                  return(-1);
879          }
880 <        if (normalize(curparams.vup) == 0)
880 >        if (normalize(curparams.vup) == 0) {
881                  if (fabs(curparams.nrm[2]) < .7)
882                          curparams.vup[2] = 1;
883                  else
884                          curparams.vup[1] = 1;
885 +        }
886          VCROSS(curparams.udir, curparams.vup, curparams.nrm);
887          if (normalize(curparams.udir) == 0) {
888                  fputs(progname, stderr);
# Line 976 | Line 1006 | add_surface(int st, const char *oname, FILE *fp)
1006          case ST_SOURCE:
1007                  if (snew->nfargs != 4)
1008                          goto badcount;
1009 <                VCOPY(snew->snrm, snew->farg);
1009 >                for (n = 3; n--; )      /* need to reverse "normal" */
1010 >                        snew->snrm[n] = -snew->farg[n];
1011                  if (normalize(snew->snrm) == 0)
1012                          goto badnorm;
1013 <                snew->area = 2.*PI*(1. - cos((PI/180./2.)*snew->farg[3]));
1013 >                snew->area = sin((PI/180./2.)*snew->farg[3]);
1014 >                snew->area *= PI*snew->area;
1015                  break;
1016          }
1017          if (snew->area <= FTINY) {
# Line 994 | Line 1026 | add_surface(int st, const char *oname, FILE *fp)
1026          curparams.nsurfs++;
1027          return;
1028   badcount:
1029 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1029 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1030                          progname, oname);
1031          exit(1);
1032   badnorm:
1033 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1033 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1034                          progname, oname);
1035          exit(1);
1036   }
# Line 1030 | Line 1062 | add_recv_object(FILE *fp)
1062                                  finish_receiver();
1063                                  clear_params(&curparams, 1);
1064                          }
1065 +                        parse_params(&curparams, newparams);
1066 +                        newparams[0] = '\0';
1067                          strcpy(curmod, thismod);
1068                  }
1069                  add_surface(st, oname, fp);     /* read & store surface */
1070                  return(1);
1071          }
1072                                          /* else skip arguments */
1073 <        if (!fscanf(fp, "%d", &n)) return;
1073 >        if (!fscanf(fp, "%d", &n)) return(0);
1074          while (n-- > 0) fscanf(fp, "%*s");
1075 <        if (!fscanf(fp, "%d", &n)) return;
1075 >        if (!fscanf(fp, "%d", &n)) return(0);
1076          while (n-- > 0) fscanf(fp, "%*d");
1077 <        if (!fscanf(fp, "%d", &n)) return;
1077 >        if (!fscanf(fp, "%d", &n)) return(0);
1078          while (n-- > 0) fscanf(fp, "%*f");
1079          return(0);
1080   }
# Line 1066 | Line 1100 | add_send_object(FILE *fp)
1100                          fputs(": cannot use source as a sender!\n", stderr);
1101                          return(-1);
1102                  }
1103 +                parse_params(&curparams, newparams);
1104 +                newparams[0] = '\0';
1105                  add_surface(st, oname, fp);     /* read & store surface */
1106                  return(0);
1107          }
1108                                          /* else skip arguments */
1109 <        if (!fscanf(fp, "%d", &n)) return;
1109 >        if (!fscanf(fp, "%d", &n)) return(0);
1110          while (n-- > 0) fscanf(fp, "%*s");
1111 <        if (!fscanf(fp, "%d", &n)) return;
1111 >        if (!fscanf(fp, "%d", &n)) return(0);
1112          while (n-- > 0) fscanf(fp, "%*d");
1113 <        if (!fscanf(fp, "%d", &n)) return;
1113 >        if (!fscanf(fp, "%d", &n)) return(0);
1114          while (n-- > 0) fscanf(fp, "%*f");
1115          return(0);
1116   }
# Line 1109 | Line 1145 | load_scene(const char *inspec, int (*ocb)(FILE *))
1145                          continue;
1146                  }
1147                  if (c == '#') {         /* parameters/comment */
1148 <                        if (fscanf(fp, "%s", inpbuf) == 1 &&
1148 >                        if ((c = getc(fp)) == EOF || ungetc(c,fp) == EOF)
1149 >                                break;
1150 >                        if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1151                                          !strcmp(inpbuf, PARAMSTART)) {
1152                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1153 <                                        parse_params(inpbuf);
1153 >                                        strcat(newparams, inpbuf);
1154                                  continue;
1155                          }
1156 <                        while ((c = getc(fp)) != EOF && c != '\n');
1156 >                        while ((c = getc(fp)) != EOF && c != '\n')
1157                                  ;       /* else skipping comment */
1158                          continue;
1159                  }
# Line 1139 | Line 1177 | int
1177   main(int argc, char *argv[])
1178   {
1179          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1180 +        char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1181 +        char    *iropt = NULL;
1182          char    *sendfn;
1183          char    sampcntbuf[32], nsbinbuf[32];
1184          FILE    *rcfp;
# Line 1163 | Line 1203 | main(int argc, char *argv[])
1203                          case 'f':
1204                          case 'd':
1205                          case 'c':
1206 <                                if (!(fmtopt[4] = argv[a][3]))
1207 <                                        fmtopt[4] = argv[a][2];
1208 <                                fmtopt[3] = argv[a][2];
1206 >                                if (!(fmtopt[3] = argv[a][3]))
1207 >                                        fmtopt[3] = argv[a][2];
1208 >                                fmtopt[2] = argv[a][2];
1209                                  na = 0;
1210                                  continue;       /* will pass later */
1211                          default:
1212                                  goto userr;
1213                          }
1214                          break;
1215 +                case 'x':               /* x-resolution */
1216 +                        xrs = argv[++a];
1217 +                        na = 0;
1218 +                        continue;
1219 +                case 'y':               /* y-resolution */
1220 +                        yrs = argv[++a];
1221 +                        na = 0;
1222 +                        continue;
1223                  case 'c':               /* number of samples */
1224 <                        sampcnt = atoi(argv[a+1]);
1224 >                        sampcnt = atoi(argv[++a]);
1225                          if (sampcnt <= 0)
1226                                  goto userr;
1227                          na = 0;         /* we re-add this later */
1228                          continue;
1229 +                case 'I':               /* only for pass-through mode */
1230 +                case 'i':
1231 +                        iropt = argv[a];
1232 +                        na = 0;
1233 +                        continue;
1234                  case 'V':               /* options without arguments */
1235                  case 'w':
1236                  case 'u':
1184                case 'i':
1237                  case 'h':
1238 +                case 'r':
1239                          break;
1240                  case 'n':               /* options with 1 argument */
1241                  case 's':
# Line 1193 | Line 1246 | main(int argc, char *argv[])
1246                          if (argv[a][2] != 'v') goto userr;
1247                          break;
1248                  case 'l':               /* special case */
1249 <                        if (argv[a][2] == 'd') goto userr;
1249 >                        if (argv[a][2] == 'd') {
1250 >                                ldopt = argv[a];
1251 >                                na = 0;
1252 >                                continue;
1253 >                        }
1254                          na = 2;
1255                          break;
1256                  case 'd':               /* special case */
# Line 1224 | Line 1281 | done_opts:
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";
1291 +                        rcarg[nrcargs++] = xrs;
1292 +                }
1293 +                if (yrs) {
1294 +                        CHECKARGC(2);
1295 +                        rcarg[nrcargs++] = "-y";
1296 +                        rcarg[nrcargs++] = yrs;
1297 +                }
1298 +                if (ldopt) {
1299 +                        CHECKARGC(1);
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 1265 | Line 1345 | done_opts:
1345          if (verbose) {
1346                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1347                  if (curparams.nsurfs > 1)
1348 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1348 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1349                  else
1350                          fputc('\n', stderr);
1351          }
# Line 1276 | Line 1356 | done_opts:
1356   userr:
1357          if (a < argc-2)
1358                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1359 <        fprintf(stderr, "Usage: %s [rcontrib options] sender.rad receiver.rad [system.rad ..]\n",
1359 >        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1360                                  progname);
1361          return(1);
1362   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines