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" |
141 |
|
if (ac-- <= 0) |
142 |
|
return(NULL); |
143 |
|
if (verbose < 0) { /* turn off warnings */ |
144 |
< |
strcpy(cp, "-w- "); |
145 |
< |
cp += 4; |
144 |
> |
strcpy(cp, "-w "); |
145 |
> |
cp += 3; |
146 |
|
} |
147 |
< |
while (ac-- > 0) { |
148 |
< |
strcpy(cp, *av++); |
149 |
< |
while (*cp) cp++; |
150 |
< |
*cp++ = ' '; |
151 |
< |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) |
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 */ |
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); |
740 |
|
{ |
741 |
|
int n = sampcnt; |
742 |
|
double samp3[3]; |
743 |
< |
double duvw[3]; |
683 |
< |
FVECT orig_dir[2]; |
743 |
> |
FVECT duvw, orig_dir[2]; |
744 |
|
int i; |
745 |
|
|
746 |
|
if (fp == NULL) /* just requesting number of bins? */ |
748 |
|
|
749 |
|
while (n--) { /* stratified hemisphere sampling */ |
750 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
751 |
< |
SDsquare2disk(duvw, samp3[1], samp3[2]); |
751 |
> |
square2disk(duvw, samp3[1], samp3[2]); |
752 |
|
duvw[2] = -sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]); |
753 |
|
for (i = 3; i--; ) |
754 |
|
orig_dir[1][i] = duvw[0]*p->udir[i] + |
768 |
|
{ |
769 |
|
int n = sampcnt; |
770 |
|
double samp3[3]; |
771 |
< |
double duvw[3]; |
712 |
< |
FVECT orig_dir[2]; |
771 |
> |
FVECT duvw, orig_dir[2]; |
772 |
|
int i; |
773 |
|
|
774 |
|
if (fp == NULL) /* just requesting number of bins? */ |
776 |
|
|
777 |
|
while (n--) { /* stratified sampling */ |
778 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
779 |
< |
SDsquare2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz, |
779 |
> |
square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz, |
780 |
|
(b%p->hsiz + samp3[2])/curparams.hsiz); |
781 |
|
duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]); |
782 |
|
for (i = 3; i--; ) |
995 |
|
VCOPY(e1, e2); |
996 |
|
} |
997 |
|
p->area = normalize(p->snrm)*0.5; |
998 |
< |
return(p->area > FTINY); |
998 |
> |
return(p->area > FTINY*FTINY); |
999 |
|
} |
1000 |
|
|
1001 |
|
/* Add a surface to our current parameters */ |
1058 |
|
snew->area *= PI*snew->area; |
1059 |
|
break; |
1060 |
|
} |
1061 |
< |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
1061 |
> |
if ((snew->area <= FTINY*FTINY) & (verbose >= 0)) { |
1062 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
1063 |
|
progname, oname); |
1064 |
|
free(snew); |
1283 |
|
yrs = argv[++a]; |
1284 |
|
na = 0; |
1285 |
|
continue; |
1286 |
< |
case 'c': /* number of samples */ |
1287 |
< |
sampcnt = atoi(argv[++a]); |
1288 |
< |
if (sampcnt <= 0) |
1289 |
< |
goto userr; |
1290 |
< |
na = 0; /* we re-add this later */ |
1286 |
> |
case 'c': /* spectral sampling or count */ |
1287 |
> |
switch (argv[a][2]) { |
1288 |
> |
case 's': |
1289 |
> |
na = 2; |
1290 |
> |
break; |
1291 |
> |
case 'w': |
1292 |
> |
na = 3; |
1293 |
> |
break; |
1294 |
> |
case '\0': |
1295 |
> |
sampcnt = atoi(argv[++a]); |
1296 |
> |
if (sampcnt <= 0) |
1297 |
> |
goto userr; |
1298 |
> |
na = 0; /* we re-add this later */ |
1299 |
> |
break; |
1300 |
> |
} |
1301 |
|
continue; |
1302 |
|
case 'I': /* only for pass-through mode */ |
1303 |
|
case 'i': |
1305 |
|
na = 0; |
1306 |
|
continue; |
1307 |
|
case 'w': /* options without arguments */ |
1308 |
< |
if (argv[a][2] != '+') verbose = -1; |
1308 |
> |
if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL) |
1309 |
> |
verbose = -1; |
1310 |
> |
break; |
1311 |
|
case 'V': |
1312 |
|
case 'u': |
1313 |
|
case 'h': |
1316 |
|
case 'n': /* options with 1 argument */ |
1317 |
|
case 's': |
1318 |
|
case 'o': |
1319 |
+ |
case 't': |
1320 |
|
na = 2; |
1321 |
|
break; |
1322 |
|
case 'b': /* special case */ |
1436 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1437 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1438 |
|
return(1); |
1439 |
< |
return(pclose(rcfp) < 0); /* all finished! */ |
1439 |
> |
return(pclose_al(rcfp) < 0); /* all finished! */ |
1440 |
|
userr: |
1441 |
|
if (a < argc-2) |
1442 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |