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.2 by greg, Thu Jul 25 10:59:09 1991 UTC vs.
Revision 2.7 by greg, Sat Feb 22 02:07:24 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 93 | Line 92 | float  *da;
92   int  n, m;
93   FVECT  u, v, w;
94   {
95 +        float  *Ninv;
96          FILE  *dfp;
97          int  i;
98  
99 <        average(il, da, n*m);
99 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL)
100 >                error(SYSTEM, "out of memory in flatout");
101 >        compinv(Ninv, da, m);
102          if (il->flags & IL_COLDST) {
103                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
104                                  il->matname, DSTSUF);
105                  printf("\n9 red green blue");
106                  for (i = 0; i < 3; i++) {
107                          dfp = dfopen(il, DATORD[i]);
108 <                        fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
109 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
108 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
109 >                                        1.+.5/n, .5/n, n+1,
110 >                                        0., 2.*PI, m+1);
111 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
112 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
113 >                        fputeol(dfp);
114                          fclose(dfp);
115                          printf(" %s", dfname(il, DATORD[i]));
116                  }
117          } else {
118                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
119                                  il->matname, DSTSUF);
120 <                printf("\n5 noop");
120 >                printf("\n5 noneg");
121                  dfp = dfopen(il, 0);
122 <                fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
123 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
122 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
123 >                                1.+.5/n, .5/n, n+1,
124 >                                0., 2.*PI, m+1);
125 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
126 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
127 >                fputeol(dfp);
128                  fclose(dfp);
129                  printf(" %s", dfname(il, 0));
130          }
# Line 124 | Line 134 | FVECT  u, v, w;
134          printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
135          printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
136          il->dfnum++;
137 +        free((void *)Ninv);
138   }
139  
140  
# Line 132 | Line 143 | struct illum_args  *il;
143   float  *da;
144   int  n, m;
145   {
146 +        float  *Ninv, *Sinv;
147          FILE  *dfp;
148          int  i;
149  
150 <        average(il, da, n*m);
150 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL ||
151 >                        (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL)
152 >                error(SYSTEM, "out of memory in roundout");
153 >        compinv(Ninv, da, m);
154 >        compinv(Sinv, da+3*m*(n-1), m);
155          if (il->flags & IL_COLDST) {
156                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
157                                  il->matname, DSTSUF);
158                  printf("\n9 red green blue");
159                  for (i = 0; i < 3; i++) {
160                          dfp = dfopen(il, DATORD[i]);
161 <                        fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
162 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
161 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
162 >                                        1.+1./n, -1.-1./n, n+2,
163 >                                        0., 2.*PI, m+1);
164 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
165 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
166 >                        colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp);
167 >                        fputeol(dfp);
168                          fclose(dfp);
169                          printf(" %s", dfname(il, DATORD[i]));
170                  }
171          } else {
172                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
173                                  il->matname, DSTSUF);
174 <                printf("\n5 noop");
174 >                printf("\n5 noneg");
175                  dfp = dfopen(il, 0);
176 <                fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
177 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
176 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
177 >                                1.+1./n, -1.-1./n, n+2,
178 >                                0., 2.*PI, m+1);
179 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
180 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
181 >                brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp);
182 >                fputeol(dfp);
183                  fclose(dfp);
184                  printf(" %s", dfname(il, 0));
185          }
186          printf("\n\t%s il_alt il_azi", FNCFNM);
187          printf("\n0\n0\n");
188          il->dfnum++;
189 +        free((void *)Ninv);
190 +        free((void *)Sinv);
191   }
192  
193  
# Line 169 | Line 197 | OBJREC  *ob;
197   {
198          double  cout[3];
199  
200 <        printf("\n%s%s %s %s", il->matname, DSTSUF,
201 <                        ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
200 >        if (il->sampdens <= 0)
201 >                printf("\n%s ", VOIDID);
202 >        else
203 >                printf("\n%s%s ", il->matname, DSTSUF);
204 >        printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
205                          il->matname);
206          if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
207                  printf("\n0");
# Line 183 | Line 214 | OBJREC  *ob;
214          } else {
215                  cout[0] = cout[1] = cout[2] = brt(il->col);
216          }
217 <        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]);
217 >        printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
218  
219          printobj(il->matname, ob);
220   }
221  
222  
223 < average(il, da, n)              /* compute average value for distribution */
224 < register struct illum_args  *il;
223 > compavg(col, da, n)             /* compute average for set of data values */
224 > float  col[3];
225   register float  *da;
226   int  n;
227   {
228          register int  i;
229  
230 <        il->col[0] = il->col[1] = il->col[2] = 0.;
230 >        col[0] = col[1] = col[2] = 0.;
231          i = n;
232          while (i-- > 0) {
233 <                il->col[0] += *da++;
234 <                il->col[1] += *da++;
235 <                il->col[2] += *da++;
233 >                col[0] += *da++;
234 >                col[1] += *da++;
235 >                col[2] += *da++;
236          }
237          for (i = 0; i < 3; i++)
238 <                il->col[i] /= (double)n*il->nsamps;
238 >                col[i] /= (double)n;
239   }
240  
241  
242 < colorout(p, da, n, mult, fp)    /* put out color distribution data */
242 > compinv(rinv, rp, m)            /* compute other side of row average */
243 > register float  *rinv, *rp;
244 > int  m;
245 > {
246 >        float  avg[3];
247 >
248 >        compavg(avg, rp, m);            /* row average */
249 >        while (m-- > 0) {
250 >                *rinv++ = 2.*avg[0] - *rp++;
251 >                *rinv++ = 2.*avg[1] - *rp++;
252 >                *rinv++ = 2.*avg[2] - *rp++;
253 >        }
254 > }
255 >
256 >
257 > average(il, da, n)              /* evaluate average value for distribution */
258 > register struct illum_args  *il;
259 > float  *da;
260 > int  n;
261 > {
262 >        compavg(il->col, da, n);        /* average */
263 >        if (il->nsamps > 1) {
264 >                il->col[0] /= (double)il->nsamps;
265 >                il->col[1] /= (double)il->nsamps;
266 >                il->col[2] /= (double)il->nsamps;
267 >        }
268 >                                        /* brighter than minimum? */
269 >        return(brt(il->col) > il->minbrt+FTINY);
270 > }
271 >
272 >
273 > static int      colmcnt = 0;    /* count of columns written */
274 >
275 > fputnum(d, fp)                  /* put out a number to fp */
276 > double  d;
277 > FILE  *fp;
278 > {
279 >        if (colmcnt++ % 5 == 0)
280 >                putc('\n', fp);
281 >        fprintf(fp, " %11e", d);
282 > }
283 >
284 >
285 > fputeol(fp)                     /* write end of line to fp */
286 > register FILE  *fp;
287 > {
288 >        putc('\n', fp);
289 >        colmcnt = 0;
290 > }
291 >
292 >
293 > colorout(p, da, n, m, mult, fp) /* put out color distribution data */
294   int  p;
295   register float  *da;
296 < int  n;
296 > int  n, m;
297   double  mult;
298   FILE  *fp;
299   {
300 <        register int  i;
300 >        register int  i, j;
301  
302          for (i = 0; i < n; i++) {
303 <                if (i%6 == 0)
304 <                        putc('\n', fp);
305 <                fprintf(fp, " %11e", mult*da[p]);
306 <                da += 3;
303 >                for (j = 0; j < m; j++) {
304 >                        fputnum(mult*da[p], fp);
305 >                        da += 3;
306 >                }
307 >                fputnum(mult*da[p-3*m], fp);    /* wrap phi */
308          }
229        putc('\n', fp);
309   }
310  
311  
312 < brightout(da, n, mult, fp)      /* put out brightness distribution data */
312 > brightout(da, n, m, mult, fp)   /* put out brightness distribution data */
313   register float  *da;
314 < int  n;
314 > int  n, m;
315   double  mult;
316   FILE  *fp;
317   {
318 <        register int  i;
318 >        register int  i, j;
319  
320          for (i = 0; i < n; i++) {
321 <                if (i%6 == 0)
322 <                        putc('\n', fp);
323 <                fprintf(fp, " %11e", mult*brt(da));
324 <                da += 3;
321 >                for (j = 0; j < m; j++) {
322 >                        fputnum(mult*brt(da), fp);
323 >                        da += 3;
324 >                }
325 >                fputnum(mult*brt(da-3*m), fp);  /* wrap phi */
326          }
247        putc('\n', fp);
327   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines