ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/lookamb.c
Revision: 2.8
Committed: Tue Feb 25 02:47:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.7: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * lookamb.c - program to examine ambient components.
6 */
7
8 #include "copyright.h"
9
10 #include "ray.h"
11
12 #include "ambient.h"
13
14
15 int dataonly = 0;
16 int header = 1;
17 int reverse = 0;
18
19 AMBVAL av;
20
21
22 main(argc, argv) /* load ambient values from a file */
23 int argc;
24 char *argv[];
25 {
26 FILE *fp;
27 int i;
28
29 for (i = 1; i < argc; i++)
30 if (argv[i][0] == '-')
31 switch (argv[i][1]) {
32 case 'd':
33 dataonly = 1;
34 break;
35 case 'r':
36 reverse = 1;
37 break;
38 case 'h':
39 header = 0;
40 break;
41 default:
42 fprintf(stderr, "%s: unknown option '%s'\n",
43 argv[0], argv[i]);
44 return(1);
45 }
46 else
47 break;
48
49 if (i >= argc)
50 fp = stdin;
51 else if ((fp = fopen(argv[i], "r")) == NULL) {
52 fprintf(stderr, "%s: file not found\n", argv[i]);
53 return(1);
54 }
55 if (reverse) {
56 if (header) {
57 if (checkheader(fp, "ascii", stdout) < 0)
58 goto formaterr;
59 } else {
60 newheader("RADIANCE", stdout);
61 printargs(argc, argv, stdout);
62 }
63 fputformat(AMBFMT, stdout);
64 putchar('\n');
65 #ifdef MSDOS
66 setmode(fileno(stdout), O_BINARY);
67 #endif
68 putambmagic(stdout);
69 writamb(fp);
70 } else {
71 #ifdef MSDOS
72 setmode(fileno(fp), O_BINARY);
73 #endif
74 if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
75 goto formaterr;
76 if (!hasambmagic(fp))
77 goto formaterr;
78 if (header) {
79 fputformat("ascii", stdout);
80 putchar('\n');
81 }
82 lookamb(fp);
83 }
84 fclose(fp);
85 return(0);
86 formaterr:
87 fprintf(stderr, "%s: format error on input\n", argv[0]);
88 exit(1);
89 }
90
91
92 void
93 lookamb(fp) /* get ambient values from a file */
94 FILE *fp;
95 {
96 while (readambval(&av, fp)) {
97 if (dataonly) {
98 printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
99 printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
100 printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
101 printf("%e\t%e\t%e\t", colval(av.val,RED),
102 colval(av.val,GRN),
103 colval(av.val,BLU));
104 printf("%f\t%f\t%f\t", av.gpos[0],
105 av.gpos[1], av.gpos[2]);
106 printf("%f\t%f\t%f\n", av.gdir[0],
107 av.gdir[1], av.gdir[2]);
108 } else {
109 printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
110 av.pos[1], av.pos[2]);
111 printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
112 av.dir[1], av.dir[2]);
113 printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
114 av.weight, av.rad);
115 printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
116 colval(av.val,GRN), colval(av.val,BLU));
117 printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
118 av.gpos[1], av.gpos[2]);
119 printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
120 av.gdir[1], av.gdir[2]);
121 }
122 if (ferror(stdout))
123 exit(1);
124 }
125 }
126
127
128 void
129 writamb(fp) /* write binary ambient values */
130 FILE *fp;
131 {
132 for ( ; ; ) {
133 if (!dataonly)
134 fscanf(fp, "%*s");
135 if (fscanf(fp, "%f %f %f",
136 &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
137 return;
138 if (!dataonly)
139 fscanf(fp, "%*s");
140 if (fscanf(fp, "%f %f %f",
141 &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
142 return;
143 if (!dataonly)
144 fscanf(fp, "%*s");
145 if (fscanf(fp, "%d %f %f",
146 &av.lvl, &av.weight, &av.rad) != 3)
147 return;
148 if (!dataonly)
149 fscanf(fp, "%*s");
150 if (fscanf(fp, "%f %f %f",
151 &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
152 return;
153 if (!dataonly)
154 fscanf(fp, "%*s");
155 if (fscanf(fp, "%f %f %f",
156 &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
157 return;
158 if (!dataonly)
159 fscanf(fp, "%*s");
160 if (fscanf(fp, "%f %f %f",
161 &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
162 return;
163 av.next = NULL;
164 writambval(&av, stdout);
165 if (ferror(stdout))
166 exit(1);
167 }
168 }