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.12 by greg, Mon Jan 8 13:38:01 1990 UTC vs.
Revision 1.27 by greg, Wed Jun 19 16:36:34 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>
20   #endif
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 */
34 + double  pixaspect = 1.0;                /* pixel aspect ratio */
35  
36   int  psample = 4;                       /* pixel sample size */
37   double  maxdiff = .05;                  /* max. difference for interpolation */
# Line 32 | 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  
45   int  maxdepth = 6;                      /* maximum recursion depth */
46   double  minweight = 5e-3;               /* minimum ray weight */
# Line 49 | Line 58 | int  ralrm = 0;                                /* seconds between reports */
58  
59   double  pctdone = 0.0;                  /* percentage done */
60  
61 + long  tlastrept = 0L;                   /* time at last report */
62 +
63 + extern long  time();
64 + extern long  tstart;                    /* starting time */
65 +
66   extern long  nrays;                     /* number of rays traced */
67  
68 < #define  MAXDIV         32              /* maximum sample size */
68 > #define  MAXDIV         15              /* maximum sample size */
69  
70   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
71  
# Line 68 | Line 82 | int  code;
82   }
83  
84  
85 + #ifdef BSD
86   report()                /* report progress */
87   {
73 #ifdef BSD
88          struct rusage  rubuf;
89          double  t;
90  
# Line 83 | Line 97 | report()               /* report progress */
97  
98          sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
99                          nrays, pctdone, t/3600.0);
100 +        eputs(errmsg);
101 +        tlastrept = time((long *)0);
102 + }
103   #else
104 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
105 < #endif
104 > report()                /* report progress */
105 > {
106 >        signal(SIGALRM, report);
107 >        tlastrept = time((long *)0);
108 >        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
109 >                        nrays, pctdone, (tlastrept-tstart)/3600.0);
110          eputs(errmsg);
90
91        if (ralrm > 0)
92                alarm(ralrm);
111   }
112 + #endif
113  
114  
115   render(zfile, oldfile)                          /* render the scene */
116   char  *zfile, *oldfile;
117   {
118 +        extern long  lseek();
119          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
120          float  *zbar[MAXDIV+1];         /* z values */
121          int  ypos;                      /* current scanline */
122 <        FILE  *zfp;
122 >        int  ystep;                     /* current y step size */
123 >        int  zfd;
124          COLOR  *colptr;
125          float  *zptr;
126          register int  i;
127                                          /* check sampling */
128          if (psample < 1)
129                  psample = 1;
130 <        else if (psample > MAXDIV)
130 >        else if (psample > MAXDIV) {
131 >                sprintf(errmsg, "pixel sampling reduced from %d to %d",
132 >                                psample, MAXDIV);
133 >                error(WARNING, errmsg);
134                  psample = MAXDIV;
135 +        }
136                                          /* allocate scanlines */
137          for (i = 0; i <= psample; i++) {
138                  scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
# Line 116 | Line 141 | char  *zfile, *oldfile;
141          }
142                                          /* open z file */
143          if (zfile != NULL) {
144 <                if ((zfp = fopen(zfile, "a+")) == NULL) {
144 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
145                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
146                          error(SYSTEM, errmsg);
147                  }
# Line 126 | Line 151 | char  *zfile, *oldfile;
151                                  goto memerr;
152                  }
153          } else {
154 <                zfp = NULL;
154 >                zfd = -1;
155                  for (i = 0; i <= psample; i++)
156                          zbar[i] = NULL;
157          }
# Line 134 | Line 159 | char  *zfile, *oldfile;
159          fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
160                                          /* recover file and compute first */
161          i = salvage(oldfile);
162 <        if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF)
162 >        if (zfd != -1 && i > 0 &&
163 >                        lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
164                  error(SYSTEM, "z file seek error in render");
165 +        pctdone = 100.0*i/vresolu;
166 +        if (ralrm > 0)                  /* report init stats */
167 +                report();
168          ypos = vresolu-1 - i;
169          fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
170 +        ystep = psample;
171                                                  /* compute scanlines */
172 <        for (ypos -= psample; ypos >= 0; ypos -= psample) {
173 <        
174 <                pctdone = 100.0*(vresolu-ypos-psample)/vresolu;
175 <
176 <                colptr = scanbar[psample];              /* move base to top */
177 <                scanbar[psample] = scanbar[0];
172 >        for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
173 >                                                        /* bottom adjust? */
174 >                if (ypos < 0) {
175 >                        ystep += ypos;
176 >                        ypos = 0;
177 >                }
178 >                colptr = scanbar[ystep];                /* move base to top */
179 >                scanbar[ystep] = scanbar[0];
180                  scanbar[0] = colptr;
181 <                zptr = zbar[psample];
182 <                zbar[psample] = zbar[0];
181 >                zptr = zbar[ystep];
182 >                zbar[ystep] = zbar[0];
183                  zbar[0] = zptr;
184                                                          /* fill base line */
185                  fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
186                                                          /* fill bar */
187 <                fillscanbar(scanbar, zbar, hresolu, ypos, psample);
187 >                fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
188                                                          /* write it out */
189 <                for (i = psample; i > 0; i--) {
190 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
189 >                for (i = ystep; i > 0; i--) {
190 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
191 >                                        hresolu*sizeof(float))
192 >                                        < hresolu*sizeof(float))
193                                  goto writerr;
194 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
194 >                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
195                                  goto writerr;
196                  }
163                if (zfp != NULL && fflush(zfp) == EOF)
164                        goto writerr;
197                  if (fflush(stdout) == EOF)
198                          goto writerr;
199 +                                                        /* record progress */
200 +                pctdone = 100.0*(vresolu-1-ypos)/vresolu;
201 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
202 +                        report();
203          }
168                                                /* compute residual */
169        colptr = scanbar[psample];
170        scanbar[psample] = scanbar[0];
171        scanbar[0] = colptr;
172        zptr = zbar[psample];
173        zbar[psample] = zbar[0];
174        zbar[0] = zptr;
175        if (ypos > -psample) {
176                fillscanline(scanbar[-ypos], zbar[-ypos], hresolu, 0, psample);
177                fillscanbar(scanbar-ypos, zbar-ypos, hresolu, 0, psample+ypos);
178        }
179        for (i = psample; i+ypos >= 0; i--) {
180                if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
181                        goto writerr;
182                if (fwritescan(scanbar[i], hresolu, stdout) < 0)
183                        goto writerr;
184        }
204                                                  /* clean up */
205 <        if (zfp != NULL) {
206 <                if (fclose(zfp) == EOF)
205 >        if (zfd != -1) {
206 >                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
207 >                                < hresolu*sizeof(float))
208                          goto writerr;
209 +                if (close(zfd) == -1)
210 +                        goto writerr;
211                  for (i = 0; i <= psample; i++)
212                          free((char *)zbar[i]);
213          }
214 +        fwritescan(scanbar[0], hresolu, stdout);
215          if (fflush(stdout) == EOF)
216                  goto writerr;
217          for (i = 0; i <= psample; i++)
# Line 214 | Line 237 | int  xres, y, xstep;
237          z = pixvalue(scanline[0], 0, y);
238          if (zline) zline[0] = z;
239  
240 <        for (i = xstep; i < xres; i += xstep) {
241 <        
240 >        for (i = xstep; i < xres-1+xstep; i += xstep) {
241 >                if (i >= xres) {
242 >                        xstep += xres-1-i;
243 >                        i = xres-1;
244 >                }
245                  z = pixvalue(scanline[i], i, y);
246                  if (zline) zline[i] = z;
247                  
248                  b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
249                                  i-xstep, y, xstep, 0, b/2);
250          }
225        if (i-xstep < xres-1) {
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        }
251   }
252  
253  
# Line 239 | Line 259 | int  xres, y, ysize;
259          COLOR  vline[MAXDIV+1];
260          float  zline[MAXDIV+1];
261          int  b = ysize;
242        double  z;
262          register int  i, j;
263          
264          for (i = 0; i < xres; i++) {
# Line 323 | Line 342 | pixvalue(col, x, y)            /* compute pixel value */
342   COLOR  col;                     /* returned color */
343   int  x, y;                      /* pixel position */
344   {
345 <        static RAY  thisray;    /* our ray for this pixel */
345 >        static RAY  thisray;
346  
347 <        viewray(thisray.rorg, thisray.rdir, &ourview,
348 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
347 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
348 >                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
349 >                setcolor(col, 0.0, 0.0, 0.0);
350 >                return(0.0);
351 >        }
352  
353          rayorigin(&thisray, NULL, PRIMARY, 1.0);
354 <        
354 >
355 >        samplendx = 3*y + x;                    /* set pixel index */
356 >
357          rayvalue(&thisray);                     /* trace ray */
358  
359          copycolor(col, thisray.rcol);           /* return color */
360          
361 <        return(thisray.rot);                    /* return distance */
361 >        return(thisray.rt);                     /* return distance */
362   }
363  
364  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines