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.15 by greg, Fri Jan 12 09:27:11 1990 UTC vs.
Revision 1.24 by greg, Tue Apr 9 09:31:01 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 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   #else
19   #include  <signal.h>
20   #endif
21 + #include  <fcntl.h>
22  
23   #include  "view.h"
24  
# Line 52 | Line 53 | int  ralrm = 0;                                /* seconds between reports */
53  
54   double  pctdone = 0.0;                  /* percentage done */
55  
56 + long  tlastrept = 0L;                   /* time at last report */
57 +
58 + extern long  time();
59 + extern long  tstart;                    /* starting time */
60 +
61   extern long  nrays;                     /* number of rays traced */
62  
63   #define  MAXDIV         32              /* maximum sample size */
# Line 71 | Line 77 | int  code;
77   }
78  
79  
80 + #ifdef BSD
81   report()                /* report progress */
82   {
76 #ifdef BSD
83          struct rusage  rubuf;
84          double  t;
85  
# Line 86 | Line 92 | report()               /* report progress */
92  
93          sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
94                          nrays, pctdone, t/3600.0);
95 +        eputs(errmsg);
96 +        tlastrept = time((long *)0);
97 + }
98   #else
99 + report()                /* report progress */
100 + {
101          signal(SIGALRM, report);
102 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
103 < #endif
102 >        tlastrept = time((long *)0);
103 >        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
104 >                        nrays, pctdone, (tlastrept-tstart)/3600.0);
105          eputs(errmsg);
94
95        if (ralrm > 0)
96                alarm(ralrm);
106   }
107 + #endif
108  
109  
110   render(zfile, oldfile)                          /* render the scene */
111   char  *zfile, *oldfile;
112   {
113 +        extern long  lseek();
114          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
115          float  *zbar[MAXDIV+1];         /* z values */
116          int  ypos;                      /* current scanline */
117          int  ystep;                     /* current y step size */
118 <        FILE  *zfp;
118 >        int  zfd;
119          COLOR  *colptr;
120          float  *zptr;
121          register int  i;
# Line 121 | Line 132 | char  *zfile, *oldfile;
132          }
133                                          /* open z file */
134          if (zfile != NULL) {
135 <                if ((zfp = fopen(zfile, "a+")) == NULL) {
135 >                if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
136                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
137                          error(SYSTEM, errmsg);
138                  }
# Line 131 | Line 142 | char  *zfile, *oldfile;
142                                  goto memerr;
143                  }
144          } else {
145 <                zfp = NULL;
145 >                zfd = -1;
146                  for (i = 0; i <= psample; i++)
147                          zbar[i] = NULL;
148          }
# Line 139 | Line 150 | char  *zfile, *oldfile;
150          fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
151                                          /* recover file and compute first */
152          i = salvage(oldfile);
153 <        if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF)
153 >        if (zfd != -1 && i > 0 &&
154 >                        lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1)
155                  error(SYSTEM, "z file seek error in render");
156 +        pctdone = 100.0*i/vresolu;
157 +        if (ralrm > 0)                  /* report init stats */
158 +                report();
159          ypos = vresolu-1 - i;
160          fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
161          ystep = psample;
162                                                  /* compute scanlines */
163          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
149                                                        /* record progress */
150                pctdone = 100.0*(vresolu-ypos-ystep)/vresolu;
164                                                          /* bottom adjust? */
165                  if (ypos < 0) {
166                          ystep += ypos;
# Line 165 | Line 178 | char  *zfile, *oldfile;
178                  fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
179                                                          /* write it out */
180                  for (i = ystep; i > 0; i--) {
181 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
181 >                        if (zfd != -1 && write(zfd, (char *)zbar[i],
182 >                                        hresolu*sizeof(float))
183 >                                        < hresolu*sizeof(float))
184                                  goto writerr;
185 <                        if (fwritescan(scanbar[i],hresolu,stdout) < 0)
185 >                        if (fwritescan(scanbar[i], hresolu, stdout) < 0)
186                                  goto writerr;
187                  }
173                if (zfp != NULL && fflush(zfp) == EOF)
174                        goto writerr;
188                  if (fflush(stdout) == EOF)
189                          goto writerr;
190 +                                                        /* record progress */
191 +                pctdone = 100.0*(vresolu-1-ypos)/vresolu;
192 +                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
193 +                        report();
194          }
195                                                  /* clean up */
196 <        if (zfp != NULL) {
197 <                fwrite(zbar[0], sizeof(float), hresolu, zfp);
198 <                if (fclose(zfp) == EOF)
196 >        if (zfd != -1) {
197 >                if (write(zfd, (char *)zbar[0], hresolu*sizeof(float))
198 >                                < hresolu*sizeof(float))
199                          goto writerr;
200 +                if (close(zfd) == -1)
201 +                        goto writerr;
202                  for (i = 0; i <= psample; i++)
203                          free((char *)zbar[i]);
204          }
# Line 231 | Line 250 | int  xres, y, ysize;
250          COLOR  vline[MAXDIV+1];
251          float  zline[MAXDIV+1];
252          int  b = ysize;
234        double  z;
253          register int  i, j;
254          
255          for (i = 0; i < xres; i++) {
# Line 317 | Line 335 | int  x, y;                     /* pixel position */
335   {
336          static RAY  thisray;    /* our ray for this pixel */
337  
338 <        viewray(thisray.rorg, thisray.rdir, &ourview,
339 <                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu);
338 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
339 >                        (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
340 >                setcolor(col, 0.0, 0.0, 0.0);
341 >                return(0.0);
342 >        }
343  
344          rayorigin(&thisray, NULL, PRIMARY, 1.0);
345          
# Line 326 | Line 347 | int  x, y;                     /* pixel position */
347  
348          copycolor(col, thisray.rcol);           /* return color */
349          
350 <        return(thisray.rot);                    /* return distance */
350 >        return(thisray.rt);                     /* return distance */
351   }
352  
353  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines