1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* lookamb.c - program to examine ambient components. |
9 |
– |
* |
10 |
– |
* 10/8/86 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
< |
#include "color.h" |
10 |
> |
#include "platform.h" |
11 |
> |
#include "ray.h" |
12 |
> |
#include "ambient.h" |
13 |
> |
#include "resolu.h" |
14 |
|
|
15 |
|
|
18 |
– |
typedef double FVECT[3]; |
19 |
– |
|
20 |
– |
typedef struct ambval { |
21 |
– |
FVECT pos; /* position in space */ |
22 |
– |
FVECT dir; /* normal direction */ |
23 |
– |
int lvl; /* recursion level of parent ray */ |
24 |
– |
float weight; /* weight of parent ray */ |
25 |
– |
COLOR val; /* computed ambient value */ |
26 |
– |
float rad; /* validity radius */ |
27 |
– |
struct ambval *next; /* next in list */ |
28 |
– |
} AMBVAL; /* ambient value */ |
29 |
– |
|
16 |
|
int dataonly = 0; |
17 |
< |
|
17 |
> |
int header = 1; |
18 |
|
int reverse = 0; |
19 |
|
|
20 |
|
AMBVAL av; |
21 |
|
|
22 |
+ |
#ifdef NEWAMB |
23 |
|
|
24 |
< |
main(argc, argv) /* load ambient values from a file */ |
25 |
< |
char *argv[]; |
24 |
> |
|
25 |
> |
static void |
26 |
> |
lookamb( /* load & convert ambient values from a file */ |
27 |
> |
FILE *fp |
28 |
> |
) |
29 |
|
{ |
30 |
< |
FILE *fp; |
41 |
< |
int i; |
30 |
> |
FVECT norm, uvec; |
31 |
|
|
32 |
< |
for (i = 1; i < argc; i++) |
33 |
< |
if (argv[i][0] == '-') |
34 |
< |
switch (argv[i][1]) { |
35 |
< |
case 'd': |
36 |
< |
dataonly = 1; |
37 |
< |
break; |
38 |
< |
case 'r': |
39 |
< |
reverse = 1; |
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; |
32 |
> |
while (readambval(&av, fp)) { |
33 |
> |
decodedir(norm, av.ndir); |
34 |
> |
decodedir(uvec, av.udir); |
35 |
> |
if (dataonly) { |
36 |
> |
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
37 |
> |
printf("%f\t%f\t%f\t", norm[0], norm[1], norm[2]); |
38 |
> |
printf("%f\t%f\t%f\t", uvec[0], uvec[1], uvec[2]); |
39 |
> |
printf("%d\t%f\t%f\t%f\t", av.lvl, av.weight, |
40 |
> |
av.rad[0], av.rad[1]); |
41 |
> |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
42 |
> |
colval(av.val,GRN), |
43 |
> |
colval(av.val,BLU)); |
44 |
> |
printf("%f\t%f\t", av.gpos[0], av.gpos[1]); |
45 |
> |
printf("%f\t%f\n", av.gdir[0], av.gdir[1]); |
46 |
> |
} else { |
47 |
> |
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
48 |
> |
av.pos[1], av.pos[2]); |
49 |
> |
printf("Normal:\t%f\t%f\t%f\n", |
50 |
> |
norm[0], norm[1], norm[2]); |
51 |
> |
printf("Uvector:\t%f\t%f\t%f\n", |
52 |
> |
uvec[0], uvec[1], uvec[2]); |
53 |
> |
printf("Lvl,Wt,Urad,Vrad:\t%d\t\t%f\t%f\n", av.lvl, |
54 |
> |
av.weight, av.rad[0], av.rad[1]); |
55 |
> |
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
56 |
> |
colval(av.val,GRN), colval(av.val,BLU)); |
57 |
> |
printf("Pos.Grad:\t%f\t%f\n", av.gpos[0], av.gpos[1]); |
58 |
> |
printf("Dir.Grad:\t%f\t%f\n", av.gdir[0], av.gdir[1]); |
59 |
> |
} |
60 |
> |
if (ferror(stdout)) |
61 |
> |
exit(1); |
62 |
> |
} |
63 |
> |
} |
64 |
|
|
65 |
< |
if (i >= argc) |
66 |
< |
fp = stdin; |
67 |
< |
else if ((fp = fopen(argv[i], "r")) == NULL) { |
68 |
< |
fprintf(stderr, "%s: file not found\n", argv[i]); |
69 |
< |
return(1); |
65 |
> |
|
66 |
> |
static void |
67 |
> |
writamb( /* write binary ambient values to stdout */ |
68 |
> |
FILE *fp |
69 |
> |
) |
70 |
> |
{ |
71 |
> |
FVECT norm; |
72 |
> |
|
73 |
> |
for ( ; ; ) { |
74 |
> |
if (!dataonly) |
75 |
> |
fscanf(fp, "%*s"); |
76 |
> |
if (fscanf(fp, "%f %f %f", |
77 |
> |
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
78 |
> |
return; |
79 |
> |
if (!dataonly) |
80 |
> |
fscanf(fp, "%*s"); |
81 |
> |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3) |
82 |
> |
return; |
83 |
> |
av.ndir = encodedir(norm); |
84 |
> |
if (!dataonly) |
85 |
> |
fscanf(fp, "%*s"); |
86 |
> |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3) |
87 |
> |
return; |
88 |
> |
av.udir = encodedir(norm); |
89 |
> |
if (!dataonly) |
90 |
> |
fscanf(fp, "%*s"); |
91 |
> |
if (fscanf(fp, "%d %f %f %f", &av.lvl, &av.weight, |
92 |
> |
&av.rad[0], &av.rad[1]) != 4) |
93 |
> |
return; |
94 |
> |
if (!dataonly) |
95 |
> |
fscanf(fp, "%*s"); |
96 |
> |
if (fscanf(fp, "%f %f %f", |
97 |
> |
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
98 |
> |
return; |
99 |
> |
if (!dataonly) |
100 |
> |
fscanf(fp, "%*s"); |
101 |
> |
if (fscanf(fp, "%f %f", &av.gpos[0], &av.gpos[1]) != 2) |
102 |
> |
return; |
103 |
> |
if (!dataonly) |
104 |
> |
fscanf(fp, "%*s"); |
105 |
> |
if (fscanf(fp, "%f %f", &av.gdir[0], &av.gdir[1]) != 2) |
106 |
> |
return; |
107 |
> |
av.next = NULL; |
108 |
> |
writambval(&av, stdout); |
109 |
> |
if (ferror(stdout)) |
110 |
> |
exit(1); |
111 |
|
} |
66 |
– |
if (reverse) |
67 |
– |
writamb(fp); |
68 |
– |
else |
69 |
– |
lookamb(fp); |
70 |
– |
fclose(fp); |
71 |
– |
return(0); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
< |
lookamb(fp) /* get ambient values from a file */ |
116 |
< |
FILE *fp; |
115 |
> |
#else /* ! NEWAMB */ |
116 |
> |
|
117 |
> |
|
118 |
> |
static void |
119 |
> |
lookamb( /* get ambient values from a file */ |
120 |
> |
FILE *fp |
121 |
> |
) |
122 |
|
{ |
123 |
< |
while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) { |
123 |
> |
while (readambval(&av, fp)) { |
124 |
|
if (dataonly) { |
125 |
|
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
126 |
|
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
127 |
|
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
128 |
< |
printf("%e\t%e\t%e\n", colval(av.val,RED), |
128 |
> |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
129 |
|
colval(av.val,GRN), |
130 |
|
colval(av.val,BLU)); |
131 |
+ |
printf("%f\t%f\t%f\t", av.gpos[0], |
132 |
+ |
av.gpos[1], av.gpos[2]); |
133 |
+ |
printf("%f\t%f\t%f\n", av.gdir[0], |
134 |
+ |
av.gdir[1], av.gdir[2]); |
135 |
|
} else { |
136 |
|
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
137 |
|
av.pos[1], av.pos[2]); |
141 |
|
av.weight, av.rad); |
142 |
|
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
143 |
|
colval(av.val,GRN), colval(av.val,BLU)); |
144 |
+ |
printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], |
145 |
+ |
av.gpos[1], av.gpos[2]); |
146 |
+ |
printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], |
147 |
+ |
av.gdir[1], av.gdir[2]); |
148 |
|
} |
149 |
|
if (ferror(stdout)) |
150 |
|
exit(1); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
writamb(fp) /* write binary ambient values */ |
156 |
< |
FILE *fp; |
155 |
> |
static void |
156 |
> |
writamb( /* write binary ambient values */ |
157 |
> |
FILE *fp |
158 |
> |
) |
159 |
|
{ |
160 |
|
for ( ; ; ) { |
161 |
|
if (!dataonly) |
162 |
|
fscanf(fp, "%*s"); |
163 |
< |
if (fscanf(fp, "%lf %lf %lf", |
163 |
> |
if (fscanf(fp, "%f %f %f", |
164 |
|
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
165 |
|
return; |
166 |
|
if (!dataonly) |
167 |
|
fscanf(fp, "%*s"); |
168 |
< |
if (fscanf(fp, "%lf %lf %lf", |
168 |
> |
if (fscanf(fp, "%f %f %f", |
169 |
|
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
170 |
|
return; |
171 |
|
if (!dataonly) |
178 |
|
if (fscanf(fp, "%f %f %f", |
179 |
|
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
180 |
|
return; |
181 |
< |
fwrite(&av, sizeof(AMBVAL), 1, stdout); |
181 |
> |
if (!dataonly) |
182 |
> |
fscanf(fp, "%*s"); |
183 |
> |
if (fscanf(fp, "%f %f %f", |
184 |
> |
&av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) |
185 |
> |
return; |
186 |
> |
if (!dataonly) |
187 |
> |
fscanf(fp, "%*s"); |
188 |
> |
if (fscanf(fp, "%f %f %f", |
189 |
> |
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
190 |
> |
return; |
191 |
> |
av.next = NULL; |
192 |
> |
writambval(&av, stdout); |
193 |
|
if (ferror(stdout)) |
194 |
|
exit(1); |
195 |
|
} |
196 |
+ |
} |
197 |
+ |
|
198 |
+ |
|
199 |
+ |
#endif /* ! NEWAMB */ |
200 |
+ |
|
201 |
+ |
|
202 |
+ |
int |
203 |
+ |
main( /* load ambient values from a file */ |
204 |
+ |
int argc, |
205 |
+ |
char *argv[] |
206 |
+ |
) |
207 |
+ |
{ |
208 |
+ |
FILE *fp; |
209 |
+ |
int i; |
210 |
+ |
|
211 |
+ |
for (i = 1; i < argc; i++) |
212 |
+ |
if (argv[i][0] == '-') |
213 |
+ |
switch (argv[i][1]) { |
214 |
+ |
case 'd': |
215 |
+ |
dataonly = 1; |
216 |
+ |
break; |
217 |
+ |
case 'r': |
218 |
+ |
reverse = 1; |
219 |
+ |
break; |
220 |
+ |
case 'h': |
221 |
+ |
header = 0; |
222 |
+ |
break; |
223 |
+ |
default: |
224 |
+ |
fprintf(stderr, "%s: unknown option '%s'\n", |
225 |
+ |
argv[0], argv[i]); |
226 |
+ |
return(1); |
227 |
+ |
} |
228 |
+ |
else |
229 |
+ |
break; |
230 |
+ |
|
231 |
+ |
if (i >= argc) |
232 |
+ |
fp = stdin; |
233 |
+ |
else if ((fp = fopen(argv[i], "r")) == NULL) { |
234 |
+ |
fprintf(stderr, "%s: file not found\n", argv[i]); |
235 |
+ |
return(1); |
236 |
+ |
} |
237 |
+ |
if (reverse) { |
238 |
+ |
if (header) { |
239 |
+ |
if (checkheader(fp, "ascii", stdout) < 0) |
240 |
+ |
goto formaterr; |
241 |
+ |
} else { |
242 |
+ |
newheader("RADIANCE", stdout); |
243 |
+ |
printargs(argc, argv, stdout); |
244 |
+ |
} |
245 |
+ |
fputformat(AMBFMT, stdout); |
246 |
+ |
putchar('\n'); |
247 |
+ |
SET_FILE_BINARY(stdout); |
248 |
+ |
putambmagic(stdout); |
249 |
+ |
writamb(fp); |
250 |
+ |
} else { |
251 |
+ |
SET_FILE_BINARY(fp); |
252 |
+ |
if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) |
253 |
+ |
goto formaterr; |
254 |
+ |
if (!hasambmagic(fp)) |
255 |
+ |
goto formaterr; |
256 |
+ |
if (header) { |
257 |
+ |
fputformat("ascii", stdout); |
258 |
+ |
putchar('\n'); |
259 |
+ |
} |
260 |
+ |
lookamb(fp); |
261 |
+ |
} |
262 |
+ |
fclose(fp); |
263 |
+ |
return(0); |
264 |
+ |
formaterr: |
265 |
+ |
fprintf(stderr, "%s: format error on input\n", argv[0]); |
266 |
+ |
exit(1); |
267 |
|
} |