ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 1.5
Committed: Fri Aug 23 12:30:35 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +2 -0 lines
Log Message:
added b variable for minimum brightness

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