ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
(Generate patch)

Comparing ray/src/gen/mkillum3.c (file contents):
Revision 1.1 by greg, Wed Jul 24 16:48:45 1991 UTC vs.
Revision 2.8 by greg, Mon Mar 10 17:26:26 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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   * Routines to print mkillum objects
6   */
7  
8   #include  "mkillum.h"
9  
10 < #define  brt(col)       (.295*(col)[0] + .636*(col)[1] + .070*(col)[2])
10 > #define  brt(col)       (.263*(col)[0]+.655*(col)[1]+.082*(col)[2])
11  
12   char    DATORD[] = "RGB";               /* data ordering */
13   char    DATSUF[] = ".dat";              /* data file suffix */
# Line 24 | Line 21 | register OBJREC  *obj;
21   {
22          register int  i;
23  
24 +        if (issurface(obj->otype) && !strcmp(mod, VOIDID))
25 +                return;         /* don't print void surfaces */
26          printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
27          printf("\n%d", obj->oargs.nsargs);
28          for (i = 0; i < obj->oargs.nsargs; i++)
# Line 50 | Line 49 | dfname(il, c)                  /* return data file name */
49   struct illum_args  *il;
50   int  c;
51   {
53        extern char  *getpath(), *strcpy();
52          char  fname[MAXSTR];
53          register char  *s;
54  
# Line 87 | Line 85 | int  c;
85   }
86  
87  
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
88   flatout(il, da, n, m, u, v, w)          /* write hemispherical distribution */
89   struct illum_args  *il;
90   float  *da;
91   int  n, m;
92   FVECT  u, v, w;
93   {
94 +        float  *Ninv;
95          FILE  *dfp;
96          int  i;
97  
98 <        average(il, da, n*m);
98 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL)
99 >                error(SYSTEM, "out of memory in flatout");
100 >        compinv(Ninv, da, m);
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\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
108 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
107 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
108 >                                        1.+.5/n, .5/n, n+1,
109 >                                        0., 2.*PI, m+1);
110 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
111 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
112 >                        fputeol(dfp);
113                          fclose(dfp);
114                          printf(" %s", dfname(il, DATORD[i]));
115                  }
116          } else {
117                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
118                                  il->matname, DSTSUF);
119 <                printf("\n5 noop");
119 >                printf("\n5 noneg");
120                  dfp = dfopen(il, 0);
121 <                fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
122 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
121 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
122 >                                1.+.5/n, .5/n, n+1,
123 >                                0., 2.*PI, m+1);
124 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
125 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
126 >                fputeol(dfp);
127                  fclose(dfp);
128                  printf(" %s", dfname(il, 0));
129          }
# Line 153 | Line 133 | FVECT  u, v, w;
133          printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
134          printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
135          il->dfnum++;
136 +        free((void *)Ninv);
137   }
138  
139  
# Line 161 | Line 142 | struct illum_args  *il;
142   float  *da;
143   int  n, m;
144   {
145 +        float  *Ninv, *Sinv;
146          FILE  *dfp;
147          int  i;
148  
149 <        average(il, da, n*m);
149 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL ||
150 >                        (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL)
151 >                error(SYSTEM, "out of memory in roundout");
152 >        compinv(Ninv, da, m);
153 >        compinv(Sinv, da+3*m*(n-1), m);
154          if (il->flags & IL_COLDST) {
155                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
156                                  il->matname, DSTSUF);
157                  printf("\n9 red green blue");
158                  for (i = 0; i < 3; i++) {
159                          dfp = dfopen(il, DATORD[i]);
160 <                        fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
161 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
160 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
161 >                                        1.+1./n, -1.-1./n, n+2,
162 >                                        0., 2.*PI, m+1);
163 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
164 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
165 >                        colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp);
166 >                        fputeol(dfp);
167                          fclose(dfp);
168                          printf(" %s", dfname(il, DATORD[i]));
169                  }
170          } else {
171                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
172                                  il->matname, DSTSUF);
173 <                printf("\n5 noop");
173 >                printf("\n5 noneg");
174                  dfp = dfopen(il, 0);
175 <                fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
176 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
175 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
176 >                                1.+1./n, -1.-1./n, n+2,
177 >                                0., 2.*PI, m+1);
178 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
179 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
180 >                brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp);
181 >                fputeol(dfp);
182                  fclose(dfp);
183                  printf(" %s", dfname(il, 0));
184          }
185          printf("\n\t%s il_alt il_azi", FNCFNM);
186          printf("\n0\n0\n");
187          il->dfnum++;
188 +        free((void *)Ninv);
189 +        free((void *)Sinv);
190   }
191  
192  
193 < average(il, da, n)              /* compute average value for distribution */
193 > illumout(il, ob)                /* print illum object */
194   register struct illum_args  *il;
195 + OBJREC  *ob;
196 + {
197 +        double  cout[3];
198 +
199 +        if (il->sampdens <= 0)
200 +                printf("\n%s ", VOIDID);
201 +        else
202 +                printf("\n%s%s ", il->matname, DSTSUF);
203 +        printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
204 +                        il->matname);
205 +        if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
206 +                printf("\n0");
207 +        else
208 +                printf("\n1 %s", il->altmat);
209 +        if (il->flags & IL_COLAVG) {
210 +                cout[0] = il->col[0];
211 +                cout[1] = il->col[1];
212 +                cout[2] = il->col[2];
213 +        } else {
214 +                cout[0] = cout[1] = cout[2] = brt(il->col);
215 +        }
216 +        printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
217 +
218 +        printobj(il->matname, ob);
219 + }
220 +
221 +
222 + compavg(col, da, n)             /* compute average for set of data values */
223 + float  col[3];
224   register float  *da;
225   int  n;
226   {
227          register int  i;
228  
229 <        il->col[0] = il->col[1] = il->col[2] = 0.;
229 >        col[0] = col[1] = col[2] = 0.;
230          i = n;
231          while (i-- > 0) {
232 <                il->col[0] += *da++;
233 <                il->col[1] += *da++;
234 <                il->col[2] += *da++;
232 >                col[0] += *da++;
233 >                col[1] += *da++;
234 >                col[2] += *da++;
235          }
236          for (i = 0; i < 3; i++)
237 <                il->col[i] /= (double)n*il->nsamps;
237 >                col[i] /= (double)n;
238   }
239  
240  
241 < colorout(p, da, n, mult, fp)    /* put out color distribution data */
241 > compinv(rinv, rp, m)            /* compute other side of row average */
242 > register float  *rinv, *rp;
243 > int  m;
244 > {
245 >        float  avg[3];
246 >
247 >        compavg(avg, rp, m);            /* row average */
248 >        while (m-- > 0) {
249 >                *rinv++ = 2.*avg[0] - *rp++;
250 >                *rinv++ = 2.*avg[1] - *rp++;
251 >                *rinv++ = 2.*avg[2] - *rp++;
252 >        }
253 > }
254 >
255 >
256 > average(il, da, n)              /* evaluate average value for distribution */
257 > register struct illum_args  *il;
258 > float  *da;
259 > int  n;
260 > {
261 >        compavg(il->col, da, n);        /* average */
262 >        if (il->nsamps > 1) {
263 >                il->col[0] /= (double)il->nsamps;
264 >                il->col[1] /= (double)il->nsamps;
265 >                il->col[2] /= (double)il->nsamps;
266 >        }
267 >                                        /* brighter than minimum? */
268 >        return(brt(il->col) > il->minbrt+FTINY);
269 > }
270 >
271 >
272 > static int      colmcnt = 0;    /* count of columns written */
273 >
274 > fputnum(d, fp)                  /* put out a number to fp */
275 > double  d;
276 > FILE  *fp;
277 > {
278 >        if (colmcnt++ % 5 == 0)
279 >                putc('\n', fp);
280 >        fprintf(fp, " %11e", d);
281 > }
282 >
283 >
284 > fputeol(fp)                     /* write end of line to fp */
285 > register FILE  *fp;
286 > {
287 >        putc('\n', fp);
288 >        colmcnt = 0;
289 > }
290 >
291 >
292 > colorout(p, da, n, m, mult, fp) /* put out color distribution data */
293   int  p;
294   register float  *da;
295 < int  n;
295 > int  n, m;
296   double  mult;
297   FILE  *fp;
298   {
299 <        register int  i;
299 >        register int  i, j;
300  
301          for (i = 0; i < n; i++) {
302 <                if (i%6 == 0)
303 <                        putc('\n', fp);
304 <                fprintf(fp, " %11e", mult*da[p]);
305 <                da += 3;
302 >                for (j = 0; j < m; j++) {
303 >                        fputnum(mult*da[p], fp);
304 >                        da += 3;
305 >                }
306 >                fputnum(mult*da[p-3*m], fp);    /* wrap phi */
307          }
229        putc('\n', fp);
308   }
309  
310  
311 < brightout(da, n, mult, fp)      /* put out brightness distribution data */
311 > brightout(da, n, m, mult, fp)   /* put out brightness distribution data */
312   register float  *da;
313 < int  n;
313 > int  n, m;
314   double  mult;
315   FILE  *fp;
316   {
317 <        register int  i;
317 >        register int  i, j;
318  
319          for (i = 0; i < n; i++) {
320 <                if (i%6 == 0)
321 <                        putc('\n', fp);
322 <                fprintf(fp, " %11e", mult*brt(da));
323 <                da += 3;
320 >                for (j = 0; j < m; j++) {
321 >                        fputnum(mult*brt(da), fp);
322 >                        da += 3;
323 >                }
324 >                fputnum(mult*brt(da-3*m), fp);  /* wrap phi */
325          }
247        putc('\n', fp);
326   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines