ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 1.1
Committed: Wed Jul 24 16:48:45 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.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     illumout(il, ob) /* print illum object */
91     register struct illum_args *il;
92     OBJREC *ob;
93     {
94     double cout[3];
95    
96     printf("\n%s%s %s %s", il->matname, DSTSUF,
97     ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
98     il->matname);
99     if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
100     printf("\n0");
101     else
102     printf("\n1 %s", il->altmat);
103     if (il->flags & IL_COLAVG) {
104     cout[0] = il->col[0];
105     cout[1] = il->col[1];
106     cout[2] = il->col[2];
107     } else {
108     cout[0] = cout[1] = cout[2] = brt(il->col);
109     }
110     if (il->flags & IL_LIGHT)
111     printf("\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
112     else
113     printf("\n4 %f %f %f 0\n", cout[0], cout[1], cout[2]);
114    
115     printobj(il->matname, ob);
116     }
117    
118    
119     flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */
120     struct illum_args *il;
121     float *da;
122     int n, m;
123     FVECT u, v, w;
124     {
125     FILE *dfp;
126     int i;
127    
128     average(il, da, n*m);
129     if (il->flags & IL_COLDST) {
130     printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
131     il->matname, DSTSUF);
132     printf("\n9 red green blue");
133     for (i = 0; i < 3; i++) {
134     dfp = dfopen(il, DATORD[i]);
135     fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
136     colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
137     fclose(dfp);
138     printf(" %s", dfname(il, DATORD[i]));
139     }
140     } else {
141     printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
142     il->matname, DSTSUF);
143     printf("\n5 noop");
144     dfp = dfopen(il, 0);
145     fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
146     brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
147     fclose(dfp);
148     printf(" %s", dfname(il, 0));
149     }
150     printf("\n\t%s il_alth il_azih", FNCFNM);
151     printf("\n0\n9\n");
152     printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]);
153     printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
154     printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
155     il->dfnum++;
156     }
157    
158    
159     roundout(il, da, n, m) /* write spherical distribution */
160     struct illum_args *il;
161     float *da;
162     int n, m;
163     {
164     FILE *dfp;
165     int i;
166    
167     average(il, da, n*m);
168     if (il->flags & IL_COLDST) {
169     printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
170     il->matname, DSTSUF);
171     printf("\n9 red green blue");
172     for (i = 0; i < 3; i++) {
173     dfp = dfopen(il, DATORD[i]);
174     fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
175     colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
176     fclose(dfp);
177     printf(" %s", dfname(il, DATORD[i]));
178     }
179     } else {
180     printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
181     il->matname, DSTSUF);
182     printf("\n5 noop");
183     dfp = dfopen(il, 0);
184     fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
185     brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
186     fclose(dfp);
187     printf(" %s", dfname(il, 0));
188     }
189     printf("\n\t%s il_alt il_azi", FNCFNM);
190     printf("\n0\n0\n");
191     il->dfnum++;
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     }