--- ray/src/util/rfluxmtx.c 2014/07/23 00:40:17 2.6 +++ ray/src/util/rfluxmtx.c 2014/07/28 16:30:18 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rfluxmtx.c,v 2.6 2014/07/23 00:40:17 greg Exp $"; +static const char RCSid[] = "$Id: rfluxmtx.c,v 2.12 2014/07/28 16:30:18 greg Exp $"; #endif /* * Calculate flux transfer matrix or matrices using rcontrib @@ -11,6 +11,7 @@ static const char RCSid[] = "$Id: rfluxmtx.c,v 2.6 201 #include #include "rtio.h" #include "rtmath.h" +#include "rtprocess.h" #include "bsdf.h" #include "bsdf_m.h" #include "random.h" @@ -401,11 +402,12 @@ finish_receiver(void) fputs(": undefined normal for hemisphere sampling\n", stderr); exit(1); } - if (normalize(curparams.vup) == 0) + if (normalize(curparams.vup) == 0) { if (fabs(curparams.nrm[2]) < .7) curparams.vup[2] = 1; else curparams.vup[1] = 1; + } /* determine sample type/bin */ if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { binv = "0"; /* uniform sampling -- one bin */ @@ -419,7 +421,7 @@ finish_receiver(void) exit(1); } calfn = shirchiufn; shirchiufn = NULL; - sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", + sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", curparams.hsiz, curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], curparams.vup[0], curparams.vup[1], curparams.vup[2]); @@ -429,7 +431,7 @@ finish_receiver(void) } else if ((tolower(curparams.hemis[0]) == 'r') | (tolower(curparams.hemis[0]) == 't')) { calfn = reinhfn; reinhfn = NULL; - sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", + sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", curparams.hsiz, curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], curparams.vup[0], curparams.vup[1], curparams.vup[2]); @@ -606,8 +608,12 @@ ssamp_poly(FVECT orig, SURF *sp, double x) } ptp->ntris = 0; v2l->p = (void *)ptp; - if (!polyTriangulate(v2l, add_triangle)) + if (!polyTriangulate(v2l, add_triangle)) { + fprintf(stderr, + "%s: cannot triangulate polygon '%s'\n", + progname, sp->sname); return(0); + } for (i = ptp->ntris; i--; ) { int a = ptp->tri[i].vndx[0]; int b = ptp->tri[i].vndx[1]; @@ -656,8 +662,12 @@ sample_origin(PARAMS *p, FVECT orig, const FVECT rdir, /* special case for lone surface */ if (p->nsurfs == 1) { sp = p->slist; - if (DOT(sp->snrm, rdir) >= -FTINY) - return(0); /* behind surface! */ + if (DOT(sp->snrm, rdir) >= -FTINY) { + fprintf(stderr, + "%s: internal - sample behind sender '%s'\n", + progname, sp->sname); + return(0); + } return((*orig_in_surf[sp->styp])(orig, sp, x)); } if (p->nsurfs > nall) { /* (re)allocate surface area cache */ @@ -671,8 +681,12 @@ sample_origin(PARAMS *p, FVECT orig, const FVECT rdir, projsa[i] = -DOT(sp->snrm, rdir) * sp->area; tarea += projsa[i] *= (double)(projsa[i] > FTINY); } - if (tarea <= FTINY) /* wrong side of sender? */ + if (tarea <= FTINY) { /* wrong side of sender? */ + fputs(progname, stderr); + fputs(": internal - sample behind all sender elements!\n", + stderr); return(0); + } tarea *= x; /* get surface from list */ for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next) tarea -= projsa[i++]; @@ -745,7 +759,7 @@ sample_reinhart(PARAMS *p, int b, FILE *fp) #define T_NALT 7 static const int tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6}; const int RowMax = T_NALT*p->hsiz + 1; - const double RAH = (.25*PI)/(RowMax-.5); + const double RAH = (.5*PI)/(RowMax-.5); #define rnaz(r) (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz]) int n = sampcnt; int row, col; @@ -770,7 +784,7 @@ sample_reinhart(PARAMS *p, int b, FILE *fp) SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); alt = (row+samp3[1])*RAH; azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); - duvw[2] = tcos(alt); /* measured from horizon */ + duvw[2] = cos(alt); /* measured from horizon */ duvw[0] = tcos(azi)*duvw[2]; duvw[1] = tsin(azi)*duvw[2]; duvw[2] = sqrt(1. - duvw[2]*duvw[2]); @@ -860,11 +874,12 @@ prepare_sampler(void) fputs(": undefined normal for sender sampling\n", stderr); return(-1); } - if (normalize(curparams.vup) == 0) + if (normalize(curparams.vup) == 0) { if (fabs(curparams.nrm[2]) < .7) curparams.vup[2] = 1; else curparams.vup[1] = 1; + } VCROSS(curparams.udir, curparams.vup, curparams.nrm); if (normalize(curparams.udir) == 0) { fputs(progname, stderr); @@ -988,7 +1003,8 @@ add_surface(int st, const char *oname, FILE *fp) case ST_SOURCE: if (snew->nfargs != 4) goto badcount; - VCOPY(snew->snrm, snew->farg); + for (n = 3; n--; ) /* need to reverse "normal" */ + snew->snrm[n] = -snew->farg[n]; if (normalize(snew->snrm) == 0) goto badnorm; snew->area = sin((PI/180./2.)*snew->farg[3]); @@ -1007,11 +1023,11 @@ add_surface(int st, const char *oname, FILE *fp) curparams.nsurfs++; return; badcount: - fprintf(stderr, "%s: bad argument count for surface '%s'\n", + fprintf(stderr, "%s: bad argument count for surface element '%s'\n", progname, oname); exit(1); badnorm: - fprintf(stderr, "%s: bad orientation for surface '%s'\n", + fprintf(stderr, "%s: bad orientation for surface element '%s'\n", progname, oname); exit(1); } @@ -1051,11 +1067,11 @@ add_recv_object(FILE *fp) return(1); } /* else skip arguments */ - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*s"); - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*d"); - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*f"); return(0); } @@ -1087,11 +1103,11 @@ add_send_object(FILE *fp) return(0); } /* else skip arguments */ - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*s"); - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*d"); - if (!fscanf(fp, "%d", &n)) return; + if (!fscanf(fp, "%d", &n)) return(0); while (n-- > 0) fscanf(fp, "%*f"); return(0); } @@ -1134,7 +1150,7 @@ load_scene(const char *inspec, int (*ocb)(FILE *)) strcat(newparams, inpbuf); continue; } - while ((c = getc(fp)) != EOF && c != '\n'); + while ((c = getc(fp)) != EOF && c != '\n') ; /* else skipping comment */ continue; } @@ -1159,6 +1175,7 @@ main(int argc, char *argv[]) { char fmtopt[6] = "-faa"; /* default output is ASCII */ char *xrs=NULL, *yrs=NULL, *ldopt=NULL; + char *iropt = NULL; char *sendfn; char sampcntbuf[32], nsbinbuf[32]; FILE *rcfp; @@ -1206,10 +1223,14 @@ main(int argc, char *argv[]) goto userr; na = 0; /* we re-add this later */ continue; + case 'I': /* only for pass-through mode */ + case 'i': + iropt = argv[a]; + na = 0; + continue; case 'V': /* options without arguments */ case 'w': case 'u': - case 'i': case 'h': case 'r': break; @@ -1257,6 +1278,10 @@ done_opts: if (sendfn[0] == '-') { /* user wants pass-through mode? */ if (sendfn[1]) goto userr; sendfn = NULL; + if (iropt) { + CHECKARGC(1); + rcarg[nrcargs++] = iropt; + } if (xrs) { CHECKARGC(2); rcarg[nrcargs++] = "-x"; @@ -1272,7 +1297,12 @@ done_opts: rcarg[nrcargs++] = ldopt; } if (sampcnt <= 0) sampcnt = 1; - } else { /* else FVECT determines input format */ + } else { /* else in sampling mode */ + if (iropt) { + fputs(progname, stderr); + fputs(": -i, -I supported for pass-through only\n", stderr); + return(1); + } fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; if (sampcnt <= 0) sampcnt = 10000; } @@ -1312,7 +1342,7 @@ done_opts: if (verbose) { fprintf(stderr, "%s: sampling %d directions", progname, nsbins); if (curparams.nsurfs > 1) - fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs); + fprintf(stderr, " (%d elements)\n", curparams.nsurfs); else fputc('\n', stderr); }