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

Comparing ray/src/rt/rpict.c (file contents):
Revision 1.10 by greg, Tue Oct 3 12:17:09 1989 UTC vs.
Revision 1.11 by greg, Sun Dec 10 13:42:45 1989 UTC

# Line 53 | Line 53 | extern long  nrays;                    /* number of rays traced */
53  
54   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
55  
56 + double  pixvalue();
57  
58 +
59   quit(code)                      /* quit program */
60   int  code;
61   {
# Line 89 | Line 91 | report()               /* report progress */
91   }
92  
93  
94 < render(oldfile)                         /* render the scene */
95 < char  *oldfile;
94 > render(zfile, oldfile)                          /* render the scene */
95 > char  *zfile, *oldfile;
96   {
97          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
98 +        float  *zbar[MAXDIV+1];         /* z values */
99          int  ypos;                      /* current scanline */
100 +        FILE  *zfp;
101          COLOR  *colptr;
102 +        float  *zptr;
103          register int  i;
104                                          /* check sampling */
105          if (psample < 1)
# Line 105 | Line 110 | char  *oldfile;
110          for (i = 0; i <= psample; i++) {
111                  scanbar[i] = (COLOR *)malloc(ourview.hresolu*sizeof(COLOR));
112                  if (scanbar[i] == NULL)
113 <                        error(SYSTEM, "out of memory in render");
113 >                        goto memerr;
114          }
115 +                                        /* open z file */
116 +        if (zfile != NULL) {
117 +                if ((zfp = fopen(zfile, "a+")) == NULL) {
118 +                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
119 +                        error(SYSTEM, errmsg);
120 +                }
121 +                for (i = 0; i <= psample; i++) {
122 +                        zbar[i] = (float *)malloc(ourview.hresolu*sizeof(float));
123 +                        if (zbar[i] == NULL)
124 +                                goto memerr;
125 +                }
126 +        } else {
127 +                zfp = NULL;
128 +                for (i = 0; i <= psample; i++)
129 +                        zbar[i] = NULL;
130 +        }
131                                          /* write out boundaries */
132          fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
133                                          /* recover file and compute first */
134 <        ypos = ourview.vresolu-1 - salvage(oldfile);
135 <        fillscanline(scanbar[0], ourview.hresolu, ypos, psample);
134 >        i = salvage(oldfile);
135 >        if (zfp != NULL && fseek(zfp, (long)i*ourview.hresolu*sizeof(float), 0) == EOF)
136 >                error(SYSTEM, "z file seek error in render");
137 >        ypos = ourview.vresolu-1 - i;
138 >        fillscanline(scanbar[0], zbar[0], ourview.hresolu, ypos, psample);
139                                                  /* compute scanlines */
140          for (ypos -= psample; ypos >= 0; ypos -= psample) {
141          
# Line 120 | Line 144 | char  *oldfile;
144                  colptr = scanbar[psample];              /* move base to top */
145                  scanbar[psample] = scanbar[0];
146                  scanbar[0] = colptr;
147 +                zptr = zbar[psample];
148 +                zbar[psample] = zbar[0];
149 +                zbar[0] = zptr;
150                                                          /* fill base line */
151 <                fillscanline(scanbar[0], ourview.hresolu, ypos, psample);
151 >                fillscanline(scanbar[0], zbar[0], ourview.hresolu, ypos, psample);
152                                                          /* fill bar */
153 <                fillscanbar(scanbar, ourview.hresolu, ypos, psample);
153 >                fillscanbar(scanbar, zbar, ourview.hresolu, ypos, psample);
154                                                          /* write it out */
155 <                for (i = psample; i > 0; i--)
156 <                        if (fwritescan(scanbar[i], ourview.hresolu, stdout) < 0)
155 >                for (i = psample; i > 0; i--) {
156 >                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),ourview.hresolu,zfp) != ourview.hresolu)
157                                  goto writerr;
158 +                        if (fwritescan(scanbar[i],ourview.hresolu,stdout) < 0)
159 +                                goto writerr;
160 +                }
161 +                if (zfp != NULL && fflush(zfp) == EOF)
162 +                        goto writerr;
163                  if (fflush(stdout) == EOF)
164                          goto writerr;
165          }
# Line 135 | Line 167 | char  *oldfile;
167          colptr = scanbar[psample];
168          scanbar[psample] = scanbar[0];
169          scanbar[0] = colptr;
170 +        zptr = zbar[psample];
171 +        zbar[psample] = zbar[0];
172 +        zbar[0] = zptr;
173          if (ypos > -psample) {
174 <                fillscanline(scanbar[-ypos], ourview.hresolu,
174 >                fillscanline(scanbar[-ypos], zbar[-ypos], ourview.hresolu,
175                                  0, psample);
176 <                fillscanbar(scanbar-ypos, ourview.hresolu,
176 >                fillscanbar(scanbar-ypos, zbar-ypos, ourview.hresolu,
177                                  0, psample+ypos);
178          }
179 <        for (i = psample; i+ypos >= 0; i--)
179 >        for (i = psample; i+ypos >= 0; i--) {
180 >                if (zfp != NULL && fwrite(zbar[i],sizeof(float),ourview.hresolu,zfp) != ourview.hresolu)
181 >                        goto writerr;
182                  if (fwritescan(scanbar[i], ourview.hresolu, stdout) < 0)
183                          goto writerr;
184 +        }
185 +                                                /* clean up */
186 +        if (zfp != NULL) {
187 +                if (fclose(zfp) == EOF)
188 +                        goto writerr;
189 +                for (i = 0; i <= psample; i++)
190 +                        free((char *)zbar[i]);
191 +        }
192          if (fflush(stdout) == EOF)
193                  goto writerr;
149        pctdone = 100.0;
150                                                /* free scanlines */
194          for (i = 0; i <= psample; i++)
195                  free((char *)scanbar[i]);
196 +        pctdone = 100.0;
197          return;
198   writerr:
199          error(SYSTEM, "write error in render");
200 + memerr:
201 +        error(SYSTEM, "out of memory in render");
202   }
203  
204  
205 < fillscanline(scanline, xres, y, xstep)          /* fill scan line at y */
205 > fillscanline(scanline, zline, xres, y, xstep)   /* fill scan line at y */
206   register COLOR  *scanline;
207 + register float  *zline;
208   int  xres, y, xstep;
209   {
210          int  b = xstep;
211 +        double  z;
212          register int  i;
213          
214 <        pixvalue(scanline[0], 0, y);
214 >        z = pixvalue(scanline[0], 0, y);
215 >        if (zline) zline[0] = z;
216  
217          for (i = xstep; i < xres; i += xstep) {
218          
219 <                pixvalue(scanline[i], i, y);
219 >                z = pixvalue(scanline[i], i, y);
220 >                if (zline) zline[i] = z;
221                  
222 <                b = fillsample(scanline+i-xstep, i-xstep, y, xstep, 0, b/2);
222 >                b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
223 >                                i-xstep, y, xstep, 0, b/2);
224          }
225          if (i-xstep < xres-1) {
226 <                pixvalue(scanline[xres-1], xres-1, y);
227 <                fillsample(scanline+i-xstep, i-xstep, y,
228 <                                xres-1-(i-xstep), 0, b/2);
226 >                z = pixvalue(scanline[xres-1], xres-1, y);
227 >                if (zline) zline[xres-1] = z;
228 >                fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
229 >                                i-xstep, y, xres-1-(i-xstep), 0, b/2);
230          }
231   }
232  
233  
234 < fillscanbar(scanbar, xres, y, ysize)            /* fill interior */
234 > fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
235   register COLOR  *scanbar[];
236 + register float  *zbar[];
237   int  xres, y, ysize;
238   {
239          COLOR  vline[MAXDIV+1];
240 +        float  zline[MAXDIV+1];
241          int  b = ysize;
242 +        double  z;
243          register int  i, j;
244          
245          for (i = 0; i < xres; i++) {
246                  
247                  copycolor(vline[0], scanbar[0][i]);
248                  copycolor(vline[ysize], scanbar[ysize][i]);
249 +                if (zbar[0]) {
250 +                        zline[0] = zbar[0][i];
251 +                        zline[ysize] = zbar[ysize][i];
252 +                }
253                  
254 <                b = fillsample(vline, i, y, 0, ysize, b/2);
254 >                b = fillsample(vline, zbar[0] ? zline : NULL,
255 >                                i, y, 0, ysize, b/2);
256                  
257                  for (j = 1; j < ysize; j++)
258                          copycolor(scanbar[j][i], vline[j]);
259 +                if (zbar[0])
260 +                        for (j = 1; j < ysize; j++)
261 +                                zbar[j][i] = zline[j];
262          }
263   }
264  
265  
266   int
267 < fillsample(colline, x, y, xlen, ylen, b)        /* fill interior points */
267 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
268   register COLOR  *colline;
269 + register float  *zline;
270   int  x, y;
271   int  xlen, ylen;
272   int  b;
273   {
274 +        extern double  fabs();
275          double  ratio;
276 +        double  z;
277          COLOR  ctmp;
278          int  ncut;
279          register int  len;
# Line 220 | Line 286 | int  b;
286          if (len <= 1)                   /* limit recursion */
287                  return(0);
288          
289 <        if (b > 0 || bigdiff(colline[0], colline[len], maxdiff)) {
289 >        if (b > 0
290 >        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
291 >                        || bigdiff(colline[0], colline[len], maxdiff)) {
292          
293 <                pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
293 >                z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
294 >                if (zline) zline[len>>1] = z;
295                  ncut = 1;
296                  
297          } else {                                        /* interpolate */
# Line 230 | Line 299 | int  b;
299                  copycolor(colline[len>>1], colline[len]);
300                  ratio = (double)(len>>1) / len;
301                  scalecolor(colline[len>>1], ratio);
302 <                copycolor(ctmp, colline[0]);
302 >                if (zline) zline[len>>1] = zline[len] * ratio;
303                  ratio = 1.0 - ratio;
304 +                copycolor(ctmp, colline[0]);
305                  scalecolor(ctmp, ratio);
306                  addcolor(colline[len>>1], ctmp);
307 +                if (zline) zline[len>>1] += zline[0] * ratio;
308                  ncut = 0;
309          }
310                                                          /* recurse */
311 <        ncut += fillsample(colline, x, y, xlen>>1, ylen>>1, (b-1)/2);
311 >        ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
312          
313 <        ncut += fillsample(colline + (len>>1), x + (xlen>>1), y + (ylen>>1),
314 <                                xlen - (xlen>>1), ylen - (ylen>>1), b/2);
313 >        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
314 >                        x+(xlen>>1), y+(ylen>>1),
315 >                        xlen-(xlen>>1), ylen-(ylen>>1), b/2);
316  
317          return(ncut);
318   }
319  
320  
321 + double
322   pixvalue(col, x, y)             /* compute pixel value */
323   COLOR  col;                     /* returned color */
324   int  x, y;                      /* pixel position */
# Line 260 | Line 333 | int  x, y;                     /* pixel position */
333          rayvalue(&thisray);                     /* trace ray */
334  
335          copycolor(col, thisray.rcol);           /* return color */
336 +        
337 +        return(thisray.rot);                    /* return distance */
338   }
339  
340  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines