ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/lookamb.c
Revision: 1.3
Committed: Thu Jun 6 10:09:50 1991 UTC (32 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +5 -7 lines
Log Message:
changed size of AMBVAL structure

File Contents

# Content
1 /* Copyright (c) 1991 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * lookamb.c - program to examine ambient components.
9 *
10 * 10/8/86
11 */
12
13 #include <stdio.h>
14
15 #include "color.h"
16
17
18 typedef struct ambval {
19 float pos[3]; /* position in space */
20 float dir[3]; /* normal direction */
21 int lvl; /* recursion level of parent ray */
22 float weight; /* weight of parent ray */
23 COLOR val; /* computed ambient value */
24 float rad; /* validity radius */
25 struct ambval *next; /* next in list */
26 } AMBVAL; /* ambient value */
27
28 int dataonly = 0;
29
30 int reverse = 0;
31
32 AMBVAL av;
33
34
35 main(argc, argv) /* load ambient values from a file */
36 char *argv[];
37 {
38 FILE *fp;
39 int i;
40
41 for (i = 1; i < argc; i++)
42 if (argv[i][0] == '-')
43 switch (argv[i][1]) {
44 case 'd':
45 dataonly = 1;
46 break;
47 case 'r':
48 reverse = 1;
49 break;
50 default:
51 fprintf(stderr, "%s: unknown option '%s'\n",
52 argv[0], argv[i]);
53 return(1);
54 }
55 else
56 break;
57
58 if (i >= argc)
59 fp = stdin;
60 else if ((fp = fopen(argv[i], "r")) == NULL) {
61 fprintf(stderr, "%s: file not found\n", argv[i]);
62 return(1);
63 }
64 if (reverse)
65 writamb(fp);
66 else
67 lookamb(fp);
68 fclose(fp);
69 return(0);
70 }
71
72
73 lookamb(fp) /* get ambient values from a file */
74 FILE *fp;
75 {
76 while (fread((char *)&av, sizeof(AMBVAL), 1, fp) == 1) {
77 if (dataonly) {
78 printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
79 printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
80 printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
81 printf("%e\t%e\t%e\n", colval(av.val,RED),
82 colval(av.val,GRN),
83 colval(av.val,BLU));
84 } else {
85 printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
86 av.pos[1], av.pos[2]);
87 printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
88 av.dir[1], av.dir[2]);
89 printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
90 av.weight, av.rad);
91 printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
92 colval(av.val,GRN), colval(av.val,BLU));
93 }
94 if (ferror(stdout))
95 exit(1);
96 }
97 }
98
99
100 writamb(fp) /* write binary ambient values */
101 FILE *fp;
102 {
103 for ( ; ; ) {
104 if (!dataonly)
105 fscanf(fp, "%*s");
106 if (fscanf(fp, "%f %f %f",
107 &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
108 return;
109 if (!dataonly)
110 fscanf(fp, "%*s");
111 if (fscanf(fp, "%f %f %f",
112 &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
113 return;
114 if (!dataonly)
115 fscanf(fp, "%*s");
116 if (fscanf(fp, "%d %f %f",
117 &av.lvl, &av.weight, &av.rad) != 3)
118 return;
119 if (!dataonly)
120 fscanf(fp, "%*s");
121 if (fscanf(fp, "%f %f %f",
122 &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
123 return;
124 fwrite((char *)&av, sizeof(AMBVAL), 1, stdout);
125 if (ferror(stdout))
126 exit(1);
127 }
128 }