ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtrace.c
Revision: 2.75
Committed: Thu Mar 28 16:33:36 2019 UTC (5 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.74: +3 -3 lines
Log Message:
Added missing initialization for rmt and rxt

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.75 static const char RCSid[] = "$Id: rtrace.c,v 2.74 2019/01/08 00:16:31 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.57 static int castonly = 0;
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 1.1 static RAY thisray; /* for our convenience */
56    
57 greg 2.65 typedef void putf_t(RREAL *v, int n);
58 schorsch 2.37 static putf_t puta, putd, putf;
59 greg 1.1
60 schorsch 2.37 typedef void oputf_t(RAY *r);
61 greg 2.51 static oputf_t oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp,
62 greg 2.73 oputr, oputR, oputx, oputX, oputn, oputN, oputs,
63     oputw, oputW, oputm, oputM, oputtilde;
64 schorsch 2.37
65     static void setoutput(char *vs);
66 greg 2.57 extern void tranotify(OBJECT obj);
67 schorsch 2.37 static void bogusray(void);
68 greg 2.59 static void raycast(RAY *r);
69     static void rayirrad(RAY *r);
70     static void rtcompute(FVECT org, FVECT dir, double dmax);
71 greg 2.57 static int printvals(RAY *r);
72     static int getvec(FVECT vec, int fmt, FILE *fp);
73     static void tabin(RAY *r);
74     static void ourtrace(RAY *r);
75 greg 1.1
76 greg 2.73 static oputf_t *ray_out[32], *every_out[32];
77 schorsch 2.37 static putf_t *putreal;
78 greg 2.27
79 greg 1.1
80 greg 2.27 void
81 schorsch 2.37 quit( /* quit program */
82     int code
83     )
84 greg 1.1 {
85 greg 2.57 if (ray_pnprocs > 0) /* close children if any */
86     ray_pclose(0);
87     #ifndef NON_POSIX
88 greg 2.58 else if (!ray_pnprocs) {
89     headclean(); /* delete header file */
90     pfclean(); /* clean up persist files */
91     }
92 greg 2.11 #endif
93 greg 1.1 exit(code);
94     }
95    
96    
97 greg 2.57 char *
98 schorsch 2.37 formstr( /* return format identifier */
99     int f
100     )
101 greg 2.6 {
102     switch (f) {
103     case 'a': return("ascii");
104     case 'f': return("float");
105     case 'd': return("double");
106     case 'c': return(COLRFMT);
107     }
108     return("unknown");
109     }
110    
111    
112 schorsch 2.37 extern void
113     rtrace( /* trace rays from file */
114 greg 2.59 char *fname,
115     int nproc
116 schorsch 2.37 )
117 greg 1.1 {
118 greg 2.45 unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
119 greg 2.66 : (unsigned long)vresolu;
120 greg 2.64 long nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : hresolu;
121 greg 1.1 FILE *fp;
122 gregl 2.25 double d;
123 greg 1.2 FVECT orig, direc;
124 greg 1.1 /* set up input */
125     if (fname == NULL)
126     fp = stdin;
127     else if ((fp = fopen(fname, "r")) == NULL) {
128     sprintf(errmsg, "cannot open input file \"%s\"", fname);
129     error(SYSTEM, errmsg);
130     }
131 greg 2.8 if (inform != 'a')
132 schorsch 2.30 SET_FILE_BINARY(fp);
133 greg 1.1 /* set up output */
134 greg 2.16 setoutput(outvals);
135 greg 2.59 if (imm_irrad)
136     castonly = 0;
137     else if (castonly)
138     nproc = 1; /* don't bother multiprocessing */
139 greg 1.1 switch (outform) {
140     case 'a': putreal = puta; break;
141     case 'f': putreal = putf; break;
142     case 'd': putreal = putd; break;
143 greg 2.6 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");
149 greg 1.1 }
150 greg 2.59 if (nproc > 1) { /* start multiprocessing */
151     ray_popen(nproc);
152 greg 2.58 ray_fifo_out = printvals;
153 greg 2.59 }
154 greg 2.12 if (hresolu > 0) {
155     if (vresolu > 0)
156     fprtresolu(hresolu, vresolu, stdout);
157     fflush(stdout);
158     }
159 greg 1.1 /* process file */
160     while (getvec(orig, inform, fp) == 0 &&
161     getvec(direc, inform, fp) == 0) {
162    
163 gregl 2.25 d = normalize(direc);
164     if (d == 0.0) { /* zero ==> flush */
165 greg 2.45 if (--nextflush <= 0 || !vcount) {
166 greg 2.74 if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
167 greg 2.71 error(USER, "child(ren) died");
168 greg 2.63 bogusray();
169 gregl 2.24 fflush(stdout);
170 greg 2.64 nextflush = (vresolu > 0) & (hresolu > 1) ? 0 :
171     hresolu;
172 greg 2.63 } else
173     bogusray();
174 greg 2.57 } else { /* compute and print */
175 greg 2.59 rtcompute(orig, direc, lim_dist ? d : 0.0);
176 greg 1.7 /* flush if time */
177 greg 2.45 if (!--nextflush) {
178 greg 2.74 if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
179 greg 2.71 error(USER, "child(ren) died");
180 gregl 2.24 fflush(stdout);
181     nextflush = hresolu;
182     }
183 greg 1.1 }
184     if (ferror(stdout))
185     error(SYSTEM, "write error");
186 greg 2.45 if (vcount && !--vcount) /* check for end */
187 greg 1.1 break;
188     }
189 greg 2.74 if (ray_pnprocs > 1) { /* clean up children */
190 greg 2.59 if (ray_fifo_flush() < 0)
191     error(USER, "unable to complete processing");
192     ray_pclose(0);
193     }
194 greg 2.50 if (fflush(stdout) < 0)
195     error(SYSTEM, "write error");
196 greg 2.45 if (vcount)
197 greg 2.42 error(USER, "unexpected EOF on input");
198 greg 2.12 if (fname != NULL)
199     fclose(fp);
200 greg 1.1 }
201    
202    
203 schorsch 2.37 static void
204 greg 2.40 trace_sources(void) /* trace rays to light sources, also */
205     {
206     int sn;
207    
208     for (sn = 0; sn < nsources; sn++)
209     source[sn].sflags |= SFOLLOW;
210     }
211    
212    
213     static void
214 schorsch 2.37 setoutput( /* set up output tables */
215 greg 2.56 char *vs
216 schorsch 2.37 )
217 greg 1.1 {
218 greg 2.56 oputf_t **table = ray_out;
219 greg 1.1
220 greg 1.11 castonly = 1;
221 greg 1.1 while (*vs)
222     switch (*vs++) {
223 greg 2.40 case 'T': /* trace sources */
224 greg 2.42 if (!*vs) break;
225 greg 2.40 trace_sources();
226     /* fall through */
227 greg 1.1 case 't': /* trace */
228 greg 2.42 if (!*vs) break;
229 greg 1.1 *table = NULL;
230     table = every_out;
231     trace = ourtrace;
232 greg 1.11 castonly = 0;
233 greg 1.1 break;
234     case 'o': /* origin */
235     *table++ = oputo;
236     break;
237     case 'd': /* direction */
238     *table++ = oputd;
239     break;
240 greg 2.73 case 'r': /* reflected contrib. */
241     *table++ = oputr;
242     castonly = 0;
243     break;
244     case 'R': /* reflected distance */
245     *table++ = oputR;
246     castonly = 0;
247     break;
248     case 'x': /* xmit contrib. */
249     *table++ = oputx;
250     castonly = 0;
251     break;
252     case 'X': /* xmit distance */
253     *table++ = oputX;
254     castonly = 0;
255     break;
256 greg 1.1 case 'v': /* value */
257     *table++ = oputv;
258 greg 1.11 castonly = 0;
259 greg 1.1 break;
260 greg 2.51 case 'V': /* contribution */
261     *table++ = oputV;
262 greg 2.73 castonly = 0;
263 greg 2.51 if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
264     error(WARNING,
265     "-otV accuracy depends on -aa 0 -as 0");
266     break;
267 greg 2.5 case 'l': /* effective distance */
268 greg 1.1 *table++ = oputl;
269 greg 1.11 castonly = 0;
270 greg 1.1 break;
271 greg 2.29 case 'c': /* local coordinates */
272     *table++ = oputc;
273     break;
274 greg 2.5 case 'L': /* single ray length */
275     *table++ = oputL;
276     break;
277 greg 1.1 case 'p': /* point */
278     *table++ = oputp;
279     break;
280 greg 2.9 case 'n': /* perturbed normal */
281 greg 1.1 *table++ = oputn;
282 greg 2.9 castonly = 0;
283 greg 1.1 break;
284 greg 2.9 case 'N': /* unperturbed normal */
285     *table++ = oputN;
286     break;
287 greg 1.1 case 's': /* surface */
288     *table++ = oputs;
289     break;
290     case 'w': /* weight */
291     *table++ = oputw;
292     break;
293 greg 2.40 case 'W': /* coefficient */
294     *table++ = oputW;
295 greg 2.73 castonly = 0;
296 greg 2.40 if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
297     error(WARNING,
298 greg 2.41 "-otW accuracy depends on -aa 0 -as 0");
299 greg 2.40 break;
300 greg 1.1 case 'm': /* modifier */
301     *table++ = oputm;
302     break;
303 greg 2.39 case 'M': /* material */
304     *table++ = oputM;
305     break;
306 greg 2.42 case '~': /* tilde */
307     *table++ = oputtilde;
308 greg 2.41 break;
309 greg 1.1 }
310     *table = NULL;
311 gregl 2.24 }
312    
313    
314 schorsch 2.37 static void
315     bogusray(void) /* print out empty record */
316 gregl 2.24 {
317     thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
318     thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
319 greg 2.40 thisray.rmax = 0.0;
320     rayorigin(&thisray, PRIMARY, NULL, NULL);
321 gregl 2.24 printvals(&thisray);
322 greg 1.1 }
323    
324    
325 schorsch 2.37 static void
326 greg 2.59 raycast( /* compute first ray intersection only */
327     RAY *r
328 schorsch 2.37 )
329 greg 1.1 {
330 greg 2.59 if (!localhit(r, &thescene)) {
331     if (r->ro == &Aftplane) { /* clipped */
332     r->ro = NULL;
333     r->rot = FHUGE;
334     } else
335     sourcehit(r);
336 greg 2.57 }
337 greg 1.1 }
338    
339    
340 schorsch 2.37 static void
341 greg 2.59 rayirrad( /* compute irradiance rather than radiance */
342     RAY *r
343     )
344     {
345 greg 2.62 void (*old_revf)(RAY *) = r->revf;
346 greg 2.75 /* pretend we hit surface */
347     r->rxt = r->rmt = r->rot = 1e-5;
348 greg 2.59 VSUM(r->rop, r->rorg, r->rdir, r->rot);
349     r->ron[0] = -r->rdir[0];
350     r->ron[1] = -r->rdir[1];
351     r->ron[2] = -r->rdir[2];
352     r->rod = 1.0;
353 greg 2.62 /* compute result */
354 greg 2.61 r->revf = raytrace;
355 greg 2.59 (*ofun[Lamb.otype].funp)(&Lamb, r);
356 greg 2.62 r->revf = old_revf;
357 greg 2.59 }
358    
359    
360     static void
361     rtcompute( /* compute and print ray value(s) */
362 schorsch 2.37 FVECT org,
363 greg 2.59 FVECT dir,
364     double dmax
365 schorsch 2.37 )
366 greg 1.1 {
367 greg 2.60 /* set up ray */
368     rayorigin(&thisray, PRIMARY, NULL, NULL);
369     if (imm_irrad) {
370 greg 2.59 VSUM(thisray.rorg, org, dir, 1.1e-4);
371     thisray.rdir[0] = -dir[0];
372     thisray.rdir[1] = -dir[1];
373     thisray.rdir[2] = -dir[2];
374     thisray.rmax = 0.0;
375 greg 2.60 thisray.revf = rayirrad;
376 greg 2.59 } else {
377     VCOPY(thisray.rorg, org);
378     VCOPY(thisray.rdir, dir);
379     thisray.rmax = dmax;
380 greg 2.60 if (castonly)
381     thisray.revf = raycast;
382 greg 2.59 }
383     if (ray_pnprocs > 1) { /* multiprocessing FIFO? */
384     if (ray_fifo_in(&thisray) < 0)
385     error(USER, "lost children");
386     return;
387     }
388     samplendx++; /* else do it ourselves */
389     rayvalue(&thisray);
390 greg 2.16 printvals(&thisray);
391     }
392    
393    
394 greg 2.57 static int
395 schorsch 2.37 printvals( /* print requested ray values */
396     RAY *r
397     )
398 greg 2.16 {
399 greg 2.56 oputf_t **tp;
400 greg 2.16
401     if (ray_out[0] == NULL)
402 greg 2.57 return(0);
403 greg 2.16 for (tp = ray_out; *tp != NULL; tp++)
404     (**tp)(r);
405 greg 1.1 if (outform == 'a')
406     putchar('\n');
407 greg 2.57 return(1);
408 greg 1.1 }
409    
410    
411 schorsch 2.37 static int
412     getvec( /* get a vector from fp */
413 greg 2.56 FVECT vec,
414 schorsch 2.37 int fmt,
415     FILE *fp
416     )
417 greg 1.1 {
418     static float vf[3];
419 greg 2.5 static double vd[3];
420 greg 1.19 char buf[32];
421 greg 2.56 int i;
422 greg 1.1
423     switch (fmt) {
424     case 'a': /* ascii */
425 greg 1.19 for (i = 0; i < 3; i++) {
426     if (fgetword(buf, sizeof(buf), fp) == NULL ||
427     !isflt(buf))
428     return(-1);
429     vec[i] = atof(buf);
430     }
431 greg 1.1 break;
432     case 'f': /* binary float */
433 greg 2.70 if (getbinary(vf, sizeof(float), 3, fp) != 3)
434 greg 1.1 return(-1);
435 greg 2.58 VCOPY(vec, vf);
436 greg 1.1 break;
437     case 'd': /* binary double */
438 greg 2.70 if (getbinary(vd, sizeof(double), 3, fp) != 3)
439 greg 1.1 return(-1);
440 greg 2.58 VCOPY(vec, vd);
441 greg 1.1 break;
442 greg 2.6 default:
443     error(CONSISTENCY, "botched input format");
444 greg 1.1 }
445     return(0);
446     }
447    
448    
449 greg 2.57 void
450 schorsch 2.37 tranotify( /* record new modifier */
451     OBJECT obj
452     )
453 greg 2.15 {
454     static int hitlimit = 0;
455 greg 2.56 OBJREC *o = objptr(obj);
456     char **tralp;
457 greg 2.15
458 greg 2.27 if (obj == OVOID) { /* starting over */
459     traset[0] = 0;
460     hitlimit = 0;
461     return;
462     }
463 greg 2.15 if (hitlimit || !ismodifier(o->otype))
464     return;
465     for (tralp = tralist; *tralp != NULL; tralp++)
466     if (!strcmp(o->oname, *tralp)) {
467     if (traset[0] >= MAXTSET) {
468     error(WARNING, "too many modifiers in trace list");
469     hitlimit++;
470     return; /* should this be fatal? */
471     }
472     insertelem(traset, obj);
473     return;
474     }
475     }
476    
477    
478 greg 2.27 static void
479 schorsch 2.37 ourtrace( /* print ray values */
480     RAY *r
481     )
482 greg 1.1 {
483 greg 2.56 oputf_t **tp;
484 greg 1.1
485     if (every_out[0] == NULL)
486 greg 2.15 return;
487 greg 2.16 if (r->ro == NULL) {
488     if (traincl == 1)
489     return;
490     } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
491 greg 1.1 return;
492     tabin(r);
493     for (tp = every_out; *tp != NULL; tp++)
494     (**tp)(r);
495 greg 2.41 if (outform == 'a')
496     putchar('\n');
497 greg 1.1 }
498    
499    
500 greg 2.27 static void
501 schorsch 2.37 tabin( /* tab in appropriate amount */
502     RAY *r
503     )
504 greg 1.1 {
505 greg 2.40 const RAY *rp;
506 greg 1.1
507     for (rp = r->parent; rp != NULL; rp = rp->parent)
508     putchar('\t');
509     }
510    
511    
512 greg 2.27 static void
513 schorsch 2.37 oputo( /* print origin */
514     RAY *r
515     )
516 greg 1.1 {
517 greg 2.65 (*putreal)(r->rorg, 3);
518 greg 1.1 }
519    
520    
521 greg 2.27 static void
522 schorsch 2.37 oputd( /* print direction */
523     RAY *r
524     )
525 greg 1.1 {
526 greg 2.65 (*putreal)(r->rdir, 3);
527 greg 1.1 }
528    
529    
530 greg 2.27 static void
531 greg 2.73 oputr( /* print mirrored contribution */
532     RAY *r
533     )
534     {
535     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);
541     }
542    
543    
544    
545     static void
546     oputR( /* print mirrored distance */
547     RAY *r
548     )
549     {
550     (*putreal)(&r->rmt, 1);
551     }
552    
553    
554     static void
555     oputx( /* print unmirrored contribution */
556     RAY *r
557     )
558     {
559     RREAL cval[3];
560    
561     cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
562     cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
563     cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
564     (*putreal)(cval, 3);
565     }
566    
567    
568     static void
569     oputX( /* print unmirrored distance */
570     RAY *r
571     )
572     {
573     (*putreal)(&r->rxt, 1);
574     }
575    
576    
577     static void
578 schorsch 2.37 oputv( /* print value */
579     RAY *r
580     )
581 greg 1.1 {
582 greg 2.65 RREAL cval[3];
583    
584 greg 2.6 if (outform == 'c') {
585 greg 2.41 COLR cout;
586 greg 2.6 setcolr(cout, colval(r->rcol,RED),
587     colval(r->rcol,GRN),
588     colval(r->rcol,BLU));
589 greg 2.69 putbinary(cout, sizeof(cout), 1, stdout);
590 greg 2.6 return;
591     }
592 greg 2.65 cval[0] = colval(r->rcol,RED);
593     cval[1] = colval(r->rcol,GRN);
594     cval[2] = colval(r->rcol,BLU);
595     (*putreal)(cval, 3);
596 greg 1.1 }
597    
598    
599 greg 2.27 static void
600 greg 2.51 oputV( /* print value contribution */
601     RAY *r
602     )
603     {
604 greg 2.65 RREAL contr[3];
605 greg 2.51
606     raycontrib(contr, r, PRIMARY);
607     multcolor(contr, r->rcol);
608 greg 2.65 (*putreal)(contr, 3);
609 greg 2.51 }
610    
611    
612     static void
613 schorsch 2.37 oputl( /* print effective distance */
614     RAY *r
615     )
616 greg 1.1 {
617 greg 2.73 RREAL d = raydistance(r);
618    
619     (*putreal)(&d, 1);
620 greg 2.5 }
621    
622    
623 greg 2.27 static void
624 schorsch 2.37 oputL( /* print single ray length */
625     RAY *r
626     )
627 greg 2.5 {
628 greg 2.65 (*putreal)(&r->rot, 1);
629 greg 1.1 }
630    
631    
632 greg 2.27 static void
633 schorsch 2.37 oputc( /* print local coordinates */
634     RAY *r
635     )
636 greg 2.29 {
637 greg 2.65 (*putreal)(r->uv, 2);
638 greg 2.29 }
639    
640    
641 greg 2.65 static RREAL vdummy[3] = {0.0, 0.0, 0.0};
642    
643    
644 greg 2.29 static void
645 schorsch 2.37 oputp( /* print point */
646     RAY *r
647     )
648 greg 1.1 {
649 greg 2.65 if (r->rot < FHUGE)
650     (*putreal)(r->rop, 3);
651     else
652     (*putreal)(vdummy, 3);
653 greg 1.1 }
654    
655    
656 greg 2.27 static void
657 schorsch 2.37 oputN( /* print unperturbed normal */
658     RAY *r
659     )
660 greg 1.1 {
661 greg 2.65 if (r->rot < FHUGE)
662     (*putreal)(r->ron, 3);
663     else
664     (*putreal)(vdummy, 3);
665 greg 2.9 }
666    
667    
668 greg 2.27 static void
669 schorsch 2.37 oputn( /* print perturbed normal */
670     RAY *r
671     )
672 greg 2.9 {
673     FVECT pnorm;
674    
675     if (r->rot >= FHUGE) {
676 greg 2.65 (*putreal)(vdummy, 3);
677 greg 2.9 return;
678     }
679     raynormal(pnorm, r);
680 greg 2.65 (*putreal)(pnorm, 3);
681 greg 1.1 }
682    
683    
684 greg 2.27 static void
685 schorsch 2.37 oputs( /* print name */
686     RAY *r
687     )
688 greg 1.1 {
689     if (r->ro != NULL)
690     fputs(r->ro->oname, stdout);
691     else
692     putchar('*');
693     putchar('\t');
694     }
695    
696    
697 greg 2.27 static void
698 schorsch 2.37 oputw( /* print weight */
699     RAY *r
700     )
701 greg 1.1 {
702 greg 2.65 RREAL rwt = r->rweight;
703    
704     (*putreal)(&rwt, 1);
705 greg 1.1 }
706    
707    
708 greg 2.27 static void
709 greg 2.51 oputW( /* print coefficient */
710 greg 2.40 RAY *r
711     )
712     {
713 greg 2.65 RREAL contr[3];
714 greg 2.67 /* shadow ray not on source? */
715     if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
716     setcolor(contr, 0.0, 0.0, 0.0);
717     else
718     raycontrib(contr, r, PRIMARY);
719 greg 2.40
720 greg 2.65 (*putreal)(contr, 3);
721 greg 2.40 }
722    
723    
724     static void
725 schorsch 2.37 oputm( /* print modifier */
726     RAY *r
727     )
728 greg 1.1 {
729     if (r->ro != NULL)
730 greg 2.23 if (r->ro->omod != OVOID)
731     fputs(objptr(r->ro->omod)->oname, stdout);
732     else
733     fputs(VOIDID, stdout);
734 greg 1.1 else
735     putchar('*');
736     putchar('\t');
737     }
738    
739    
740 greg 2.27 static void
741 greg 2.39 oputM( /* print material */
742     RAY *r
743     )
744     {
745     OBJREC *mat;
746    
747     if (r->ro != NULL) {
748     if ((mat = findmaterial(r->ro)) != NULL)
749     fputs(mat->oname, stdout);
750     else
751     fputs(VOIDID, stdout);
752     } else
753     putchar('*');
754     putchar('\t');
755     }
756    
757    
758     static void
759 greg 2.42 oputtilde( /* output tilde (spacer) */
760 greg 2.41 RAY *r
761     )
762     {
763 greg 2.42 fputs("~\t", stdout);
764 greg 2.41 }
765    
766    
767     static void
768 greg 2.65 puta( /* print ascii value(s) */
769     RREAL *v, int n
770 schorsch 2.37 )
771 greg 1.1 {
772 greg 2.65 if (n == 3) {
773     printf("%e\t%e\t%e\t", v[0], v[1], v[2]);
774     return;
775     }
776     while (n--)
777     printf("%e\t", *v++);
778 greg 1.1 }
779    
780    
781 greg 2.27 static void
782 greg 2.65 putd(RREAL *v, int n) /* print binary double(s) */
783 greg 1.1 {
784 greg 2.68 #ifdef SMLFLT
785     double da[3];
786     int i;
787    
788     if (n > 3)
789 greg 2.65 error(INTERNAL, "code error in putd()");
790 greg 2.68 for (i = n; i--; )
791     da[i] = v[i];
792 greg 2.69 putbinary(da, sizeof(double), n, stdout);
793 greg 2.68 #else
794 greg 2.69 putbinary(v, sizeof(RREAL), n, stdout);
795 greg 2.68 #endif
796 greg 1.1 }
797    
798    
799 greg 2.27 static void
800 greg 2.65 putf(RREAL *v, int n) /* print binary float(s) */
801 greg 1.1 {
802 greg 2.68 #ifndef SMLFLT
803 greg 2.65 float fa[3];
804     int i;
805 greg 1.1
806 greg 2.65 if (n > 3)
807     error(INTERNAL, "code error in putf()");
808     for (i = n; i--; )
809     fa[i] = v[i];
810 greg 2.69 putbinary(fa, sizeof(float), n, stdout);
811 greg 2.68 #else
812 greg 2.69 putbinary(v, sizeof(RREAL), n, stdout);
813 greg 2.68 #endif
814 greg 1.1 }