| 11 |
|
#include <stdlib.h> |
| 12 |
|
#include "rtio.h" |
| 13 |
|
#include "rtmath.h" |
| 14 |
< |
#include "paths.h" |
| 14 |
> |
#include "rtprocess.h" |
| 15 |
|
#include "bsdf.h" |
| 16 |
|
#include "bsdf_m.h" |
| 17 |
|
#include "random.h" |
| 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 |
|
|
| 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 += 3; |
| 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)) { |
| 178 |
|
exit(1); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
| 182 |
+ |
|
| 183 |
|
/* Open a pipe to/from a command given as an argument list */ |
| 184 |
|
static FILE * |
| 185 |
|
popen_arglist(char *av[], char *mode) |
| 197 |
|
return(popen(cmd, mode)); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
< |
#if defined(_WIN32) || defined(_WIN64) |
| 200 |
> |
#define pclose_al pclose |
| 201 |
> |
|
| 202 |
|
/* Execute system command (Windows version) */ |
| 203 |
|
static int |
| 204 |
|
my_exec(char *av[]) |
| 214 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
| 215 |
|
return(system(cmd)); |
| 216 |
|
} |
| 217 |
< |
#else |
| 217 |
> |
|
| 218 |
> |
#else /* UNIX */ |
| 219 |
> |
|
| 220 |
> |
static SUBPROC rt_proc = SP_INACTIVE; /* we only support one of these */ |
| 221 |
> |
|
| 222 |
> |
/* Open a pipe to a command using an argument list */ |
| 223 |
> |
static FILE * |
| 224 |
> |
popen_arglist(char *av[], char *mode) |
| 225 |
> |
{ |
| 226 |
> |
int fd; |
| 227 |
> |
|
| 228 |
> |
if (rt_proc.pid > 0) { |
| 229 |
> |
fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname); |
| 230 |
> |
return(NULL); |
| 231 |
> |
} |
| 232 |
> |
if (verbose > 0) { |
| 233 |
> |
char cmd[4096]; |
| 234 |
> |
if (!convert_commandline(cmd, sizeof(cmd), av)) |
| 235 |
> |
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
| 236 |
> |
fprintf(stderr, "%s: opening pipe %s: %s\n", |
| 237 |
> |
progname, (*mode=='w') ? "to" : "from", cmd); |
| 238 |
> |
} |
| 239 |
> |
if (*mode == 'w') { |
| 240 |
> |
fd = rt_proc.w = dup(fileno(stdout)); |
| 241 |
> |
rt_proc.flags |= PF_FILT_OUT; |
| 242 |
> |
} else if (*mode == 'r') { |
| 243 |
> |
fd = rt_proc.r = dup(fileno(stdin)); |
| 244 |
> |
rt_proc.flags |= PF_FILT_INP; |
| 245 |
> |
} |
| 246 |
> |
if (fd < 0 || open_process(&rt_proc, av) <= 0) { |
| 247 |
> |
perror(av[0]); |
| 248 |
> |
return(NULL); |
| 249 |
> |
} |
| 250 |
> |
return(fdopen(fd, mode)); |
| 251 |
> |
} |
| 252 |
> |
|
| 253 |
> |
/* Close command pipe (returns -1 on error to match pclose) */ |
| 254 |
> |
static int |
| 255 |
> |
pclose_al(FILE *fp) |
| 256 |
> |
{ |
| 257 |
> |
int prob = (fclose(fp) == EOF); |
| 258 |
> |
|
| 259 |
> |
if (rt_proc.pid <= 0) |
| 260 |
> |
return(-1); |
| 261 |
> |
|
| 262 |
> |
prob |= (close_process(&rt_proc) != 0); |
| 263 |
> |
|
| 264 |
> |
return(-prob); |
| 265 |
> |
} |
| 266 |
> |
|
| 267 |
|
/* Execute system command in our stead (Unix version) */ |
| 268 |
|
static int |
| 269 |
|
my_exec(char *av[]) |
| 284 |
|
perror(compath); |
| 285 |
|
return(1); |
| 286 |
|
} |
| 287 |
+ |
|
| 288 |
|
#endif |
| 289 |
|
|
| 290 |
|
/* Get normalized direction vector from string specification */ |
| 446 |
|
curparams.vup[1] = 1; |
| 447 |
|
} |
| 448 |
|
/* determine sample type/bin */ |
| 449 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
| 449 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
| 450 |
|
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
| 451 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
| 452 |
|
binv = savqstr(sbuf); |
| 720 |
|
/* compute projected areas */ |
| 721 |
|
for (i = 0, sp = p->slist; sp != NULL; i++, sp = sp->next) { |
| 722 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
| 723 |
< |
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
| 723 |
> |
tarea += projsa[i] *= (double)(projsa[i] > 0); |
| 724 |
|
} |
| 725 |
< |
if (tarea <= FTINY) { /* wrong side of sender? */ |
| 725 |
> |
if (tarea < FTINY*FTINY) { /* wrong side of sender? */ |
| 726 |
|
fputs(progname, stderr); |
| 727 |
|
fputs(": internal - sample behind all sender elements!\n", |
| 728 |
|
stderr); |
| 823 |
|
} |
| 824 |
|
while (n--) { /* stratified sampling */ |
| 825 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
| 826 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
| 827 |
+ |
samp3[1] *= samp3[1]; |
| 828 |
|
alt = (row+samp3[1])*RAH; |
| 829 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
| 830 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
| 831 |
|
duvw[0] = tsin(azi)*duvw[2]; |
| 832 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
| 832 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
| 833 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
| 834 |
|
for (i = 3; i--; ) |
| 835 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
| 936 |
|
curparams.udir[1] *= -1.; |
| 937 |
|
curparams.udir[2] *= -1.; |
| 938 |
|
} |
| 939 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
| 939 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
| 940 |
|
curparams.sample_basis = sample_uniform; |
| 941 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
| 942 |
|
tolower(curparams.hemis[1]) == 'c') |
| 997 |
|
VCOPY(e1, e2); |
| 998 |
|
} |
| 999 |
|
p->area = normalize(p->snrm)*0.5; |
| 1000 |
< |
return(p->area > FTINY); |
| 1000 |
> |
return(p->area > FTINY*FTINY); |
| 1001 |
|
} |
| 1002 |
|
|
| 1003 |
|
/* Add a surface to our current parameters */ |
| 1060 |
|
snew->area *= PI*snew->area; |
| 1061 |
|
break; |
| 1062 |
|
} |
| 1063 |
< |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
| 1063 |
> |
if ((snew->area <= FTINY*FTINY) & (verbose >= 0)) { |
| 1064 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
| 1065 |
|
progname, oname); |
| 1066 |
|
free(snew); |
| 1297 |
|
na = 0; |
| 1298 |
|
continue; |
| 1299 |
|
case 'w': /* options without arguments */ |
| 1300 |
< |
if (argv[a][2] != '+') verbose = -1; |
| 1300 |
> |
if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL) |
| 1301 |
> |
verbose = -1; |
| 1302 |
> |
break; |
| 1303 |
|
case 'V': |
| 1304 |
|
case 'u': |
| 1305 |
|
case 'h': |
| 1376 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
| 1377 |
|
return(1); |
| 1378 |
|
} |
| 1379 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
| 1379 |
> |
#ifdef SMLFLT |
| 1380 |
> |
fmtopt[2] = 'f'; |
| 1381 |
> |
#else |
| 1382 |
> |
fmtopt[2] = 'd'; |
| 1383 |
> |
#endif |
| 1384 |
|
if (sampcnt <= 0) sampcnt = 10000; |
| 1385 |
|
} |
| 1386 |
|
sprintf(sampcntbuf, "%d", sampcnt); |
| 1427 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
| 1428 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
| 1429 |
|
return(1); |
| 1430 |
< |
return(pclose(rcfp) < 0); /* all finished! */ |
| 1430 |
> |
return(pclose_al(rcfp) < 0); /* all finished! */ |
| 1431 |
|
userr: |
| 1432 |
|
if (a < argc-2) |
| 1433 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |