--- ray/src/util/rfluxmtx.c 2016/08/19 18:31:26 2.39 +++ ray/src/util/rfluxmtx.c 2018/10/01 15:51:48 2.46 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rfluxmtx.c,v 2.39 2016/08/19 18:31:26 greg Exp $"; +static const char RCSid[] = "$Id: rfluxmtx.c,v 2.46 2018/10/01 15:51:48 greg Exp $"; #endif /* * Calculate flux transfer matrix or matrices using rcontrib @@ -18,7 +18,9 @@ static const char RCSid[] = "$Id: rfluxmtx.c,v 2.39 20 #include "triangulate.h" #include "platform.h" -#define MAXRCARG 512 +#ifndef MAXRCARG +#define MAXRCARG 10000 +#endif char *progname; /* global argv[0] */ @@ -64,7 +66,7 @@ typedef struct { FVECT uva[2]; /* tangent axes */ int ntris; /* number of triangles */ struct ptri { - float afrac; /* fraction of total area */ + double afrac; /* fraction of total area */ short vndx[3]; /* vertex indices */ } tri[1]; /* triangle array (extends struct) */ } POLYTRIS; /* triangulated polygon */ @@ -138,6 +140,10 @@ oconv_command(int ac, char *av[]) if (ac-- <= 0) return(NULL); + if (verbose < 0) { /* turn off warnings */ + strcpy(cp, "-w- "); + cp += 4; + } while (ac-- > 0) { strcpy(cp, *av++); while (*cp) cp++; @@ -379,7 +385,7 @@ finish_receiver(void) curparams.vup[1] = 1; } /* determine sample type/bin */ - if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { + if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); binv = savqstr(sbuf); @@ -558,7 +564,7 @@ ssamp_poly(FVECT orig, SURF *sp, double x) if (ptp == NULL) { /* need to triangulate */ ptp = (POLYTRIS *)malloc(sizeof(POLYTRIS) + - sizeof(struct ptri)*(sp->nfargs/3 - 1)); + sizeof(struct ptri)*(sp->nfargs/3 - 3)); if (ptp == NULL) goto memerr; if (sp->nfargs == 3) { /* simple case */ @@ -602,7 +608,7 @@ ssamp_poly(FVECT orig, SURF *sp, double x) sp->priv = (void *)ptp; } /* pick triangle by partial area */ - for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) + for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) x -= ptp->tri[i].afrac; SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); samp2[0] *= samp2[1] = sqrt(samp2[1]); @@ -756,11 +762,13 @@ sample_reinhart(PARAMS *p, int b, FILE *fp) } while (n--) { /* stratified sampling */ SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); + if (row >= RowMax-1) /* avoid crowding at zenith */ + samp3[1] *= samp3[1]; alt = (row+samp3[1])*RAH; azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); duvw[2] = cos(alt); /* measured from horizon */ duvw[0] = tsin(azi)*duvw[2]; - duvw[1] = tcos(azi)*duvw[2]; + duvw[1] = -tcos(azi)*duvw[2]; duvw[2] = sqrt(1. - duvw[2]*duvw[2]); for (i = 3; i--; ) orig_dir[1][i] = -duvw[0]*p->udir[i] - @@ -867,7 +875,7 @@ prepare_sampler(void) curparams.udir[1] *= -1.; curparams.udir[2] *= -1.; } - if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') + if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) curparams.sample_basis = sample_uniform; else if (tolower(curparams.hemis[0]) == 's' && tolower(curparams.hemis[1]) == 'c') @@ -1305,7 +1313,11 @@ main(int argc, char *argv[]) fputs(": -i, -I supported for pass-through only\n", stderr); return(1); } - fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; +#ifdef SMLFLT + fmtopt[2] = 'f'; +#else + fmtopt[2] = 'd'; +#endif if (sampcnt <= 0) sampcnt = 10000; } sprintf(sampcntbuf, "%d", sampcnt);