ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtrace.c
Revision: 2.106
Committed: Mon Feb 6 22:40:21 2023 UTC (15 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4
Changes since 2.105: +2 -2 lines
Log Message:
refactor: Changed some char* args to const char* to avoid warnings

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.106 static const char RCSid[] = "$Id: rtrace.c,v 2.105 2023/02/02 18:45:23 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * rtrace.c - program and variables for individual ray tracing.
6 greg 2.27 */
7    
8 greg 2.28 #include "copyright.h"
9 greg 1.1
10     /*
11     * Input is in the form:
12     *
13     * xorg yorg zorg xdir ydir zdir
14     *
15     * The direction need not be normalized. Output is flexible.
16 greg 1.7 * If the direction vector is (0,0,0), then the output is flushed.
17 greg 1.1 * 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 greg 1.13 * radiance is computed. The '-i' or '-I' options indicate that
21 greg 1.1 * irradiance values are desired.
22     */
23 greg 2.32
24     #include <time.h>
25 greg 1.1
26 schorsch 2.30 #include "platform.h"
27 greg 1.1 #include "ray.h"
28 schorsch 2.37 #include "ambient.h"
29     #include "source.h"
30 greg 1.1 #include "otypes.h"
31 greg 2.72 #include "otspecial.h"
32 greg 2.6 #include "resolu.h"
33 schorsch 2.49 #include "random.h"
34 greg 2.6
35 greg 2.57 extern int inform; /* input format */
36     extern int outform; /* output format */
37     extern char *outvals; /* output values */
38 greg 2.27
39 greg 2.57 extern int imm_irrad; /* compute immediate irradiance? */
40     extern int lim_dist; /* limit distance? */
41 greg 1.14
42 greg 2.57 extern char *tralist[]; /* list of modifers to trace (or no) */
43     extern int traincl; /* include == 1, exclude == 0 */
44 greg 1.13
45 greg 2.57 extern int hresolu; /* horizontal resolution */
46     extern int vresolu; /* vertical resolution */
47 greg 1.1
48 greg 2.105 extern int castonly; /* only doing ray-casting? */
49 greg 2.55
50 greg 2.46 #ifndef MAXTSET
51 greg 2.55 #define MAXTSET 8191 /* maximum number in trace set */
52 greg 2.46 #endif
53 greg 2.15 OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */
54    
55 greg 2.102 static int Tflag = 0; /* source tracing enabled? */
56    
57 greg 1.1 static RAY thisray; /* for our convenience */
58    
59 greg 2.89 static FILE *inpfp = NULL; /* input stream pointer */
60    
61     static FVECT *inp_queue = NULL; /* ray input queue if flushing */
62     static int inp_qpos = 0; /* next ray to return */
63     static int inp_qend = 0; /* number of rays in this work group */
64    
65 greg 2.65 typedef void putf_t(RREAL *v, int n);
66 greg 2.80 static putf_t puta, putd, putf, putrgbe;
67 greg 1.1
68 schorsch 2.37 typedef void oputf_t(RAY *r);
69 greg 2.51 static oputf_t oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp,
70 greg 2.73 oputr, oputR, oputx, oputX, oputn, oputN, oputs,
71     oputw, oputW, oputm, oputM, oputtilde;
72 schorsch 2.37
73 greg 2.92 extern void tranotify(OBJECT obj);
74     static int is_fifo(FILE *fp);
75 schorsch 2.37 static void bogusray(void);
76 greg 2.59 static void raycast(RAY *r);
77     static void rayirrad(RAY *r);
78     static void rtcompute(FVECT org, FVECT dir, double dmax);
79 greg 2.57 static int printvals(RAY *r);
80     static int getvec(FVECT vec, int fmt, FILE *fp);
81 greg 2.89 static int iszerovec(const FVECT vec);
82     static double nextray(FVECT org, FVECT dir);
83 greg 2.57 static void tabin(RAY *r);
84     static void ourtrace(RAY *r);
85 greg 1.1
86 greg 2.73 static oputf_t *ray_out[32], *every_out[32];
87 schorsch 2.37 static putf_t *putreal;
88 greg 2.27
89 greg 1.1
90 greg 2.27 void
91 schorsch 2.37 quit( /* quit program */
92     int code
93     )
94 greg 1.1 {
95 greg 2.57 if (ray_pnprocs > 0) /* close children if any */
96     ray_pclose(0);
97 greg 2.99 else if (ray_pnprocs < 0)
98     _exit(code); /* avoid flush() in child */
99 greg 2.57 #ifndef NON_POSIX
100 greg 2.99 else {
101 greg 2.58 headclean(); /* delete header file */
102     pfclean(); /* clean up persist files */
103     }
104 greg 2.11 #endif
105 greg 1.1 exit(code);
106     }
107    
108    
109 greg 2.106 const char *
110 schorsch 2.37 formstr( /* return format identifier */
111     int f
112     )
113 greg 2.6 {
114     switch (f) {
115     case 'a': return("ascii");
116     case 'f': return("float");
117     case 'd': return("double");
118     case 'c': return(COLRFMT);
119     }
120     return("unknown");
121     }
122    
123    
124 greg 2.102 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 greg 2.92 void
135 schorsch 2.37 rtrace( /* trace rays from file */
136 greg 2.59 char *fname,
137     int nproc
138 schorsch 2.37 )
139 greg 1.1 {
140 greg 2.45 unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
141 greg 2.66 : (unsigned long)vresolu;
142 greg 2.85 long nextflush = (!vresolu | (hresolu <= 1)) * hresolu;
143 greg 2.79 int something2flush = 0;
144 greg 1.1 FILE *fp;
145 gregl 2.25 double d;
146 greg 1.2 FVECT orig, direc;
147 greg 1.1 /* set up input */
148     if (fname == NULL)
149 greg 2.89 inpfp = stdin;
150     else if ((inpfp = fopen(fname, "r")) == NULL) {
151 greg 1.1 sprintf(errmsg, "cannot open input file \"%s\"", fname);
152     error(SYSTEM, errmsg);
153     }
154 greg 2.89 #ifdef getc_unlocked
155     flockfile(inpfp); /* avoid lock/unlock overhead */
156     flockfile(stdout);
157     #endif
158 greg 2.8 if (inform != 'a')
159 greg 2.89 SET_FILE_BINARY(inpfp);
160 greg 1.1 /* set up output */
161 greg 2.94 if (castonly || every_out[0] != NULL)
162 greg 2.59 nproc = 1; /* don't bother multiprocessing */
163 greg 2.104 if (every_out[0] != NULL) {
164     trace = ourtrace; /* enable full tree tracing */
165     if (Tflag) /* light sources, too? */
166     trace_sources();
167     }
168 greg 2.79 if ((nextflush > 0) & (nproc > nextflush)) {
169     error(WARNING, "reducing number of processes to match flush interval");
170     nproc = nextflush;
171     }
172 greg 2.59 if (nproc > 1) { /* start multiprocessing */
173     ray_popen(nproc);
174 greg 2.58 ray_fifo_out = printvals;
175 greg 2.59 }
176 greg 2.12 if (hresolu > 0) {
177     if (vresolu > 0)
178     fprtresolu(hresolu, vresolu, stdout);
179 greg 2.78 else
180     fflush(stdout);
181 greg 2.12 }
182 greg 2.89 /* process input rays */
183     while ((d = nextray(orig, direc)) >= 0.0) {
184 greg 2.87 if (d == 0.0) { /* flush request? */
185 greg 2.85 if (something2flush) {
186 greg 2.74 if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
187 greg 2.71 error(USER, "child(ren) died");
188 greg 2.87 bogusray();
189 gregl 2.24 fflush(stdout);
190 greg 2.86 nextflush = (!vresolu | (hresolu <= 1)) * hresolu;
191 greg 2.79 something2flush = 0;
192 greg 2.87 } else
193     bogusray();
194 greg 2.57 } else { /* compute and print */
195 greg 2.59 rtcompute(orig, direc, lim_dist ? d : 0.0);
196 greg 2.89 if (!--nextflush) { /* flush if time */
197 greg 2.74 if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
198 greg 2.71 error(USER, "child(ren) died");
199 gregl 2.24 fflush(stdout);
200     nextflush = hresolu;
201 greg 2.78 } else
202 greg 2.79 something2flush = 1;
203 greg 1.1 }
204     if (ferror(stdout))
205     error(SYSTEM, "write error");
206 greg 2.45 if (vcount && !--vcount) /* check for end */
207 greg 1.1 break;
208     }
209 greg 2.74 if (ray_pnprocs > 1) { /* clean up children */
210 greg 2.59 if (ray_fifo_flush() < 0)
211     error(USER, "unable to complete processing");
212     ray_pclose(0);
213     }
214 greg 2.89 if (vcount)
215     error(WARNING, "unexpected EOF on input");
216 greg 2.50 if (fflush(stdout) < 0)
217     error(SYSTEM, "write error");
218 greg 2.89 if (fname != NULL) {
219     fclose(inpfp);
220     inpfp = NULL;
221     }
222     nextray(NULL, NULL);
223 greg 1.1 }
224    
225    
226 greg 2.91 int
227     setrtoutput(void) /* set up output tables, return #comp */
228 greg 1.1 {
229 greg 2.91 char *vs = outvals;
230 greg 2.56 oputf_t **table = ray_out;
231 greg 2.91 int ncomp = 0;
232    
233     if (!*vs)
234     error(USER, "empty output specification");
235 greg 1.1
236 greg 2.103 switch (outform) { /* make sure (*putreal)() calls someone! */
237     case 'a': putreal = puta; break;
238     case 'f': putreal = putf; break;
239     case 'd': putreal = putd; break;
240     case 'c':
241     if (outvals[1] || !strchr("vrx", outvals[0]))
242     error(USER, "color format only with -ov, -or, -ox");
243     putreal = putrgbe; break;
244     default:
245     error(CONSISTENCY, "botched output format");
246     }
247 greg 2.94 castonly = 1; /* sets castonly as side-effect */
248 greg 2.91 do
249     switch (*vs) {
250 greg 2.40 case 'T': /* trace sources */
251 greg 2.102 Tflag++;
252 greg 2.40 /* fall through */
253 greg 1.1 case 't': /* trace */
254 greg 2.91 if (!vs[1]) break;
255 greg 1.1 *table = NULL;
256     table = every_out;
257 greg 1.11 castonly = 0;
258 greg 1.1 break;
259     case 'o': /* origin */
260     *table++ = oputo;
261 greg 2.91 ncomp += 3;
262 greg 1.1 break;
263     case 'd': /* direction */
264     *table++ = oputd;
265 greg 2.91 ncomp += 3;
266 greg 1.1 break;
267 greg 2.73 case 'r': /* reflected contrib. */
268     *table++ = oputr;
269 greg 2.91 ncomp += 3;
270 greg 2.73 castonly = 0;
271     break;
272     case 'R': /* reflected distance */
273     *table++ = oputR;
274 greg 2.91 ncomp++;
275 greg 2.73 castonly = 0;
276     break;
277     case 'x': /* xmit contrib. */
278     *table++ = oputx;
279 greg 2.91 ncomp += 3;
280 greg 2.73 castonly = 0;
281     break;
282     case 'X': /* xmit distance */
283     *table++ = oputX;
284 greg 2.91 ncomp++;
285 greg 2.73 castonly = 0;
286     break;
287 greg 1.1 case 'v': /* value */
288     *table++ = oputv;
289 greg 2.91 ncomp += 3;
290 greg 1.11 castonly = 0;
291 greg 1.1 break;
292 greg 2.51 case 'V': /* contribution */
293     *table++ = oputV;
294 greg 2.91 ncomp += 3;
295 greg 2.94 castonly = 0;
296 greg 2.51 if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
297     error(WARNING,
298     "-otV accuracy depends on -aa 0 -as 0");
299     break;
300 greg 2.5 case 'l': /* effective distance */
301 greg 1.1 *table++ = oputl;
302 greg 2.91 ncomp++;
303 greg 1.11 castonly = 0;
304 greg 1.1 break;
305 greg 2.29 case 'c': /* local coordinates */
306     *table++ = oputc;
307 greg 2.91 ncomp += 2;
308 greg 2.29 break;
309 greg 2.5 case 'L': /* single ray length */
310     *table++ = oputL;
311 greg 2.91 ncomp++;
312 greg 2.5 break;
313 greg 1.1 case 'p': /* point */
314     *table++ = oputp;
315 greg 2.91 ncomp += 3;
316 greg 1.1 break;
317 greg 2.9 case 'n': /* perturbed normal */
318 greg 1.1 *table++ = oputn;
319 greg 2.91 ncomp += 3;
320 greg 2.9 castonly = 0;
321 greg 1.1 break;
322 greg 2.9 case 'N': /* unperturbed normal */
323     *table++ = oputN;
324 greg 2.91 ncomp += 3;
325 greg 2.9 break;
326 greg 1.1 case 's': /* surface */
327     *table++ = oputs;
328 greg 2.91 ncomp++;
329 greg 1.1 break;
330     case 'w': /* weight */
331     *table++ = oputw;
332 greg 2.91 ncomp++;
333 greg 1.1 break;
334 greg 2.40 case 'W': /* coefficient */
335     *table++ = oputW;
336 greg 2.91 ncomp += 3;
337 greg 2.73 castonly = 0;
338 greg 2.80 if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0))
339 greg 2.40 error(WARNING,
340 greg 2.41 "-otW accuracy depends on -aa 0 -as 0");
341 greg 2.40 break;
342 greg 1.1 case 'm': /* modifier */
343     *table++ = oputm;
344 greg 2.91 ncomp++;
345 greg 1.1 break;
346 greg 2.39 case 'M': /* material */
347     *table++ = oputM;
348 greg 2.91 ncomp++;
349 greg 2.39 break;
350 greg 2.42 case '~': /* tilde */
351     *table++ = oputtilde;
352 greg 2.41 break;
353 greg 2.91 default:
354     sprintf(errmsg, "unrecognized output option '%c'", *vs);
355     error(USER, errmsg);
356 greg 1.1 }
357 greg 2.91 while (*++vs);
358    
359 greg 1.1 *table = NULL;
360 greg 2.91 if (*every_out != NULL)
361     ncomp = 0;
362 greg 2.81 /* compatibility */
363 greg 2.94 if ((do_irrad | imm_irrad) && castonly)
364     error(USER, "-I+ and -i+ options require some value output");
365 greg 2.81 for (table = ray_out; *table != NULL; table++) {
366     if ((*table == oputV) | (*table == oputW))
367     error(WARNING, "-oVW options require trace mode");
368     if ((do_irrad | imm_irrad) &&
369     (*table == oputr) | (*table == oputR) |
370     (*table == oputx) | (*table == oputX))
371     error(WARNING, "-orRxX options incompatible with -I+ and -i+");
372     }
373 greg 2.91 return(ncomp);
374 gregl 2.24 }
375    
376    
377 schorsch 2.37 static void
378     bogusray(void) /* print out empty record */
379 gregl 2.24 {
380 greg 2.40 rayorigin(&thisray, PRIMARY, NULL, NULL);
381 gregl 2.24 printvals(&thisray);
382 greg 1.1 }
383    
384    
385 schorsch 2.37 static void
386 greg 2.59 raycast( /* compute first ray intersection only */
387     RAY *r
388 schorsch 2.37 )
389 greg 1.1 {
390 greg 2.59 if (!localhit(r, &thescene)) {
391     if (r->ro == &Aftplane) { /* clipped */
392     r->ro = NULL;
393     r->rot = FHUGE;
394     } else
395     sourcehit(r);
396 greg 2.57 }
397 greg 1.1 }
398    
399    
400 schorsch 2.37 static void
401 greg 2.59 rayirrad( /* compute irradiance rather than radiance */
402     RAY *r
403     )
404     {
405 greg 2.62 void (*old_revf)(RAY *) = r->revf;
406 greg 2.75 /* pretend we hit surface */
407 greg 2.76 r->rxt = r->rot = 1e-5;
408 greg 2.59 VSUM(r->rop, r->rorg, r->rdir, r->rot);
409     r->ron[0] = -r->rdir[0];
410     r->ron[1] = -r->rdir[1];
411     r->ron[2] = -r->rdir[2];
412     r->rod = 1.0;
413 greg 2.62 /* compute result */
414 greg 2.61 r->revf = raytrace;
415 greg 2.59 (*ofun[Lamb.otype].funp)(&Lamb, r);
416 greg 2.62 r->revf = old_revf;
417 greg 2.59 }
418    
419    
420     static void
421     rtcompute( /* compute and print ray value(s) */
422 schorsch 2.37 FVECT org,
423 greg 2.59 FVECT dir,
424     double dmax
425 schorsch 2.37 )
426 greg 1.1 {
427 greg 2.60 /* set up ray */
428     if (imm_irrad) {
429 greg 2.59 VSUM(thisray.rorg, org, dir, 1.1e-4);
430     thisray.rdir[0] = -dir[0];
431     thisray.rdir[1] = -dir[1];
432     thisray.rdir[2] = -dir[2];
433     thisray.rmax = 0.0;
434     } else {
435     VCOPY(thisray.rorg, org);
436     VCOPY(thisray.rdir, dir);
437     thisray.rmax = dmax;
438     }
439 greg 2.101 rayorigin(&thisray, PRIMARY, NULL, NULL);
440     if (imm_irrad)
441     thisray.revf = rayirrad;
442     else if (castonly)
443     thisray.revf = raycast;
444 greg 2.59 if (ray_pnprocs > 1) { /* multiprocessing FIFO? */
445     if (ray_fifo_in(&thisray) < 0)
446     error(USER, "lost children");
447     return;
448     }
449     samplendx++; /* else do it ourselves */
450     rayvalue(&thisray);
451 greg 2.16 printvals(&thisray);
452     }
453    
454    
455 greg 2.57 static int
456 schorsch 2.37 printvals( /* print requested ray values */
457     RAY *r
458     )
459 greg 2.16 {
460 greg 2.56 oputf_t **tp;
461 greg 2.16
462     if (ray_out[0] == NULL)
463 greg 2.57 return(0);
464 greg 2.16 for (tp = ray_out; *tp != NULL; tp++)
465     (**tp)(r);
466 greg 1.1 if (outform == 'a')
467     putchar('\n');
468 greg 2.57 return(1);
469 greg 1.1 }
470    
471    
472 schorsch 2.37 static int
473 greg 2.92 is_fifo( /* check if file pointer connected to pipe */
474     FILE *fp
475     )
476     {
477     #ifdef S_ISFIFO
478     struct stat sbuf;
479    
480     if (fstat(fileno(fp), &sbuf) < 0)
481     error(SYSTEM, "fstat() failed on input stream");
482     return(S_ISFIFO(sbuf.st_mode));
483     #else
484     return (fp == stdin); /* just a guess, really */
485     #endif
486     }
487    
488    
489     static int
490 greg 2.89 getvec( /* get a vector from fp */
491 greg 2.56 FVECT vec,
492 schorsch 2.37 int fmt,
493     FILE *fp
494     )
495 greg 1.1 {
496     static float vf[3];
497 greg 2.5 static double vd[3];
498 greg 1.19 char buf[32];
499 greg 2.56 int i;
500 greg 1.1
501     switch (fmt) {
502     case 'a': /* ascii */
503 greg 1.19 for (i = 0; i < 3; i++) {
504     if (fgetword(buf, sizeof(buf), fp) == NULL ||
505     !isflt(buf))
506     return(-1);
507     vec[i] = atof(buf);
508     }
509 greg 1.1 break;
510     case 'f': /* binary float */
511 greg 2.70 if (getbinary(vf, sizeof(float), 3, fp) != 3)
512 greg 1.1 return(-1);
513 greg 2.58 VCOPY(vec, vf);
514 greg 1.1 break;
515     case 'd': /* binary double */
516 greg 2.70 if (getbinary(vd, sizeof(double), 3, fp) != 3)
517 greg 1.1 return(-1);
518 greg 2.58 VCOPY(vec, vd);
519 greg 1.1 break;
520 greg 2.6 default:
521     error(CONSISTENCY, "botched input format");
522 greg 1.1 }
523     return(0);
524     }
525    
526    
527 greg 2.89 static int
528     iszerovec(const FVECT vec)
529     {
530     return (vec[0] == 0.0) & (vec[1] == 0.0) & (vec[2] == 0.0);
531     }
532    
533    
534     static double
535     nextray( /* return next ray in work group (-1.0 if EOF) */
536     FVECT org,
537     FVECT dir
538     )
539     {
540     const size_t qlength = !vresolu * hresolu;
541    
542     if ((org == NULL) | (dir == NULL)) {
543     if (inp_queue != NULL) /* asking to free queue */
544     free(inp_queue);
545     inp_queue = NULL;
546     inp_qpos = inp_qend = 0;
547     return(-1.);
548     }
549     if (!inp_qend) { /* initialize FIFO queue */
550     int rsiz = 6*20; /* conservative ascii ray size */
551     if (inform == 'f') rsiz = 6*sizeof(float);
552     else if (inform == 'd') rsiz = 6*sizeof(double);
553 greg 2.92 /* check against pipe limit */
554     if (qlength*rsiz > 512 && is_fifo(inpfp))
555 greg 2.89 inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength);
556     inp_qend = -(inp_queue == NULL); /* flag for no queue */
557     }
558     if (inp_qend < 0) { /* not queuing? */
559     if (getvec(org, inform, inpfp) < 0 ||
560     getvec(dir, inform, inpfp) < 0)
561     return(-1.);
562     return normalize(dir);
563     }
564     if (inp_qpos >= inp_qend) { /* need to refill input queue? */
565     for (inp_qend = 0; inp_qend < qlength; inp_qend++) {
566     if (getvec(inp_queue[2*inp_qend], inform, inpfp) < 0
567     || getvec(inp_queue[2*inp_qend+1],
568     inform, inpfp) < 0)
569     break; /* hit EOF */
570     if (iszerovec(inp_queue[2*inp_qend+1])) {
571     ++inp_qend; /* flush request */
572     break;
573     }
574     }
575     inp_qpos = 0;
576     }
577     if (inp_qpos >= inp_qend) /* unexpected EOF? */
578     return(-1.);
579     VCOPY(org, inp_queue[2*inp_qpos]);
580     VCOPY(dir, inp_queue[2*inp_qpos+1]);
581     ++inp_qpos;
582     return normalize(dir);
583     }
584    
585    
586 greg 2.57 void
587 schorsch 2.37 tranotify( /* record new modifier */
588     OBJECT obj
589     )
590 greg 2.15 {
591     static int hitlimit = 0;
592 greg 2.56 OBJREC *o = objptr(obj);
593     char **tralp;
594 greg 2.15
595 greg 2.27 if (obj == OVOID) { /* starting over */
596     traset[0] = 0;
597     hitlimit = 0;
598     return;
599     }
600 greg 2.15 if (hitlimit || !ismodifier(o->otype))
601     return;
602     for (tralp = tralist; *tralp != NULL; tralp++)
603     if (!strcmp(o->oname, *tralp)) {
604     if (traset[0] >= MAXTSET) {
605     error(WARNING, "too many modifiers in trace list");
606     hitlimit++;
607     return; /* should this be fatal? */
608     }
609     insertelem(traset, obj);
610     return;
611     }
612     }
613    
614    
615 greg 2.27 static void
616 schorsch 2.37 ourtrace( /* print ray values */
617     RAY *r
618     )
619 greg 1.1 {
620 greg 2.56 oputf_t **tp;
621 greg 1.1
622     if (every_out[0] == NULL)
623 greg 2.15 return;
624 greg 2.16 if (r->ro == NULL) {
625     if (traincl == 1)
626     return;
627     } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
628 greg 1.1 return;
629     tabin(r);
630     for (tp = every_out; *tp != NULL; tp++)
631     (**tp)(r);
632 greg 2.41 if (outform == 'a')
633     putchar('\n');
634 greg 1.1 }
635    
636    
637 greg 2.27 static void
638 schorsch 2.37 tabin( /* tab in appropriate amount */
639     RAY *r
640     )
641 greg 1.1 {
642 greg 2.40 const RAY *rp;
643 greg 1.1
644     for (rp = r->parent; rp != NULL; rp = rp->parent)
645     putchar('\t');
646     }
647    
648    
649 greg 2.27 static void
650 schorsch 2.37 oputo( /* print origin */
651     RAY *r
652     )
653 greg 1.1 {
654 greg 2.65 (*putreal)(r->rorg, 3);
655 greg 1.1 }
656    
657    
658 greg 2.27 static void
659 schorsch 2.37 oputd( /* print direction */
660     RAY *r
661     )
662 greg 1.1 {
663 greg 2.65 (*putreal)(r->rdir, 3);
664 greg 1.1 }
665    
666    
667 greg 2.27 static void
668 greg 2.73 oputr( /* print mirrored contribution */
669     RAY *r
670     )
671     {
672     RREAL cval[3];
673    
674     cval[0] = colval(r->mcol,RED);
675     cval[1] = colval(r->mcol,GRN);
676     cval[2] = colval(r->mcol,BLU);
677     (*putreal)(cval, 3);
678     }
679    
680    
681    
682     static void
683     oputR( /* print mirrored distance */
684     RAY *r
685     )
686     {
687     (*putreal)(&r->rmt, 1);
688     }
689    
690    
691     static void
692     oputx( /* print unmirrored contribution */
693     RAY *r
694     )
695     {
696     RREAL cval[3];
697    
698     cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
699     cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
700     cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
701     (*putreal)(cval, 3);
702     }
703    
704    
705     static void
706     oputX( /* print unmirrored distance */
707     RAY *r
708     )
709     {
710     (*putreal)(&r->rxt, 1);
711     }
712    
713    
714     static void
715 schorsch 2.37 oputv( /* print value */
716     RAY *r
717     )
718 greg 1.1 {
719 greg 2.65 RREAL cval[3];
720    
721     cval[0] = colval(r->rcol,RED);
722     cval[1] = colval(r->rcol,GRN);
723     cval[2] = colval(r->rcol,BLU);
724     (*putreal)(cval, 3);
725 greg 1.1 }
726    
727    
728 greg 2.27 static void
729 greg 2.51 oputV( /* print value contribution */
730     RAY *r
731     )
732     {
733 greg 2.65 RREAL contr[3];
734 greg 2.51
735     raycontrib(contr, r, PRIMARY);
736     multcolor(contr, r->rcol);
737 greg 2.65 (*putreal)(contr, 3);
738 greg 2.51 }
739    
740    
741     static void
742 schorsch 2.37 oputl( /* print effective distance */
743     RAY *r
744     )
745 greg 1.1 {
746 greg 2.73 RREAL d = raydistance(r);
747    
748     (*putreal)(&d, 1);
749 greg 2.5 }
750    
751    
752 greg 2.27 static void
753 schorsch 2.37 oputL( /* print single ray length */
754     RAY *r
755     )
756 greg 2.5 {
757 greg 2.65 (*putreal)(&r->rot, 1);
758 greg 1.1 }
759    
760    
761 greg 2.27 static void
762 schorsch 2.37 oputc( /* print local coordinates */
763     RAY *r
764     )
765 greg 2.29 {
766 greg 2.65 (*putreal)(r->uv, 2);
767 greg 2.29 }
768    
769    
770 greg 2.65 static RREAL vdummy[3] = {0.0, 0.0, 0.0};
771    
772    
773 greg 2.29 static void
774 greg 2.100 oputp( /* print intersection point */
775 schorsch 2.37 RAY *r
776     )
777 greg 1.1 {
778 greg 2.100 (*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */
779 greg 1.1 }
780    
781    
782 greg 2.27 static void
783 schorsch 2.37 oputN( /* print unperturbed normal */
784     RAY *r
785     )
786 greg 1.1 {
787 greg 2.100 if (r->ro == NULL) { /* zero vector if clipped or no hit */
788     (*putreal)(vdummy, 3);
789     return;
790     }
791     if (r->rflips & 1) { /* undo any flippin' flips */
792     FVECT unrm;
793     unrm[0] = -r->ron[0];
794     unrm[1] = -r->ron[1];
795     unrm[2] = -r->ron[2];
796     (*putreal)(unrm, 3);
797 greg 2.82 } else
798 greg 2.100 (*putreal)(r->ron, 3);
799 greg 2.9 }
800    
801    
802 greg 2.27 static void
803 schorsch 2.37 oputn( /* print perturbed normal */
804     RAY *r
805     )
806 greg 2.9 {
807     FVECT pnorm;
808    
809 greg 2.100 if (r->ro == NULL) { /* clipped or no hit */
810 greg 2.65 (*putreal)(vdummy, 3);
811 greg 2.9 return;
812     }
813     raynormal(pnorm, r);
814 greg 2.65 (*putreal)(pnorm, 3);
815 greg 1.1 }
816    
817    
818 greg 2.27 static void
819 schorsch 2.37 oputs( /* print name */
820     RAY *r
821     )
822 greg 1.1 {
823     if (r->ro != NULL)
824     fputs(r->ro->oname, stdout);
825     else
826     putchar('*');
827     putchar('\t');
828     }
829    
830    
831 greg 2.27 static void
832 schorsch 2.37 oputw( /* print weight */
833     RAY *r
834     )
835 greg 1.1 {
836 greg 2.65 RREAL rwt = r->rweight;
837    
838     (*putreal)(&rwt, 1);
839 greg 1.1 }
840    
841    
842 greg 2.27 static void
843 greg 2.51 oputW( /* print coefficient */
844 greg 2.40 RAY *r
845     )
846     {
847 greg 2.65 RREAL contr[3];
848 greg 2.67 /* shadow ray not on source? */
849     if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
850     setcolor(contr, 0.0, 0.0, 0.0);
851     else
852     raycontrib(contr, r, PRIMARY);
853 greg 2.40
854 greg 2.65 (*putreal)(contr, 3);
855 greg 2.40 }
856    
857    
858     static void
859 schorsch 2.37 oputm( /* print modifier */
860     RAY *r
861     )
862 greg 1.1 {
863     if (r->ro != NULL)
864 greg 2.23 if (r->ro->omod != OVOID)
865     fputs(objptr(r->ro->omod)->oname, stdout);
866     else
867     fputs(VOIDID, stdout);
868 greg 1.1 else
869     putchar('*');
870     putchar('\t');
871     }
872    
873    
874 greg 2.27 static void
875 greg 2.39 oputM( /* print material */
876     RAY *r
877     )
878     {
879     OBJREC *mat;
880    
881     if (r->ro != NULL) {
882     if ((mat = findmaterial(r->ro)) != NULL)
883     fputs(mat->oname, stdout);
884     else
885     fputs(VOIDID, stdout);
886     } else
887     putchar('*');
888     putchar('\t');
889     }
890    
891    
892     static void
893 greg 2.42 oputtilde( /* output tilde (spacer) */
894 greg 2.41 RAY *r
895     )
896     {
897 greg 2.42 fputs("~\t", stdout);
898 greg 2.41 }
899    
900    
901     static void
902 greg 2.65 puta( /* print ascii value(s) */
903     RREAL *v, int n
904 schorsch 2.37 )
905 greg 1.1 {
906 greg 2.65 if (n == 3) {
907     printf("%e\t%e\t%e\t", v[0], v[1], v[2]);
908     return;
909     }
910     while (n--)
911     printf("%e\t", *v++);
912 greg 1.1 }
913    
914    
915 greg 2.27 static void
916 greg 2.80 putd(RREAL *v, int n) /* output binary double(s) */
917 greg 1.1 {
918 greg 2.68 #ifdef SMLFLT
919     double da[3];
920     int i;
921    
922     if (n > 3)
923 greg 2.65 error(INTERNAL, "code error in putd()");
924 greg 2.68 for (i = n; i--; )
925     da[i] = v[i];
926 greg 2.69 putbinary(da, sizeof(double), n, stdout);
927 greg 2.68 #else
928 greg 2.69 putbinary(v, sizeof(RREAL), n, stdout);
929 greg 2.68 #endif
930 greg 1.1 }
931    
932    
933 greg 2.27 static void
934 greg 2.80 putf(RREAL *v, int n) /* output binary float(s) */
935 greg 1.1 {
936 greg 2.68 #ifndef SMLFLT
937 greg 2.65 float fa[3];
938     int i;
939 greg 1.1
940 greg 2.65 if (n > 3)
941     error(INTERNAL, "code error in putf()");
942     for (i = n; i--; )
943     fa[i] = v[i];
944 greg 2.69 putbinary(fa, sizeof(float), n, stdout);
945 greg 2.68 #else
946 greg 2.69 putbinary(v, sizeof(RREAL), n, stdout);
947 greg 2.68 #endif
948 greg 1.1 }
949 greg 2.80
950    
951     static void
952     putrgbe(RREAL *v, int n) /* output RGBE color */
953     {
954     COLR cout;
955    
956     if (n != 3)
957     error(INTERNAL, "putrgbe() not called with 3 components");
958     setcolr(cout, v[0], v[1], v[2]);
959     putbinary(cout, sizeof(cout), 1, stdout);
960     }