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.38 by greg, Thu Aug 18 00:52:48 2016 UTC vs.
Revision 2.67 by greg, Fri Nov 14 23:51:42 2025 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"
14 > #include "rtprocess.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
17   #include "random.h"
18   #include "triangulate.h"
19   #include "platform.h"
20  
21 < #define MAXRCARG        512
21 > #ifndef MAXRCARG
22 > #define MAXRCARG        10000
23 > #endif
24  
25 < char            *progname;              /* global argv[0] */
25 > #define         NOWARN          1
26 > #define         VERBO           2
27  
28 < int             verbose = 0;            /* verbose mode (< 0 no warnings) */
28 > int             verbose = 0;            /* verbose/warning mode */
29  
30   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
31   int             nrcargs = 2;
# Line 39 | 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 + char            *binjitter = NULL;
48                                          /* string indicating parameters */
49 < const char      PARAMSTART[] = "@rfluxmtx";
49 > #define PARAMSTART      "@rfluxmtx"
50  
51                                  /* surface type IDs */
52   #define ST_NONE         0
# Line 64 | Line 69 | typedef struct {
69          FVECT   uva[2];                 /* tangent axes */
70          int     ntris;                  /* number of triangles */
71          struct ptri {
72 <                float   afrac;                  /* fraction of total area */
72 >                double  afrac;                  /* fraction of total area */
73                  short   vndx[3];                /* vertex indices */
74          }       tri[1];                 /* triangle array (extends struct) */
75   } POLYTRIS;                     /* triangulated polygon */
# Line 95 | Line 100 | SURFSAMP       *orig_in_surf[4] = {
100          };
101  
102   /* Clear parameter set */
103 < static void
103 > void
104   clear_params(PARAMS *p, int reset_only)
105   {
106          while (p->slist != NULL) {
# Line 106 | Line 111 | clear_params(PARAMS *p, int reset_only)
111                  free(sdel);
112          }
113          if (reset_only) {
114 +                p->slist = NULL;
115                  p->nsurfs = 0;
116                  memset(p->nrm, 0, sizeof(FVECT));
117                  memset(p->vup, 0, sizeof(FVECT));
# Line 116 | Line 122 | clear_params(PARAMS *p, int reset_only)
122   }
123  
124   /* Get surface type from name */
125 < static int
125 > int
126   surf_type(const char *otype)
127   {
128          if (!strcmp(otype, "polygon"))
# Line 129 | Line 135 | surf_type(const char *otype)
135   }
136  
137   /* Add arguments to oconv command */
138 < static char *
138 > char *
139   oconv_command(int ac, char *av[])
140   {
141          static char     oconvbuf[2048] = "!oconv -f ";
# Line 138 | Line 144 | oconv_command(int ac, char *av[])
144          
145          if (ac-- <= 0)
146                  return(NULL);
147 <        while (ac-- > 0) {
148 <                strcpy(cp, *av++);
149 <                while (*cp) cp++;
150 <                *cp++ = ' ';
151 <                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
147 >        if (verbose & NOWARN) { /* warnings off? */
148 >                strcpy(cp, "-w ");
149 >                cp += 3;
150 >        }
151 >        while (ac-- > 0) {      /* copy each argument */
152 >                int     len = strlen(*av);
153 >                if (cp+len+4 >= oconvbuf+sizeof(oconvbuf))
154                          goto overrun;
155 +                if (matchany(*av, SPECIALS)) {
156 +                        *cp++ = QUOTCHAR;
157 +                        strcpy(cp, *av++);
158 +                        cp += len;
159 +                        *cp++ = QUOTCHAR;
160 +                } else {
161 +                        strcpy(cp, *av++);
162 +                        cp += len;
163 +                }
164 +                *cp++ = ' ';
165          }
166                                  /* receiver goes last */
167          if (matchany(recv, SPECIALS)) {
# Line 164 | Line 182 | overrun:
182          exit(1);
183   }
184  
185 + #if defined(_WIN32) || defined(_WIN64)
186 +
187   /* Open a pipe to/from a command given as an argument list */
188 < static FILE *
188 > FILE *
189   popen_arglist(char *av[], char *mode)
190   {
191          char    cmd[10240];
# Line 175 | Line 195 | popen_arglist(char *av[], char *mode)
195                  fputs(": command line too long in popen_arglist()\n", stderr);
196                  return(NULL);
197          }
198 <        if (verbose > 0)
198 >        if (verbose & VERBO)
199                  fprintf(stderr, "%s: opening pipe %s: %s\n",
200                                  progname, (*mode=='w') ? "to" : "from", cmd);
201          return(popen(cmd, mode));
202   }
203  
204 < #if defined(_WIN32) || defined(_WIN64)
204 > #define pclose_al       pclose
205 >
206   /* Execute system command (Windows version) */
207 < static int
207 > int
208   my_exec(char *av[])
209   {
210          char    cmd[10240];
# Line 193 | Line 214 | my_exec(char *av[])
214                  fputs(": command line too long in my_exec()\n", stderr);
215                  return(1);
216          }
217 <        if (verbose > 0)
217 >        if (verbose & VERBO)
218                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
219          return(system(cmd));
220   }
221 < #else
221 >
222 > #else   /* UNIX */
223 >
224 > static SUBPROC  rt_proc = SP_INACTIVE;  /* we only support one of these */
225 >
226 > /* Open a pipe to a command using an argument list */
227 > FILE *
228 > popen_arglist(char *av[], char *mode)
229 > {
230 >        int     fd;
231 >
232 >        if (rt_proc.pid > 0) {
233 >                fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname);
234 >                return(NULL);
235 >        }
236 >        if (verbose & VERBO) {
237 >                char    cmd[4096];
238 >                if (!convert_commandline(cmd, sizeof(cmd), av))
239 >                        strcpy(cmd, "COMMAND TOO LONG TO SHOW");
240 >                fprintf(stderr, "%s: opening pipe %s: %s\n",
241 >                                progname, (*mode=='w') ? "to" : "from", cmd);
242 >        }
243 >        if (*mode == 'w') {
244 >                fd = rt_proc.w = dup(fileno(stdout));
245 >                rt_proc.flags |= PF_FILT_OUT;
246 >        } else if (*mode == 'r') {
247 >                fd = rt_proc.r = dup(fileno(stdin));
248 >                rt_proc.flags |= PF_FILT_INP;
249 >        }
250 >        if (fd < 0 || open_process(&rt_proc, av) <= 0) {
251 >                perror(av[0]);
252 >                return(NULL);
253 >        }
254 >        return(fdopen(fd, mode));
255 > }
256 >
257 > /* Close command pipe (returns -1 on error to match pclose) */
258 > int
259 > pclose_al(FILE *fp)
260 > {
261 >        int     prob = (fclose(fp) == EOF);
262 >
263 >        if (rt_proc.pid <= 0)
264 >                return(-1);
265 >
266 >        prob |= (close_process(&rt_proc) != 0);
267 >
268 >        return(-prob);
269 > }
270 >
271   /* Execute system command in our stead (Unix version) */
272 < static int
272 > int
273   my_exec(char *av[])
274   {
275          char    *compath;
# Line 208 | Line 278 | my_exec(char *av[])
278                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
279                  return(1);
280          }
281 <        if (verbose > 0) {
281 >        if (verbose & VERBO) {
282                  char    cmd[4096];
283                  if (!convert_commandline(cmd, sizeof(cmd), av))
284                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 218 | Line 288 | my_exec(char *av[])
288          perror(compath);
289          return(1);
290   }
291 +
292   #endif
293  
294   /* Get normalized direction vector from string specification */
295 < static int
295 > int
296   get_direction(FVECT dv, const char *s)
297   {
298          int     sign = 1;
# Line 261 | Line 332 | nextchar:
332   }
333  
334   /* Parse program parameters (directives) */
335 < static int
335 > int
336   parse_params(PARAMS *p, char *pargs)
337   {
338          char    *cp = pargs;
# Line 339 | Line 410 | parse_params(PARAMS *p, char *pargs)
410          return(-1);     /* pro forma return */
411   }
412  
413 + /* Append bin jitter to the parameter string */
414 + int
415 + addbinjitter(char *s)
416 + {
417 +        if (binjitter == NULL)
418 +                return(0);
419 +        s += strlen(s);
420 +        strcpy(s, ",JTR=");
421 +        strcpy(s+5, binjitter);
422 +        return(1);
423 + }
424 +
425   /* Add receiver arguments (directives) corresponding to the current modifier */
426 < static void
426 > void
427   finish_receiver(void)
428   {
429          char    sbuf[256];
# Line 379 | Line 462 | finish_receiver(void)
462                          curparams.vup[1] = 1;
463          }
464                                          /* determine sample type/bin */
465 <        if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
466 <                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
467 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
468 <                binv = savqstr(sbuf);
465 >        if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) {
466 >                if (curparams.slist->styp != ST_SOURCE) {
467 >                        sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
468 >                                curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
469 >                        binv = savqstr(sbuf);
470 >                } else
471 >                        binv = "0";
472                  nbins = "1";            /* uniform sampling -- one bin */
473                  uniform = 1;
474          } else if (tolower(curparams.hemis[0]) == 's' &&
# Line 399 | Line 485 | finish_receiver(void)
485                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
486                          curparams.vup[0], curparams.vup[1], curparams.vup[2],
487                          curparams.sign);
488 +                addbinjitter(sbuf);
489                  params = savqstr(sbuf);
490                  binv = "scbin";
491                  nbins = "SCdim*SCdim";
# Line 410 | Line 497 | finish_receiver(void)
497                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
498                          curparams.vup[0], curparams.vup[1], curparams.vup[2],
499                          curparams.sign);
500 +                addbinjitter(sbuf);
501                  params = savqstr(sbuf);
502                  binv = "rbin";
503                  nbins = "Nrbins";
# Line 432 | Line 520 | finish_receiver(void)
520                  calfn = kquarterfn; kquarterfn = NULL;
521                  binf = "kqbin";
522                  nbins = "Nkqbins";
523 +        } else if (!strcasecmp(curparams.hemis, "cie")) {
524 +                calfn = ciefn; ciefn = NULL;
525 +                sprintf(sbuf, "rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
526 +                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
527 +                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
528 +                        curparams.sign);
529 +                addbinjitter(sbuf);
530 +                params = savqstr(sbuf);
531 +                binv = "cbin";
532 +                nbins = "Ncbins";
533          } else {
534                  fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n",
535                                  progname, curparams.hemis);
# Line 439 | Line 537 | finish_receiver(void)
537          }
538          if (tolower(curparams.hemis[0]) == 'k') {
539                  sprintf(sbuf, "RHS=%c1", curparams.sign);
540 +                addbinjitter(sbuf);
541                  params = savqstr(sbuf);
542          }
543 <        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
543 >        if (!uniform) {
544                  SURF    *sp;
545                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
546 <                        if (fabs(sp->area - PI) > 1e-3) {
546 >                        if (sp->styp == ST_SOURCE && fabs(sp->area - PI) > 1e-3) {
547                                  fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
548                                                  progname, sp->sname);
549                                  exit(1);
# Line 483 | Line 582 | finish_receiver(void)
582   }
583  
584   /* Make randomly oriented tangent plane axes for given normal direction */
585 < static void
585 > void
586   make_axes(FVECT uva[2], const FVECT nrm)
587   {
588          int     i;
# Line 497 | Line 596 | make_axes(FVECT uva[2], const FVECT nrm)
596   }
597  
598   /* Illegal sender surfaces end up here */
599 < static int
599 > int
600   ssamp_bad(FVECT orig, SURF *sp, double x)
601   {
602          fprintf(stderr, "%s: illegal sender surface '%s'\n",
# Line 506 | Line 605 | ssamp_bad(FVECT orig, SURF *sp, double x)
605   }
606  
607   /* Generate origin on ring surface from uniform random variable */
608 < static int
608 > int
609   ssamp_ring(FVECT orig, SURF *sp, double x)
610   {
611          FVECT   *uva = (FVECT *)sp->priv;
# Line 535 | Line 634 | ssamp_ring(FVECT orig, SURF *sp, double x)
634   }
635  
636   /* Add triangle to polygon's list (call-back function) */
637 < static int
637 > int
638   add_triangle(const Vert2_list *tp, int a, int b, int c)
639   {
640          POLYTRIS        *ptp = (POLYTRIS *)tp->p;
# Line 548 | Line 647 | add_triangle(const Vert2_list *tp, int a, int b, int c
647   }
648  
649   /* Generate origin on polygon surface from uniform random variable */
650 < static int
650 > int
651   ssamp_poly(FVECT orig, SURF *sp, double x)
652   {
653          POLYTRIS        *ptp = (POLYTRIS *)sp->priv;
# Line 602 | Line 701 | ssamp_poly(FVECT orig, SURF *sp, double x)
701                  sp->priv = (void *)ptp;
702          }
703                                          /* pick triangle by partial area */
704 <        for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++)
704 >        for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++)
705                  x -= ptp->tri[i].afrac;
706          SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac);
707          samp2[0] *= samp2[1] = sqrt(samp2[1]);
# Line 621 | Line 720 | memerr:
720   }
721  
722   /* Compute sample origin based on projected areas of sender subsurfaces */
723 < static int
723 > int
724   sample_origin(PARAMS *p, FVECT orig, const FVECT rdir, double x)
725   {
726          static double   *projsa;
# Line 653 | Line 752 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
752                                          /* compute projected areas */
753          for (i = 0, sp = p->slist; sp != NULL; i++, sp = sp->next) {
754                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
755 <                tarea += projsa[i] *= (double)(projsa[i] > FTINY);
755 >                tarea += projsa[i] *= (double)(projsa[i] > 0);
756          }
757 <        if (tarea <= FTINY) {           /* wrong side of sender? */
757 >        if (tarea < FTINY*FTINY) {      /* wrong side of sender? */
758                  fputs(progname, stderr);
759                  fputs(": internal - sample behind all sender elements!\n",
760                                  stderr);
# Line 668 | Line 767 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
767   }
768  
769   /* Uniform sample generator */
770 < static int
770 > int
771   sample_uniform(PARAMS *p, int b, FILE *fp)
772   {
773          int     n = sampcnt;
774          double  samp3[3];
775 <        double  duvw[3];
677 <        FVECT   orig_dir[2];
775 >        FVECT   duvw, orig_dir[2];
776          int     i;
777  
778          if (fp == NULL)                 /* just requesting number of bins? */
# Line 682 | Line 780 | sample_uniform(PARAMS *p, int b, FILE *fp)
780  
781          while (n--) {                   /* stratified hemisphere sampling */
782                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
783 <                SDsquare2disk(duvw, samp3[1], samp3[2]);
783 >                square2disk(duvw, samp3[1], samp3[2]);
784                  duvw[2] = -sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
785                  for (i = 3; i--; )
786                          orig_dir[1][i] = duvw[0]*p->udir[i] +
# Line 697 | Line 795 | sample_uniform(PARAMS *p, int b, FILE *fp)
795   }
796  
797   /* Shirly-Chiu sample generator */
798 < static int
798 > int
799   sample_shirchiu(PARAMS *p, int b, FILE *fp)
800   {
801          int     n = sampcnt;
802          double  samp3[3];
803 <        double  duvw[3];
706 <        FVECT   orig_dir[2];
803 >        FVECT   duvw, orig_dir[2];
804          int     i;
805  
806          if (fp == NULL)                 /* just requesting number of bins? */
# Line 711 | Line 808 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
808  
809          while (n--) {                   /* stratified sampling */
810                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
811 <                SDsquare2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
811 >                square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
812                                  (b%p->hsiz + samp3[2])/curparams.hsiz);
813                  duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
814                  for (i = 3; i--; )
# Line 727 | Line 824 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
824   }
825  
826   /* Reinhart/Tregenza sample generator */
827 < static int
827 > int
828   sample_reinhart(PARAMS *p, int b, FILE *fp)
829   {
830   #define T_NALT  7
# Line 756 | Line 853 | sample_reinhart(PARAMS *p, int b, FILE *fp)
853          }
854          while (n--) {                   /* stratified sampling */
855                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
856 +                if (row >= RowMax-1)    /* avoid crowding at zenith */
857 +                        samp3[1] *= samp3[1];
858                  alt = (row+samp3[1])*RAH;
859                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
860                  duvw[2] = cos(alt);     /* measured from horizon */
861                  duvw[0] = tsin(azi)*duvw[2];
862 <                duvw[1] = tcos(azi)*duvw[2];
862 >                duvw[1] = -tcos(azi)*duvw[2];
863                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
864                  for (i = 3; i--; )
865                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 777 | Line 876 | sample_reinhart(PARAMS *p, int b, FILE *fp)
876   }
877  
878   /* Klems sample generator */
879 < static int
879 > int
880   sample_klems(PARAMS *p, int b, FILE *fp)
881   {
882          static const char       bname[4][20] = {
# Line 826 | Line 925 | sample_klems(PARAMS *p, int b, FILE *fp)
925   }
926  
927   /* Prepare hemisphere basis sampler that will send rays to rcontrib */
928 < static int
929 < prepare_sampler(void)
928 > int
929 > prepare_sampler(PARAMS *p)
930   {
931 <        if (curparams.slist == NULL) {  /* missing sample surface! */
931 >        if (p->slist == NULL) { /* missing sample surface! */
932                  fputs(progname, stderr);
933                  fputs(": no sender surface!\n", stderr);
934                  return(-1);
935          }
936                                          /* misplaced output file spec. */
937 <        if ((curparams.outfn != NULL) & (verbose >= 0))
937 >        if ((p->outfn != NULL) & !(verbose & NOWARN))
938                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
939 <                                progname, curparams.outfn);
939 >                                progname, p->outfn);
940                                          /* check/set basis hemisphere */
941 <        if (!curparams.hemis[0]) {
941 >        if (!p->hemis[0]) {
942                  fputs(progname, stderr);
943                  fputs(": missing sender sampling type!\n", stderr);
944                  return(-1);
945          }
946 <        if (normalize(curparams.nrm) == 0) {
946 >        if (normalize(p->nrm) == 0) {
947                  fputs(progname, stderr);
948                  fputs(": undefined normal for sender sampling\n", stderr);
949                  return(-1);
950          }
951 <        if (normalize(curparams.vup) == 0) {
952 <                if (fabs(curparams.nrm[2]) < .7)
953 <                        curparams.vup[2] = 1;
951 >        if (normalize(p->vup) == 0) {
952 >                if (fabs(p->nrm[2]) < .7)
953 >                        p->vup[2] = 1;
954                  else
955 <                        curparams.vup[1] = 1;
955 >                        p->vup[1] = 1;
956          }
957 <        fcross(curparams.udir, curparams.vup, curparams.nrm);
958 <        if (normalize(curparams.udir) == 0) {
957 >        fcross(p->udir, p->vup, p->nrm);
958 >        if (normalize(p->udir) == 0) {
959                  fputs(progname, stderr);
960                  fputs(": up vector coincides with sender normal\n", stderr);
961                  return(-1);
962          }
963 <        fcross(curparams.vdir, curparams.nrm, curparams.udir);
964 <        if (curparams.sign == '-') {    /* left-handed coordinate system? */
965 <                curparams.udir[0] *= -1.;
966 <                curparams.udir[1] *= -1.;
967 <                curparams.udir[2] *= -1.;
963 >        fcross(p->vdir, p->nrm, p->udir);
964 >        if (p->sign == '-') {   /* left-handed coordinate system? */
965 >                p->udir[0] *= -1.;
966 >                p->udir[1] *= -1.;
967 >                p->udir[2] *= -1.;
968          }
969 <        if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
970 <                curparams.sample_basis = sample_uniform;
971 <        else if (tolower(curparams.hemis[0]) == 's' &&
972 <                                tolower(curparams.hemis[1]) == 'c')
973 <                curparams.sample_basis = sample_shirchiu;
974 <        else if ((tolower(curparams.hemis[0]) == 'r') |
975 <                        (tolower(curparams.hemis[0]) == 't'))
976 <                curparams.sample_basis = sample_reinhart;
977 <        else if (tolower(curparams.hemis[0]) == 'k') {
978 <                switch (curparams.hemis[1]) {
969 >        if ((tolower(p->hemis[0]) == 'u') | (p->hemis[0] == '1'))
970 >                p->sample_basis = sample_uniform;
971 >        else if (tolower(p->hemis[0]) == 's' &&
972 >                                tolower(p->hemis[1]) == 'c')
973 >                p->sample_basis = sample_shirchiu;
974 >        else if ((tolower(p->hemis[0]) == 'r') |
975 >                        (tolower(p->hemis[0]) == 't'))
976 >                p->sample_basis = sample_reinhart;
977 >        else if (tolower(p->hemis[0]) == 'k') {
978 >                switch (p->hemis[1]) {
979                  case '1':
980                  case '2':
981                  case '4':
# Line 884 | Line 983 | prepare_sampler(void)
983                  case 'f':
984                  case 'F':
985                  case '\0':
986 <                        curparams.hemis[1] = '1';
986 >                        p->hemis[1] = '1';
987                          break;
988                  case 'h':
989                  case 'H':
990 <                        curparams.hemis[1] = '2';
990 >                        p->hemis[1] = '2';
991                          break;
992                  case 'q':
993                  case 'Q':
994 <                        curparams.hemis[1] = '4';
994 >                        p->hemis[1] = '4';
995                          break;
996                  default:
997                          goto unrecognized;
998                  }
999 <                curparams.hemis[2] = '\0';
1000 <                curparams.sample_basis = sample_klems;
999 >                p->hemis[2] = '\0';
1000 >                p->sample_basis = sample_klems;
1001          } else
1002                  goto unrecognized;
1003                                          /* return number of bins */
1004 <        return((*curparams.sample_basis)(&curparams,0,NULL));
1004 >        return((*p->sample_basis)(p,0,NULL));
1005   unrecognized:
1006          fprintf(stderr, "%s: unrecognized sender sampling: h=%s\n",
1007 <                        progname, curparams.hemis);
1007 >                        progname, p->hemis);
1008          return(-1);
1009   }
1010  
1011   /* Compute normal and area for polygon */
1012 < static int
1012 > int
1013   finish_polygon(SURF *p)
1014   {
1015          const int       nv = p->nfargs / 3;
# Line 928 | Line 1027 | finish_polygon(SURF *p)
1027                  VCOPY(e1, e2);
1028          }
1029          p->area = normalize(p->snrm)*0.5;
1030 <        return(p->area > FTINY);
1030 >        return(p->area > FTINY*FTINY);
1031   }
1032  
1033   /* Add a surface to our current parameters */
1034 < static void
1034 > void
1035   add_surface(int st, const char *oname, FILE *fp)
1036   {
1037          SURF    *snew;
# Line 991 | Line 1090 | add_surface(int st, const char *oname, FILE *fp)
1090                  snew->area *= PI*snew->area;
1091                  break;
1092          }
1093 <        if ((snew->area <= FTINY) & (verbose >= 0)) {
1093 >        if ((snew->area <= FTINY*FTINY) & !(verbose & NOWARN)) {
1094                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1095                                  progname, oname);
1096                  free(snew);
# Line 1013 | Line 1112 | badnorm:
1112   }
1113  
1114   /* Parse a receiver object (look for modifiers to add to rcontrib command) */
1115 < static int
1115 > int
1116   add_recv_object(FILE *fp)
1117   {
1118          int             st;
# Line 1028 | Line 1127 | add_recv_object(FILE *fp)
1127          }
1128                                          /* is it a new receiver? */
1129          if ((st = surf_type(otype)) != ST_NONE) {
1031                if (curparams.slist != NULL && (st == ST_SOURCE) ^
1032                                (curparams.slist->styp == ST_SOURCE)) {
1033                        fputs(progname, stderr);
1034                        fputs(": cannot mix source/non-source receivers!\n", stderr);
1035                        return(-1);
1036                }
1130                  if (strcmp(thismod, curmod)) {
1131                          if (curmod[0]) {        /* output last receiver? */
1132                                  finish_receiver();
# Line 1057 | Line 1150 | add_recv_object(FILE *fp)
1150   }
1151  
1152   /* Parse a sender object */
1153 < static int
1153 > int
1154   add_send_object(FILE *fp)
1155   {
1156          int             st;
# Line 1101 | Line 1194 | add_send_object(FILE *fp)
1194   }
1195  
1196   /* Load a Radiance scene using the given callback function for objects */
1197 < static int
1197 > int
1198   load_scene(const char *inspec, int (*ocb)(FILE *))
1199   {
1200          int     rv = 0;
# Line 1165 | Line 1258 | main(int argc, char *argv[])
1258          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1259          char    *iropt = NULL;
1260          char    *sendfn;
1261 <        char    sampcntbuf[32], nsbinbuf[32];
1261 >        char    sampcntbuf[32], nsbinbuf[32], binjitbuf[32];
1262          FILE    *rcfp;
1263          int     nsbins;
1264          int     a, i;
1265 +                                        /* set global progname */
1266 +        fixargv0(argv[0]);
1267                                          /* screen rcontrib options */
1173        progname = argv[0];
1268          for (a = 1; a < argc-2; a++) {
1269                  int     na;
1270                                          /* check for argument expansion */
# Line 1186 | Line 1280 | main(int argc, char *argv[])
1280                  na = 1;
1281                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1282                  case 'v':               /* verbose mode */
1283 <                        verbose = 1;
1283 >                        verbose ^= VERBO;
1284                          na = 0;
1285                          continue;
1286                  case 'f':               /* special case for -fo, -ff, etc. */
1287                          switch (argv[a][2]) {
1288                          case '\0':              /* cal file */
1289 <                                goto userr;
1289 >                                na = 2;
1290 >                                break;
1291                          case 'o':               /* force output */
1292                                  goto userr;
1293                          case 'a':               /* output format */
# Line 1216 | Line 1311 | main(int argc, char *argv[])
1311                          yrs = argv[++a];
1312                          na = 0;
1313                          continue;
1314 <                case 'c':               /* number of samples */
1315 <                        sampcnt = atoi(argv[++a]);
1316 <                        if (sampcnt <= 0)
1317 <                                goto userr;
1318 <                        na = 0;         /* we re-add this later */
1319 <                        continue;
1314 >                case 'c':               /* spectral sampling or count */
1315 >                        switch (argv[a][2]) {
1316 >                        case 's':
1317 >                                na = 2;
1318 >                                break;
1319 >                        case 'w':
1320 >                                na = 3;
1321 >                                break;
1322 >                        case '\0':
1323 >                                sampcnt = atoi(argv[++a]);
1324 >                                if (sampcnt <= 0)
1325 >                                        goto userr;
1326 >                                na = 0;         /* we re-add this later */
1327 >                                continue;
1328 >                        }
1329 >                        break;
1330                  case 'I':               /* only for pass-through mode */
1331                  case 'i':
1332                          iropt = argv[a];
1333                          na = 0;
1334                          continue;
1335                  case 'w':               /* options without arguments */
1336 <                        if (argv[a][2] != '+') verbose = -1;
1336 >                        if (!argv[a][2])
1337 >                                verbose ^= NOWARN;
1338 >                        else if (strchr("+1tTyY", argv[a][2]) != NULL)
1339 >                                verbose &= ~NOWARN;
1340 >                        else
1341 >                                verbose |= NOWARN;
1342 >                        break;
1343                  case 'V':
1344                  case 'u':
1345                  case 'h':
# Line 1237 | Line 1348 | main(int argc, char *argv[])
1348                  case 'n':               /* options with 1 argument */
1349                  case 's':
1350                  case 'o':
1351 +                case 't':
1352 +                case 'e':
1353                          na = 2;
1354                          break;
1355                  case 'b':               /* special case */
1356 +                        if (argv[a][2] == 'j') {
1357 +                                binjitter = argv[++a];
1358 +                                na = 0;
1359 +                                continue;
1360 +                        }
1361                          if (argv[a][2] != 'v') goto userr;
1362                          break;
1363                  case 'l':               /* special case */
# Line 1305 | Line 1423 | main(int argc, char *argv[])
1423                          fputs(": -i, -I supported for pass-through only\n", stderr);
1424                          return(1);
1425                  }
1426 <                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1426 > #ifdef SMLFLT
1427 >                fmtopt[2] = 'f';
1428 > #else
1429 >                fmtopt[2] = 'd';
1430 > #endif
1431                  if (sampcnt <= 0) sampcnt = 10000;
1432          }
1433          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1327 | Line 1449 | main(int argc, char *argv[])
1449          curmod[0] = '\0';
1450          if (load_scene(sendfn, add_send_object) < 0)
1451                  return(1);
1452 <        if ((nsbins = prepare_sampler()) <= 0)
1452 >        if ((nsbins = prepare_sampler(&curparams)) <= 0)
1453                  return(1);
1454          CHECKARGC(3);                   /* add row count and octree */
1455          rcarg[nrcargs++] = "-y";
# Line 1342 | Line 1464 | main(int argc, char *argv[])
1464   #ifdef getc_unlocked
1465          flockfile(rcfp);
1466   #endif
1467 <        if (verbose > 0) {
1467 >        if (verbose & VERBO) {
1468                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1469                  if (curparams.nsurfs > 1)
1470                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
# Line 1352 | Line 1474 | main(int argc, char *argv[])
1474          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1475                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1476                          return(1);
1477 <        return(pclose(rcfp) < 0);       /* all finished! */
1477 >        return(pclose_al(rcfp) < 0);    /* all finished! */
1478   userr:
1479          if (a < argc-2)
1480 <                fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1481 <        fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1480 >                fprintf(stderr, "%s: unsupported option '%s'\n", progname, argv[a]);
1481 >        fprintf(stderr, "Usage: %s [-v][-bj frac][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1482                                  progname);
1483          return(1);
1484   }

Diff Legend

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