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.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 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  
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  
45   int  maxdepth = 6;                      /* maximum recursion depth */
46   double  minweight = 5e-3;               /* minimum ray weight */
# Line 52 | 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 71 | Line 82 | int  code;
82   }
83  
84  
85 + #ifdef BSD
86   report()                /* report progress */
87   {
76 #ifdef BSD
88          struct rusage  rubuf;
89          double  t;
90  
# Line 86 | 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 + report()                /* report progress */
105 + {
106          signal(SIGALRM, report);
107 <        sprintf(errmsg, "%ld rays, %4.2f%% done\n", nrays, pctdone);
108 < #endif
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);
94
95        if (ralrm > 0)
96                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          int  ystep;                     /* current y step size */
123 <        FILE  *zfp;
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 121 | 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 131 | 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 139 | 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 -= ystep; ypos > -ystep; ypos -= ystep) {
149                                                        /* record progress */
150                pctdone = 100.0*(vresolu-ypos-ystep)/vresolu;
173                                                          /* bottom adjust? */
174                  if (ypos < 0) {
175                          ystep += ypos;
# Line 165 | Line 187 | char  *zfile, *oldfile;
187                  fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
188                                                          /* write it out */
189                  for (i = ystep; i > 0; i--) {
190 <                        if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu)
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                  }
173                if (zfp != NULL && fflush(zfp) == EOF)
174                        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          }
204                                                  /* clean up */
205 <        if (zfp != NULL) {
206 <                fwrite(zbar[0], sizeof(float), hresolu, zfp);
207 <                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          }
# Line 231 | Line 259 | int  xres, y, ysize;
259          COLOR  vline[MAXDIV+1];
260          float  zline[MAXDIV+1];
261          int  b = ysize;
234        double  z;
262          register int  i, j;
263          
264          for (i = 0; i < xres; i++) {
# Line 315 | 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