| 45 |
|
extern int hresolu; /* horizontal resolution */ |
| 46 |
|
extern int vresolu; /* vertical resolution */ |
| 47 |
|
|
| 48 |
< |
static int castonly = 0; |
| 48 |
> |
int castonly = 0; /* only doing ray-casting? */ |
| 49 |
|
|
| 50 |
|
#ifndef MAXTSET |
| 51 |
|
#define MAXTSET 8191 /* maximum number in trace set */ |
| 68 |
|
oputr, oputR, oputx, oputX, oputn, oputN, oputs, |
| 69 |
|
oputw, oputW, oputm, oputM, oputtilde; |
| 70 |
|
|
| 71 |
– |
static void setoutput(char *vs); |
| 71 |
|
extern void tranotify(OBJECT obj); |
| 72 |
+ |
static int is_fifo(FILE *fp); |
| 73 |
|
static void bogusray(void); |
| 74 |
|
static void raycast(RAY *r); |
| 75 |
|
static void rayirrad(RAY *r); |
| 92 |
|
{ |
| 93 |
|
if (ray_pnprocs > 0) /* close children if any */ |
| 94 |
|
ray_pclose(0); |
| 95 |
+ |
else if (ray_pnprocs < 0) |
| 96 |
+ |
_exit(code); /* avoid flush() in child */ |
| 97 |
|
#ifndef NON_POSIX |
| 98 |
< |
else if (!ray_pnprocs) { |
| 98 |
> |
else { |
| 99 |
|
headclean(); /* delete header file */ |
| 100 |
|
pfclean(); /* clean up persist files */ |
| 101 |
|
} |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
< |
extern void |
| 122 |
> |
void |
| 123 |
|
rtrace( /* trace rays from file */ |
| 124 |
|
char *fname, |
| 125 |
|
int nproc |
| 146 |
|
if (inform != 'a') |
| 147 |
|
SET_FILE_BINARY(inpfp); |
| 148 |
|
/* set up output */ |
| 149 |
< |
setoutput(outvals); |
| 148 |
< |
if (imm_irrad) |
| 149 |
< |
castonly = 0; |
| 150 |
< |
else if (castonly || every_out[0] != NULL) |
| 149 |
> |
if (castonly || every_out[0] != NULL) |
| 150 |
|
nproc = 1; /* don't bother multiprocessing */ |
| 151 |
|
if ((nextflush > 0) & (nproc > nextflush)) { |
| 152 |
|
error(WARNING, "reducing number of processes to match flush interval"); |
| 157 |
|
case 'f': putreal = putf; break; |
| 158 |
|
case 'd': putreal = putd; break; |
| 159 |
|
case 'c': |
| 160 |
< |
if (outvals[0] && (outvals[1] || !strchr("vrx", outvals[0]))) |
| 160 |
> |
if (outvals[1] || !strchr("vrx", outvals[0])) |
| 161 |
|
error(USER, "color format only with -ov, -or, -ox"); |
| 162 |
|
putreal = putrgbe; break; |
| 163 |
|
default: |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
|
| 230 |
< |
static void |
| 231 |
< |
setoutput( /* set up output tables */ |
| 233 |
< |
char *vs |
| 234 |
< |
) |
| 230 |
> |
int |
| 231 |
> |
setrtoutput(void) /* set up output tables, return #comp */ |
| 232 |
|
{ |
| 233 |
+ |
char *vs = outvals; |
| 234 |
|
oputf_t **table = ray_out; |
| 235 |
+ |
int ncomp = 0; |
| 236 |
|
|
| 237 |
< |
castonly = 1; |
| 238 |
< |
while (*vs) |
| 239 |
< |
switch (*vs++) { |
| 237 |
> |
if (!*vs) |
| 238 |
> |
error(USER, "empty output specification"); |
| 239 |
> |
|
| 240 |
> |
castonly = 1; /* sets castonly as side-effect */ |
| 241 |
> |
do |
| 242 |
> |
switch (*vs) { |
| 243 |
|
case 'T': /* trace sources */ |
| 244 |
< |
if (!*vs) break; |
| 244 |
> |
if (!vs[1]) break; |
| 245 |
|
trace_sources(); |
| 246 |
|
/* fall through */ |
| 247 |
|
case 't': /* trace */ |
| 248 |
< |
if (!*vs) break; |
| 248 |
> |
if (!vs[1]) break; |
| 249 |
|
*table = NULL; |
| 250 |
|
table = every_out; |
| 251 |
|
trace = ourtrace; |
| 253 |
|
break; |
| 254 |
|
case 'o': /* origin */ |
| 255 |
|
*table++ = oputo; |
| 256 |
+ |
ncomp += 3; |
| 257 |
|
break; |
| 258 |
|
case 'd': /* direction */ |
| 259 |
|
*table++ = oputd; |
| 260 |
+ |
ncomp += 3; |
| 261 |
|
break; |
| 262 |
|
case 'r': /* reflected contrib. */ |
| 263 |
|
*table++ = oputr; |
| 264 |
+ |
ncomp += 3; |
| 265 |
|
castonly = 0; |
| 266 |
|
break; |
| 267 |
|
case 'R': /* reflected distance */ |
| 268 |
|
*table++ = oputR; |
| 269 |
+ |
ncomp++; |
| 270 |
|
castonly = 0; |
| 271 |
|
break; |
| 272 |
|
case 'x': /* xmit contrib. */ |
| 273 |
|
*table++ = oputx; |
| 274 |
+ |
ncomp += 3; |
| 275 |
|
castonly = 0; |
| 276 |
|
break; |
| 277 |
|
case 'X': /* xmit distance */ |
| 278 |
|
*table++ = oputX; |
| 279 |
+ |
ncomp++; |
| 280 |
|
castonly = 0; |
| 281 |
|
break; |
| 282 |
|
case 'v': /* value */ |
| 283 |
|
*table++ = oputv; |
| 284 |
+ |
ncomp += 3; |
| 285 |
|
castonly = 0; |
| 286 |
|
break; |
| 287 |
|
case 'V': /* contribution */ |
| 288 |
|
*table++ = oputV; |
| 289 |
+ |
ncomp += 3; |
| 290 |
+ |
castonly = 0; |
| 291 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
| 292 |
|
error(WARNING, |
| 293 |
|
"-otV accuracy depends on -aa 0 -as 0"); |
| 294 |
|
break; |
| 295 |
|
case 'l': /* effective distance */ |
| 296 |
|
*table++ = oputl; |
| 297 |
+ |
ncomp++; |
| 298 |
|
castonly = 0; |
| 299 |
|
break; |
| 300 |
|
case 'c': /* local coordinates */ |
| 301 |
|
*table++ = oputc; |
| 302 |
+ |
ncomp += 2; |
| 303 |
|
break; |
| 304 |
|
case 'L': /* single ray length */ |
| 305 |
|
*table++ = oputL; |
| 306 |
+ |
ncomp++; |
| 307 |
|
break; |
| 308 |
|
case 'p': /* point */ |
| 309 |
|
*table++ = oputp; |
| 310 |
+ |
ncomp += 3; |
| 311 |
|
break; |
| 312 |
|
case 'n': /* perturbed normal */ |
| 313 |
|
*table++ = oputn; |
| 314 |
+ |
ncomp += 3; |
| 315 |
|
castonly = 0; |
| 316 |
|
break; |
| 317 |
|
case 'N': /* unperturbed normal */ |
| 318 |
|
*table++ = oputN; |
| 319 |
+ |
ncomp += 3; |
| 320 |
|
break; |
| 321 |
|
case 's': /* surface */ |
| 322 |
|
*table++ = oputs; |
| 323 |
+ |
ncomp++; |
| 324 |
|
break; |
| 325 |
|
case 'w': /* weight */ |
| 326 |
|
*table++ = oputw; |
| 327 |
+ |
ncomp++; |
| 328 |
|
break; |
| 329 |
|
case 'W': /* coefficient */ |
| 330 |
|
*table++ = oputW; |
| 331 |
+ |
ncomp += 3; |
| 332 |
|
castonly = 0; |
| 333 |
|
if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0)) |
| 334 |
|
error(WARNING, |
| 336 |
|
break; |
| 337 |
|
case 'm': /* modifier */ |
| 338 |
|
*table++ = oputm; |
| 339 |
+ |
ncomp++; |
| 340 |
|
break; |
| 341 |
|
case 'M': /* material */ |
| 342 |
|
*table++ = oputM; |
| 343 |
+ |
ncomp++; |
| 344 |
|
break; |
| 345 |
|
case '~': /* tilde */ |
| 346 |
|
*table++ = oputtilde; |
| 347 |
|
break; |
| 348 |
+ |
default: |
| 349 |
+ |
sprintf(errmsg, "unrecognized output option '%c'", *vs); |
| 350 |
+ |
error(USER, errmsg); |
| 351 |
|
} |
| 352 |
+ |
while (*++vs); |
| 353 |
+ |
|
| 354 |
|
*table = NULL; |
| 355 |
+ |
if (*every_out != NULL) |
| 356 |
+ |
ncomp = 0; |
| 357 |
|
/* compatibility */ |
| 358 |
+ |
if ((do_irrad | imm_irrad) && castonly) |
| 359 |
+ |
error(USER, "-I+ and -i+ options require some value output"); |
| 360 |
|
for (table = ray_out; *table != NULL; table++) { |
| 361 |
|
if ((*table == oputV) | (*table == oputW)) |
| 362 |
|
error(WARNING, "-oVW options require trace mode"); |
| 365 |
|
(*table == oputx) | (*table == oputX)) |
| 366 |
|
error(WARNING, "-orRxX options incompatible with -I+ and -i+"); |
| 367 |
|
} |
| 368 |
+ |
return(ncomp); |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
|
| 464 |
|
|
| 465 |
|
|
| 466 |
|
static int |
| 467 |
+ |
is_fifo( /* check if file pointer connected to pipe */ |
| 468 |
+ |
FILE *fp |
| 469 |
+ |
) |
| 470 |
+ |
{ |
| 471 |
+ |
#ifdef S_ISFIFO |
| 472 |
+ |
struct stat sbuf; |
| 473 |
+ |
|
| 474 |
+ |
if (fstat(fileno(fp), &sbuf) < 0) |
| 475 |
+ |
error(SYSTEM, "fstat() failed on input stream"); |
| 476 |
+ |
return(S_ISFIFO(sbuf.st_mode)); |
| 477 |
+ |
#else |
| 478 |
+ |
return (fp == stdin); /* just a guess, really */ |
| 479 |
+ |
#endif |
| 480 |
+ |
} |
| 481 |
+ |
|
| 482 |
+ |
|
| 483 |
+ |
static int |
| 484 |
|
getvec( /* get a vector from fp */ |
| 485 |
|
FVECT vec, |
| 486 |
|
int fmt, |
| 544 |
|
int rsiz = 6*20; /* conservative ascii ray size */ |
| 545 |
|
if (inform == 'f') rsiz = 6*sizeof(float); |
| 546 |
|
else if (inform == 'd') rsiz = 6*sizeof(double); |
| 547 |
< |
if ((inpfp == stdin) & (qlength*rsiz > 512)) /* pipe limit */ |
| 547 |
> |
/* check against pipe limit */ |
| 548 |
> |
if (qlength*rsiz > 512 && is_fifo(inpfp)) |
| 549 |
|
inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength); |
| 550 |
|
inp_qend = -(inp_queue == NULL); /* flag for no queue */ |
| 551 |
|
} |
| 765 |
|
|
| 766 |
|
|
| 767 |
|
static void |
| 768 |
< |
oputp( /* print point */ |
| 768 |
> |
oputp( /* print intersection point */ |
| 769 |
|
RAY *r |
| 770 |
|
) |
| 771 |
|
{ |
| 772 |
< |
if (r->rot < FHUGE*.99) |
| 723 |
< |
(*putreal)(r->rop, 3); |
| 724 |
< |
else |
| 725 |
< |
(*putreal)(vdummy, 3); |
| 772 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
| 773 |
|
} |
| 774 |
|
|
| 775 |
|
|
| 778 |
|
RAY *r |
| 779 |
|
) |
| 780 |
|
{ |
| 781 |
< |
if (r->rot < FHUGE*.99) { |
| 735 |
< |
if (r->rflips & 1) { /* undo any flippin' flips */ |
| 736 |
< |
FVECT unrm; |
| 737 |
< |
unrm[0] = -r->ron[0]; |
| 738 |
< |
unrm[1] = -r->ron[1]; |
| 739 |
< |
unrm[2] = -r->ron[2]; |
| 740 |
< |
(*putreal)(unrm, 3); |
| 741 |
< |
} else |
| 742 |
< |
(*putreal)(r->ron, 3); |
| 743 |
< |
} else |
| 781 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
| 782 |
|
(*putreal)(vdummy, 3); |
| 783 |
+ |
return; |
| 784 |
+ |
} |
| 785 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
| 786 |
+ |
FVECT unrm; |
| 787 |
+ |
unrm[0] = -r->ron[0]; |
| 788 |
+ |
unrm[1] = -r->ron[1]; |
| 789 |
+ |
unrm[2] = -r->ron[2]; |
| 790 |
+ |
(*putreal)(unrm, 3); |
| 791 |
+ |
} else |
| 792 |
+ |
(*putreal)(r->ron, 3); |
| 793 |
|
} |
| 794 |
|
|
| 795 |
|
|
| 800 |
|
{ |
| 801 |
|
FVECT pnorm; |
| 802 |
|
|
| 803 |
< |
if (r->rot >= FHUGE*.99) { |
| 803 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
| 804 |
|
(*putreal)(vdummy, 3); |
| 805 |
|
return; |
| 806 |
|
} |