| 18 |
|
#include "triangulate.h" |
| 19 |
|
#include "platform.h" |
| 20 |
|
|
| 21 |
< |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
| 22 |
< |
#undef getc |
| 23 |
< |
#define getc getc_unlocked |
| 21 |
> |
#ifndef MAXRCARG |
| 22 |
> |
#define MAXRCARG 10000 |
| 23 |
|
#endif |
| 24 |
|
|
| 26 |
– |
#define MAXRCARG 512 |
| 27 |
– |
|
| 25 |
|
char *progname; /* global argv[0] */ |
| 26 |
|
|
| 27 |
|
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
| 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 |
< |
while (ac-- > 0) { |
| 144 |
< |
strcpy(cp, *av++); |
| 145 |
< |
while (*cp) cp++; |
| 146 |
< |
*cp++ = ' '; |
| 147 |
< |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) |
| 143 |
> |
if (verbose < 0) { /* turn off warnings */ |
| 144 |
> |
strcpy(cp, "-w "); |
| 145 |
> |
cp += 4; |
| 146 |
> |
} |
| 147 |
> |
while (ac-- > 0) { /* copy each argument */ |
| 148 |
> |
int len = strlen(*av); |
| 149 |
> |
if (cp+len+4 >= oconvbuf+sizeof(oconvbuf)) |
| 150 |
|
goto overrun; |
| 151 |
+ |
if (matchany(*av, SPECIALS)) { |
| 152 |
+ |
*cp++ = QUOTCHAR; |
| 153 |
+ |
strcpy(cp, *av++); |
| 154 |
+ |
cp += len; |
| 155 |
+ |
*cp++ = QUOTCHAR; |
| 156 |
+ |
} else { |
| 157 |
+ |
strcpy(cp, *av++); |
| 158 |
+ |
cp += len; |
| 159 |
+ |
} |
| 160 |
+ |
*cp++ = ' '; |
| 161 |
|
} |
| 162 |
|
/* receiver goes last */ |
| 163 |
|
if (matchany(recv, SPECIALS)) { |
| 195 |
|
return(popen(cmd, mode)); |
| 196 |
|
} |
| 197 |
|
|
| 198 |
< |
#ifdef _WIN32 |
| 198 |
> |
#if defined(_WIN32) || defined(_WIN64) |
| 199 |
|
/* Execute system command (Windows version) */ |
| 200 |
|
static int |
| 201 |
|
my_exec(char *av[]) |
| 393 |
|
curparams.vup[1] = 1; |
| 394 |
|
} |
| 395 |
|
/* determine sample type/bin */ |
| 396 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
| 396 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
| 397 |
|
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
| 398 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
| 399 |
|
binv = savqstr(sbuf); |
| 616 |
|
sp->priv = (void *)ptp; |
| 617 |
|
} |
| 618 |
|
/* pick triangle by partial area */ |
| 619 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
| 619 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
| 620 |
|
x -= ptp->tri[i].afrac; |
| 621 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
| 622 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
| 657 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
| 658 |
|
if (projsa) free(projsa); |
| 659 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
| 660 |
< |
if (!projsa) return(0); |
| 660 |
> |
if (projsa == NULL) { |
| 661 |
> |
fputs(progname, stderr); |
| 662 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
| 663 |
> |
exit(1); |
| 664 |
> |
} |
| 665 |
|
nall = p->nsurfs; |
| 666 |
|
} |
| 667 |
|
/* compute projected areas */ |
| 669 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
| 670 |
|
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
| 671 |
|
} |
| 672 |
< |
if (tarea <= FTINY) { /* wrong side of sender? */ |
| 672 |
> |
if (tarea < 0) { /* wrong side of sender? */ |
| 673 |
|
fputs(progname, stderr); |
| 674 |
|
fputs(": internal - sample behind all sender elements!\n", |
| 675 |
|
stderr); |
| 704 |
|
duvw[2]*p->nrm[i] ; |
| 705 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
| 706 |
|
return(0); |
| 707 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 707 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 708 |
|
return(0); |
| 709 |
|
} |
| 710 |
|
return(1); |
| 734 |
|
duvw[2]*p->nrm[i] ; |
| 735 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
| 736 |
|
return(0); |
| 737 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 737 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 738 |
|
return(0); |
| 739 |
|
} |
| 740 |
|
return(1); |
| 770 |
|
} |
| 771 |
|
while (n--) { /* stratified sampling */ |
| 772 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
| 773 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
| 774 |
+ |
samp3[1] *= samp3[1]; |
| 775 |
|
alt = (row+samp3[1])*RAH; |
| 776 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
| 777 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
| 778 |
|
duvw[0] = tsin(azi)*duvw[2]; |
| 779 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
| 779 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
| 780 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
| 781 |
|
for (i = 3; i--; ) |
| 782 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
| 784 |
|
duvw[2]*p->nrm[i] ; |
| 785 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
| 786 |
|
return(0); |
| 787 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 787 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 788 |
|
return(0); |
| 789 |
|
} |
| 790 |
|
return(1); |
| 835 |
|
duvw[2]*p->nrm[i] ; |
| 836 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
| 837 |
|
return(0); |
| 838 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 838 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
| 839 |
|
return(0); |
| 840 |
|
} |
| 841 |
|
return(1); |
| 883 |
|
curparams.udir[1] *= -1.; |
| 884 |
|
curparams.udir[2] *= -1.; |
| 885 |
|
} |
| 886 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
| 886 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
| 887 |
|
curparams.sample_basis = sample_uniform; |
| 888 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
| 889 |
|
tolower(curparams.hemis[1]) == 'c') |
| 962 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
| 963 |
|
if (snew == NULL) { |
| 964 |
|
fputs(progname, stderr); |
| 965 |
< |
fputs(": out of memory!\n", stderr); |
| 965 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
| 966 |
|
exit(1); |
| 967 |
|
} |
| 968 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
| 1244 |
|
na = 0; |
| 1245 |
|
continue; |
| 1246 |
|
case 'w': /* options without arguments */ |
| 1247 |
< |
if (argv[a][2] != '+') verbose = -1; |
| 1247 |
> |
if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL) |
| 1248 |
> |
verbose = -1; |
| 1249 |
> |
break; |
| 1250 |
|
case 'V': |
| 1251 |
|
case 'u': |
| 1252 |
|
case 'h': |
| 1323 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
| 1324 |
|
return(1); |
| 1325 |
|
} |
| 1326 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
| 1326 |
> |
#ifdef SMLFLT |
| 1327 |
> |
fmtopt[2] = 'f'; |
| 1328 |
> |
#else |
| 1329 |
> |
fmtopt[2] = 'd'; |
| 1330 |
> |
#endif |
| 1331 |
|
if (sampcnt <= 0) sampcnt = 10000; |
| 1332 |
|
} |
| 1333 |
|
sprintf(sampcntbuf, "%d", sampcnt); |