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.14 by greg, Thu Jan 11 08:30:42 1990 UTC vs.
Revision 1.34 by greg, Thu Oct 10 12:58:13 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #ifdef BSD
16   #include  <sys/time.h>
17   #include  <sys/resource.h>
18 #else
19 #include  <signal.h>
18   #endif
19  
20 + #include  <signal.h>
21 + #include  <fcntl.h>
22 +
23   #include  "view.h"
24  
25   #include  "random.h"
26  
27 + int  dimlist[MAXDIM];                   /* sampling dimensions */
28 + int  ndims = 0;                         /* number of sampling dimensions */
29 + int  samplendx;                         /* sample index number */
30 +
31   VIEW  ourview = STDVIEW;                /* view parameters */
32   int  hresolu = 512;                     /* horizontal resolution */
33   int  vresolu = 512;                     /* vertical resolution */
# Line 35 | Line 40 | double  dstrpix = 0.67;                        /* square pixel distribution
40   double  dstrsrc = 0.0;                  /* square source distribution */
41   double  shadthresh = .05;               /* shadow threshold */
42   double  shadcert = .5;                  /* shadow certainty */
43 + int  directrelay = 0;                   /* number of source relays */
44 + int  vspretest = 512;                   /* virtual source pretest density */
45 + int  directinvis = 0;                   /* sources invisible? */
46  
47   int  maxdepth = 6;                      /* maximum recursion depth */
48   double  minweight = 5e-3;               /* minimum ray weight */
# Line 52 | Line 60 | int  ralrm = 0;                                /* seconds between reports */
60  
61   double  pctdone = 0.0;                  /* percentage done */
62  
63 + long  tlastrept = 0L;                   /* time at last report */
64 +
65 + extern long  time();
66 + extern long  tstart;                    /* starting time */
67 +
68   extern long  nrays;                     /* number of rays traced */
69  
70 < #define  MAXDIV         32              /* maximum sample size */
70 > #define  MAXDIV         15              /* maximum sample size */
71  
72   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
73  
# Line 71 | Line 84 | int  code;
84   }
85  
86  
87 + #ifdef BSD
88   report()                /* report progress */
89   {
76 #ifdef BSD
90          struct rusage  rubuf;
91          double  t;
92  
# Line 86 | Line 99 | report()               /* report progress */
99  
100          sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
101                          nrays, pctdone, t/3600.0);
102 +        eputs(errmsg);
103 +        tlastrept = time((long *)0);
104 + }
105   #else
106 + report()                /* report progress */
107 + {
108          signal(SIGALRM, report);
109 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
110 < #endif
109 >        tlastrept = time((long *)0);
110 >        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
111 >                        nrays, pctdone, (tlastrept-tstart)/3600.0);
112          eputs(errmsg);
94
95        if (ralrm > 0)
96                alarm(ralrm);
113   }
114 + #endif
115  
116  
117   render(zfile, oldfile)                          /* render the scene */
118   char  *zfile, *oldfile;
119   {
120 +        extern long  lseek();
121          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
122          float  *zbar[MAXDIV+1];         /* z values */
123          int  ypos;                      /* current scanline */
124 <        FILE  *zfp;
124 >        int  ystep;                     /* current y step size */
125 >        int  hstep;                     /* h step size */
126 >        int  zfd;
127          COLOR  *colptr;
128          float  *zptr;
129          register int  i;
130                                          /* check sampling */
131          if (psample < 1)
132                  psample = 1;
133 <        else if (psample > MAXDIV)
133 >        else if (psample > MAXDIV) {
134 >                sprintf(errmsg, "pixel sampling reduced from %d to %d",
135 >                                psample, MAXDIV);
136 >                error(WARNING, errmsg);
137                  psample = MAXDIV;
138 +        }
139                                          /* allocate scanlines */
140          for (i = 0; i <= psample; i++) {
141                  scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
# Line 120 | Line 144 | char  *zfile, *oldfile;
144          }
145                                          /* open z file */
146          if (zfile != NULL) {
147 <                if ((zfp = fopen(zfile, "a+")) == NULL) {
147 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
148                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
149                          error(SYSTEM, errmsg);
150                  }
# Line 130 | Line 154 | char  *zfile, *oldfile;
154                                  goto memerr;
155                  }
156          } else {
157 <                zfp = NULL;
157 >                zfd = -1;
158                  for (i = 0; i <= psample; i++)
159                          zbar[i] = NULL;
160          }
# Line 138 | Line 162 | char  *zfile, *oldfile;
162          fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
163                                          /* recover file and compute first */
164          i = salvage(oldfile);
165 <        if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF)
165 >        if (zfd != -1 && i > 0 &&
166 >                        lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
167                  error(SYSTEM, "z file seek error in render");
168 +        pctdone = 100.0*i/vresolu;
169 +        if (ralrm > 0)                  /* report init stats */
170 +                report();
171 + #ifndef  BSD
172 +        else
173 + #endif
174 +        signal(SIGALRM, report);
175          ypos = vresolu-1 - i;
176 <        fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
176 >        hstep = (psample*140+49)/99;            /* quincunx sampling */
177 >        ystep = (psample*99+70)/140;
178 >        fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep);
179                                                  /* compute scanlines */
180 <        for (ypos -= psample; ypos >= 0; ypos -= psample) {
181 <        
182 <                pctdone = 100.0*(vresolu-ypos-psample)/vresolu;
183 <
184 <                colptr = scanbar[psample];              /* move base to top */
185 <                scanbar[psample] = scanbar[0];
180 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
181 >                                                        /* bottom adjust? */
182 >                if (ypos < 0) {
183 >                        ystep += ypos;
184 >                        ypos = 0;
185 >                }
186 >                colptr = scanbar[ystep];                /* move base to top */
187 >                scanbar[ystep] = scanbar[0];
188                  scanbar[0] = colptr;
189 <                zptr = zbar[psample];
190 <                zbar[psample] = zbar[0];
189 >                zptr = zbar[ystep];
190 >                zbar[ystep] = zbar[0];
191                  zbar[0] = zptr;
192                                                          /* fill base line */
193 <                fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
193 >                fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep);
194                                                          /* fill bar */
195 <                fillscanbar(scanbar, zbar, hresolu, ypos, psample);
195 >                fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
196                                                          /* write it out */
197 <                for (i = psample; i > 0; i--) {
198 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
197 > #ifndef  BSD
198 >                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
199 > #endif
200 >                for (i = ystep; i > 0; i--) {
201 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
202 >                                        hresolu*sizeof(float))
203 >                                        < hresolu*sizeof(float))
204                                  goto writerr;
205 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
205 >                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
206                                  goto writerr;
207                  }
167                if (zfp != NULL && fflush(zfp) == EOF)
168                        goto writerr;
208                  if (fflush(stdout) == EOF)
209                          goto writerr;
210 +                                                        /* record progress */
211 +                pctdone = 100.0*(vresolu-1-ypos)/vresolu;
212 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
213 +                        report();
214 + #ifndef  BSD
215 +                else
216 +                        signal(SIGALRM, report);
217 + #endif
218          }
172                                                /* compute residual */
173        colptr = scanbar[psample];
174        scanbar[psample] = scanbar[0];
175        scanbar[0] = colptr;
176        zptr = zbar[psample];
177        zbar[psample] = zbar[0];
178        zbar[0] = zptr;
179        if (ypos > -psample) {
180                fillscanline(scanbar[-ypos], zbar[-ypos], hresolu, 0, psample);
181                fillscanbar(scanbar-ypos, zbar-ypos, hresolu, 0, psample+ypos);
182        }
183        for (i = psample; i+ypos >= 0; i--) {
184                if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
185                        goto writerr;
186                if (fwritescan(scanbar[i], hresolu, stdout) < 0)
187                        goto writerr;
188        }
219                                                  /* clean up */
220 <        if (zfp != NULL) {
221 <                if (fclose(zfp) == EOF)
220 >        if (zfd != -1) {
221 >                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
222 >                                < hresolu*sizeof(float))
223                          goto writerr;
224 +                if (close(zfd) == -1)
225 +                        goto writerr;
226                  for (i = 0; i <= psample; i++)
227                          free((char *)zbar[i]);
228          }
229 +        fwritescan(scanbar[0], hresolu, stdout);
230          if (fflush(stdout) == EOF)
231                  goto writerr;
232          for (i = 0; i <= psample; i++)
# Line 211 | Line 245 | register COLOR  *scanline;
245   register float  *zline;
246   int  xres, y, xstep;
247   {
248 +        static int  nc = 0;             /* number of calls */
249          int  b = xstep;
250          double  z;
251          register int  i;
252          
253          z = pixvalue(scanline[0], 0, y);
254          if (zline) zline[0] = z;
255 <
256 <        for (i = xstep; i < xres; i += xstep) {
257 <        
255 >                                /* zig-zag start for quincunx pattern */
256 >        for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) {
257 >                if (i >= xres) {
258 >                        xstep += xres-1-i;
259 >                        i = xres-1;
260 >                }
261                  z = pixvalue(scanline[i], i, y);
262                  if (zline) zline[i] = z;
263                  
264                  b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
265                                  i-xstep, y, xstep, 0, b/2);
266          }
229        if (i-xstep < xres-1) {
230                z = pixvalue(scanline[xres-1], xres-1, y);
231                if (zline) zline[xres-1] = z;
232                fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
233                                i-xstep, y, xres-1-(i-xstep), 0, b/2);
234        }
267   }
268  
269  
# Line 243 | Line 275 | int  xres, y, ysize;
275          COLOR  vline[MAXDIV+1];
276          float  zline[MAXDIV+1];
277          int  b = ysize;
246        double  z;
278          register int  i, j;
279          
280          for (i = 0; i < xres; i++) {
# Line 327 | Line 358 | pixvalue(col, x, y)            /* compute pixel value */
358   COLOR  col;                     /* returned color */
359   int  x, y;                      /* pixel position */
360   {
361 <        static RAY  thisray;    /* our ray for this pixel */
361 >        static RAY  thisray;
362  
363 <        viewray(thisray.rorg, thisray.rdir, &ourview,
364 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
363 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
364 >                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
365 >                setcolor(col, 0.0, 0.0, 0.0);
366 >                return(0.0);
367 >        }
368  
369          rayorigin(&thisray, NULL, PRIMARY, 1.0);
370 <        
370 >
371 >        samplendx = pixnumber(x,y,hresolu,vresolu);     /* set pixel index */
372 >
373          rayvalue(&thisray);                     /* trace ray */
374  
375          copycolor(col, thisray.rcol);           /* return color */
376          
377 <        return(thisray.rot);                    /* return distance */
377 >        return(thisray.rt);                     /* return distance */
378   }
379  
380  
# Line 391 | Line 427 | char  *oldfile;
427          return(y);
428   writerr:
429          error(SYSTEM, "write error in salvage");
430 + }
431 +
432 +
433 + int
434 + pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
435 + register int  x, y;
436 + int  xres, yres;
437 + {
438 +        x -= y;
439 +        while (x < 0)
440 +                x += xres;
441 +        return((((x>>2)*yres + y) << 2) + (x & 3));
442   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines