1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* rtrace.c - program and variables for individual ray tracing. |
9 |
– |
* |
10 |
– |
* 6/11/86 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
/* |
11 |
|
* Input is in the form: |
12 |
|
* |
17 |
|
* All values default to ascii representation of real |
18 |
|
* numbers. Binary representations can be selected |
19 |
|
* with '-ff' for float or '-fd' for double. By default, |
20 |
< |
* radiance is computed. The '-i' option indicates that |
20 |
> |
* radiance is computed. The '-i' or '-I' options indicate that |
21 |
|
* irradiance values are desired. |
22 |
|
*/ |
23 |
|
|
24 |
< |
#include "ray.h" |
24 |
> |
#include <time.h> |
25 |
|
|
26 |
< |
#include "octree.h" |
27 |
< |
|
26 |
> |
#include "platform.h" |
27 |
> |
#include "ray.h" |
28 |
> |
#include "ambient.h" |
29 |
> |
#include "source.h" |
30 |
|
#include "otypes.h" |
31 |
+ |
#include "otspecial.h" |
32 |
+ |
#include "resolu.h" |
33 |
+ |
#include "random.h" |
34 |
|
|
35 |
< |
int inform = 'a'; /* input format */ |
36 |
< |
int outform = 'a'; /* output format */ |
37 |
< |
char *outvals = "v"; /* output specification */ |
35 |
> |
extern int inform; /* input format */ |
36 |
> |
extern int outform; /* output format */ |
37 |
> |
extern char *outvals; /* output values */ |
38 |
|
|
39 |
< |
int hresolu = 0; /* horizontal (scan) size */ |
40 |
< |
int vresolu = 0; /* vertical resolution */ |
39 |
> |
extern int imm_irrad; /* compute immediate irradiance? */ |
40 |
> |
extern int lim_dist; /* limit distance? */ |
41 |
|
|
42 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
43 |
< |
double shadthresh = .05; /* shadow threshold */ |
42 |
< |
double shadcert = .5; /* shadow certainty */ |
42 |
> |
extern char *tralist[]; /* list of modifers to trace (or no) */ |
43 |
> |
extern int traincl; /* include == 1, exclude == 0 */ |
44 |
|
|
45 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
46 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
45 |
> |
extern int hresolu; /* horizontal resolution */ |
46 |
> |
extern int vresolu; /* vertical resolution */ |
47 |
|
|
48 |
< |
COLOR ambval = BLKCOLOR; /* ambient value */ |
48 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
49 |
< |
int ambres = 32; /* ambient resolution */ |
50 |
< |
int ambdiv = 128; /* ambient divisions */ |
51 |
< |
int ambssamp = 0; /* ambient super-samples */ |
52 |
< |
int ambounce = 0; /* ambient bounces */ |
53 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
54 |
< |
int ambincl = -1; /* include == 1, exclude == 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 RAY thisray; /* for our convenience */ |
56 |
|
|
57 |
< |
static int oputo(), oputd(), oputv(), oputl(), |
59 |
< |
oputp(), oputn(), oputs(), oputw(), oputm(); |
57 |
> |
static FILE *inpfp = NULL; /* input stream pointer */ |
58 |
|
|
59 |
< |
static int (*ray_out[10])(), (*every_out[10])(); |
60 |
< |
static int castonly; |
59 |
> |
static FVECT *inp_queue = NULL; /* ray input queue if flushing */ |
60 |
> |
static int inp_qpos = 0; /* next ray to return */ |
61 |
> |
static int inp_qend = 0; /* number of rays in this work group */ |
62 |
|
|
63 |
< |
static int puta(), putf(), putd(); |
63 |
> |
typedef void putf_t(RREAL *v, int n); |
64 |
> |
static putf_t puta, putd, putf, putrgbe; |
65 |
|
|
66 |
< |
static int (*putreal)(); |
66 |
> |
typedef void oputf_t(RAY *r); |
67 |
> |
static oputf_t oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp, |
68 |
> |
oputr, oputR, oputx, oputX, oputn, oputN, oputs, |
69 |
> |
oputw, oputW, oputm, oputM, oputtilde; |
70 |
|
|
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); |
76 |
+ |
static void rtcompute(FVECT org, FVECT dir, double dmax); |
77 |
+ |
static int printvals(RAY *r); |
78 |
+ |
static int getvec(FVECT vec, int fmt, FILE *fp); |
79 |
+ |
static int iszerovec(const FVECT vec); |
80 |
+ |
static double nextray(FVECT org, FVECT dir); |
81 |
+ |
static void tabin(RAY *r); |
82 |
+ |
static void ourtrace(RAY *r); |
83 |
|
|
84 |
< |
quit(code) /* quit program */ |
85 |
< |
int code; |
84 |
> |
static oputf_t *ray_out[32], *every_out[32]; |
85 |
> |
static putf_t *putreal; |
86 |
> |
|
87 |
> |
|
88 |
> |
void |
89 |
> |
quit( /* quit program */ |
90 |
> |
int code |
91 |
> |
) |
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 { |
99 |
+ |
headclean(); /* delete header file */ |
100 |
+ |
pfclean(); /* clean up persist files */ |
101 |
+ |
} |
102 |
+ |
#endif |
103 |
|
exit(code); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
< |
rtrace(fname) /* trace rays from file */ |
108 |
< |
char *fname; |
107 |
> |
char * |
108 |
> |
formstr( /* return format identifier */ |
109 |
> |
int f |
110 |
> |
) |
111 |
|
{ |
112 |
< |
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
113 |
< |
long nextflush = hresolu; |
112 |
> |
switch (f) { |
113 |
> |
case 'a': return("ascii"); |
114 |
> |
case 'f': return("float"); |
115 |
> |
case 'd': return("double"); |
116 |
> |
case 'c': return(COLRFMT); |
117 |
> |
} |
118 |
> |
return("unknown"); |
119 |
> |
} |
120 |
> |
|
121 |
> |
|
122 |
> |
void |
123 |
> |
rtrace( /* trace rays from file */ |
124 |
> |
char *fname, |
125 |
> |
int nproc |
126 |
> |
) |
127 |
> |
{ |
128 |
> |
unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu |
129 |
> |
: (unsigned long)vresolu; |
130 |
> |
long nextflush = (!vresolu | (hresolu <= 1)) * hresolu; |
131 |
> |
int something2flush = 0; |
132 |
|
FILE *fp; |
133 |
+ |
double d; |
134 |
|
FVECT orig, direc; |
135 |
|
/* set up input */ |
136 |
|
if (fname == NULL) |
137 |
< |
fp = stdin; |
138 |
< |
else if ((fp = fopen(fname, "r")) == NULL) { |
137 |
> |
inpfp = stdin; |
138 |
> |
else if ((inpfp = fopen(fname, "r")) == NULL) { |
139 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
140 |
|
error(SYSTEM, errmsg); |
141 |
|
} |
142 |
+ |
#ifdef getc_unlocked |
143 |
+ |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
144 |
+ |
flockfile(stdout); |
145 |
+ |
#endif |
146 |
+ |
if (inform != 'a') |
147 |
+ |
SET_FILE_BINARY(inpfp); |
148 |
|
/* set up output */ |
149 |
< |
setoutput(outvals); |
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"); |
153 |
> |
nproc = nextflush; |
154 |
> |
} |
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 |
|
} |
166 |
< |
/* process file */ |
167 |
< |
while (getvec(orig, inform, fp) == 0 && |
168 |
< |
getvec(direc, inform, fp) == 0) { |
169 |
< |
|
170 |
< |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
171 |
< |
fflush(stdout); |
172 |
< |
continue; |
104 |
< |
} |
105 |
< |
/* compute and print */ |
106 |
< |
if (outvals[0] == 'i') |
107 |
< |
irrad(orig, direc); |
166 |
> |
if (nproc > 1) { /* start multiprocessing */ |
167 |
> |
ray_popen(nproc); |
168 |
> |
ray_fifo_out = printvals; |
169 |
> |
} |
170 |
> |
if (hresolu > 0) { |
171 |
> |
if (vresolu > 0) |
172 |
> |
fprtresolu(hresolu, vresolu, stdout); |
173 |
|
else |
109 |
– |
radiance(orig, direc); |
110 |
– |
/* flush if time */ |
111 |
– |
if (--nextflush == 0) { |
174 |
|
fflush(stdout); |
175 |
< |
nextflush = hresolu; |
175 |
> |
} |
176 |
> |
/* process input rays */ |
177 |
> |
while ((d = nextray(orig, direc)) >= 0.0) { |
178 |
> |
if (d == 0.0) { /* flush request? */ |
179 |
> |
if (something2flush) { |
180 |
> |
if (ray_pnprocs > 1 && ray_fifo_flush() < 0) |
181 |
> |
error(USER, "child(ren) died"); |
182 |
> |
bogusray(); |
183 |
> |
fflush(stdout); |
184 |
> |
nextflush = (!vresolu | (hresolu <= 1)) * hresolu; |
185 |
> |
something2flush = 0; |
186 |
> |
} else |
187 |
> |
bogusray(); |
188 |
> |
} else { /* compute and print */ |
189 |
> |
rtcompute(orig, direc, lim_dist ? d : 0.0); |
190 |
> |
if (!--nextflush) { /* flush if time */ |
191 |
> |
if (ray_pnprocs > 1 && ray_fifo_flush() < 0) |
192 |
> |
error(USER, "child(ren) died"); |
193 |
> |
fflush(stdout); |
194 |
> |
nextflush = hresolu; |
195 |
> |
} else |
196 |
> |
something2flush = 1; |
197 |
|
} |
198 |
|
if (ferror(stdout)) |
199 |
|
error(SYSTEM, "write error"); |
200 |
< |
if (--vcount == 0) /* check for end */ |
200 |
> |
if (vcount && !--vcount) /* check for end */ |
201 |
|
break; |
202 |
|
} |
203 |
< |
if (vcount > 0) |
204 |
< |
error(USER, "read error"); |
205 |
< |
fclose(fp); |
203 |
> |
if (ray_pnprocs > 1) { /* clean up children */ |
204 |
> |
if (ray_fifo_flush() < 0) |
205 |
> |
error(USER, "unable to complete processing"); |
206 |
> |
ray_pclose(0); |
207 |
> |
} |
208 |
> |
if (vcount) |
209 |
> |
error(WARNING, "unexpected EOF on input"); |
210 |
> |
if (fflush(stdout) < 0) |
211 |
> |
error(SYSTEM, "write error"); |
212 |
> |
if (fname != NULL) { |
213 |
> |
fclose(inpfp); |
214 |
> |
inpfp = NULL; |
215 |
> |
} |
216 |
> |
nextray(NULL, NULL); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
< |
setoutput(vs) /* set up output tables */ |
221 |
< |
register char *vs; |
220 |
> |
static void |
221 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
222 |
|
{ |
223 |
< |
extern int ourtrace(), (*trace)(); |
224 |
< |
register int (**table)() = ray_out; |
223 |
> |
int sn; |
224 |
> |
|
225 |
> |
for (sn = 0; sn < nsources; sn++) |
226 |
> |
source[sn].sflags |= SFOLLOW; |
227 |
> |
} |
228 |
|
|
229 |
< |
castonly = 1; |
230 |
< |
while (*vs) |
231 |
< |
switch (*vs++) { |
229 |
> |
|
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 |
> |
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[1]) break; |
245 |
> |
trace_sources(); |
246 |
> |
/* fall through */ |
247 |
|
case 't': /* trace */ |
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 'l': /* length */ |
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': /* normal */ |
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, |
335 |
+ |
"-otW accuracy depends on -aa 0 -as 0"); |
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"); |
363 |
+ |
if ((do_irrad | imm_irrad) && |
364 |
+ |
(*table == oputr) | (*table == oputR) | |
365 |
+ |
(*table == oputx) | (*table == oputX)) |
366 |
+ |
error(WARNING, "-orRxX options incompatible with -I+ and -i+"); |
367 |
+ |
} |
368 |
+ |
return(ncomp); |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
< |
radiance(org, dir) /* compute radiance value */ |
373 |
< |
FVECT org, dir; |
372 |
> |
static void |
373 |
> |
bogusray(void) /* print out empty record */ |
374 |
|
{ |
375 |
< |
register int (**tp)(); |
375 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
376 |
> |
printvals(&thisray); |
377 |
> |
} |
378 |
|
|
180 |
– |
VCOPY(thisray.rorg, org); |
181 |
– |
VCOPY(thisray.rdir, dir); |
182 |
– |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
183 |
– |
if (castonly) |
184 |
– |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
185 |
– |
else |
186 |
– |
rayvalue(&thisray); |
379 |
|
|
380 |
< |
if (ray_out[0] == NULL) |
380 |
> |
static void |
381 |
> |
raycast( /* compute first ray intersection only */ |
382 |
> |
RAY *r |
383 |
> |
) |
384 |
> |
{ |
385 |
> |
if (!localhit(r, &thescene)) { |
386 |
> |
if (r->ro == &Aftplane) { /* clipped */ |
387 |
> |
r->ro = NULL; |
388 |
> |
r->rot = FHUGE; |
389 |
> |
} else |
390 |
> |
sourcehit(r); |
391 |
> |
} |
392 |
> |
} |
393 |
> |
|
394 |
> |
|
395 |
> |
static void |
396 |
> |
rayirrad( /* compute irradiance rather than radiance */ |
397 |
> |
RAY *r |
398 |
> |
) |
399 |
> |
{ |
400 |
> |
void (*old_revf)(RAY *) = r->revf; |
401 |
> |
/* pretend we hit surface */ |
402 |
> |
r->rxt = r->rot = 1e-5; |
403 |
> |
VSUM(r->rop, r->rorg, r->rdir, r->rot); |
404 |
> |
r->ron[0] = -r->rdir[0]; |
405 |
> |
r->ron[1] = -r->rdir[1]; |
406 |
> |
r->ron[2] = -r->rdir[2]; |
407 |
> |
r->rod = 1.0; |
408 |
> |
/* compute result */ |
409 |
> |
r->revf = raytrace; |
410 |
> |
(*ofun[Lamb.otype].funp)(&Lamb, r); |
411 |
> |
r->revf = old_revf; |
412 |
> |
} |
413 |
> |
|
414 |
> |
|
415 |
> |
static void |
416 |
> |
rtcompute( /* compute and print ray value(s) */ |
417 |
> |
FVECT org, |
418 |
> |
FVECT dir, |
419 |
> |
double dmax |
420 |
> |
) |
421 |
> |
{ |
422 |
> |
/* set up ray */ |
423 |
> |
if (imm_irrad) { |
424 |
> |
VSUM(thisray.rorg, org, dir, 1.1e-4); |
425 |
> |
thisray.rdir[0] = -dir[0]; |
426 |
> |
thisray.rdir[1] = -dir[1]; |
427 |
> |
thisray.rdir[2] = -dir[2]; |
428 |
> |
thisray.rmax = 0.0; |
429 |
> |
} else { |
430 |
> |
VCOPY(thisray.rorg, org); |
431 |
> |
VCOPY(thisray.rdir, dir); |
432 |
> |
thisray.rmax = dmax; |
433 |
> |
} |
434 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
435 |
> |
if (imm_irrad) |
436 |
> |
thisray.revf = rayirrad; |
437 |
> |
else if (castonly) |
438 |
> |
thisray.revf = raycast; |
439 |
> |
if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ |
440 |
> |
if (ray_fifo_in(&thisray) < 0) |
441 |
> |
error(USER, "lost children"); |
442 |
|
return; |
443 |
+ |
} |
444 |
+ |
samplendx++; /* else do it ourselves */ |
445 |
+ |
rayvalue(&thisray); |
446 |
+ |
printvals(&thisray); |
447 |
+ |
} |
448 |
+ |
|
449 |
+ |
|
450 |
+ |
static int |
451 |
+ |
printvals( /* print requested ray values */ |
452 |
+ |
RAY *r |
453 |
+ |
) |
454 |
+ |
{ |
455 |
+ |
oputf_t **tp; |
456 |
+ |
|
457 |
+ |
if (ray_out[0] == NULL) |
458 |
+ |
return(0); |
459 |
|
for (tp = ray_out; *tp != NULL; tp++) |
460 |
< |
(**tp)(&thisray); |
460 |
> |
(**tp)(r); |
461 |
|
if (outform == 'a') |
462 |
|
putchar('\n'); |
463 |
+ |
return(1); |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
< |
irrad(org, dir) /* compute irradiance value */ |
468 |
< |
FVECT org, dir; |
467 |
> |
static int |
468 |
> |
is_fifo( /* check if file pointer connected to pipe */ |
469 |
> |
FILE *fp |
470 |
> |
) |
471 |
|
{ |
472 |
< |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
473 |
< |
static OBJREC Lamb = { |
202 |
< |
OVOID, MAT_PLASTIC, "Lambertian", |
203 |
< |
{0, 5, NULL, Lambfa}, NULL, -1, |
204 |
< |
}; |
205 |
< |
register int i; |
472 |
> |
#ifdef S_ISFIFO |
473 |
> |
struct stat sbuf; |
474 |
|
|
475 |
< |
for (i = 0; i < 3; i++) { |
476 |
< |
thisray.rorg[i] = org[i] + dir[i]; |
477 |
< |
thisray.rdir[i] = -dir[i]; |
478 |
< |
} |
479 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
480 |
< |
/* pretend we hit surface */ |
213 |
< |
thisray.rot = 1.0; |
214 |
< |
thisray.rod = 1.0; |
215 |
< |
VCOPY(thisray.ron, dir); |
216 |
< |
for (i = 0; i < 3; i++) /* fudge factor */ |
217 |
< |
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
218 |
< |
/* compute and print */ |
219 |
< |
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
220 |
< |
oputv(&thisray); |
221 |
< |
if (outform == 'a') |
222 |
< |
putchar('\n'); |
475 |
> |
if (fstat(fileno(fp), &sbuf) < 0) |
476 |
> |
error(SYSTEM, "fstat() failed on input stream"); |
477 |
> |
return(S_ISFIFO(sbuf.st_mode)); |
478 |
> |
#else |
479 |
> |
return (fp == stdin); /* just a guess, really */ |
480 |
> |
#endif |
481 |
|
} |
482 |
|
|
483 |
|
|
484 |
< |
getvec(vec, fmt, fp) /* get a vector from fp */ |
485 |
< |
register FVECT vec; |
486 |
< |
int fmt; |
487 |
< |
FILE *fp; |
484 |
> |
static int |
485 |
> |
getvec( /* get a vector from fp */ |
486 |
> |
FVECT vec, |
487 |
> |
int fmt, |
488 |
> |
FILE *fp |
489 |
> |
) |
490 |
|
{ |
491 |
|
static float vf[3]; |
492 |
+ |
static double vd[3]; |
493 |
+ |
char buf[32]; |
494 |
+ |
int i; |
495 |
|
|
496 |
|
switch (fmt) { |
497 |
|
case 'a': /* ascii */ |
498 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
499 |
< |
return(-1); |
498 |
> |
for (i = 0; i < 3; i++) { |
499 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
500 |
> |
!isflt(buf)) |
501 |
> |
return(-1); |
502 |
> |
vec[i] = atof(buf); |
503 |
> |
} |
504 |
|
break; |
505 |
|
case 'f': /* binary float */ |
506 |
< |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
506 |
> |
if (getbinary(vf, sizeof(float), 3, fp) != 3) |
507 |
|
return(-1); |
508 |
< |
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
508 |
> |
VCOPY(vec, vf); |
509 |
|
break; |
510 |
|
case 'd': /* binary double */ |
511 |
< |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
511 |
> |
if (getbinary(vd, sizeof(double), 3, fp) != 3) |
512 |
|
return(-1); |
513 |
+ |
VCOPY(vec, vd); |
514 |
|
break; |
515 |
+ |
default: |
516 |
+ |
error(CONSISTENCY, "botched input format"); |
517 |
|
} |
518 |
|
return(0); |
519 |
|
} |
520 |
|
|
521 |
|
|
522 |
< |
static |
523 |
< |
ourtrace(r) /* print ray values */ |
254 |
< |
RAY *r; |
522 |
> |
static int |
523 |
> |
iszerovec(const FVECT vec) |
524 |
|
{ |
525 |
< |
register int (**tp)(); |
525 |
> |
return (vec[0] == 0.0) & (vec[1] == 0.0) & (vec[2] == 0.0); |
526 |
> |
} |
527 |
|
|
528 |
+ |
|
529 |
+ |
static double |
530 |
+ |
nextray( /* return next ray in work group (-1.0 if EOF) */ |
531 |
+ |
FVECT org, |
532 |
+ |
FVECT dir |
533 |
+ |
) |
534 |
+ |
{ |
535 |
+ |
const size_t qlength = !vresolu * hresolu; |
536 |
+ |
|
537 |
+ |
if ((org == NULL) | (dir == NULL)) { |
538 |
+ |
if (inp_queue != NULL) /* asking to free queue */ |
539 |
+ |
free(inp_queue); |
540 |
+ |
inp_queue = NULL; |
541 |
+ |
inp_qpos = inp_qend = 0; |
542 |
+ |
return(-1.); |
543 |
+ |
} |
544 |
+ |
if (!inp_qend) { /* initialize FIFO queue */ |
545 |
+ |
int rsiz = 6*20; /* conservative ascii ray size */ |
546 |
+ |
if (inform == 'f') rsiz = 6*sizeof(float); |
547 |
+ |
else if (inform == 'd') rsiz = 6*sizeof(double); |
548 |
+ |
/* check against pipe limit */ |
549 |
+ |
if (qlength*rsiz > 512 && is_fifo(inpfp)) |
550 |
+ |
inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength); |
551 |
+ |
inp_qend = -(inp_queue == NULL); /* flag for no queue */ |
552 |
+ |
} |
553 |
+ |
if (inp_qend < 0) { /* not queuing? */ |
554 |
+ |
if (getvec(org, inform, inpfp) < 0 || |
555 |
+ |
getvec(dir, inform, inpfp) < 0) |
556 |
+ |
return(-1.); |
557 |
+ |
return normalize(dir); |
558 |
+ |
} |
559 |
+ |
if (inp_qpos >= inp_qend) { /* need to refill input queue? */ |
560 |
+ |
for (inp_qend = 0; inp_qend < qlength; inp_qend++) { |
561 |
+ |
if (getvec(inp_queue[2*inp_qend], inform, inpfp) < 0 |
562 |
+ |
|| getvec(inp_queue[2*inp_qend+1], |
563 |
+ |
inform, inpfp) < 0) |
564 |
+ |
break; /* hit EOF */ |
565 |
+ |
if (iszerovec(inp_queue[2*inp_qend+1])) { |
566 |
+ |
++inp_qend; /* flush request */ |
567 |
+ |
break; |
568 |
+ |
} |
569 |
+ |
} |
570 |
+ |
inp_qpos = 0; |
571 |
+ |
} |
572 |
+ |
if (inp_qpos >= inp_qend) /* unexpected EOF? */ |
573 |
+ |
return(-1.); |
574 |
+ |
VCOPY(org, inp_queue[2*inp_qpos]); |
575 |
+ |
VCOPY(dir, inp_queue[2*inp_qpos+1]); |
576 |
+ |
++inp_qpos; |
577 |
+ |
return normalize(dir); |
578 |
+ |
} |
579 |
+ |
|
580 |
+ |
|
581 |
+ |
void |
582 |
+ |
tranotify( /* record new modifier */ |
583 |
+ |
OBJECT obj |
584 |
+ |
) |
585 |
+ |
{ |
586 |
+ |
static int hitlimit = 0; |
587 |
+ |
OBJREC *o = objptr(obj); |
588 |
+ |
char **tralp; |
589 |
+ |
|
590 |
+ |
if (obj == OVOID) { /* starting over */ |
591 |
+ |
traset[0] = 0; |
592 |
+ |
hitlimit = 0; |
593 |
+ |
return; |
594 |
+ |
} |
595 |
+ |
if (hitlimit || !ismodifier(o->otype)) |
596 |
+ |
return; |
597 |
+ |
for (tralp = tralist; *tralp != NULL; tralp++) |
598 |
+ |
if (!strcmp(o->oname, *tralp)) { |
599 |
+ |
if (traset[0] >= MAXTSET) { |
600 |
+ |
error(WARNING, "too many modifiers in trace list"); |
601 |
+ |
hitlimit++; |
602 |
+ |
return; /* should this be fatal? */ |
603 |
+ |
} |
604 |
+ |
insertelem(traset, obj); |
605 |
+ |
return; |
606 |
+ |
} |
607 |
+ |
} |
608 |
+ |
|
609 |
+ |
|
610 |
+ |
static void |
611 |
+ |
ourtrace( /* print ray values */ |
612 |
+ |
RAY *r |
613 |
+ |
) |
614 |
+ |
{ |
615 |
+ |
oputf_t **tp; |
616 |
+ |
|
617 |
|
if (every_out[0] == NULL) |
618 |
|
return; |
619 |
+ |
if (r->ro == NULL) { |
620 |
+ |
if (traincl == 1) |
621 |
+ |
return; |
622 |
+ |
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
623 |
+ |
return; |
624 |
|
tabin(r); |
625 |
|
for (tp = every_out; *tp != NULL; tp++) |
626 |
|
(**tp)(r); |
627 |
< |
putchar('\n'); |
627 |
> |
if (outform == 'a') |
628 |
> |
putchar('\n'); |
629 |
|
} |
630 |
|
|
631 |
|
|
632 |
< |
static |
633 |
< |
tabin(r) /* tab in appropriate amount */ |
634 |
< |
RAY *r; |
632 |
> |
static void |
633 |
> |
tabin( /* tab in appropriate amount */ |
634 |
> |
RAY *r |
635 |
> |
) |
636 |
|
{ |
637 |
< |
register RAY *rp; |
637 |
> |
const RAY *rp; |
638 |
|
|
639 |
|
for (rp = r->parent; rp != NULL; rp = rp->parent) |
640 |
|
putchar('\t'); |
641 |
|
} |
642 |
|
|
643 |
|
|
644 |
< |
static |
645 |
< |
oputo(r) /* print origin */ |
646 |
< |
register RAY *r; |
644 |
> |
static void |
645 |
> |
oputo( /* print origin */ |
646 |
> |
RAY *r |
647 |
> |
) |
648 |
|
{ |
649 |
< |
(*putreal)(r->rorg[0]); |
283 |
< |
(*putreal)(r->rorg[1]); |
284 |
< |
(*putreal)(r->rorg[2]); |
649 |
> |
(*putreal)(r->rorg, 3); |
650 |
|
} |
651 |
|
|
652 |
|
|
653 |
< |
static |
654 |
< |
oputd(r) /* print direction */ |
655 |
< |
register RAY *r; |
653 |
> |
static void |
654 |
> |
oputd( /* print direction */ |
655 |
> |
RAY *r |
656 |
> |
) |
657 |
|
{ |
658 |
< |
(*putreal)(r->rdir[0]); |
293 |
< |
(*putreal)(r->rdir[1]); |
294 |
< |
(*putreal)(r->rdir[2]); |
658 |
> |
(*putreal)(r->rdir, 3); |
659 |
|
} |
660 |
|
|
661 |
|
|
662 |
< |
static |
663 |
< |
oputv(r) /* print value */ |
664 |
< |
register RAY *r; |
662 |
> |
static void |
663 |
> |
oputr( /* print mirrored contribution */ |
664 |
> |
RAY *r |
665 |
> |
) |
666 |
|
{ |
667 |
< |
(*putreal)(colval(r->rcol,RED)); |
668 |
< |
(*putreal)(colval(r->rcol,GRN)); |
669 |
< |
(*putreal)(colval(r->rcol,BLU)); |
667 |
> |
RREAL cval[3]; |
668 |
> |
|
669 |
> |
cval[0] = colval(r->mcol,RED); |
670 |
> |
cval[1] = colval(r->mcol,GRN); |
671 |
> |
cval[2] = colval(r->mcol,BLU); |
672 |
> |
(*putreal)(cval, 3); |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
< |
static |
677 |
< |
oputl(r) /* print length */ |
678 |
< |
register RAY *r; |
676 |
> |
|
677 |
> |
static void |
678 |
> |
oputR( /* print mirrored distance */ |
679 |
> |
RAY *r |
680 |
> |
) |
681 |
|
{ |
682 |
< |
(*putreal)(r->rt); |
682 |
> |
(*putreal)(&r->rmt, 1); |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
< |
static |
687 |
< |
oputp(r) /* print point */ |
688 |
< |
register RAY *r; |
686 |
> |
static void |
687 |
> |
oputx( /* print unmirrored contribution */ |
688 |
> |
RAY *r |
689 |
> |
) |
690 |
|
{ |
691 |
< |
if (r->rot < FHUGE) { |
692 |
< |
(*putreal)(r->rop[0]); |
693 |
< |
(*putreal)(r->rop[1]); |
694 |
< |
(*putreal)(r->rop[2]); |
695 |
< |
} else { |
696 |
< |
(*putreal)(0.0); |
697 |
< |
(*putreal)(0.0); |
698 |
< |
(*putreal)(0.0); |
691 |
> |
RREAL cval[3]; |
692 |
> |
|
693 |
> |
cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED); |
694 |
> |
cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN); |
695 |
> |
cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU); |
696 |
> |
(*putreal)(cval, 3); |
697 |
> |
} |
698 |
> |
|
699 |
> |
|
700 |
> |
static void |
701 |
> |
oputX( /* print unmirrored distance */ |
702 |
> |
RAY *r |
703 |
> |
) |
704 |
> |
{ |
705 |
> |
(*putreal)(&r->rxt, 1); |
706 |
> |
} |
707 |
> |
|
708 |
> |
|
709 |
> |
static void |
710 |
> |
oputv( /* print value */ |
711 |
> |
RAY *r |
712 |
> |
) |
713 |
> |
{ |
714 |
> |
RREAL cval[3]; |
715 |
> |
|
716 |
> |
cval[0] = colval(r->rcol,RED); |
717 |
> |
cval[1] = colval(r->rcol,GRN); |
718 |
> |
cval[2] = colval(r->rcol,BLU); |
719 |
> |
(*putreal)(cval, 3); |
720 |
> |
} |
721 |
> |
|
722 |
> |
|
723 |
> |
static void |
724 |
> |
oputV( /* print value contribution */ |
725 |
> |
RAY *r |
726 |
> |
) |
727 |
> |
{ |
728 |
> |
RREAL contr[3]; |
729 |
> |
|
730 |
> |
raycontrib(contr, r, PRIMARY); |
731 |
> |
multcolor(contr, r->rcol); |
732 |
> |
(*putreal)(contr, 3); |
733 |
> |
} |
734 |
> |
|
735 |
> |
|
736 |
> |
static void |
737 |
> |
oputl( /* print effective distance */ |
738 |
> |
RAY *r |
739 |
> |
) |
740 |
> |
{ |
741 |
> |
RREAL d = raydistance(r); |
742 |
> |
|
743 |
> |
(*putreal)(&d, 1); |
744 |
> |
} |
745 |
> |
|
746 |
> |
|
747 |
> |
static void |
748 |
> |
oputL( /* print single ray length */ |
749 |
> |
RAY *r |
750 |
> |
) |
751 |
> |
{ |
752 |
> |
(*putreal)(&r->rot, 1); |
753 |
> |
} |
754 |
> |
|
755 |
> |
|
756 |
> |
static void |
757 |
> |
oputc( /* print local coordinates */ |
758 |
> |
RAY *r |
759 |
> |
) |
760 |
> |
{ |
761 |
> |
(*putreal)(r->uv, 2); |
762 |
> |
} |
763 |
> |
|
764 |
> |
|
765 |
> |
static RREAL vdummy[3] = {0.0, 0.0, 0.0}; |
766 |
> |
|
767 |
> |
|
768 |
> |
static void |
769 |
> |
oputp( /* print intersection point */ |
770 |
> |
RAY *r |
771 |
> |
) |
772 |
> |
{ |
773 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
774 |
> |
} |
775 |
> |
|
776 |
> |
|
777 |
> |
static void |
778 |
> |
oputN( /* print unperturbed normal */ |
779 |
> |
RAY *r |
780 |
> |
) |
781 |
> |
{ |
782 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
783 |
> |
(*putreal)(vdummy, 3); |
784 |
> |
return; |
785 |
|
} |
786 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
787 |
+ |
FVECT unrm; |
788 |
+ |
unrm[0] = -r->ron[0]; |
789 |
+ |
unrm[1] = -r->ron[1]; |
790 |
+ |
unrm[2] = -r->ron[2]; |
791 |
+ |
(*putreal)(unrm, 3); |
792 |
+ |
} else |
793 |
+ |
(*putreal)(r->ron, 3); |
794 |
|
} |
795 |
|
|
796 |
|
|
797 |
< |
static |
798 |
< |
oputn(r) /* print normal */ |
799 |
< |
register RAY *r; |
797 |
> |
static void |
798 |
> |
oputn( /* print perturbed normal */ |
799 |
> |
RAY *r |
800 |
> |
) |
801 |
|
{ |
802 |
< |
if (r->rot < FHUGE) { |
803 |
< |
(*putreal)(r->ron[0]); |
804 |
< |
(*putreal)(r->ron[1]); |
805 |
< |
(*putreal)(r->ron[2]); |
806 |
< |
} else { |
341 |
< |
(*putreal)(0.0); |
342 |
< |
(*putreal)(0.0); |
343 |
< |
(*putreal)(0.0); |
802 |
> |
FVECT pnorm; |
803 |
> |
|
804 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
805 |
> |
(*putreal)(vdummy, 3); |
806 |
> |
return; |
807 |
|
} |
808 |
+ |
raynormal(pnorm, r); |
809 |
+ |
(*putreal)(pnorm, 3); |
810 |
|
} |
811 |
|
|
812 |
|
|
813 |
< |
static |
814 |
< |
oputs(r) /* print name */ |
815 |
< |
register RAY *r; |
813 |
> |
static void |
814 |
> |
oputs( /* print name */ |
815 |
> |
RAY *r |
816 |
> |
) |
817 |
|
{ |
818 |
|
if (r->ro != NULL) |
819 |
|
fputs(r->ro->oname, stdout); |
823 |
|
} |
824 |
|
|
825 |
|
|
826 |
< |
static |
827 |
< |
oputw(r) /* print weight */ |
828 |
< |
register RAY *r; |
826 |
> |
static void |
827 |
> |
oputw( /* print weight */ |
828 |
> |
RAY *r |
829 |
> |
) |
830 |
|
{ |
831 |
< |
(*putreal)(r->rweight); |
831 |
> |
RREAL rwt = r->rweight; |
832 |
> |
|
833 |
> |
(*putreal)(&rwt, 1); |
834 |
|
} |
835 |
|
|
836 |
|
|
837 |
< |
static |
838 |
< |
oputm(r) /* print modifier */ |
839 |
< |
register RAY *r; |
837 |
> |
static void |
838 |
> |
oputW( /* print coefficient */ |
839 |
> |
RAY *r |
840 |
> |
) |
841 |
|
{ |
842 |
+ |
RREAL contr[3]; |
843 |
+ |
/* shadow ray not on source? */ |
844 |
+ |
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
845 |
+ |
setcolor(contr, 0.0, 0.0, 0.0); |
846 |
+ |
else |
847 |
+ |
raycontrib(contr, r, PRIMARY); |
848 |
+ |
|
849 |
+ |
(*putreal)(contr, 3); |
850 |
+ |
} |
851 |
+ |
|
852 |
+ |
|
853 |
+ |
static void |
854 |
+ |
oputm( /* print modifier */ |
855 |
+ |
RAY *r |
856 |
+ |
) |
857 |
+ |
{ |
858 |
|
if (r->ro != NULL) |
859 |
< |
fputs(objptr(r->ro->omod)->oname, stdout); |
859 |
> |
if (r->ro->omod != OVOID) |
860 |
> |
fputs(objptr(r->ro->omod)->oname, stdout); |
861 |
> |
else |
862 |
> |
fputs(VOIDID, stdout); |
863 |
|
else |
864 |
|
putchar('*'); |
865 |
|
putchar('\t'); |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
< |
static |
870 |
< |
puta(v) /* print ascii value */ |
871 |
< |
double v; |
869 |
> |
static void |
870 |
> |
oputM( /* print material */ |
871 |
> |
RAY *r |
872 |
> |
) |
873 |
|
{ |
874 |
< |
printf("%e\t", v); |
874 |
> |
OBJREC *mat; |
875 |
> |
|
876 |
> |
if (r->ro != NULL) { |
877 |
> |
if ((mat = findmaterial(r->ro)) != NULL) |
878 |
> |
fputs(mat->oname, stdout); |
879 |
> |
else |
880 |
> |
fputs(VOIDID, stdout); |
881 |
> |
} else |
882 |
> |
putchar('*'); |
883 |
> |
putchar('\t'); |
884 |
|
} |
885 |
|
|
886 |
|
|
887 |
< |
static |
888 |
< |
putd(v) /* print binary double */ |
889 |
< |
double v; |
887 |
> |
static void |
888 |
> |
oputtilde( /* output tilde (spacer) */ |
889 |
> |
RAY *r |
890 |
> |
) |
891 |
|
{ |
892 |
< |
fwrite((char *)&v, sizeof(v), 1, stdout); |
892 |
> |
fputs("~\t", stdout); |
893 |
|
} |
894 |
|
|
895 |
|
|
896 |
< |
static |
897 |
< |
putf(v) /* print binary float */ |
898 |
< |
double v; |
896 |
> |
static void |
897 |
> |
puta( /* print ascii value(s) */ |
898 |
> |
RREAL *v, int n |
899 |
> |
) |
900 |
|
{ |
901 |
< |
float f = v; |
901 |
> |
if (n == 3) { |
902 |
> |
printf("%e\t%e\t%e\t", v[0], v[1], v[2]); |
903 |
> |
return; |
904 |
> |
} |
905 |
> |
while (n--) |
906 |
> |
printf("%e\t", *v++); |
907 |
> |
} |
908 |
|
|
909 |
< |
fwrite((char *)&f, sizeof(f), 1, stdout); |
909 |
> |
|
910 |
> |
static void |
911 |
> |
putd(RREAL *v, int n) /* output binary double(s) */ |
912 |
> |
{ |
913 |
> |
#ifdef SMLFLT |
914 |
> |
double da[3]; |
915 |
> |
int i; |
916 |
> |
|
917 |
> |
if (n > 3) |
918 |
> |
error(INTERNAL, "code error in putd()"); |
919 |
> |
for (i = n; i--; ) |
920 |
> |
da[i] = v[i]; |
921 |
> |
putbinary(da, sizeof(double), n, stdout); |
922 |
> |
#else |
923 |
> |
putbinary(v, sizeof(RREAL), n, stdout); |
924 |
> |
#endif |
925 |
> |
} |
926 |
> |
|
927 |
> |
|
928 |
> |
static void |
929 |
> |
putf(RREAL *v, int n) /* output binary float(s) */ |
930 |
> |
{ |
931 |
> |
#ifndef SMLFLT |
932 |
> |
float fa[3]; |
933 |
> |
int i; |
934 |
> |
|
935 |
> |
if (n > 3) |
936 |
> |
error(INTERNAL, "code error in putf()"); |
937 |
> |
for (i = n; i--; ) |
938 |
> |
fa[i] = v[i]; |
939 |
> |
putbinary(fa, sizeof(float), n, stdout); |
940 |
> |
#else |
941 |
> |
putbinary(v, sizeof(RREAL), n, stdout); |
942 |
> |
#endif |
943 |
> |
} |
944 |
> |
|
945 |
> |
|
946 |
> |
static void |
947 |
> |
putrgbe(RREAL *v, int n) /* output RGBE color */ |
948 |
> |
{ |
949 |
> |
COLR cout; |
950 |
> |
|
951 |
> |
if (n != 3) |
952 |
> |
error(INTERNAL, "putrgbe() not called with 3 components"); |
953 |
> |
setcolr(cout, v[0], v[1], v[2]); |
954 |
> |
putbinary(cout, sizeof(cout), 1, stdout); |
955 |
|
} |