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.7 by greg, Wed Jul 23 22:39:40 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 554 | Line 553 | ssamp_ring(FVECT orig, SURF *sp, double x)
553                  sp->priv = (void *)uva;
554          }
555          SDmultiSamp(samp2, 2, x);
556 <        samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI));
556 >        samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]);
557          samp2[1] *= 2.*PI;
558          uv[0] = samp2[0]*tcos(samp2[1]);
559          uv[1] = samp2[0]*tsin(samp2[1]);
# Line 607 | Line 606 | ssamp_poly(FVECT orig, SURF *sp, double x)
606                          }
607                          ptp->ntris = 0;
608                          v2l->p = (void *)ptp;
609 <                        if (!polyTriangulate(v2l, add_triangle))
609 >                        if (!polyTriangulate(v2l, add_triangle)) {
610 >                                fprintf(stderr,
611 >                                        "%s: cannot triangulate polygon '%s'\n",
612 >                                                progname, sp->sname);
613                                  return(0);
614 +                        }
615                          for (i = ptp->ntris; i--; ) {
616                                  int     a = ptp->tri[i].vndx[0];
617                                  int     b = ptp->tri[i].vndx[1];
# Line 657 | Line 660 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
660                                          /* special case for lone surface */
661          if (p->nsurfs == 1) {
662                  sp = p->slist;
663 <                if (DOT(sp->snrm, rdir) >= -FTINY)
664 <                        return(0);      /* behind surface! */
663 >                if (DOT(sp->snrm, rdir) >= -FTINY) {
664 >                        fprintf(stderr,
665 >                                "%s: internal - sample behind sender '%s'\n",
666 >                                        progname, sp->sname);
667 >                        return(0);
668 >                }
669                  return((*orig_in_surf[sp->styp])(orig, sp, x));
670          }
671          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
# Line 672 | Line 679 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
679                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
680                  tarea += projsa[i] *= (double)(projsa[i] > FTINY);
681          }
682 <        if (tarea <= FTINY)             /* wrong side of sender? */
682 >        if (tarea <= FTINY) {           /* wrong side of sender? */
683 >                fputs(progname, stderr);
684 >                fputs(": internal - sample behind all sender elements!\n",
685 >                                stderr);
686                  return(0);
687 +        }
688          tarea *= x;                     /* get surface from list */
689          for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next)
690                  tarea -= projsa[i++];
# Line 746 | Line 757 | sample_reinhart(PARAMS *p, int b, FILE *fp)
757   #define T_NALT  7
758          static const int        tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6};
759          const int               RowMax = T_NALT*p->hsiz + 1;
760 <        const double            RAH = (.25*PI)/(RowMax-.5);
760 >        const double            RAH = (.5*PI)/(RowMax-.5);
761   #define rnaz(r)                 (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz])
762          int                     n = sampcnt;
763          int                     row, col;
# Line 771 | Line 782 | sample_reinhart(PARAMS *p, int b, FILE *fp)
782                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
783                  alt = (row+samp3[1])*RAH;
784                  azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row);
785 <                duvw[2] = tcos(alt);    /* measured from horizon */
785 >                duvw[2] = cos(alt);     /* measured from horizon */
786                  duvw[0] = tcos(azi)*duvw[2];
787                  duvw[1] = tsin(azi)*duvw[2];
788                  duvw[2] = sqrt(1. - duvw[2]*duvw[2]);
# Line 1008 | Line 1019 | add_surface(int st, const char *oname, FILE *fp)
1019          curparams.nsurfs++;
1020          return;
1021   badcount:
1022 <        fprintf(stderr, "%s: bad argument count for surface '%s'\n",
1022 >        fprintf(stderr, "%s: bad argument count for surface element '%s'\n",
1023                          progname, oname);
1024          exit(1);
1025   badnorm:
1026 <        fprintf(stderr, "%s: bad orientation for surface '%s'\n",
1026 >        fprintf(stderr, "%s: bad orientation for surface element '%s'\n",
1027                          progname, oname);
1028          exit(1);
1029   }
# Line 1044 | Line 1055 | add_recv_object(FILE *fp)
1055                                  finish_receiver();
1056                                  clear_params(&curparams, 1);
1057                          }
1058 +                        parse_params(&curparams, newparams);
1059 +                        newparams[0] = '\0';
1060                          strcpy(curmod, thismod);
1061                  }
1062                  add_surface(st, oname, fp);     /* read & store surface */
# Line 1080 | Line 1093 | add_send_object(FILE *fp)
1093                          fputs(": cannot use source as a sender!\n", stderr);
1094                          return(-1);
1095                  }
1096 +                parse_params(&curparams, newparams);
1097 +                newparams[0] = '\0';
1098                  add_surface(st, oname, fp);     /* read & store surface */
1099                  return(0);
1100          }
# Line 1128 | Line 1143 | load_scene(const char *inspec, int (*ocb)(FILE *))
1143                          if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 &&
1144                                          !strcmp(inpbuf, PARAMSTART)) {
1145                                  if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL)
1146 <                                        parse_params(inpbuf);
1146 >                                        strcat(newparams, inpbuf);
1147                                  continue;
1148                          }
1149                          while ((c = getc(fp)) != EOF && c != '\n');
# Line 1180 | Line 1195 | main(int argc, char *argv[])
1195                          case 'f':
1196                          case 'd':
1197                          case 'c':
1198 <                                if (!(fmtopt[4] = argv[a][3]))
1199 <                                        fmtopt[4] = argv[a][2];
1200 <                                fmtopt[3] = argv[a][2];
1198 >                                if (!(fmtopt[3] = argv[a][3]))
1199 >                                        fmtopt[3] = argv[a][2];
1200 >                                fmtopt[2] = argv[a][2];
1201                                  na = 0;
1202                                  continue;       /* will pass later */
1203                          default:
# Line 1198 | Line 1213 | main(int argc, char *argv[])
1213                          na = 0;
1214                          continue;
1215                  case 'c':               /* number of samples */
1216 <                        sampcnt = atoi(argv[a+1]);
1216 >                        sampcnt = atoi(argv[++a]);
1217                          if (sampcnt <= 0)
1218                                  goto userr;
1219                          na = 0;         /* we re-add this later */
# Line 1270 | Line 1285 | done_opts:
1285                  }
1286                  if (sampcnt <= 0) sampcnt = 1;
1287          } else {                        /* else FVECT determines input format */
1288 <                fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1288 >                fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f';
1289                  if (sampcnt <= 0) sampcnt = 10000;
1290          }
1291          sprintf(sampcntbuf, "%d", sampcnt);
# Line 1309 | Line 1324 | done_opts:
1324          if (verbose) {
1325                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1326                  if (curparams.nsurfs > 1)
1327 <                        fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs);
1327 >                        fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
1328                  else
1329                          fputc('\n', stderr);
1330          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines