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 |
|
|
14 |
|
|
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 |
– |
|
15 |
|
int dataonly = 0; |
16 |
< |
|
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; |
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]); |
52 |
|
fprintf(stderr, "%s: file not found\n", argv[i]); |
53 |
|
return(1); |
54 |
|
} |
55 |
< |
if (reverse) |
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 |
> |
SET_FILE_BINARY(stdout); |
66 |
> |
putambmagic(stdout); |
67 |
|
writamb(fp); |
68 |
< |
else |
68 |
> |
} else { |
69 |
> |
SET_FILE_BINARY(fp); |
70 |
> |
if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) |
71 |
> |
goto formaterr; |
72 |
> |
if (!hasambmagic(fp)) |
73 |
> |
goto formaterr; |
74 |
> |
if (header) { |
75 |
> |
fputformat("ascii", stdout); |
76 |
> |
putchar('\n'); |
77 |
> |
} |
78 |
|
lookamb(fp); |
79 |
+ |
} |
80 |
|
fclose(fp); |
81 |
|
return(0); |
82 |
+ |
formaterr: |
83 |
+ |
fprintf(stderr, "%s: format error on input\n", argv[0]); |
84 |
+ |
exit(1); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
+ |
void |
89 |
|
lookamb(fp) /* get ambient values from a file */ |
90 |
|
FILE *fp; |
91 |
|
{ |
92 |
< |
while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) { |
92 |
> |
while (readambval(&av, fp)) { |
93 |
|
if (dataonly) { |
94 |
|
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
95 |
|
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
96 |
|
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
97 |
< |
printf("%e\t%e\t%e\n", colval(av.val,RED), |
97 |
> |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
98 |
|
colval(av.val,GRN), |
99 |
|
colval(av.val,BLU)); |
100 |
+ |
printf("%f\t%f\t%f\t", av.gpos[0], |
101 |
+ |
av.gpos[1], av.gpos[2]); |
102 |
+ |
printf("%f\t%f\t%f\n", av.gdir[0], |
103 |
+ |
av.gdir[1], av.gdir[2]); |
104 |
|
} else { |
105 |
|
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
106 |
|
av.pos[1], av.pos[2]); |
110 |
|
av.weight, av.rad); |
111 |
|
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
112 |
|
colval(av.val,GRN), colval(av.val,BLU)); |
113 |
+ |
printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], |
114 |
+ |
av.gpos[1], av.gpos[2]); |
115 |
+ |
printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], |
116 |
+ |
av.gdir[1], av.gdir[2]); |
117 |
|
} |
118 |
|
if (ferror(stdout)) |
119 |
|
exit(1); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
+ |
void |
125 |
|
writamb(fp) /* write binary ambient values */ |
126 |
|
FILE *fp; |
127 |
|
{ |
128 |
|
for ( ; ; ) { |
129 |
|
if (!dataonly) |
130 |
|
fscanf(fp, "%*s"); |
131 |
< |
if (fscanf(fp, "%lf %lf %lf", |
131 |
> |
if (fscanf(fp, "%f %f %f", |
132 |
|
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
133 |
|
return; |
134 |
|
if (!dataonly) |
135 |
|
fscanf(fp, "%*s"); |
136 |
< |
if (fscanf(fp, "%lf %lf %lf", |
136 |
> |
if (fscanf(fp, "%f %f %f", |
137 |
|
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
138 |
|
return; |
139 |
|
if (!dataonly) |
146 |
|
if (fscanf(fp, "%f %f %f", |
147 |
|
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
148 |
|
return; |
149 |
< |
fwrite(&av, sizeof(AMBVAL), 1, stdout); |
149 |
> |
if (!dataonly) |
150 |
> |
fscanf(fp, "%*s"); |
151 |
> |
if (fscanf(fp, "%f %f %f", |
152 |
> |
&av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) |
153 |
> |
return; |
154 |
> |
if (!dataonly) |
155 |
> |
fscanf(fp, "%*s"); |
156 |
> |
if (fscanf(fp, "%f %f %f", |
157 |
> |
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
158 |
> |
return; |
159 |
> |
av.next = NULL; |
160 |
> |
writambval(&av, stdout); |
161 |
|
if (ferror(stdout)) |
162 |
|
exit(1); |
163 |
|
} |