ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtrace.c
Revision: 2.78
Committed: Sat May 4 23:10:32 2019 UTC (5 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.77: +8 -5 lines
Log Message:
Removed unnecessary clear + made multiple zero directions -> single flush

File Contents

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