18 |
|
#include "triangulate.h" |
19 |
|
#include "platform.h" |
20 |
|
|
21 |
< |
#define MAXRCARG 512 |
21 |
> |
#ifndef MAXRCARG |
22 |
> |
#define MAXRCARG 10000 |
23 |
> |
#endif |
24 |
|
|
25 |
|
char *progname; /* global argv[0] */ |
26 |
|
|
66 |
|
FVECT uva[2]; /* tangent axes */ |
67 |
|
int ntris; /* number of triangles */ |
68 |
|
struct ptri { |
69 |
< |
float afrac; /* fraction of total area */ |
69 |
> |
double afrac; /* fraction of total area */ |
70 |
|
short vndx[3]; /* vertex indices */ |
71 |
|
} tri[1]; /* triangle array (extends struct) */ |
72 |
|
} POLYTRIS; /* triangulated polygon */ |
140 |
|
|
141 |
|
if (ac-- <= 0) |
142 |
|
return(NULL); |
143 |
+ |
if (verbose < 0) { /* turn off warnings */ |
144 |
+ |
strcpy(cp, "-w- "); |
145 |
+ |
cp += 4; |
146 |
+ |
} |
147 |
|
while (ac-- > 0) { |
148 |
|
strcpy(cp, *av++); |
149 |
|
while (*cp) cp++; |
385 |
|
curparams.vup[1] = 1; |
386 |
|
} |
387 |
|
/* determine sample type/bin */ |
388 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
388 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
389 |
|
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
390 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
391 |
|
binv = savqstr(sbuf); |
564 |
|
|
565 |
|
if (ptp == NULL) { /* need to triangulate */ |
566 |
|
ptp = (POLYTRIS *)malloc(sizeof(POLYTRIS) + |
567 |
< |
sizeof(struct ptri)*(sp->nfargs/3 - 1)); |
567 |
> |
sizeof(struct ptri)*(sp->nfargs/3 - 3)); |
568 |
|
if (ptp == NULL) |
569 |
|
goto memerr; |
570 |
|
if (sp->nfargs == 3) { /* simple case */ |
608 |
|
sp->priv = (void *)ptp; |
609 |
|
} |
610 |
|
/* pick triangle by partial area */ |
611 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
611 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
612 |
|
x -= ptp->tri[i].afrac; |
613 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
614 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
661 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
662 |
|
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
663 |
|
} |
664 |
< |
if (tarea <= FTINY) { /* wrong side of sender? */ |
664 |
> |
if (tarea < 0) { /* wrong side of sender? */ |
665 |
|
fputs(progname, stderr); |
666 |
|
fputs(": internal - sample behind all sender elements!\n", |
667 |
|
stderr); |
762 |
|
} |
763 |
|
while (n--) { /* stratified sampling */ |
764 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
765 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
766 |
+ |
samp3[1] *= samp3[1]; |
767 |
|
alt = (row+samp3[1])*RAH; |
768 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
769 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
770 |
|
duvw[0] = tsin(azi)*duvw[2]; |
771 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
771 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
772 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
773 |
|
for (i = 3; i--; ) |
774 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
875 |
|
curparams.udir[1] *= -1.; |
876 |
|
curparams.udir[2] *= -1.; |
877 |
|
} |
878 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
878 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
879 |
|
curparams.sample_basis = sample_uniform; |
880 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
881 |
|
tolower(curparams.hemis[1]) == 'c') |
1313 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
1314 |
|
return(1); |
1315 |
|
} |
1316 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1316 |
> |
#ifdef SMLFLT |
1317 |
> |
fmtopt[2] = 'f'; |
1318 |
> |
#else |
1319 |
> |
fmtopt[2] = 'd'; |
1320 |
> |
#endif |
1321 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1322 |
|
} |
1323 |
|
sprintf(sampcntbuf, "%d", sampcnt); |