ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 1.2
Committed: Thu Jul 25 10:59:09 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +29 -29 lines
Log Message:
visual debugging pass

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 * Routines to print mkillum objects
9 */
10
11 #include "mkillum.h"
12
13 #define brt(col) (.295*(col)[0] + .636*(col)[1] + .070*(col)[2])
14
15 char DATORD[] = "RGB"; /* data ordering */
16 char DATSUF[] = ".dat"; /* data file suffix */
17 char DSTSUF[] = ".dist"; /* distribution suffix */
18 char FNCFNM[] = "illum.cal"; /* function file name */
19
20
21 printobj(mod, obj) /* print out an object */
22 char *mod;
23 register OBJREC *obj;
24 {
25 register int i;
26
27 printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
28 printf("\n%d", obj->oargs.nsargs);
29 for (i = 0; i < obj->oargs.nsargs; i++)
30 printf(" %s", obj->oargs.sarg[i]);
31 #ifdef IARGS
32 printf("\n%d", obj->oargs.niargs);
33 for (i = 0; i < obj->oargs.niargs; i++)
34 printf(" %d", obj->oargs.iarg[i]);
35 #else
36 printf("\n0");
37 #endif
38 printf("\n%d", obj->oargs.nfargs);
39 for (i = 0; i < obj->oargs.nfargs; i++) {
40 if (i%3 == 0)
41 putchar('\n');
42 printf(" %18.12g", obj->oargs.farg[i]);
43 }
44 putchar('\n');
45 }
46
47
48 char *
49 dfname(il, c) /* return data file name */
50 struct illum_args *il;
51 int c;
52 {
53 extern char *getpath(), *strcpy();
54 char fname[MAXSTR];
55 register char *s;
56
57 s = strcpy(fname, il->datafile);
58 s += strlen(s);
59 if (c) *s++ = c;
60 if (il->dfnum > 0) {
61 sprintf(s, "%d", il->dfnum);
62 s += strlen(s);
63 }
64 strcpy(s, DATSUF);
65 return(getpath(fname, NULL, 0));
66 }
67
68
69 FILE *
70 dfopen(il, c) /* open data file */
71 register struct illum_args *il;
72 int c;
73 {
74 char *fn;
75 FILE *fp;
76 /* get a usable file name */
77 for (fn = dfname(il, c);
78 !(il->flags & IL_DATCLB) && access(fn, F_OK) == 0;
79 fn = dfname(il, c))
80 il->dfnum++;
81 /* open it for writing */
82 if ((fp = fopen(fn, "w")) == NULL) {
83 sprintf(errmsg, "cannot open data file \"%s\"", fn);
84 error(SYSTEM, errmsg);
85 }
86 return(fp);
87 }
88
89
90 flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */
91 struct illum_args *il;
92 float *da;
93 int n, m;
94 FVECT u, v, w;
95 {
96 FILE *dfp;
97 int i;
98
99 average(il, da, n*m);
100 if (il->flags & IL_COLDST) {
101 printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
102 il->matname, DSTSUF);
103 printf("\n9 red green blue");
104 for (i = 0; i < 3; i++) {
105 dfp = dfopen(il, DATORD[i]);
106 fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
107 colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
108 fclose(dfp);
109 printf(" %s", dfname(il, DATORD[i]));
110 }
111 } else {
112 printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
113 il->matname, DSTSUF);
114 printf("\n5 noop");
115 dfp = dfopen(il, 0);
116 fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
117 brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
118 fclose(dfp);
119 printf(" %s", dfname(il, 0));
120 }
121 printf("\n\t%s il_alth il_azih", FNCFNM);
122 printf("\n0\n9\n");
123 printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]);
124 printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
125 printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
126 il->dfnum++;
127 }
128
129
130 roundout(il, da, n, m) /* write spherical distribution */
131 struct illum_args *il;
132 float *da;
133 int n, m;
134 {
135 FILE *dfp;
136 int i;
137
138 average(il, da, n*m);
139 if (il->flags & IL_COLDST) {
140 printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
141 il->matname, DSTSUF);
142 printf("\n9 red green blue");
143 for (i = 0; i < 3; i++) {
144 dfp = dfopen(il, DATORD[i]);
145 fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
146 colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
147 fclose(dfp);
148 printf(" %s", dfname(il, DATORD[i]));
149 }
150 } else {
151 printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
152 il->matname, DSTSUF);
153 printf("\n5 noop");
154 dfp = dfopen(il, 0);
155 fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
156 brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
157 fclose(dfp);
158 printf(" %s", dfname(il, 0));
159 }
160 printf("\n\t%s il_alt il_azi", FNCFNM);
161 printf("\n0\n0\n");
162 il->dfnum++;
163 }
164
165
166 illumout(il, ob) /* print illum object */
167 register struct illum_args *il;
168 OBJREC *ob;
169 {
170 double cout[3];
171
172 printf("\n%s%s %s %s", il->matname, DSTSUF,
173 ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
174 il->matname);
175 if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
176 printf("\n0");
177 else
178 printf("\n1 %s", il->altmat);
179 if (il->flags & IL_COLAVG) {
180 cout[0] = il->col[0];
181 cout[1] = il->col[1];
182 cout[2] = il->col[2];
183 } else {
184 cout[0] = cout[1] = cout[2] = brt(il->col);
185 }
186 if (il->flags & IL_LIGHT)
187 printf("\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
188 else
189 printf("\n4 %f %f %f 0\n", cout[0], cout[1], cout[2]);
190
191 printobj(il->matname, ob);
192 }
193
194
195 average(il, da, n) /* compute average value for distribution */
196 register struct illum_args *il;
197 register float *da;
198 int n;
199 {
200 register int i;
201
202 il->col[0] = il->col[1] = il->col[2] = 0.;
203 i = n;
204 while (i-- > 0) {
205 il->col[0] += *da++;
206 il->col[1] += *da++;
207 il->col[2] += *da++;
208 }
209 for (i = 0; i < 3; i++)
210 il->col[i] /= (double)n*il->nsamps;
211 }
212
213
214 colorout(p, da, n, mult, fp) /* put out color distribution data */
215 int p;
216 register float *da;
217 int n;
218 double mult;
219 FILE *fp;
220 {
221 register int i;
222
223 for (i = 0; i < n; i++) {
224 if (i%6 == 0)
225 putc('\n', fp);
226 fprintf(fp, " %11e", mult*da[p]);
227 da += 3;
228 }
229 putc('\n', fp);
230 }
231
232
233 brightout(da, n, mult, fp) /* put out brightness distribution data */
234 register float *da;
235 int n;
236 double mult;
237 FILE *fp;
238 {
239 register int i;
240
241 for (i = 0; i < n; i++) {
242 if (i%6 == 0)
243 putc('\n', fp);
244 fprintf(fp, " %11e", mult*brt(da));
245 da += 3;
246 }
247 putc('\n', fp);
248 }