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.14 by greg, Wed Aug 6 02:38:24 2014 UTC vs.
Revision 2.32 by greg, Fri Dec 4 22:16:18 2015 UTC

# Line 36 | Line 36 | static const char RCSid[] = "$Id$";
36  
37   char            *progname;              /* global argv[0] */
38  
39 < int             verbose = 0;            /* verbose mode? */
39 > int             verbose = 0;            /* verbose mode (< 0 no warnings) */
40  
41   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
42   int             nrcargs = 2;
# Line 84 | Line 84 | typedef struct {
84   } POLYTRIS;                     /* triangulated polygon */
85  
86   typedef struct param_s {
87 <        char            hemis[32];      /* hemispherical sampling spec. */
87 >        char            sign;           /* '-' for axis reversal */
88 >        char            hemis[31];      /* hemispherical sampling spec. */
89          int             hsiz;           /* hemisphere basis size */
90          int             nsurfs;         /* number of surfaces */
91          SURF            *slist;         /* list of surfaces */
92          FVECT           vup;            /* up vector (zero if unset) */
93          FVECT           nrm;            /* average normal direction */
94 <        FVECT           udir, vdir;     /* v-up tangent axes */
94 >        FVECT           udir, vdir;     /* tangent axes */
95          char            *outfn;         /* output file name (receiver) */
96          int             (*sample_basis)(struct param_s *p, int, FILE *);
97   } PARAMS;                       /* sender/receiver parameters */
# Line 141 | Line 142 | surf_type(const char *otype)
142          return(ST_NONE);
143   }
144  
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 +
159   /* Add arguments to oconv command */
160   static char *
161   oconv_command(int ac, char *av[])
# Line 155 | Line 170 | oconv_command(int ac, char *av[])
170                  strcpy(cp, *av++);
171                  while (*cp) cp++;
172                  *cp++ = ' ';
173 <                if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) {
174 <                        fputs(progname, stderr);
160 <                        fputs(": too many file arguments!\n", stderr);
161 <                        exit(1);
162 <                }
173 >                if (cp >= oconvbuf+(sizeof(oconvbuf)-32))
174 >                        goto overrun;
175          }
176 <        strcpy(cp, recv);       /* receiver goes last */
176 >                                /* receiver goes last */
177 >        if (matchany(recv, SPECIALS)) {
178 >                *cp++ = QUOTCHAR;
179 >                while (*recv) {
180 >                        if (cp >= oconvbuf+(sizeof(oconvbuf)-3))
181 >                                goto overrun;
182 >                        *cp++ = *recv++;
183 >                }
184 >                *cp++ = QUOTCHAR;
185 >                *cp = '\0';
186 >        } else
187 >                strcpy(cp, recv);
188          return(oconvbuf);
189 + overrun:
190 +        fputs(progname, stderr);
191 +        fputs(": too many file arguments!\n", stderr);
192 +        exit(1);
193   }
194  
168 /* Check if any of the characters in str2 are found in str1 */
169 static int
170 matchany(const char *str1, const char *str2)
171 {
172        while (*str1) {
173                const char      *cp = str2;
174                while (*cp)
175                        if (*cp++ == *str1)
176                                return(*str1);
177                ++str1;
178        }
179        return(0);
180 }
181
182
195   /* 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[])
# Line 193 | Line 205 | convert_commandline(char *cmd, const int len, char *av
205                          fputs(progname, stderr);
206                          return(NULL);
207                  }
208 <                if ((match = matchany(*av, SPECIALS))) {
208 >                if (matchany(*av, SPECIALS)) {
209                          const int       quote =
210   #ifdef ALTQUOT
211 <                                (match == QUOTCHAR) ? ALTQUOT :
211 >                                strchr(*av, QUOTCHAR) ? ALTQUOT :
212   #endif
213                                          QUOTCHAR;
214                          *cp++ = quote;
# Line 226 | Line 238 | popen_arglist(char *av[], char *mode)
238                  fputs(": command line too long in popen_arglist()\n", stderr);
239                  return(NULL);
240          }
241 <        if (verbose)
241 >        if (verbose > 0)
242                  fprintf(stderr, "%s: opening pipe %s: %s\n",
243                                  progname, (*mode=='w') ? "to" : "from", cmd);
244          return(popen(cmd, mode));
# Line 244 | Line 256 | my_exec(char *av[])
256                  fputs(": command line too long in my_exec()\n", stderr);
257                  return(1);
258          }
259 <        if (verbose)
259 >        if (verbose > 0)
260                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
261          return(system(cmd));
262   }
# Line 259 | Line 271 | my_exec(char *av[])
271                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
272                  return(1);
273          }
274 <        if (verbose) {
274 >        if (verbose > 0) {
275                  char    cmd[4096];
276                  if (!convert_commandline(cmd, sizeof(cmd), av))
277                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 317 | Line 329 | parse_params(PARAMS *p, char *pargs)
329   {
330          char    *cp = pargs;
331          int     nparams = 0;
332 +        int     quot;
333          int     i;
334  
335 <        for ( ; ; )
335 >        for ( ; ; ) {
336                  switch (*cp++) {
337                  case 'h':
338                          if (*cp++ != '=')
339                                  break;
340 +                        if ((*cp == '+') | (*cp == '-'))
341 +                                p->sign = *cp++;
342 +                        else
343 +                                p->sign = '+';
344                          p->hsiz = 0;
345                          i = 0;
346                          while (*cp && !isspace(*cp)) {
# Line 342 | Line 359 | parse_params(PARAMS *p, char *pargs)
359                                  break;
360                          if (!get_direction(p->vup, cp))
361                                  break;
362 +                        while (*cp && !isspace(*cp++))
363 +                                ;
364                          ++nparams;
365                          continue;
366                  case 'o':
367                          if (*cp++ != '=')
368                                  break;
369 +                        quot = 0;
370 +                        if ((*cp == '"') | (*cp == '\''))
371 +                                quot = *cp++;
372                          i = 0;
373 <                        while (*cp && !isspace(*cp++))
374 <                                i++;
373 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
374 >                                i++; cp++;
375 >                        }
376                          if (!i)
377                                  break;
378 <                        *--cp = '\0';
378 >                        if (!*cp) {
379 >                                if (quot)
380 >                                        break;
381 >                                cp[1] = '\0';
382 >                        }
383 >                        *cp = '\0';
384                          p->outfn = savqstr(cp-i);
385 <                        *cp++ = ' ';
385 >                        *cp++ = quot ? quot : ' ';
386                          ++nparams;
387                          continue;
388                  case ' ':
# Line 367 | Line 395 | parse_params(PARAMS *p, char *pargs)
395                  default:
396                          break;
397                  }
398 <        fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs);
398 >                break;
399 >        }
400 >        fprintf(stderr, "%s: bad parameter string: %s", progname, pargs);
401          exit(1);
402          return(-1);     /* pro forma return */
403   }
# Line 413 | Line 443 | finish_receiver(void)
443          }
444                                          /* determine sample type/bin */
445          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
446 <                binv = "0";             /* uniform sampling -- one bin */
446 >                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
447 >                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
448 >                binv = savqstr(sbuf);
449 >                nbins = "1";            /* uniform sampling -- one bin */
450                  uniform = 1;
451          } else if (tolower(curparams.hemis[0]) == 's' &&
452                                  tolower(curparams.hemis[1]) == 'c') {
# Line 424 | Line 457 | finish_receiver(void)
457                          exit(1);
458                  }
459                  calfn = shirchiufn; shirchiufn = NULL;
460 <                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
460 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
461                                  curparams.hsiz,
462                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
463 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
463 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
464 >                        curparams.sign);
465                  params = savqstr(sbuf);
466                  binv = "scbin";
467                  nbins = "SCdim*SCdim";
468          } else if ((tolower(curparams.hemis[0]) == 'r') |
469                          (tolower(curparams.hemis[0]) == 't')) {
470                  calfn = reinhfn; reinhfn = NULL;
471 <                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
471 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
472                                  curparams.hsiz,
473                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
474 <                        curparams.vup[0], curparams.vup[1], curparams.vup[2]);
474 >                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
475 >                        curparams.sign);
476                  params = savqstr(sbuf);
477                  binv = "rbin";
478                  nbins = "Nrbins";
# Line 465 | Line 500 | finish_receiver(void)
500                                  progname, curparams.hemis);
501                  exit(1);
502          }
503 +        if (tolower(curparams.hemis[0]) == 'k') {
504 +                sprintf(sbuf, "RHS=%c1", curparams.sign);
505 +                params = savqstr(sbuf);
506 +        }
507          if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
508                  SURF    *sp;
509                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
# Line 512 | Line 551 | make_axes(FVECT uva[2], const FVECT nrm)
551   {
552          int     i;
553  
554 <        uva[1][0] = 0.5 - frandom();
516 <        uva[1][1] = 0.5 - frandom();
517 <        uva[1][2] = 0.5 - frandom();
518 <        for (i = 3; i--; )
519 <                if ((-0.6 < nrm[i]) & (nrm[i] < 0.6))
520 <                        break;
521 <        if (i < 0) {
554 >        if (!getperpendicular(uva[0], nrm, 1)) {
555                  fputs(progname, stderr);
556                  fputs(": bad surface normal in make_axes!\n", stderr);
557                  exit(1);
558          }
559 <        uva[1][i] = 1.0;
527 <        VCROSS(uva[0], uva[1], nrm);
528 <        normalize(uva[0]);
529 <        VCROSS(uva[1], nrm, uva[0]);
559 >        fcross(uva[1], nrm, uva[0]);
560   }
561  
562   /* Illegal sender surfaces end up here */
# Line 665 | Line 695 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
695                                          /* special case for lone surface */
696          if (p->nsurfs == 1) {
697                  sp = p->slist;
698 <                if (DOT(sp->snrm, rdir) >= -FTINY) {
698 >                if (DOT(sp->snrm, rdir) >= FTINY) {
699                          fprintf(stderr,
700                                  "%s: internal - sample behind sender '%s'\n",
701                                          progname, sp->sname);
# Line 788 | Line 818 | sample_reinhart(PARAMS *p, int b, FILE *fp)
818                  alt = (row+samp3[1])*RAH;
819                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
820                  duvw[2] = cos(alt);     /* measured from horizon */
821 <                duvw[0] = tcos(azi)*duvw[2];
822 <                duvw[1] = tsin(azi)*duvw[2];
821 >                duvw[0] = tsin(azi)*duvw[2];
822 >                duvw[1] = tcos(azi)*duvw[2];
823                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
824                  for (i = 3; i--; )
825                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 840 | Line 870 | sample_klems(PARAMS *p, int b, FILE *fp)
870  
871          while (n--) {                   /* stratified sampling */
872                  SDmultiSamp(samp2, 2, (n+frandom())/sampcnt);
873 <                if (!bo_getvec(duvw, b+samp2[1], kbasis[bi]))
873 >                if (!fo_getvec(duvw, b+samp2[1], kbasis[bi]))
874                          return(0);
875                  for (i = 3; i--; )
876 <                        orig_dir[1][i] = duvw[0]*p->udir[i] +
877 <                                                duvw[1]*p->vdir[i] +
876 >                        orig_dir[1][i] = -duvw[0]*p->udir[i] -
877 >                                                duvw[1]*p->vdir[i] -
878                                                  duvw[2]*p->nrm[i] ;
879                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
880                          return(0);
# Line 863 | Line 893 | prepare_sampler(void)
893                  fputs(": no sender surface!\n", stderr);
894                  return(-1);
895          }
896 <        if (curparams.outfn != NULL)    /* misplaced output file spec. */
896 >                                        /* misplaced output file spec. */
897 >        if ((curparams.outfn != NULL) & (verbose >= 0))
898                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
899                                  progname, curparams.outfn);
900                                          /* check/set basis hemisphere */
# Line 883 | Line 914 | prepare_sampler(void)
914                  else
915                          curparams.vup[1] = 1;
916          }
917 <        VCROSS(curparams.udir, curparams.vup, curparams.nrm);
917 >        fcross(curparams.udir, curparams.vup, curparams.nrm);
918          if (normalize(curparams.udir) == 0) {
919                  fputs(progname, stderr);
920                  fputs(": up vector coincides with sender normal\n", stderr);
921                  return(-1);
922          }
923 <        VCROSS(curparams.vdir, curparams.nrm, curparams.udir);
923 >        fcross(curparams.vdir, curparams.nrm, curparams.udir);
924 >        if (curparams.sign == '-') {    /* left-handed coordinate system? */
925 >                curparams.udir[0] *= -1.;
926 >                curparams.udir[1] *= -1.;
927 >                curparams.udir[2] *= -1.;
928 >        }
929          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1')
930                  curparams.sample_basis = sample_uniform;
931          else if (tolower(curparams.hemis[0]) == 's' &&
# Line 1014 | Line 1050 | add_surface(int st, const char *oname, FILE *fp)
1050                  snew->area *= PI*snew->area;
1051                  break;
1052          }
1053 <        if (snew->area <= FTINY) {
1053 >        if ((snew->area <= FTINY) & (verbose >= 0)) {
1054                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1055                                  progname, oname);
1056                  free(snew);
# Line 1084 | Line 1120 | static int
1120   add_send_object(FILE *fp)
1121   {
1122          int             st;
1123 <        char            otype[32], oname[128];
1123 >        char            thismod[128], otype[32], oname[128];
1124          int             n;
1125  
1126 <        if (fscanf(fp, "%*s %s %s", otype, oname) != 2)
1126 >        if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3)
1127                  return(0);              /* must have hit EOF! */
1128          if (!strcmp(otype, "alias")) {
1129                  fscanf(fp, "%*s");      /* skip alias */
# Line 1100 | Line 1136 | add_send_object(FILE *fp)
1136                          fputs(": cannot use source as a sender!\n", stderr);
1137                          return(-1);
1138                  }
1139 +                if (strcmp(thismod, curmod)) {
1140 +                        if (curmod[0]) {
1141 +                                fputs(progname, stderr);
1142 +                                fputs(": warning - multiple modifiers in sender\n",
1143 +                                                stderr);
1144 +                        }
1145 +                        strcpy(curmod, thismod);
1146 +                }
1147                  parse_params(&curparams, newparams);
1148                  newparams[0] = '\0';
1149                  add_surface(st, oname, fp);     /* read & store surface */
# Line 1201 | Line 1245 | main(int argc, char *argv[])
1245                  na = 1;
1246                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1247                  case 'v':               /* verbose mode */
1248 <                        verbose = !verbose;
1248 >                        verbose = 1;
1249                          na = 0;
1250                          continue;
1251                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1242 | Line 1286 | main(int argc, char *argv[])
1286                          iropt = argv[a];
1287                          na = 0;
1288                          continue;
1289 <                case 'V':               /* options without arguments */
1290 <                case 'w':
1289 >                case 'w':               /* options without arguments */
1290 >                        if (argv[a][2] != '+') verbose = -1;
1291 >                case 'V':
1292                  case 'u':
1293                  case 'h':
1294                  case 'r':
# Line 1268 | Line 1313 | main(int argc, char *argv[])
1313                          if (argv[a][2] != 'v') na = 2;
1314                          break;
1315                  case 'a':               /* special case */
1316 <                        na = (argv[a][2] == 'v') ? 4 : 2;
1316 >                        if (argv[a][2] == 'p') {
1317 >                                na = 2; /* photon map [+ bandwidth(s)] */
1318 >                                if (a < argc-3 && atoi(argv[a+1]) > 0)
1319 >                                        na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0);
1320 >                        } else
1321 >                                na = (argv[a][2] == 'v') ? 4 : 2;
1322                          break;
1323                  case 'm':               /* special case */
1324                          if (!argv[a][2]) goto userr;
# Line 1333 | Line 1383 | main(int argc, char *argv[])
1383                  return(my_exec(rcarg)); /* rcontrib does everything */
1384          }
1385          clear_params(&curparams, 0);    /* else load sender surface & params */
1386 +        curmod[0] = '\0';
1387          if (load_scene(sendfn, add_send_object) < 0)
1388                  return(1);
1389          if ((nsbins = prepare_sampler()) <= 0)
# Line 1350 | Line 1401 | main(int argc, char *argv[])
1401   #ifdef getc_unlocked
1402          flockfile(rcfp);
1403   #endif
1404 <        if (verbose) {
1404 >        if (verbose > 0) {
1405                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1406                  if (curparams.nsurfs > 1)
1407                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
# Line 1360 | Line 1411 | main(int argc, char *argv[])
1411          for (i = 0; i < nsbins; i++)    /* send rcontrib ray samples */
1412                  if (!(*curparams.sample_basis)(&curparams, i, rcfp))
1413                          return(1);
1414 <        return(pclose(rcfp) == 0);      /* all finished! */
1414 >        return(pclose(rcfp) < 0);       /* all finished! */
1415   userr:
1416          if (a < argc-2)
1417                  fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines