ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/util/rfluxmtx.c
(Generate patch)

Comparing ray/src/util/rfluxmtx.c (file contents):
Revision 2.30 by greg, Wed Jul 22 04:23:27 2015 UTC vs.
Revision 2.64 by greg, Wed Oct 22 17:04:14 2025 UTC

# Line 18 | Line 18 | static const char RCSid[] = "$Id$";
18   #include "triangulate.h"
19   #include "platform.h"
20  
21 < #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
22 < #undef getc
23 < #define getc    getc_unlocked
21 > #ifndef MAXRCARG
22 > #define MAXRCARG        10000
23   #endif
24  
25 < #ifdef _WIN32
26 < #define SPECIALS        " \t\"$*?"
28 < #define QUOTCHAR        '"'
29 < #else
30 < #define SPECIALS        " \t\n'\"()${}*?[];|&"
31 < #define QUOTCHAR        '\''
32 < #define ALTQUOT         '"'
33 < #endif
25 > #define         NOWARN          1
26 > #define         VERBO           2
27  
28 < #define MAXRCARG        512
28 > int             verbose = 0;            /* verbose/warning mode */
29  
37 char            *progname;              /* global argv[0] */
38
39 int             verbose = 0;            /* verbose mode (< 0 no warnings) */
40
30   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
31   int             nrcargs = 2;
32  
# Line 53 | Line 42 | char           *shirchiufn = "disk2square.cal";
42   char            *kfullfn = "klems_full.cal";
43   char            *khalffn = "klems_half.cal";
44   char            *kquarterfn = "klems_quarter.cal";
45 + char            *ciefn = "cieskyscan.cal";
46  
47                                          /* string indicating parameters */
48 < const char      PARAMSTART[] = "@rfluxmtx";
48 > #define PARAMSTART      "@rfluxmtx"
49  
50                                  /* surface type IDs */
51   #define ST_NONE         0
# Line 78 | Line 68 | typedef struct {
68          FVECT   uva[2];                 /* tangent axes */
69          int     ntris;                  /* number of triangles */
70          struct ptri {
71 <                float   afrac;                  /* fraction of total area */
71 >                double  afrac;                  /* fraction of total area */
72                  short   vndx[3];                /* vertex indices */
73          }       tri[1];                 /* triangle array (extends struct) */
74   } POLYTRIS;                     /* triangulated polygon */
# Line 120 | Line 110 | clear_params(PARAMS *p, int reset_only)
110                  free(sdel);
111          }
112          if (reset_only) {
113 +                p->slist = NULL;
114                  p->nsurfs = 0;
115                  memset(p->nrm, 0, sizeof(FVECT));
116                  memset(p->vup, 0, sizeof(FVECT));
# Line 142 | Line 133 | surf_type(const char *otype)
133          return(ST_NONE);
134   }
135  
145 /* Check if any of the characters in str2 are found in str1 */
146 static int
147 matchany(const char *str1, const char *str2)
148 {
149        while (*str1) {
150                const char      *cp = str2;
151                while (*cp)
152                        if (*cp++ == *str1)
153                                return(*str1);
154                ++str1;
155        }
156        return(0);
157 }
158
136   /* Add arguments to oconv command */
137   static char *
138   oconv_command(int ac, char *av[])
# Line 166 | Line 143 | oconv_command(int ac, char *av[])
143          
144          if (ac-- <= 0)
145                  return(NULL);
146 <        while (ac-- > 0) {
147 <                strcpy(cp, *av++);
148 <                while (*cp) cp++;
149 <                *cp++ = ' ';
150 <                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
146 >        if (verbose & NOWARN) { /* warnings off? */
147 >                strcpy(cp, "-w ");
148 >                cp += 3;
149 >        }
150 >        while (ac-- > 0) {      /* copy each argument */
151 >                int     len = strlen(*av);
152 >                if (cp+len+4 >= oconvbuf+sizeof(oconvbuf))
153                          goto overrun;
154 +                if (matchany(*av, SPECIALS)) {
155 +                        *cp++ = QUOTCHAR;
156 +                        strcpy(cp, *av++);
157 +                        cp += len;
158 +                        *cp++ = QUOTCHAR;
159 +                } else {
160 +                        strcpy(cp, *av++);
161 +                        cp += len;
162 +                }
163 +                *cp++ = ' ';
164          }
165                                  /* receiver goes last */
166          if (matchany(recv, SPECIALS)) {
# Line 192 | Line 181 | overrun:
181          exit(1);
182   }
183  
184 < /* Convert a set of arguments into a command line for pipe() or system() */
196 < static char *
197 < convert_commandline(char *cmd, const int len, char *av[])
198 < {
199 <        int     match;
200 <        char    *cp;
184 > #if defined(_WIN32) || defined(_WIN64)
185  
202        for (cp = cmd; *av != NULL; av++) {
203                const int       n = strlen(*av);
204                if (cp+n >= cmd+(len-3)) {
205                        fputs(progname, stderr);
206                        return(NULL);
207                }
208                if (matchany(*av, SPECIALS)) {
209                        const int       quote =
210 #ifdef ALTQUOT
211                                strchr(*av, QUOTCHAR) ? ALTQUOT :
212 #endif
213                                        QUOTCHAR;
214                        *cp++ = quote;
215                        strcpy(cp, *av);
216                        cp += n;
217                        *cp++ = quote;
218                } else {
219                        strcpy(cp, *av);
220                        cp += n;
221                }
222                *cp++ = ' ';
223        }
224        if (cp <= cmd)
225                return(NULL);
226        *--cp = '\0';
227        return(cmd);
228 }
229
186   /* Open a pipe to/from a command given as an argument list */
187   static FILE *
188   popen_arglist(char *av[], char *mode)
# Line 238 | Line 194 | popen_arglist(char *av[], char *mode)
194                  fputs(": command line too long in popen_arglist()\n", stderr);
195                  return(NULL);
196          }
197 <        if (verbose > 0)
197 >        if (verbose & VERBO)
198                  fprintf(stderr, "%s: opening pipe %s: %s\n",
199                                  progname, (*mode=='w') ? "to" : "from", cmd);
200          return(popen(cmd, mode));
201   }
202  
203 < #ifdef _WIN32
203 > #define pclose_al       pclose
204 >
205   /* Execute system command (Windows version) */
206   static int
207   my_exec(char *av[])
# Line 256 | Line 213 | my_exec(char *av[])
213                  fputs(": command line too long in my_exec()\n", stderr);
214                  return(1);
215          }
216 <        if (verbose > 0)
216 >        if (verbose & VERBO)
217                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
218          return(system(cmd));
219   }
220 < #else
220 >
221 > #else   /* UNIX */
222 >
223 > static SUBPROC  rt_proc = SP_INACTIVE;  /* we only support one of these */
224 >
225 > /* Open a pipe to a command using an argument list */
226 > static FILE *
227 > popen_arglist(char *av[], char *mode)
228 > {
229 >        int     fd;
230 >
231 >        if (rt_proc.pid > 0) {
232 >                fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname);
233 >                return(NULL);
234 >        }
235 >        if (verbose & VERBO) {
236 >                char    cmd[4096];
237 >                if (!convert_commandline(cmd, sizeof(cmd), av))
238 >                        strcpy(cmd, "COMMAND TOO LONG TO SHOW");
239 >                fprintf(stderr, "%s: opening pipe %s: %s\n",
240 >                                progname, (*mode=='w') ? "to" : "from", cmd);
241 >        }
242 >        if (*mode == 'w') {
243 >                fd = rt_proc.w = dup(fileno(stdout));
244 >                rt_proc.flags |= PF_FILT_OUT;
245 >        } else if (*mode == 'r') {
246 >                fd = rt_proc.r = dup(fileno(stdin));
247 >                rt_proc.flags |= PF_FILT_INP;
248 >        }
249 >        if (fd < 0 || open_process(&rt_proc, av) <= 0) {
250 >                perror(av[0]);
251 >                return(NULL);
252 >        }
253 >        return(fdopen(fd, mode));
254 > }
255 >
256 > /* Close command pipe (returns -1 on error to match pclose) */
257 > static int
258 > pclose_al(FILE *fp)
259 > {
260 >        int     prob = (fclose(fp) == EOF);
261 >
262 >        if (rt_proc.pid <= 0)
263 >                return(-1);
264 >
265 >        prob |= (close_process(&rt_proc) != 0);
266 >
267 >        return(-prob);
268 > }
269 >
270   /* Execute system command in our stead (Unix version) */
271   static int
272   my_exec(char *av[])
# Line 271 | Line 277 | my_exec(char *av[])
277                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
278                  return(1);
279          }
280 <        if (verbose > 0) {
280 >        if (verbose & VERBO) {
281                  char    cmd[4096];
282                  if (!convert_commandline(cmd, sizeof(cmd), av))
283                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 281 | Line 287 | my_exec(char *av[])
287          perror(compath);
288          return(1);
289   }
290 +
291   #endif
292  
293   /* Get normalized direction vector from string specification */
# Line 329 | Line 336 | parse_params(PARAMS *p, char *pargs)
336   {
337          char    *cp = pargs;
338          int     nparams = 0;
339 +        int     quot;
340          int     i;
341  
342          for ( ; ; ) {
# Line 365 | Line 373 | parse_params(PARAMS *p, char *pargs)
373                  case 'o':
374                          if (*cp++ != '=')
375                                  break;
376 +                        quot = 0;
377 +                        if ((*cp == '"') | (*cp == '\''))
378 +                                quot = *cp++;
379                          i = 0;
380 <                        while (*cp && !isspace(*cp++))
381 <                                i++;
380 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
381 >                                i++; cp++;
382 >                        }
383                          if (!i)
384                                  break;
385 <                        *--cp = '\0';
385 >                        if (!*cp) {
386 >                                if (quot)
387 >                                        break;
388 >                                cp[1] = '\0';
389 >                        }
390 >                        *cp = '\0';
391                          p->outfn = savqstr(cp-i);
392 <                        *cp++ = ' ';
392 >                        *cp++ = quot ? quot : ' ';
393                          ++nparams;
394                          continue;
395                  case ' ':
# Line 432 | Line 449 | finish_receiver(void)
449                          curparams.vup[1] = 1;
450          }
451                                          /* determine sample type/bin */
452 <        if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
452 >        if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) {
453                  sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
454                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
455                  binv = savqstr(sbuf);
# Line 485 | Line 502 | finish_receiver(void)
502                  calfn = kquarterfn; kquarterfn = NULL;
503                  binf = "kqbin";
504                  nbins = "Nkqbins";
505 +        } else if (!strcasecmp(curparams.hemis, "cie")) {
506 +                calfn = ciefn; ciefn = NULL;
507 +                sprintf(sbuf, "rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
508 +                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
509 +                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
510 +                        curparams.sign);
511 +                params = savqstr(sbuf);
512 +                binv = "cbin";
513 +                nbins = "Ncbins";
514          } else {
515                  fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n",
516                                  progname, curparams.hemis);
# Line 494 | Line 520 | finish_receiver(void)
520                  sprintf(sbuf, "RHS=%c1", curparams.sign);
521                  params = savqstr(sbuf);
522          }
523 <        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
523 >        if (!uniform) {
524                  SURF    *sp;
525                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
526 <                        if (fabs(sp->area - PI) > 1e-3) {
526 >                        if (sp->styp == ST_SOURCE && fabs(sp->area - PI) > 1e-3) {
527                                  fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
528                                                  progname, sp->sname);
529                                  exit(1);
# Line 655 | Line 681 | ssamp_poly(FVECT orig, SURF *sp, double x)
681                  sp->priv = (void *)ptp;
682          }
683                                          /* pick triangle by partial area */
684 <        for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++)
684 >        for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++)
685                  x -= ptp->tri[i].afrac;
686          SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac);
687          samp2[0] *= samp2[1] = sqrt(samp2[1]);
# Line 685 | Line 711 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
711                                          /* special case for lone surface */
712          if (p->nsurfs == 1) {
713                  sp = p->slist;
714 <                if (DOT(sp->snrm, rdir) >= -FTINY) {
714 >                if (DOT(sp->snrm, rdir) >= FTINY) {
715                          fprintf(stderr,
716                                  "%s: internal - sample behind sender '%s'\n",
717                                          progname, sp->sname);
# Line 696 | Line 722 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
722          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
723                  if (projsa) free(projsa);
724                  projsa = (double *)malloc(sizeof(double)*p->nsurfs);
725 <                if (!projsa) return(0);
725 >                if (projsa == NULL) {
726 >                        fputs(progname, stderr);
727 >                        fputs(": out of memory in sample_origin!\n", stderr);
728 >                        exit(1);
729 >                }
730                  nall = p->nsurfs;
731          }
732                                          /* compute projected areas */
733          for (i = 0, sp = p->slist; sp != NULL; i++, sp = sp->next) {
734                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
735 <                tarea += projsa[i] *= (double)(projsa[i] > FTINY);
735 >                tarea += projsa[i] *= (double)(projsa[i] > 0);
736          }
737 <        if (tarea <= FTINY) {           /* wrong side of sender? */
737 >        if (tarea < FTINY*FTINY) {      /* wrong side of sender? */
738                  fputs(progname, stderr);
739                  fputs(": internal - sample behind all sender elements!\n",
740                                  stderr);
# Line 722 | Line 752 | sample_uniform(PARAMS *p, int b, FILE *fp)
752   {
753          int     n = sampcnt;
754          double  samp3[3];
755 <        double  duvw[3];
726 <        FVECT   orig_dir[2];
755 >        FVECT   duvw, orig_dir[2];
756          int     i;
757  
758          if (fp == NULL)                 /* just requesting number of bins? */
# Line 731 | Line 760 | sample_uniform(PARAMS *p, int b, FILE *fp)
760  
761          while (n--) {                   /* stratified hemisphere sampling */
762                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
763 <                SDsquare2disk(duvw, samp3[1], samp3[2]);
763 >                square2disk(duvw, samp3[1], samp3[2]);
764                  duvw[2] = -sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
765                  for (i = 3; i--; )
766                          orig_dir[1][i] = duvw[0]*p->udir[i] +
# Line 739 | Line 768 | sample_uniform(PARAMS *p, int b, FILE *fp)
768                                                  duvw[2]*p->nrm[i] ;
769                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
770                          return(0);
771 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
771 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
772                          return(0);
773          }
774          return(1);
# Line 751 | Line 780 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
780   {
781          int     n = sampcnt;
782          double  samp3[3];
783 <        double  duvw[3];
755 <        FVECT   orig_dir[2];
783 >        FVECT   duvw, orig_dir[2];
784          int     i;
785  
786          if (fp == NULL)                 /* just requesting number of bins? */
# Line 760 | Line 788 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
788  
789          while (n--) {                   /* stratified sampling */
790                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
791 <                SDsquare2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
791 >                square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
792                                  (b%p->hsiz + samp3[2])/curparams.hsiz);
793                  duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
794                  for (i = 3; i--; )
# Line 769 | Line 797 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
797                                                  duvw[2]*p->nrm[i] ;
798                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
799                          return(0);
800 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
800 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
801                          return(0);
802          }
803          return(1);
# Line 805 | Line 833 | sample_reinhart(PARAMS *p, int b, FILE *fp)
833          }
834          while (n--) {                   /* stratified sampling */
835                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
836 +                if (row >= RowMax-1)    /* avoid crowding at zenith */
837 +                        samp3[1] *= samp3[1];
838                  alt = (row+samp3[1])*RAH;
839                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
840                  duvw[2] = cos(alt);     /* measured from horizon */
841                  duvw[0] = tsin(azi)*duvw[2];
842 <                duvw[1] = tcos(azi)*duvw[2];
842 >                duvw[1] = -tcos(azi)*duvw[2];
843                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
844                  for (i = 3; i--; )
845                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 817 | Line 847 | sample_reinhart(PARAMS *p, int b, FILE *fp)
847                                                  duvw[2]*p->nrm[i] ;
848                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
849                          return(0);
850 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
850 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
851                          return(0);
852          }
853          return(1);
# Line 868 | Line 898 | sample_klems(PARAMS *p, int b, FILE *fp)
898                                                  duvw[2]*p->nrm[i] ;
899                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
900                          return(0);
901 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
901 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
902                          return(0);
903          }
904          return(1);
# Line 876 | Line 906 | sample_klems(PARAMS *p, int b, FILE *fp)
906  
907   /* Prepare hemisphere basis sampler that will send rays to rcontrib */
908   static int
909 < prepare_sampler(void)
909 > prepare_sampler(PARAMS *p)
910   {
911 <        if (curparams.slist == NULL) {  /* missing sample surface! */
911 >        if (p->slist == NULL) { /* missing sample surface! */
912                  fputs(progname, stderr);
913                  fputs(": no sender surface!\n", stderr);
914                  return(-1);
915          }
916                                          /* misplaced output file spec. */
917 <        if ((curparams.outfn != NULL) & (verbose >= 0))
917 >        if ((p->outfn != NULL) & !(verbose & NOWARN))
918                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
919 <                                progname, curparams.outfn);
919 >                                progname, p->outfn);
920                                          /* check/set basis hemisphere */
921 <        if (!curparams.hemis[0]) {
921 >        if (!p->hemis[0]) {
922                  fputs(progname, stderr);
923                  fputs(": missing sender sampling type!\n", stderr);
924                  return(-1);
925          }
926 <        if (normalize(curparams.nrm) == 0) {
926 >        if (normalize(p->nrm) == 0) {
927                  fputs(progname, stderr);
928                  fputs(": undefined normal for sender sampling\n", stderr);
929                  return(-1);
930          }
931 <        if (normalize(curparams.vup) == 0) {
932 <                if (fabs(curparams.nrm[2]) < .7)
933 <                        curparams.vup[2] = 1;
931 >        if (normalize(p->vup) == 0) {
932 >                if (fabs(p->nrm[2]) < .7)
933 >                        p->vup[2] = 1;
934                  else
935 <                        curparams.vup[1] = 1;
935 >                        p->vup[1] = 1;
936          }
937 <        fcross(curparams.udir, curparams.vup, curparams.nrm);
938 <        if (normalize(curparams.udir) == 0) {
937 >        fcross(p->udir, p->vup, p->nrm);
938 >        if (normalize(p->udir) == 0) {
939                  fputs(progname, stderr);
940                  fputs(": up vector coincides with sender normal\n", stderr);
941                  return(-1);
942          }
943 <        fcross(curparams.vdir, curparams.nrm, curparams.udir);
944 <        if (curparams.sign == '-') {    /* left-handed coordinate system? */
945 <                curparams.udir[0] *= -1.;
946 <                curparams.udir[1] *= -1.;
947 <                curparams.udir[2] *= -1.;
943 >        fcross(p->vdir, p->nrm, p->udir);
944 >        if (p->sign == '-') {   /* left-handed coordinate system? */
945 >                p->udir[0] *= -1.;
946 >                p->udir[1] *= -1.;
947 >                p->udir[2] *= -1.;
948          }
949 <        if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
950 <                curparams.sample_basis = sample_uniform;
951 <        else if (tolower(curparams.hemis[0]) == 's' &&
952 <                                tolower(curparams.hemis[1]) == 'c')
953 <                curparams.sample_basis = sample_shirchiu;
954 <        else if ((tolower(curparams.hemis[0]) == 'r') |
955 <                        (tolower(curparams.hemis[0]) == 't'))
956 <                curparams.sample_basis = sample_reinhart;
957 <        else if (tolower(curparams.hemis[0]) == 'k') {
958 <                switch (curparams.hemis[1]) {
949 >        if ((tolower(p->hemis[0]) == 'u') | (p->hemis[0] == '1'))
950 >                p->sample_basis = sample_uniform;
951 >        else if (tolower(p->hemis[0]) == 's' &&
952 >                                tolower(p->hemis[1]) == 'c')
953 >                p->sample_basis = sample_shirchiu;
954 >        else if ((tolower(p->hemis[0]) == 'r') |
955 >                        (tolower(p->hemis[0]) == 't'))
956 >                p->sample_basis = sample_reinhart;
957 >        else if (tolower(p->hemis[0]) == 'k') {
958 >                switch (p->hemis[1]) {
959                  case '1':
960                  case '2':
961                  case '4':
# Line 933 | Line 963 | prepare_sampler(void)
963                  case 'f':
964                  case 'F':
965                  case '\0':
966 <                        curparams.hemis[1] = '1';
966 >                        p->hemis[1] = '1';
967                          break;
968                  case 'h':
969                  case 'H':
970 <                        curparams.hemis[1] = '2';
970 >                        p->hemis[1] = '2';
971                          break;
972                  case 'q':
973                  case 'Q':
974 <                        curparams.hemis[1] = '4';
974 >                        p->hemis[1] = '4';
975                          break;
976                  default:
977                          goto unrecognized;
978                  }
979 <                curparams.hemis[2] = '\0';
980 <                curparams.sample_basis = sample_klems;
979 >                p->hemis[2] = '\0';
980 >                p->sample_basis = sample_klems;
981          } else
982                  goto unrecognized;
983                                          /* return number of bins */
984 <        return((*curparams.sample_basis)(&curparams,0,NULL));
984 >        return((*p->sample_basis)(p,0,NULL));
985   unrecognized:
986          fprintf(stderr, "%s: unrecognized sender sampling: h=%s\n",
987 <                        progname, curparams.hemis);
987 >                        progname, p->hemis);
988          return(-1);
989   }
990  
# Line 977 | Line 1007 | finish_polygon(SURF *p)
1007                  VCOPY(e1, e2);
1008          }
1009          p->area = normalize(p->snrm)*0.5;
1010 <        return(p->area > FTINY);
1010 >        return(p->area > FTINY*FTINY);
1011   }
1012  
1013   /* Add a surface to our current parameters */
# Line 995 | Line 1025 | add_surface(int st, const char *oname, FILE *fp)
1025          snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1));
1026          if (snew == NULL) {
1027                  fputs(progname, stderr);
1028 <                fputs(": out of memory!\n", stderr);
1028 >                fputs(": out of memory in add_surface!\n", stderr);
1029                  exit(1);
1030          }
1031          strncpy(snew->sname, oname, sizeof(snew->sname)-1);
# Line 1040 | Line 1070 | add_surface(int st, const char *oname, FILE *fp)
1070                  snew->area *= PI*snew->area;
1071                  break;
1072          }
1073 <        if ((snew->area <= FTINY) & (verbose >= 0)) {
1073 >        if ((snew->area <= FTINY*FTINY) & !(verbose & NOWARN)) {
1074                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1075                                  progname, oname);
1076                  free(snew);
# Line 1077 | Line 1107 | add_recv_object(FILE *fp)
1107          }
1108                                          /* is it a new receiver? */
1109          if ((st = surf_type(otype)) != ST_NONE) {
1080                if (curparams.slist != NULL && (st == ST_SOURCE) ^
1081                                (curparams.slist->styp == ST_SOURCE)) {
1082                        fputs(progname, stderr);
1083                        fputs(": cannot mix source/non-source receivers!\n", stderr);
1084                        return(-1);
1085                }
1110                  if (strcmp(thismod, curmod)) {
1111                          if (curmod[0]) {        /* output last receiver? */
1112                                  finish_receiver();
# Line 1218 | Line 1242 | main(int argc, char *argv[])
1242          FILE    *rcfp;
1243          int     nsbins;
1244          int     a, i;
1245 +                                        /* set global progname */
1246 +        fixargv0(argv[0]);
1247                                          /* screen rcontrib options */
1222        progname = argv[0];
1248          for (a = 1; a < argc-2; a++) {
1249                  int     na;
1250                                          /* check for argument expansion */
# Line 1235 | Line 1260 | main(int argc, char *argv[])
1260                  na = 1;
1261                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1262                  case 'v':               /* verbose mode */
1263 <                        verbose = 1;
1263 >                        verbose ^= VERBO;
1264                          na = 0;
1265                          continue;
1266                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1265 | Line 1290 | main(int argc, char *argv[])
1290                          yrs = argv[++a];
1291                          na = 0;
1292                          continue;
1293 <                case 'c':               /* number of samples */
1294 <                        sampcnt = atoi(argv[++a]);
1295 <                        if (sampcnt <= 0)
1296 <                                goto userr;
1297 <                        na = 0;         /* we re-add this later */
1298 <                        continue;
1293 >                case 'c':               /* spectral sampling or count */
1294 >                        switch (argv[a][2]) {
1295 >                        case 's':
1296 >                                na = 2;
1297 >                                break;
1298 >                        case 'w':
1299 >                                na = 3;
1300 >                                break;
1301 >                        case '\0':
1302 >                                sampcnt = atoi(argv[++a]);
1303 >                                if (sampcnt <= 0)
1304 >                                        goto userr;
1305 >                                na = 0;         /* we re-add this later */
1306 >                                continue;
1307 >                        }
1308 >                        break;
1309                  case 'I':               /* only for pass-through mode */
1310                  case 'i':
1311                          iropt = argv[a];
1312                          na = 0;
1313                          continue;
1314                  case 'w':               /* options without arguments */
1315 <                        if (argv[a][2] != '+') verbose = -1;
1315 >                        if (!argv[a][2])
1316 >                                verbose ^= NOWARN;
1317 >                        else if (strchr("+1tTyY", argv[a][2]) != NULL)
1318 >                                verbose &= ~NOWARN;
1319 >                        else
1320 >                                verbose |= NOWARN;
1321 >                        break;
1322                  case 'V':
1323                  case 'u':
1324                  case 'h':
# Line 1286 | Line 1327 | main(int argc, char *argv[])
1327                  case 'n':               /* options with 1 argument */
1328                  case 's':
1329                  case 'o':
1330 +                case 't':
1331                          na = 2;
1332                          break;
1333                  case 'b':               /* special case */
# Line 1354 | Line 1396 | main(int argc, char *argv[])
1396                          fputs(": -i, -I supported for pass-through only\n", stderr);
1397                          return(1);
1398                  }
1399 <                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1399 > #ifdef SMLFLT
1400 >                fmtopt[2] = 'f';
1401 > #else
1402 >                fmtopt[2] = 'd';
1403 > #endif
1404                  if (sampcnt <= 0) sampcnt = 10000;
1405          }
1406          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1376 | Line 1422 | main(int argc, char *argv[])
1422          curmod[0] = '\0';
1423          if (load_scene(sendfn, add_send_object) < 0)
1424                  return(1);
1425 <        if ((nsbins = prepare_sampler()) <= 0)
1425 >        if ((nsbins = prepare_sampler(&curparams)) <= 0)
1426                  return(1);
1427          CHECKARGC(3);                   /* add row count and octree */
1428          rcarg[nrcargs++] = "-y";
# Line 1391 | Line 1437 | main(int argc, char *argv[])
1437   #ifdef getc_unlocked
1438          flockfile(rcfp);
1439   #endif
1440 <        if (verbose > 0) {
1440 >        if (verbose & VERBO) {
1441                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1442                  if (curparams.nsurfs > 1)
1443                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
# Line 1401 | Line 1447 | main(int argc, char *argv[])
1447          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1448                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1449                          return(1);
1450 <        return(pclose(rcfp) < 0);       /* all finished! */
1450 >        return(pclose_al(rcfp) < 0);    /* all finished! */
1451   userr:
1452          if (a < argc-2)
1453 <                fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1453 >                fprintf(stderr, "%s: unsupported option '%s'\n", progname, argv[a]);
1454          fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1455                                  progname);
1456          return(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)