ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 2.3
Committed: Thu Mar 12 11:44:01 1992 UTC (32 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -2 lines
Log Message:
fixed handling of surfaces

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