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

Comparing ray/src/util/rfluxmtx.c (file contents):
Revision 2.5 by greg, Tue Jul 22 23:21:56 2014 UTC vs.
Revision 2.10 by greg, Fri Jul 25 17:03:06 2014 UTC

# Line 96 | Line 96 | typedef struct param_s {
96  
97   PARAMS          curparams;
98   char            curmod[128];
99 + char            newparams[1024];
100  
101   typedef int     SURFSAMP(FVECT, SURF *, double);
102  
# Line 109 | Line 110 | SURFSAMP       *orig_in_surf[4] = {
110   static void
111   clear_params(PARAMS *p, int reset_only)
112   {
112        curmod[0] = '\0';
113          while (p->slist != NULL) {
114                  SURF    *sdel = p->slist;
115                  p->slist = sdel->next;
# Line 124 | Line 124 | clear_params(PARAMS *p, int reset_only)
124                  p->outfn = NULL;
125                  return;
126          }
127 <        memset(p, 0, sizeof(curparams));
127 >        memset(p, 0, sizeof(PARAMS));
128   }
129  
130   /* Get surface type from name */
# Line 309 | Line 309 | nextchar:
309  
310   /* Parse program parameters (directives) */
311   static int
312 < parse_params(char *pargs)
312 > parse_params(PARAMS *p, char *pargs)
313   {
314          char    *cp = pargs;
315          int     nparams = 0;
# Line 320 | Line 320 | parse_params(char *pargs)
320                  case 'h':
321                          if (*cp++ != '=')
322                                  break;
323 <                        curparams.hsiz = 0;
323 >                        p->hsiz = 0;
324                          i = 0;
325                          while (*cp && !isspace(*cp)) {
326                                  if (isdigit(*cp))
327 <                                        curparams.hsiz = 10*curparams.hsiz +
328 <                                                                *cp - '0';
329 <                                curparams.hemis[i++] = *cp++;
327 >                                        p->hsiz = 10*p->hsiz + *cp - '0';
328 >                                p->hemis[i++] = *cp++;
329                          }
330                          if (!i)
331                                  break;
332 <                        curparams.hemis[i] = '\0';
333 <                        curparams.hsiz += !curparams.hsiz;
332 >                        p->hemis[i] = '\0';
333 >                        p->hsiz += !p->hsiz;
334                          ++nparams;
335                          continue;
336                  case 'u':
337                          if (*cp++ != '=')
338                                  break;
339 <                        if (!get_direction(curparams.vup, cp))
339 >                        if (!get_direction(p->vup, cp))
340                                  break;
341                          ++nparams;
342                          continue;
# Line 350 | Line 349 | parse_params(char *pargs)
349                          if (!i)
350                                  break;
351                          *--cp = '\0';
352 <                        curparams.outfn = savqstr(cp-i);
352 >                        p->outfn = savqstr(cp-i);
353                          *cp++ = ' ';
354                          ++nparams;
355                          continue;
# Line 402 | Line 401 | finish_receiver(void)
401                  fputs(": undefined normal for hemisphere sampling\n", stderr);
402                  exit(1);
403          }
404 <        if (normalize(curparams.vup) == 0)
404 >        if (normalize(curparams.vup) == 0) {
405                  if (fabs(curparams.nrm[2]) < .7)
406                          curparams.vup[2] = 1;
407                  else
408                          curparams.vup[1] = 1;
409 +        }
410                                          /* determine sample type/bin */
411          if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') {
412                  binv = "0";             /* uniform sampling -- one bin */
# Line 420 | Line 420 | finish_receiver(void)
420                          exit(1);
421                  }
422                  calfn = shirchiufn; shirchiufn = NULL;
423 <                sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
423 >                sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
424                                  curparams.hsiz,
425                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
426                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 430 | Line 430 | finish_receiver(void)
430          } else if ((tolower(curparams.hemis[0]) == 'r') |
431                          (tolower(curparams.hemis[0]) == 't')) {
432                  calfn = reinhfn; reinhfn = NULL;
433 <                sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g",
433 >                sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g",
434                                  curparams.hsiz,
435                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
436                          curparams.vup[0], curparams.vup[1], curparams.vup[2]);
# Line 554 | Line 554 | ssamp_ring(FVECT orig, SURF *sp, double x)
554                  sp->priv = (void *)uva;
555          }
556          SDmultiSamp(samp2, 2, x);
557 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
557 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
558          samp2[1] *= 2.*PI;
559          uv[0] = samp2[0]*tcos(samp2[1]);
560          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 607 | ssamp_poly(FVECT orig, SURF *sp, double x)
607                          }
608                          ptp->ntris = 0;
609                          v2l->p = (void *)ptp;
610 <                        if (!polyTriangulate(v2l, add_triangle))
610 >                        if (!polyTriangulate(v2l, add_triangle)) {
611 >                                fprintf(stderr,
612 >                                        "%s: cannot triangulate polygon '%s'\n",
613 >                                                progname, sp->sname);
614                                  return(0);
615 +                        }
616                          for (i = ptp->ntris; i--; ) {
617                                  int     a = ptp->tri[i].vndx[0];
618                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 661 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
661                                          /* special case for lone surface */
662          if (p->nsurfs == 1) {
663                  sp = p->slist;
664 <                if (DOT(sp->snrm, rdir) >= -FTINY)
665 <                        return(0);      /* behind surface! */
664 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
665 >                        fprintf(stderr,
666 >                                "%s: internal - sample behind sender '%s'\n",
667 >                                        progname, sp->sname);
668 >                        return(0);
669 >                }
670                  return((*orig_in_surf[sp->styp])(orig, sp, x));
671          }
672          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 680 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
680                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
681                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
682          }
683 <        if (tarea <= FTINY)             /* wrong side of sender? */
683 >        if (tarea <= FTINY) {           /* wrong side of sender? */
684 >                fputs(progname, stderr);
685 >                fputs(": internal - sample behind all sender elements!\n",
686 >                                stderr);
687                  return(0);
688 +        }
689          tarea *= x;                     /* get surface from list */
690          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
691                  tarea -= projsa[i++];
# Line 746 | Line 758 | sample_reinhart(PARAMS *p, int b, FILE *fp)
758   #define T_NALT  7
759          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
760          const int               RowMax = T_NALT*p->hsiz + 1;
761 <        const double            RAH = (.25*PI)/(RowMax-.5);
761 >        const double            RAH = (.5*PI)/(RowMax-.5);
762   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
763          int                     n = sampcnt;
764          int                     row, col;
# Line 771 | Line 783 | sample_reinhart(PARAMS *p, int b, FILE *fp)
783                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
784                  alt = (row+samp3[1])*RAH;
785                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
786 <                duvw[2] = tcos(alt);    /* measured from horizon */
786 >                duvw[2] = cos(alt);     /* measured from horizon */
787                  duvw[0] = tcos(azi)*duvw[2];
788                  duvw[1] = tsin(azi)*duvw[2];
789                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
# Line 861 | Line 873 | prepare_sampler(void)
873                  fputs(": undefined normal for sender sampling\n", stderr);
874                  return(-1);
875          }
876 <        if (normalize(curparams.vup) == 0)
876 >        if (normalize(curparams.vup) == 0) {
877                  if (fabs(curparams.nrm[2]) < .7)
878                          curparams.vup[2] = 1;
879                  else
880                          curparams.vup[1] = 1;
881 +        }
882          VCROSS(curparams.udir, curparams.vup, curparams.nrm);
883          if (normalize(curparams.udir) == 0) {
884                  fputs(progname, stderr);
# Line 989 | Line 1002 | add_surface(int st, const char *oname, FILE *fp)
1002          case ST_SOURCE:
1003                  if (snew->nfargs != 4)
1004                          goto badcount;
1005 <                VCOPY(snew->snrm, snew->farg);
1005 >                for (n = 3; n--; )      /* need to reverse "normal" */
1006 >                        snew->snrm[n] = -snew->farg[n];
1007                  if (normalize(snew->snrm) == 0)
1008                          goto badnorm;
1009                  snew->area = sin((PI/180./2.)*snew->farg[3]);
# Line 1008 | Line 1022 | add_surface(int st, const char *oname, FILE *fp)
1022          curparams.nsurfs++;
1023          return;
1024   badcount:
1025 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1025 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1026                          progname, oname);
1027          exit(1);
1028   badnorm:
1029 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1029 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1030                          progname, oname);
1031          exit(1);
1032   }
# Line 1044 | Line 1058 | add_recv_object(FILE *fp)
1058                                  finish_receiver();
1059                                  clear_params(&curparams, 1);
1060                          }
1061 +                        parse_params(&curparams, newparams);
1062 +                        newparams[0] = '\0';
1063                          strcpy(curmod, thismod);
1064                  }
1065                  add_surface(st, oname, fp);     /* read & store surface */
1066                  return(1);
1067          }
1068                                          /* else skip arguments */
1069 <        if (!fscanf(fp, "%d", &n)) return;
1069 >        if (!fscanf(fp, "%d", &n)) return(0);
1070          while (n-- > 0) fscanf(fp, "%*s");
1071 <        if (!fscanf(fp, "%d", &n)) return;
1071 >        if (!fscanf(fp, "%d", &n)) return(0);
1072          while (n-- > 0) fscanf(fp, "%*d");
1073 <        if (!fscanf(fp, "%d", &n)) return;
1073 >        if (!fscanf(fp, "%d", &n)) return(0);
1074          while (n-- > 0) fscanf(fp, "%*f");
1075          return(0);
1076   }
# Line 1080 | Line 1096 | add_send_object(FILE *fp)
1096                          fputs(": cannot use source as a sender!\n", stderr);
1097                          return(-1);
1098                  }
1099 +                parse_params(&curparams, newparams);
1100 +                newparams[0] = '\0';
1101                  add_surface(st, oname, fp);     /* read & store surface */
1102                  return(0);
1103          }
1104                                          /* else skip arguments */
1105 <        if (!fscanf(fp, "%d", &n)) return;
1105 >        if (!fscanf(fp, "%d", &n)) return(0);
1106          while (n-- > 0) fscanf(fp, "%*s");
1107 <        if (!fscanf(fp, "%d", &n)) return;
1107 >        if (!fscanf(fp, "%d", &n)) return(0);
1108          while (n-- > 0) fscanf(fp, "%*d");
1109 <        if (!fscanf(fp, "%d", &n)) return;
1109 >        if (!fscanf(fp, "%d", &n)) return(0);
1110          while (n-- > 0) fscanf(fp, "%*f");
1111          return(0);
1112   }
# Line 1128 | Line 1146 | load_scene(const char *inspec, int (*ocb)(FILE *))
1146                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1147                                          !strcmp(inpbuf, PARAMSTART)) {
1148                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1149 <                                        parse_params(inpbuf);
1149 >                                        strcat(newparams, inpbuf);
1150                                  continue;
1151                          }
1152 <                        while ((c = getc(fp)) != EOF && c != '\n');
1152 >                        while ((c = getc(fp)) != EOF && c != '\n')
1153                                  ;       /* else skipping comment */
1154                          continue;
1155                  }
# Line 1156 | Line 1174 | main(int argc, char *argv[])
1174   {
1175          char    fmtopt[6] = "-faa";     /* default output is ASCII */
1176          char    *xrs=NULL, *yrs=NULL, *ldopt=NULL;
1177 +        int     wantIrradiance = 0;
1178          char    *sendfn;
1179          char    sampcntbuf[32], nsbinbuf[32];
1180          FILE    *rcfp;
# Line 1180 | Line 1199 | main(int argc, char *argv[])
1199                          case 'f':
1200                          case 'd':
1201                          case 'c':
1202 <                                if (!(fmtopt[4] = argv[a][3]))
1203 <                                        fmtopt[4] = argv[a][2];
1204 <                                fmtopt[3] = argv[a][2];
1202 >                                if (!(fmtopt[3] = argv[a][3]))
1203 >                                        fmtopt[3] = argv[a][2];
1204 >                                fmtopt[2] = argv[a][2];
1205                                  na = 0;
1206                                  continue;       /* will pass later */
1207                          default:
# Line 1198 | Line 1217 | main(int argc, char *argv[])
1217                          na = 0;
1218                          continue;
1219                  case 'c':               /* number of samples */
1220 <                        sampcnt = atoi(argv[a+1]);
1220 >                        sampcnt = atoi(argv[++a]);
1221                          if (sampcnt <= 0)
1222                                  goto userr;
1223                          na = 0;         /* we re-add this later */
1224                          continue;
1225 +                case 'I':               /* only for pass-through mode */
1226 +                        wantIrradiance = 1;
1227 +                        na = 0;
1228 +                        continue;
1229                  case 'V':               /* options without arguments */
1230                  case 'w':
1231                  case 'u':
# Line 1254 | Line 1277 | done_opts:
1277          if (sendfn[0] == '-') {         /* user wants pass-through mode? */
1278                  if (sendfn[1]) goto userr;
1279                  sendfn = NULL;
1280 +                if (wantIrradiance) {
1281 +                        CHECKARGC(1);
1282 +                        rcarg[nrcargs++] = "-I";
1283 +                }
1284                  if (xrs) {
1285                          CHECKARGC(2);
1286                          rcarg[nrcargs++] = "-x";
# Line 1269 | Line 1296 | done_opts:
1296                          rcarg[nrcargs++] = ldopt;
1297                  }
1298                  if (sampcnt <= 0) sampcnt = 1;
1299 <        } else {                        /* else FVECT determines input format */
1300 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1299 >        } else {                        /* else in sampling mode */
1300 >                if (wantIrradiance) {
1301 >                        fputs(progname, stderr);
1302 >                        fputs(": -I supported for pass-through only\n", stderr);
1303 >                        return(1);
1304 >                }
1305 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1306                  if (sampcnt <= 0) sampcnt = 10000;
1307          }
1308          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1309 | Line 1341 | done_opts:
1341          if (verbose) {
1342                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1343                  if (curparams.nsurfs > 1)
1344 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1344 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1345                  else
1346                          fputc('\n', stderr);
1347          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines