| 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 */ |
| 52 |
|
#endif |
| 53 |
|
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
| 54 |
|
|
| 55 |
+ |
static int Tflag = 0; /* source tracing enabled? */ |
| 56 |
+ |
|
| 57 |
|
static RAY thisray; /* for our convenience */ |
| 58 |
|
|
| 59 |
|
static FILE *inpfp = NULL; /* input stream pointer */ |
| 70 |
|
oputr, oputR, oputx, oputX, oputn, oputN, oputs, |
| 71 |
|
oputw, oputW, oputm, oputM, oputtilde; |
| 72 |
|
|
| 71 |
– |
static void setoutput(char *vs); |
| 73 |
|
extern void tranotify(OBJECT obj); |
| 74 |
+ |
static int is_fifo(FILE *fp); |
| 75 |
|
static void bogusray(void); |
| 76 |
|
static void raycast(RAY *r); |
| 77 |
|
static void rayirrad(RAY *r); |
| 94 |
|
{ |
| 95 |
|
if (ray_pnprocs > 0) /* close children if any */ |
| 96 |
|
ray_pclose(0); |
| 97 |
+ |
else if (ray_pnprocs < 0) |
| 98 |
+ |
_exit(code); /* avoid flush() in child */ |
| 99 |
|
#ifndef NON_POSIX |
| 100 |
< |
else if (!ray_pnprocs) { |
| 100 |
> |
else { |
| 101 |
|
headclean(); /* delete header file */ |
| 102 |
|
pfclean(); /* clean up persist files */ |
| 103 |
|
} |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
< |
extern void |
| 124 |
> |
static void |
| 125 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
| 126 |
> |
{ |
| 127 |
> |
int sn; |
| 128 |
> |
|
| 129 |
> |
for (sn = 0; sn < nsources; sn++) |
| 130 |
> |
source[sn].sflags |= SFOLLOW; |
| 131 |
> |
} |
| 132 |
> |
|
| 133 |
> |
|
| 134 |
> |
void |
| 135 |
|
rtrace( /* trace rays from file */ |
| 136 |
|
char *fname, |
| 137 |
|
int nproc |
| 158 |
|
if (inform != 'a') |
| 159 |
|
SET_FILE_BINARY(inpfp); |
| 160 |
|
/* set up output */ |
| 161 |
< |
if (imm_irrad) |
| 148 |
< |
castonly = 0; |
| 149 |
< |
else if (castonly || every_out[0] != NULL) |
| 161 |
> |
if (castonly || every_out[0] != NULL) |
| 162 |
|
nproc = 1; /* don't bother multiprocessing */ |
| 163 |
+ |
if (Tflag && every_out[0] != NULL) |
| 164 |
+ |
trace_sources(); /* asking to trace light sources */ |
| 165 |
|
if ((nextflush > 0) & (nproc > nextflush)) { |
| 166 |
|
error(WARNING, "reducing number of processes to match flush interval"); |
| 167 |
|
nproc = nextflush; |
| 168 |
|
} |
| 155 |
– |
switch (outform) { |
| 156 |
– |
case 'a': putreal = puta; break; |
| 157 |
– |
case 'f': putreal = putf; break; |
| 158 |
– |
case 'd': putreal = putd; break; |
| 159 |
– |
case 'c': |
| 160 |
– |
if (outvals[1] || !strchr("vrx", outvals[0])) |
| 161 |
– |
error(USER, "color format only with -ov, -or, -ox"); |
| 162 |
– |
putreal = putrgbe; break; |
| 163 |
– |
default: |
| 164 |
– |
error(CONSISTENCY, "botched output format"); |
| 165 |
– |
} |
| 169 |
|
if (nproc > 1) { /* start multiprocessing */ |
| 170 |
|
ray_popen(nproc); |
| 171 |
|
ray_fifo_out = printvals; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
|
| 220 |
– |
static void |
| 221 |
– |
trace_sources(void) /* trace rays to light sources, also */ |
| 222 |
– |
{ |
| 223 |
– |
int sn; |
| 224 |
– |
|
| 225 |
– |
for (sn = 0; sn < nsources; sn++) |
| 226 |
– |
source[sn].sflags |= SFOLLOW; |
| 227 |
– |
} |
| 228 |
– |
|
| 229 |
– |
|
| 223 |
|
int |
| 224 |
|
setrtoutput(void) /* set up output tables, return #comp */ |
| 225 |
|
{ |
| 230 |
|
if (!*vs) |
| 231 |
|
error(USER, "empty output specification"); |
| 232 |
|
|
| 233 |
< |
castonly = 1; |
| 233 |
> |
switch (outform) { /* make sure (*putreal)() calls someone! */ |
| 234 |
> |
case 'a': putreal = puta; break; |
| 235 |
> |
case 'f': putreal = putf; break; |
| 236 |
> |
case 'd': putreal = putd; break; |
| 237 |
> |
case 'c': |
| 238 |
> |
if (outvals[1] || !strchr("vrx", outvals[0])) |
| 239 |
> |
error(USER, "color format only with -ov, -or, -ox"); |
| 240 |
> |
putreal = putrgbe; break; |
| 241 |
> |
default: |
| 242 |
> |
error(CONSISTENCY, "botched output format"); |
| 243 |
> |
} |
| 244 |
> |
castonly = 1; /* sets castonly as side-effect */ |
| 245 |
|
do |
| 246 |
|
switch (*vs) { |
| 247 |
|
case 'T': /* trace sources */ |
| 248 |
< |
if (!vs[1]) break; |
| 245 |
< |
trace_sources(); |
| 248 |
> |
Tflag++; |
| 249 |
|
/* fall through */ |
| 250 |
|
case 't': /* trace */ |
| 251 |
|
if (!vs[1]) break; |
| 290 |
|
case 'V': /* contribution */ |
| 291 |
|
*table++ = oputV; |
| 292 |
|
ncomp += 3; |
| 293 |
+ |
castonly = 0; |
| 294 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
| 295 |
|
error(WARNING, |
| 296 |
|
"-otV accuracy depends on -aa 0 -as 0"); |
| 358 |
|
if (*every_out != NULL) |
| 359 |
|
ncomp = 0; |
| 360 |
|
/* compatibility */ |
| 361 |
+ |
if ((do_irrad | imm_irrad) && castonly) |
| 362 |
+ |
error(USER, "-I+ and -i+ options require some value output"); |
| 363 |
|
for (table = ray_out; *table != NULL; table++) { |
| 364 |
|
if ((*table == oputV) | (*table == oputW)) |
| 365 |
|
error(WARNING, "-oVW options require trace mode"); |
| 423 |
|
) |
| 424 |
|
{ |
| 425 |
|
/* set up ray */ |
| 420 |
– |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 426 |
|
if (imm_irrad) { |
| 427 |
|
VSUM(thisray.rorg, org, dir, 1.1e-4); |
| 428 |
|
thisray.rdir[0] = -dir[0]; |
| 429 |
|
thisray.rdir[1] = -dir[1]; |
| 430 |
|
thisray.rdir[2] = -dir[2]; |
| 431 |
|
thisray.rmax = 0.0; |
| 427 |
– |
thisray.revf = rayirrad; |
| 432 |
|
} else { |
| 433 |
|
VCOPY(thisray.rorg, org); |
| 434 |
|
VCOPY(thisray.rdir, dir); |
| 435 |
|
thisray.rmax = dmax; |
| 432 |
– |
if (castonly) |
| 433 |
– |
thisray.revf = raycast; |
| 436 |
|
} |
| 437 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 438 |
+ |
if (imm_irrad) |
| 439 |
+ |
thisray.revf = rayirrad; |
| 440 |
+ |
else if (castonly) |
| 441 |
+ |
thisray.revf = raycast; |
| 442 |
|
if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ |
| 443 |
|
if (ray_fifo_in(&thisray) < 0) |
| 444 |
|
error(USER, "lost children"); |
| 468 |
|
|
| 469 |
|
|
| 470 |
|
static int |
| 471 |
+ |
is_fifo( /* check if file pointer connected to pipe */ |
| 472 |
+ |
FILE *fp |
| 473 |
+ |
) |
| 474 |
+ |
{ |
| 475 |
+ |
#ifdef S_ISFIFO |
| 476 |
+ |
struct stat sbuf; |
| 477 |
+ |
|
| 478 |
+ |
if (fstat(fileno(fp), &sbuf) < 0) |
| 479 |
+ |
error(SYSTEM, "fstat() failed on input stream"); |
| 480 |
+ |
return(S_ISFIFO(sbuf.st_mode)); |
| 481 |
+ |
#else |
| 482 |
+ |
return (fp == stdin); /* just a guess, really */ |
| 483 |
+ |
#endif |
| 484 |
+ |
} |
| 485 |
+ |
|
| 486 |
+ |
|
| 487 |
+ |
static int |
| 488 |
|
getvec( /* get a vector from fp */ |
| 489 |
|
FVECT vec, |
| 490 |
|
int fmt, |
| 548 |
|
int rsiz = 6*20; /* conservative ascii ray size */ |
| 549 |
|
if (inform == 'f') rsiz = 6*sizeof(float); |
| 550 |
|
else if (inform == 'd') rsiz = 6*sizeof(double); |
| 551 |
< |
if ((inpfp == stdin) & (qlength*rsiz > 512)) /* pipe limit */ |
| 551 |
> |
/* check against pipe limit */ |
| 552 |
> |
if (qlength*rsiz > 512 && is_fifo(inpfp)) |
| 553 |
|
inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength); |
| 554 |
|
inp_qend = -(inp_queue == NULL); /* flag for no queue */ |
| 555 |
|
} |
| 769 |
|
|
| 770 |
|
|
| 771 |
|
static void |
| 772 |
< |
oputp( /* print point */ |
| 772 |
> |
oputp( /* print intersection point */ |
| 773 |
|
RAY *r |
| 774 |
|
) |
| 775 |
|
{ |
| 776 |
< |
if (r->rot < FHUGE*.99) |
| 752 |
< |
(*putreal)(r->rop, 3); |
| 753 |
< |
else |
| 754 |
< |
(*putreal)(vdummy, 3); |
| 776 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
| 777 |
|
} |
| 778 |
|
|
| 779 |
|
|
| 782 |
|
RAY *r |
| 783 |
|
) |
| 784 |
|
{ |
| 785 |
< |
if (r->rot < FHUGE*.99) { |
| 764 |
< |
if (r->rflips & 1) { /* undo any flippin' flips */ |
| 765 |
< |
FVECT unrm; |
| 766 |
< |
unrm[0] = -r->ron[0]; |
| 767 |
< |
unrm[1] = -r->ron[1]; |
| 768 |
< |
unrm[2] = -r->ron[2]; |
| 769 |
< |
(*putreal)(unrm, 3); |
| 770 |
< |
} else |
| 771 |
< |
(*putreal)(r->ron, 3); |
| 772 |
< |
} else |
| 785 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
| 786 |
|
(*putreal)(vdummy, 3); |
| 787 |
+ |
return; |
| 788 |
+ |
} |
| 789 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
| 790 |
+ |
FVECT unrm; |
| 791 |
+ |
unrm[0] = -r->ron[0]; |
| 792 |
+ |
unrm[1] = -r->ron[1]; |
| 793 |
+ |
unrm[2] = -r->ron[2]; |
| 794 |
+ |
(*putreal)(unrm, 3); |
| 795 |
+ |
} else |
| 796 |
+ |
(*putreal)(r->ron, 3); |
| 797 |
|
} |
| 798 |
|
|
| 799 |
|
|
| 804 |
|
{ |
| 805 |
|
FVECT pnorm; |
| 806 |
|
|
| 807 |
< |
if (r->rot >= FHUGE*.99) { |
| 807 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
| 808 |
|
(*putreal)(vdummy, 3); |
| 809 |
|
return; |
| 810 |
|
} |