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.24 by greg, Tue Apr 9 09:31:01 1991 UTC vs.
Revision 2.5 by greg, Tue Jan 14 16:15:57 1992 UTC

# 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  "resolu.h"
26 +
27   #include  "random.h"
28  
29 + int  dimlist[MAXDIM];                   /* sampling dimensions */
30 + int  ndims = 0;                         /* number of sampling dimensions */
31 + int  samplendx;                         /* sample index number */
32 +
33   VIEW  ourview = STDVIEW;                /* view parameters */
34   int  hresolu = 512;                     /* horizontal resolution */
35   int  vresolu = 512;                     /* vertical resolution */
# Line 36 | Line 42 | double  dstrpix = 0.67;                        /* square pixel distribution
42   double  dstrsrc = 0.0;                  /* square source distribution */
43   double  shadthresh = .05;               /* shadow threshold */
44   double  shadcert = .5;                  /* shadow certainty */
45 + int  directrelay = 1;                   /* number of source relays */
46 + int  vspretest = 512;                   /* virtual source pretest density */
47 + int  directinvis = 0;                   /* sources invisible? */
48 + double  srcsizerat = .25;               /* maximum ratio source size/dist. */
49  
50 + double  specthresh = .5;                /* specular sampling threshold */
51 + double  specjitter = 1.;                /* specular sampling jitter */
52 +
53   int  maxdepth = 6;                      /* maximum recursion depth */
54   double  minweight = 5e-3;               /* minimum ray weight */
55  
# Line 60 | Line 73 | extern long  tstart;                   /* starting time */
73  
74   extern long  nrays;                     /* number of rays traced */
75  
76 < #define  MAXDIV         32              /* maximum sample size */
76 > #define  MAXDIV         16              /* maximum sample size */
77  
78   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
79  
# Line 98 | Line 111 | report()               /* report progress */
111   #else
112   report()                /* report progress */
113   {
101        signal(SIGALRM, report);
114          tlastrept = time((long *)0);
115          sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
116                          nrays, pctdone, (tlastrept-tstart)/3600.0);
117          eputs(errmsg);
118 +        signal(SIGALRM, report);
119   }
120   #endif
121  
# Line 113 | Line 126 | char  *zfile, *oldfile;
126          extern long  lseek();
127          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
128          float  *zbar[MAXDIV+1];         /* z values */
129 +        char  *sampdens;                /* previous sample density */
130          int  ypos;                      /* current scanline */
131          int  ystep;                     /* current y step size */
132 +        int  hstep;                     /* h step size */
133          int  zfd;
134          COLOR  *colptr;
135          float  *zptr;
# Line 122 | Line 137 | char  *zfile, *oldfile;
137                                          /* check sampling */
138          if (psample < 1)
139                  psample = 1;
140 <        else if (psample > MAXDIV)
140 >        else if (psample > MAXDIV) {
141 >                sprintf(errmsg, "pixel sampling reduced from %d to %d",
142 >                                psample, MAXDIV);
143 >                error(WARNING, errmsg);
144                  psample = MAXDIV;
145 +        }
146                                          /* allocate scanlines */
147          for (i = 0; i <= psample; i++) {
148                  scanbar[i] = (COLOR *)malloc(hresolu*sizeof(COLOR));
149                  if (scanbar[i] == NULL)
150                          goto memerr;
151          }
152 +        hstep = (psample*140+49)/99;            /* quincunx sampling */
153 +        ystep = (psample*99+70)/140;
154 +        if (hstep > 2) {
155 +                i = hresolu/hstep + 2;
156 +                if ((sampdens = malloc(i)) == NULL)
157 +                        goto memerr;
158 +                while (i--)
159 +                        sampdens[i] = hstep;
160 +        } else
161 +                sampdens = NULL;
162                                          /* open z file */
163          if (zfile != NULL) {
164                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
# Line 147 | Line 176 | char  *zfile, *oldfile;
176                          zbar[i] = NULL;
177          }
178                                          /* write out boundaries */
179 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
179 >        fprtresolu(hresolu, vresolu, stdout);
180                                          /* recover file and compute first */
181          i = salvage(oldfile);
182          if (zfd != -1 && i > 0 &&
# Line 156 | Line 185 | char  *zfile, *oldfile;
185          pctdone = 100.0*i/vresolu;
186          if (ralrm > 0)                  /* report init stats */
187                  report();
188 + #ifndef  BSD
189 +        else
190 + #endif
191 +        signal(SIGALRM, report);
192          ypos = vresolu-1 - i;
193 <        fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
161 <        ystep = psample;
193 >        fillscanline(scanbar[0], zbar[0], sampdens, hresolu, ypos, hstep);
194                                                  /* compute scanlines */
195          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
196                                                          /* bottom adjust? */
# Line 173 | Line 205 | char  *zfile, *oldfile;
205                  zbar[ystep] = zbar[0];
206                  zbar[0] = zptr;
207                                                          /* fill base line */
208 <                fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample);
208 >                fillscanline(scanbar[0], zbar[0], sampdens,
209 >                                hresolu, ypos, hstep);
210                                                          /* fill bar */
211                  fillscanbar(scanbar, zbar, hresolu, ypos, ystep);
212                                                          /* write it out */
213 + #ifndef  BSD
214 +                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
215 + #endif
216                  for (i = ystep; i > 0; i--) {
217                          if (zfd != -1 && write(zfd, (char *)zbar[i],
218                                          hresolu*sizeof(float))
# Line 191 | Line 227 | char  *zfile, *oldfile;
227                  pctdone = 100.0*(vresolu-1-ypos)/vresolu;
228                  if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
229                          report();
230 + #ifndef  BSD
231 +                else
232 +                        signal(SIGALRM, report);
233 + #endif
234          }
235                                                  /* clean up */
236          if (zfd != -1) {
# Line 207 | Line 247 | char  *zfile, *oldfile;
247                  goto writerr;
248          for (i = 0; i <= psample; i++)
249                  free((char *)scanbar[i]);
250 +        if (sampdens != NULL)
251 +                free(sampdens);
252          pctdone = 100.0;
253          return;
254   writerr:
# Line 216 | Line 258 | memerr:
258   }
259  
260  
261 < fillscanline(scanline, zline, xres, y, xstep)   /* fill scan line at y */
261 > fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
262   register COLOR  *scanline;
263   register float  *zline;
264 + register char  *sd;
265   int  xres, y, xstep;
266   {
267 <        int  b = xstep;
267 >        static int  nc = 0;             /* number of calls */
268 >        int  bl = xstep, b = xstep;
269          double  z;
270          register int  i;
271          
272          z = pixvalue(scanline[0], 0, y);
273          if (zline) zline[0] = z;
274 <
275 <        for (i = xstep; i < xres-1+xstep; i += xstep) {
274 >                                /* zig-zag start for quincunx pattern */
275 >        for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) {
276                  if (i >= xres) {
277                          xstep += xres-1-i;
278                          i = xres-1;
279                  }
280                  z = pixvalue(scanline[i], i, y);
281                  if (zline) zline[i] = z;
282 <                
283 <                b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL,
284 <                                i-xstep, y, xstep, 0, b/2);
282 >                if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1];
283 >                if (i <= xstep)
284 >                        b = fillsample(scanline, zline, 0, y, i, 0, b/2);
285 >                else
286 >                        b = fillsample(scanline+i-xstep,
287 >                                        zline ? zline+i-xstep : NULL,
288 >                                        i-xstep, y, xstep, 0, b/2);
289 >                if (sd) *sd++ = nc & 1 ? bl : b;
290 >                bl = b;
291          }
292 +        if (sd && nc & 1) *sd = bl;
293   }
294  
295  
# Line 333 | Line 384 | pixvalue(col, x, y)            /* compute pixel value */
384   COLOR  col;                     /* returned color */
385   int  x, y;                      /* pixel position */
386   {
387 <        static RAY  thisray;    /* our ray for this pixel */
387 >        static RAY  thisray;
388  
389          if (viewray(thisray.rorg, thisray.rdir, &ourview,
390                          (x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) {
# Line 342 | Line 393 | int  x, y;                     /* pixel position */
393          }
394  
395          rayorigin(&thisray, NULL, PRIMARY, 1.0);
396 <        
396 >
397 >        samplendx = pixnumber(x,y,hresolu,vresolu);     /* set pixel index */
398 >
399          rayvalue(&thisray);                     /* trace ray */
400  
401          copycolor(col, thisray.rcol);           /* return color */
# Line 370 | Line 423 | char  *oldfile;
423                                  /* discard header */
424          getheader(fp, NULL);
425                                  /* get picture size */
426 <        if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) {
426 >        if (!fscnresolu(&x, &y, fp)) {
427                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);
428                  error(WARNING, errmsg);
429                  fclose(fp);
# Line 400 | Line 453 | char  *oldfile;
453          return(y);
454   writerr:
455          error(SYSTEM, "write error in salvage");
456 + }
457 +
458 +
459 + int
460 + pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
461 + register int  x, y;
462 + int  xres, yres;
463 + {
464 +        x -= y;
465 +        while (x < 0)
466 +                x += xres;
467 +        return((((x>>2)*yres + y) << 2) + (x & 3));
468   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines