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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines