45 |
|
extern int hresolu; /* horizontal resolution */ |
46 |
|
extern int vresolu; /* vertical resolution */ |
47 |
|
|
48 |
< |
static int castonly = 0; |
48 |
> |
extern int castonly; /* only doing ray-casting? */ |
49 |
|
|
50 |
+ |
extern double (*sens_curve)(SCOLOR scol); /* spectral conversion for 1-channel */ |
51 |
+ |
extern double out_scalefactor; /* output calibration scale factor */ |
52 |
+ |
extern RGBPRIMP out_prims; /* output color primitives (NULL if spectral) */ |
53 |
+ |
|
54 |
|
#ifndef MAXTSET |
55 |
|
#define MAXTSET 8191 /* maximum number in trace set */ |
56 |
|
#endif |
57 |
|
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
58 |
|
|
59 |
+ |
static int Tflag = 0; /* source tracing enabled? */ |
60 |
+ |
|
61 |
|
static RAY thisray; /* for our convenience */ |
62 |
|
|
63 |
+ |
static FILE *inpfp = NULL; /* input stream pointer */ |
64 |
+ |
|
65 |
+ |
static FVECT *inp_queue = NULL; /* ray input queue if flushing */ |
66 |
+ |
static int inp_qpos = 0; /* next ray to return */ |
67 |
+ |
static int inp_qend = 0; /* number of rays in this work group */ |
68 |
+ |
|
69 |
|
typedef void putf_t(RREAL *v, int n); |
70 |
|
static putf_t puta, putd, putf; |
71 |
|
|
74 |
|
oputr, oputR, oputx, oputX, oputn, oputN, oputs, |
75 |
|
oputw, oputW, oputm, oputM, oputtilde; |
76 |
|
|
65 |
– |
static void setoutput(char *vs); |
77 |
|
extern void tranotify(OBJECT obj); |
78 |
+ |
static int is_fifo(FILE *fp); |
79 |
|
static void bogusray(void); |
80 |
|
static void raycast(RAY *r); |
81 |
|
static void rayirrad(RAY *r); |
82 |
|
static void rtcompute(FVECT org, FVECT dir, double dmax); |
83 |
|
static int printvals(RAY *r); |
84 |
|
static int getvec(FVECT vec, int fmt, FILE *fp); |
85 |
+ |
static int iszerovec(const FVECT vec); |
86 |
+ |
static double nextray(FVECT org, FVECT dir); |
87 |
|
static void tabin(RAY *r); |
88 |
|
static void ourtrace(RAY *r); |
89 |
|
|
90 |
+ |
static void putscolor(COLORV *scol); |
91 |
+ |
|
92 |
|
static oputf_t *ray_out[32], *every_out[32]; |
93 |
|
static putf_t *putreal; |
94 |
|
|
100 |
|
{ |
101 |
|
if (ray_pnprocs > 0) /* close children if any */ |
102 |
|
ray_pclose(0); |
103 |
+ |
else if (ray_pnprocs < 0) |
104 |
+ |
_exit(code); /* avoid flush() in child */ |
105 |
|
#ifndef NON_POSIX |
106 |
< |
else if (!ray_pnprocs) { |
106 |
> |
else { |
107 |
|
headclean(); /* delete header file */ |
108 |
|
pfclean(); /* clean up persist files */ |
109 |
|
} |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
< |
char * |
115 |
> |
const char * |
116 |
|
formstr( /* return format identifier */ |
117 |
|
int f |
118 |
|
) |
121 |
|
case 'a': return("ascii"); |
122 |
|
case 'f': return("float"); |
123 |
|
case 'd': return("double"); |
124 |
< |
case 'c': return(COLRFMT); |
124 |
> |
case 'c': |
125 |
> |
if (out_prims == NULL) |
126 |
> |
return(SPECFMT); |
127 |
> |
if (out_prims == xyzprims) |
128 |
> |
return(CIEFMT); |
129 |
> |
return(COLRFMT); |
130 |
|
} |
131 |
|
return("unknown"); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
< |
extern void |
135 |
> |
static void |
136 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
137 |
> |
{ |
138 |
> |
int sn; |
139 |
> |
|
140 |
> |
for (sn = 0; sn < nsources; sn++) |
141 |
> |
source[sn].sflags |= SFOLLOW; |
142 |
> |
} |
143 |
> |
|
144 |
> |
|
145 |
> |
void |
146 |
|
rtrace( /* trace rays from file */ |
147 |
|
char *fname, |
148 |
|
int nproc |
150 |
|
{ |
151 |
|
unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu |
152 |
|
: (unsigned long)vresolu; |
153 |
< |
long nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : hresolu; |
153 |
> |
long nextflush = (!vresolu | (hresolu <= 1)) * hresolu; |
154 |
> |
int something2flush = 0; |
155 |
|
FILE *fp; |
156 |
|
double d; |
157 |
|
FVECT orig, direc; |
158 |
|
/* set up input */ |
159 |
|
if (fname == NULL) |
160 |
< |
fp = stdin; |
161 |
< |
else if ((fp = fopen(fname, "r")) == NULL) { |
160 |
> |
inpfp = stdin; |
161 |
> |
else if ((inpfp = fopen(fname, "r")) == NULL) { |
162 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
163 |
|
error(SYSTEM, errmsg); |
164 |
|
} |
165 |
+ |
#ifdef getc_unlocked |
166 |
+ |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
167 |
+ |
flockfile(stdout); |
168 |
+ |
#endif |
169 |
|
if (inform != 'a') |
170 |
< |
SET_FILE_BINARY(fp); |
170 |
> |
SET_FILE_BINARY(inpfp); |
171 |
|
/* set up output */ |
172 |
< |
setoutput(outvals); |
135 |
< |
if (imm_irrad) |
136 |
< |
castonly = 0; |
137 |
< |
else if (castonly) |
172 |
> |
if (castonly || every_out[0] != NULL) |
173 |
|
nproc = 1; /* don't bother multiprocessing */ |
174 |
< |
switch (outform) { |
175 |
< |
case 'a': putreal = puta; break; |
176 |
< |
case 'f': putreal = putf; break; |
177 |
< |
case 'd': putreal = putd; break; |
143 |
< |
case 'c': |
144 |
< |
if (strcmp(outvals, "v")) |
145 |
< |
error(USER, "color format with value output only"); |
146 |
< |
break; |
147 |
< |
default: |
148 |
< |
error(CONSISTENCY, "botched output format"); |
174 |
> |
if (every_out[0] != NULL) { |
175 |
> |
trace = ourtrace; /* enable full tree tracing */ |
176 |
> |
if (Tflag) /* light sources, too? */ |
177 |
> |
trace_sources(); |
178 |
|
} |
179 |
+ |
if ((nextflush > 0) & (nproc > nextflush)) { |
180 |
+ |
error(WARNING, "reducing number of processes to match flush interval"); |
181 |
+ |
nproc = nextflush; |
182 |
+ |
} |
183 |
|
if (nproc > 1) { /* start multiprocessing */ |
184 |
|
ray_popen(nproc); |
185 |
|
ray_fifo_out = printvals; |
187 |
|
if (hresolu > 0) { |
188 |
|
if (vresolu > 0) |
189 |
|
fprtresolu(hresolu, vresolu, stdout); |
190 |
< |
fflush(stdout); |
190 |
> |
else |
191 |
> |
fflush(stdout); |
192 |
|
} |
193 |
< |
/* process file */ |
194 |
< |
while (getvec(orig, inform, fp) == 0 && |
195 |
< |
getvec(direc, inform, fp) == 0) { |
196 |
< |
|
197 |
< |
d = normalize(direc); |
164 |
< |
if (d == 0.0) { /* zero ==> flush */ |
165 |
< |
if (--nextflush <= 0 || !vcount) { |
166 |
< |
if (nproc > 1 && ray_fifo_flush() < 0) |
193 |
> |
/* process input rays */ |
194 |
> |
while ((d = nextray(orig, direc)) >= 0.0) { |
195 |
> |
if (d == 0.0) { /* flush request? */ |
196 |
> |
if (something2flush) { |
197 |
> |
if (ray_pnprocs > 1 && ray_fifo_flush() < 0) |
198 |
|
error(USER, "child(ren) died"); |
199 |
|
bogusray(); |
200 |
|
fflush(stdout); |
201 |
< |
nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : |
202 |
< |
hresolu; |
201 |
> |
nextflush = (!vresolu | (hresolu <= 1)) * hresolu; |
202 |
> |
something2flush = 0; |
203 |
|
} else |
204 |
|
bogusray(); |
205 |
|
} else { /* compute and print */ |
206 |
|
rtcompute(orig, direc, lim_dist ? d : 0.0); |
207 |
< |
/* flush if time */ |
208 |
< |
if (!--nextflush) { |
178 |
< |
if (nproc > 1 && ray_fifo_flush() < 0) |
207 |
> |
if (!--nextflush) { /* flush if time */ |
208 |
> |
if (ray_pnprocs > 1 && ray_fifo_flush() < 0) |
209 |
|
error(USER, "child(ren) died"); |
210 |
|
fflush(stdout); |
211 |
|
nextflush = hresolu; |
212 |
< |
} |
212 |
> |
} else |
213 |
> |
something2flush = 1; |
214 |
|
} |
215 |
|
if (ferror(stdout)) |
216 |
|
error(SYSTEM, "write error"); |
217 |
|
if (vcount && !--vcount) /* check for end */ |
218 |
|
break; |
219 |
|
} |
220 |
< |
if (nproc > 1) { /* clean up children */ |
220 |
> |
if (ray_pnprocs > 1) { /* clean up children */ |
221 |
|
if (ray_fifo_flush() < 0) |
222 |
|
error(USER, "unable to complete processing"); |
223 |
|
ray_pclose(0); |
224 |
|
} |
225 |
+ |
if (vcount) |
226 |
+ |
error(WARNING, "unexpected EOF on input"); |
227 |
|
if (fflush(stdout) < 0) |
228 |
|
error(SYSTEM, "write error"); |
229 |
< |
if (vcount) |
230 |
< |
error(USER, "unexpected EOF on input"); |
231 |
< |
if (fname != NULL) |
232 |
< |
fclose(fp); |
229 |
> |
if (fname != NULL) { |
230 |
> |
fclose(inpfp); |
231 |
> |
inpfp = NULL; |
232 |
> |
} |
233 |
> |
nextray(NULL, NULL); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
< |
static void |
238 |
< |
trace_sources(void) /* trace rays to light sources, also */ |
237 |
> |
int |
238 |
> |
setrtoutput(void) /* set up output tables, return #comp */ |
239 |
|
{ |
240 |
< |
int sn; |
207 |
< |
|
208 |
< |
for (sn = 0; sn < nsources; sn++) |
209 |
< |
source[sn].sflags |= SFOLLOW; |
210 |
< |
} |
211 |
< |
|
212 |
< |
|
213 |
< |
static void |
214 |
< |
setoutput( /* set up output tables */ |
215 |
< |
char *vs |
216 |
< |
) |
217 |
< |
{ |
240 |
> |
char *vs = outvals; |
241 |
|
oputf_t **table = ray_out; |
242 |
+ |
const int nco = (sens_curve != NULL) ? 1 : |
243 |
+ |
(out_prims != NULL) ? 3 : NCSAMP; |
244 |
+ |
int ncomp = 0; |
245 |
|
|
246 |
< |
castonly = 1; |
247 |
< |
while (*vs) |
248 |
< |
switch (*vs++) { |
246 |
> |
if (!*vs) |
247 |
> |
error(USER, "empty output specification"); |
248 |
> |
|
249 |
> |
switch (outform) { /* make sure (*putreal)() calls someone! */ |
250 |
> |
case 'a': putreal = puta; break; |
251 |
> |
case 'f': putreal = putf; break; |
252 |
> |
case 'd': putreal = putd; break; |
253 |
> |
case 'c': |
254 |
> |
if (outvals[1] || !strchr("vrx", outvals[0])) |
255 |
> |
error(USER, "color format only with -ov, -or, -ox"); |
256 |
> |
if (nco < 3) |
257 |
> |
error(USER, "color format incompatible with -pY, -pS, -pM"); |
258 |
> |
break; |
259 |
> |
default: |
260 |
> |
error(CONSISTENCY, "botched output format"); |
261 |
> |
} |
262 |
> |
castonly = 1; /* sets castonly as side-effect */ |
263 |
> |
do |
264 |
> |
switch (*vs) { |
265 |
|
case 'T': /* trace sources */ |
266 |
< |
if (!*vs) break; |
225 |
< |
trace_sources(); |
266 |
> |
Tflag++; |
267 |
|
/* fall through */ |
268 |
|
case 't': /* trace */ |
269 |
< |
if (!*vs) break; |
269 |
> |
if (!vs[1]) break; |
270 |
|
*table = NULL; |
271 |
|
table = every_out; |
231 |
– |
trace = ourtrace; |
272 |
|
castonly = 0; |
273 |
|
break; |
274 |
|
case 'o': /* origin */ |
275 |
|
*table++ = oputo; |
276 |
+ |
ncomp += 3; |
277 |
|
break; |
278 |
|
case 'd': /* direction */ |
279 |
|
*table++ = oputd; |
280 |
+ |
ncomp += 3; |
281 |
|
break; |
282 |
|
case 'r': /* reflected contrib. */ |
283 |
|
*table++ = oputr; |
284 |
+ |
ncomp += nco; |
285 |
|
castonly = 0; |
286 |
|
break; |
287 |
|
case 'R': /* reflected distance */ |
288 |
|
*table++ = oputR; |
289 |
+ |
ncomp++; |
290 |
|
castonly = 0; |
291 |
|
break; |
292 |
|
case 'x': /* xmit contrib. */ |
293 |
|
*table++ = oputx; |
294 |
+ |
ncomp += nco; |
295 |
|
castonly = 0; |
296 |
|
break; |
297 |
|
case 'X': /* xmit distance */ |
298 |
|
*table++ = oputX; |
299 |
+ |
ncomp++; |
300 |
|
castonly = 0; |
301 |
|
break; |
302 |
|
case 'v': /* value */ |
303 |
|
*table++ = oputv; |
304 |
+ |
ncomp += nco; |
305 |
|
castonly = 0; |
306 |
|
break; |
307 |
|
case 'V': /* contribution */ |
308 |
|
*table++ = oputV; |
309 |
+ |
ncomp += nco; |
310 |
|
castonly = 0; |
311 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
312 |
|
error(WARNING, |
314 |
|
break; |
315 |
|
case 'l': /* effective distance */ |
316 |
|
*table++ = oputl; |
317 |
+ |
ncomp++; |
318 |
|
castonly = 0; |
319 |
|
break; |
320 |
|
case 'c': /* local coordinates */ |
321 |
|
*table++ = oputc; |
322 |
+ |
ncomp += 2; |
323 |
|
break; |
324 |
|
case 'L': /* single ray length */ |
325 |
|
*table++ = oputL; |
326 |
+ |
ncomp++; |
327 |
|
break; |
328 |
|
case 'p': /* point */ |
329 |
|
*table++ = oputp; |
330 |
+ |
ncomp += 3; |
331 |
|
break; |
332 |
|
case 'n': /* perturbed normal */ |
333 |
|
*table++ = oputn; |
334 |
+ |
ncomp += 3; |
335 |
|
castonly = 0; |
336 |
|
break; |
337 |
|
case 'N': /* unperturbed normal */ |
338 |
|
*table++ = oputN; |
339 |
+ |
ncomp += 3; |
340 |
|
break; |
341 |
|
case 's': /* surface */ |
342 |
|
*table++ = oputs; |
343 |
+ |
ncomp++; |
344 |
|
break; |
345 |
|
case 'w': /* weight */ |
346 |
|
*table++ = oputw; |
347 |
+ |
ncomp++; |
348 |
|
break; |
349 |
|
case 'W': /* coefficient */ |
350 |
|
*table++ = oputW; |
351 |
+ |
ncomp += nco; |
352 |
|
castonly = 0; |
353 |
< |
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
353 |
> |
if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0)) |
354 |
|
error(WARNING, |
355 |
|
"-otW accuracy depends on -aa 0 -as 0"); |
356 |
|
break; |
357 |
|
case 'm': /* modifier */ |
358 |
|
*table++ = oputm; |
359 |
+ |
ncomp++; |
360 |
|
break; |
361 |
|
case 'M': /* material */ |
362 |
|
*table++ = oputM; |
363 |
+ |
ncomp++; |
364 |
|
break; |
365 |
|
case '~': /* tilde */ |
366 |
|
*table++ = oputtilde; |
367 |
|
break; |
368 |
+ |
default: |
369 |
+ |
sprintf(errmsg, "unrecognized output option '%c'", *vs); |
370 |
+ |
error(USER, errmsg); |
371 |
|
} |
372 |
+ |
while (*++vs); |
373 |
+ |
|
374 |
|
*table = NULL; |
375 |
+ |
if (*every_out != NULL) |
376 |
+ |
ncomp = 0; |
377 |
+ |
/* compatibility */ |
378 |
+ |
if ((do_irrad | imm_irrad) && castonly) |
379 |
+ |
error(USER, "-I+ and -i+ options require some value output"); |
380 |
+ |
for (table = ray_out; *table != NULL; table++) { |
381 |
+ |
if ((*table == oputV) | (*table == oputW)) |
382 |
+ |
error(WARNING, "-oVW options require trace mode"); |
383 |
+ |
if ((do_irrad | imm_irrad) && |
384 |
+ |
(*table == oputr) | (*table == oputR) | |
385 |
+ |
(*table == oputx) | (*table == oputX)) |
386 |
+ |
error(WARNING, "-orRxX options incompatible with -I+ and -i+"); |
387 |
+ |
} |
388 |
+ |
return(ncomp); |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
|
static void |
393 |
|
bogusray(void) /* print out empty record */ |
394 |
|
{ |
317 |
– |
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
318 |
– |
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
319 |
– |
thisray.rmax = 0.0; |
395 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
396 |
|
printvals(&thisray); |
397 |
|
} |
418 |
|
) |
419 |
|
{ |
420 |
|
void (*old_revf)(RAY *) = r->revf; |
421 |
< |
|
422 |
< |
r->rot = 1e-5; /* pretend we hit surface */ |
421 |
> |
/* pretend we hit surface */ |
422 |
> |
r->rxt = r->rot = 1e-5; |
423 |
|
VSUM(r->rop, r->rorg, r->rdir, r->rot); |
424 |
|
r->ron[0] = -r->rdir[0]; |
425 |
|
r->ron[1] = -r->rdir[1]; |
440 |
|
) |
441 |
|
{ |
442 |
|
/* set up ray */ |
368 |
– |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
443 |
|
if (imm_irrad) { |
444 |
|
VSUM(thisray.rorg, org, dir, 1.1e-4); |
445 |
|
thisray.rdir[0] = -dir[0]; |
446 |
|
thisray.rdir[1] = -dir[1]; |
447 |
|
thisray.rdir[2] = -dir[2]; |
448 |
|
thisray.rmax = 0.0; |
375 |
– |
thisray.revf = rayirrad; |
449 |
|
} else { |
450 |
|
VCOPY(thisray.rorg, org); |
451 |
|
VCOPY(thisray.rdir, dir); |
452 |
|
thisray.rmax = dmax; |
380 |
– |
if (castonly) |
381 |
– |
thisray.revf = raycast; |
453 |
|
} |
454 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
455 |
+ |
if (imm_irrad) |
456 |
+ |
thisray.revf = rayirrad; |
457 |
+ |
else if (castonly) |
458 |
+ |
thisray.revf = raycast; |
459 |
|
if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ |
460 |
|
if (ray_fifo_in(&thisray) < 0) |
461 |
|
error(USER, "lost children"); |
485 |
|
|
486 |
|
|
487 |
|
static int |
488 |
< |
getvec( /* get a vector from fp */ |
488 |
> |
is_fifo( /* check if file pointer connected to pipe */ |
489 |
> |
FILE *fp |
490 |
> |
) |
491 |
> |
{ |
492 |
> |
#ifdef S_ISFIFO |
493 |
> |
struct stat sbuf; |
494 |
> |
|
495 |
> |
if (fstat(fileno(fp), &sbuf) < 0) |
496 |
> |
error(SYSTEM, "fstat() failed on input stream"); |
497 |
> |
return(S_ISFIFO(sbuf.st_mode)); |
498 |
> |
#else |
499 |
> |
return (fp == stdin); /* just a guess, really */ |
500 |
> |
#endif |
501 |
> |
} |
502 |
> |
|
503 |
> |
|
504 |
> |
static int |
505 |
> |
getvec( /* get a vector from fp */ |
506 |
|
FVECT vec, |
507 |
|
int fmt, |
508 |
|
FILE *fp |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
+ |
static int |
543 |
+ |
iszerovec(const FVECT vec) |
544 |
+ |
{ |
545 |
+ |
return (vec[0] == 0.0) & (vec[1] == 0.0) & (vec[2] == 0.0); |
546 |
+ |
} |
547 |
+ |
|
548 |
+ |
|
549 |
+ |
static double |
550 |
+ |
nextray( /* return next ray in work group (-1.0 if EOF) */ |
551 |
+ |
FVECT org, |
552 |
+ |
FVECT dir |
553 |
+ |
) |
554 |
+ |
{ |
555 |
+ |
const size_t qlength = !vresolu * hresolu; |
556 |
+ |
|
557 |
+ |
if ((org == NULL) | (dir == NULL)) { |
558 |
+ |
if (inp_queue != NULL) /* asking to free queue */ |
559 |
+ |
free(inp_queue); |
560 |
+ |
inp_queue = NULL; |
561 |
+ |
inp_qpos = inp_qend = 0; |
562 |
+ |
return(-1.); |
563 |
+ |
} |
564 |
+ |
if (!inp_qend) { /* initialize FIFO queue */ |
565 |
+ |
int rsiz = 6*20; /* conservative ascii ray size */ |
566 |
+ |
if (inform == 'f') rsiz = 6*sizeof(float); |
567 |
+ |
else if (inform == 'd') rsiz = 6*sizeof(double); |
568 |
+ |
/* check against pipe limit */ |
569 |
+ |
if (qlength*rsiz > 512 && is_fifo(inpfp)) |
570 |
+ |
inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength); |
571 |
+ |
inp_qend = -(inp_queue == NULL); /* flag for no queue */ |
572 |
+ |
} |
573 |
+ |
if (inp_qend < 0) { /* not queuing? */ |
574 |
+ |
if (getvec(org, inform, inpfp) < 0 || |
575 |
+ |
getvec(dir, inform, inpfp) < 0) |
576 |
+ |
return(-1.); |
577 |
+ |
return normalize(dir); |
578 |
+ |
} |
579 |
+ |
if (inp_qpos >= inp_qend) { /* need to refill input queue? */ |
580 |
+ |
for (inp_qend = 0; inp_qend < qlength; inp_qend++) { |
581 |
+ |
if (getvec(inp_queue[2*inp_qend], inform, inpfp) < 0 |
582 |
+ |
|| getvec(inp_queue[2*inp_qend+1], |
583 |
+ |
inform, inpfp) < 0) |
584 |
+ |
break; /* hit EOF */ |
585 |
+ |
if (iszerovec(inp_queue[2*inp_qend+1])) { |
586 |
+ |
++inp_qend; /* flush request */ |
587 |
+ |
break; |
588 |
+ |
} |
589 |
+ |
} |
590 |
+ |
inp_qpos = 0; |
591 |
+ |
} |
592 |
+ |
if (inp_qpos >= inp_qend) /* unexpected EOF? */ |
593 |
+ |
return(-1.); |
594 |
+ |
VCOPY(org, inp_queue[2*inp_qpos]); |
595 |
+ |
VCOPY(dir, inp_queue[2*inp_qpos+1]); |
596 |
+ |
++inp_qpos; |
597 |
+ |
return normalize(dir); |
598 |
+ |
} |
599 |
+ |
|
600 |
+ |
|
601 |
|
void |
602 |
|
tranotify( /* record new modifier */ |
603 |
|
OBJECT obj |
684 |
|
RAY *r |
685 |
|
) |
686 |
|
{ |
687 |
< |
RREAL cval[3]; |
536 |
< |
|
537 |
< |
cval[0] = colval(r->mcol,RED); |
538 |
< |
cval[1] = colval(r->mcol,GRN); |
539 |
< |
cval[2] = colval(r->mcol,BLU); |
540 |
< |
(*putreal)(cval, 3); |
687 |
> |
putscolor(r->mcol); |
688 |
|
} |
689 |
|
|
690 |
|
|
703 |
|
RAY *r |
704 |
|
) |
705 |
|
{ |
706 |
< |
RREAL cval[3]; |
706 |
> |
SCOLOR cdiff; |
707 |
|
|
708 |
< |
cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED); |
709 |
< |
cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN); |
710 |
< |
cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU); |
711 |
< |
(*putreal)(cval, 3); |
708 |
> |
copyscolor(cdiff, r->rcol); |
709 |
> |
sopscolor(cdiff, -=, r->mcol); |
710 |
> |
|
711 |
> |
putscolor(cdiff); |
712 |
|
} |
713 |
|
|
714 |
|
|
726 |
|
RAY *r |
727 |
|
) |
728 |
|
{ |
729 |
< |
RREAL cval[3]; |
583 |
< |
|
584 |
< |
if (outform == 'c') { |
585 |
< |
COLR cout; |
586 |
< |
setcolr(cout, colval(r->rcol,RED), |
587 |
< |
colval(r->rcol,GRN), |
588 |
< |
colval(r->rcol,BLU)); |
589 |
< |
putbinary(cout, sizeof(cout), 1, stdout); |
590 |
< |
return; |
591 |
< |
} |
592 |
< |
cval[0] = colval(r->rcol,RED); |
593 |
< |
cval[1] = colval(r->rcol,GRN); |
594 |
< |
cval[2] = colval(r->rcol,BLU); |
595 |
< |
(*putreal)(cval, 3); |
729 |
> |
putscolor(r->rcol); |
730 |
|
} |
731 |
|
|
732 |
|
|
735 |
|
RAY *r |
736 |
|
) |
737 |
|
{ |
738 |
< |
RREAL contr[3]; |
738 |
> |
SCOLOR contr; |
739 |
|
|
740 |
|
raycontrib(contr, r, PRIMARY); |
741 |
< |
multcolor(contr, r->rcol); |
742 |
< |
(*putreal)(contr, 3); |
741 |
> |
smultscolor(contr, r->rcol); |
742 |
> |
putscolor(contr); |
743 |
|
} |
744 |
|
|
745 |
|
|
776 |
|
|
777 |
|
|
778 |
|
static void |
779 |
< |
oputp( /* print point */ |
779 |
> |
oputp( /* print intersection point */ |
780 |
|
RAY *r |
781 |
|
) |
782 |
|
{ |
783 |
< |
if (r->rot < FHUGE) |
650 |
< |
(*putreal)(r->rop, 3); |
651 |
< |
else |
652 |
< |
(*putreal)(vdummy, 3); |
783 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
784 |
|
} |
785 |
|
|
786 |
|
|
789 |
|
RAY *r |
790 |
|
) |
791 |
|
{ |
792 |
< |
if (r->rot < FHUGE) |
662 |
< |
(*putreal)(r->ron, 3); |
663 |
< |
else |
792 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
793 |
|
(*putreal)(vdummy, 3); |
794 |
+ |
return; |
795 |
+ |
} |
796 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
797 |
+ |
FVECT unrm; |
798 |
+ |
unrm[0] = -r->ron[0]; |
799 |
+ |
unrm[1] = -r->ron[1]; |
800 |
+ |
unrm[2] = -r->ron[2]; |
801 |
+ |
(*putreal)(unrm, 3); |
802 |
+ |
} else |
803 |
+ |
(*putreal)(r->ron, 3); |
804 |
|
} |
805 |
|
|
806 |
|
|
811 |
|
{ |
812 |
|
FVECT pnorm; |
813 |
|
|
814 |
< |
if (r->rot >= FHUGE) { |
814 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
815 |
|
(*putreal)(vdummy, 3); |
816 |
|
return; |
817 |
|
} |
849 |
|
RAY *r |
850 |
|
) |
851 |
|
{ |
852 |
< |
RREAL contr[3]; |
852 |
> |
SCOLOR contr; |
853 |
|
/* shadow ray not on source? */ |
854 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
855 |
< |
setcolor(contr, 0.0, 0.0, 0.0); |
855 |
> |
scolorblack(contr); |
856 |
|
else |
857 |
|
raycontrib(contr, r, PRIMARY); |
858 |
|
|
859 |
< |
(*putreal)(contr, 3); |
859 |
> |
putscolor(contr); |
860 |
|
} |
861 |
|
|
862 |
|
|
918 |
|
|
919 |
|
|
920 |
|
static void |
921 |
< |
putd(RREAL *v, int n) /* print binary double(s) */ |
921 |
> |
putd(RREAL *v, int n) /* output binary double(s) */ |
922 |
|
{ |
923 |
|
#ifdef SMLFLT |
924 |
< |
double da[3]; |
924 |
> |
double da[MAXCSAMP]; |
925 |
|
int i; |
926 |
|
|
927 |
< |
if (n > 3) |
927 |
> |
if (n > MAXCSAMP) |
928 |
|
error(INTERNAL, "code error in putd()"); |
929 |
|
for (i = n; i--; ) |
930 |
|
da[i] = v[i]; |
936 |
|
|
937 |
|
|
938 |
|
static void |
939 |
< |
putf(RREAL *v, int n) /* print binary float(s) */ |
939 |
> |
putf(RREAL *v, int n) /* output binary float(s) */ |
940 |
|
{ |
941 |
|
#ifndef SMLFLT |
942 |
< |
float fa[3]; |
942 |
> |
float fa[MAXCSAMP]; |
943 |
|
int i; |
944 |
|
|
945 |
< |
if (n > 3) |
945 |
> |
if (n > MAXCSAMP) |
946 |
|
error(INTERNAL, "code error in putf()"); |
947 |
|
for (i = n; i--; ) |
948 |
|
fa[i] = v[i]; |
950 |
|
#else |
951 |
|
putbinary(v, sizeof(RREAL), n, stdout); |
952 |
|
#endif |
953 |
+ |
} |
954 |
+ |
|
955 |
+ |
|
956 |
+ |
static void |
957 |
+ |
putscolor(COLORV *scol) /* output (spectral) color */ |
958 |
+ |
{ |
959 |
+ |
static COLORMAT xyz2myrgbmat; |
960 |
+ |
SCOLOR my_scol; |
961 |
+ |
COLOR col; |
962 |
+ |
/* apply scalefactor if any */ |
963 |
+ |
if (out_scalefactor != 1.) { |
964 |
+ |
copyscolor(my_scol, scol); |
965 |
+ |
scalescolor(my_scol, out_scalefactor); |
966 |
+ |
scol = my_scol; |
967 |
+ |
} |
968 |
+ |
if (sens_curve != NULL) { /* single channel output */ |
969 |
+ |
RREAL v = (*sens_curve)(scol); |
970 |
+ |
(*putreal)(&v, 1); |
971 |
+ |
return; |
972 |
+ |
} |
973 |
+ |
if (out_prims == NULL) { /* full spectral reporting */ |
974 |
+ |
if (outform == 'c') { |
975 |
+ |
SCOLR sclr; |
976 |
+ |
scolor_scolr(sclr, scol); |
977 |
+ |
putbinary(sclr, LSCOLR, 1, stdout); |
978 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
979 |
+ |
RREAL sreal[MAXCSAMP]; |
980 |
+ |
int i = NCSAMP; |
981 |
+ |
while (i--) sreal[i] = scol[i]; |
982 |
+ |
(*putreal)(sreal, NCSAMP); |
983 |
+ |
} else |
984 |
+ |
(*putreal)((RREAL *)scol, NCSAMP); |
985 |
+ |
return; |
986 |
+ |
} |
987 |
+ |
if (out_prims == xyzprims) { |
988 |
+ |
scolor_cie(col, scol); |
989 |
+ |
} else if (out_prims == stdprims) { |
990 |
+ |
scolor_rgb(col, scol); |
991 |
+ |
} else { |
992 |
+ |
COLOR xyz; |
993 |
+ |
if (xyz2myrgbmat[0][0] == 0) |
994 |
+ |
compxyz2rgbWBmat(xyz2myrgbmat, out_prims); |
995 |
+ |
scolor_cie(xyz, scol); |
996 |
+ |
colortrans(col, xyz2myrgbmat, xyz); |
997 |
+ |
clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); |
998 |
+ |
} |
999 |
+ |
if (outform == 'c') { |
1000 |
+ |
COLR clr; |
1001 |
+ |
setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU)); |
1002 |
+ |
putbinary(clr, sizeof(COLR), 1, stdout); |
1003 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
1004 |
+ |
RREAL creal[3]; |
1005 |
+ |
copycolor(creal, col); |
1006 |
+ |
(*putreal)(creal, 3); |
1007 |
+ |
} else |
1008 |
+ |
(*putreal)((RREAL *)col, 3); |
1009 |
|
} |