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 2.18 by greg, Tue Nov 10 21:24:34 1992 UTC vs.
Revision 2.43 by greg, Wed Feb 7 16:35:18 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  "ray.h"
14  
15 + #include  <sys/types.h>
16 +
17 + #ifndef NIX
18   #ifdef BSD
19   #include  <sys/time.h>
20   #include  <sys/resource.h>
21 + #else
22 + #include  <sys/times.h>
23 + #include  <unistd.h>
24   #endif
25 + #endif
26  
27 + extern time_t   time();
28 +
29   #include  <signal.h>
30  
31   #include  "view.h"
# Line 27 | Line 36 | static char SCCSid[] = "$SunId$ LBL";
36  
37   #include  "paths.h"
38  
39 + #define  RFTEMPLATE     "rfXXXXXX"
40 +
41 + #ifndef SIGCONT
42 + #define SIGCONT         SIGIO
43 + #endif
44 +
45   int  dimlist[MAXDIM];                   /* sampling dimensions */
46   int  ndims = 0;                         /* number of sampling dimensions */
47   int  samplendx;                         /* sample index number */
# Line 45 | Line 60 | double shadthresh = .05;               /* shadow threshold */
60   double  shadcert = .5;                  /* shadow certainty */
61   int  directrelay = 1;                   /* number of source relays */
62   int  vspretest = 512;                   /* virtual source pretest density */
63 < int  directinvis = 0;                   /* sources invisible? */
63 > int  directvis = 1;                     /* sources visible? */
64   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
65  
66 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
67 + double  salbedo = 0.;                   /* global scattering albedo */
68 + double  seccg = 0.;                     /* global scattering eccentricity */
69 + double  ssampdist = 0.;                 /* scatter sampling distance */
70 +
71   double  specthresh = .15;               /* specular sampling threshold */
72   double  specjitter = 1.;                /* specular sampling jitter */
73  
74 + int  backvis = 1;                       /* back face visibility */
75 +
76   int  maxdepth = 6;                      /* maximum recursion depth */
77   double  minweight = 5e-3;               /* minimum ray weight */
78  
# Line 71 | Line 93 | int  ralrm = 0;                                /* seconds between reports */
93  
94   double  pctdone = 0.0;                  /* percentage done */
95  
96 < long  tlastrept = 0L;                   /* time at last report */
96 > time_t  tlastrept = 0L;                 /* time at last report */
97  
98 < extern long  time();
77 < extern long  tstart;                    /* starting time */
98 > extern time_t  tstart;                  /* starting time */
99  
100 < extern long  nrays;                     /* number of rays traced */
100 > extern unsigned long  nrays;            /* number of rays traced */
101  
102   #define  MAXDIV         16              /* maximum sample size */
103  
104   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
105  
85 #define  RFTEMPLATE     "rfXXXXXX"
86 #define  HFTEMPLATE     TEMPLATE
87
88 static char  *hfname = NULL;            /* header file name */
89 static FILE  *hfp = NULL;               /* header file pointer */
90
106   static int  hres, vres;                 /* resolution for this frame */
107  
108   extern char  *mktemp();
109  
110   double  pixvalue();
111  
112 + #ifdef NIX
113 + #define  file_exists(f) (access(f,F_OK)==0)
114 + #else
115 + #include  <sys/types.h>
116 + #include  <sys/stat.h>
117 + int
118 + file_exists(fname)                              /* ordinary file exists? */
119 + char  *fname;
120 + {
121 +        struct stat  sbuf;
122 +        if (stat(fname, &sbuf) < 0) return(0);
123 +        return((sbuf.st_mode & S_IFREG) != 0);
124 + }
125 + #endif
126  
127 +
128   quit(code)                      /* quit program */
129   int  code;
130   {
131          if (code)                       /* report status */
132                  report();
133 <        if (hfname != NULL) {           /* delete header file */
134 <                if (hfp != NULL)
105 <                        fclose(hfp);
106 <                unlink(hfname);
107 <        }
133 >        headclean();                    /* delete header file */
134 >        pfclean();                      /* clean up persist files */
135          exit(code);
136   }
137  
138  
139 < #ifdef BSD
139 > #ifndef NIX
140   report()                /* report progress */
141   {
142 +        extern char  *myhostname();
143 +        double  u, s;
144 + #ifdef BSD
145          struct rusage  rubuf;
146 <        double  t;
146 > #else
147 >        struct tms  tbuf;
148 >        double  period;
149 > #endif
150  
151 +        tlastrept = time((time_t *)NULL);
152 + #ifdef BSD
153          getrusage(RUSAGE_SELF, &rubuf);
154 <        t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
155 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
154 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
155 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
156          getrusage(RUSAGE_CHILDREN, &rubuf);
157 <        t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
158 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
157 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
158 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
159 > #else
160 >        times(&tbuf);
161 > #ifdef _SC_CLK_TCK
162 >        period = 1.0 / sysconf(_SC_CLK_TCK);
163 > #else
164 >        period = 1.0 / 60.0;
165 > #endif
166 >        u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
167 >        s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
168 > #endif
169  
170 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
171 <                        nrays, pctdone, t/3600.0);
170 >        sprintf(errmsg,
171 >                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
172 >                        nrays, pctdone, u/3600., s/3600.,
173 >                        (tlastrept-tstart)/3600., myhostname());
174          eputs(errmsg);
175 <        tlastrept = time((long *)0);
175 > #ifndef BSD
176 >        signal(SIGCONT, report);
177 > #endif
178   }
179   #else
180   report()                /* report progress */
181   {
182 <        tlastrept = time((long *)0);
183 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
182 >        tlastrept = time((time_t *)NULL);
183 >        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
184                          nrays, pctdone, (tlastrept-tstart)/3600.0);
185          eputs(errmsg);
137        signal(SIGALRM, report);
186   }
187   #endif
188  
189  
142 openheader()                    /* save standard output to header file */
143 {
144        hfname = mktemp(HFTEMPLATE);
145        if (freopen(hfname, "w", stdout) == NULL) {
146                sprintf(errmsg, "cannot open header file \"%s\"", hfname);
147                error(SYSTEM, errmsg);
148        }
149 }
150
151
152 dupheader()                     /* repeat header on standard output */
153 {
154        register int  c;
155
156        if (hfp == NULL) {
157                if ((hfp = fopen(hfname, "r")) == NULL)
158                        error(SYSTEM, "error reopening header file");
159 #ifdef MSDOS
160                setmode(fileno(hfp), O_BINARY);
161 #endif
162        } else if (fseek(hfp, 0L, 0) < 0)
163                error(SYSTEM, "seek error on header file");
164        while ((c = getc(hfp)) != EOF)
165                putchar(c);
166 }
167
168
190   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
191   int  seq;
192   char  *pout, *zout, *prvr;
# Line 181 | Line 202 | char  *pout, *zout, *prvr;
202   * sequenced file naming.
203   */
204   {
205 <        extern char  *rindex(), *strncpy(), *strcat();
205 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
206          char  fbuf[128], fbuf2[128];
207 +        int  npicts;
208          register char  *cp;
209          RESOLU  rs;
210          double  pa;
# Line 219 | Line 241 | char  *pout, *zout, *prvr;
241                                  cp--;
242                          strcpy(cp, RFTEMPLATE);
243                          prvr = mktemp(fbuf2);
244 <                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
245 <                                sprintf(errmsg,
244 >                        if (rename(fbuf, prvr) < 0)
245 >                                if (errno == ENOENT) {  /* ghost file */
246 >                                        sprintf(errmsg,
247 >                                                "new output file \"%s\"",
248 >                                                fbuf);
249 >                                        error(WARNING, errmsg);
250 >                                        prvr = NULL;
251 >                                } else {                /* serious error */
252 >                                        sprintf(errmsg,
253                                          "cannot rename \"%s\" to \"%s\"",
254                                                  fbuf, prvr);
255 <                                error(SYSTEM, errmsg);
256 <                        }
255 >                                        error(SYSTEM, errmsg);
256 >                                }
257                  }
258          }
259 <                                        /* render sequence */
259 >        npicts = 0;                     /* render sequence */
260          do {
261                  if (seq && nextview(stdin) == EOF)
262                          break;
263 +                pctdone = 0.0;
264                  if (pout != NULL) {
265                          sprintf(fbuf, pout, seq);
266 +                        if (file_exists(fbuf)) {
267 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
268 +                                        sprintf(errmsg,
269 +                                                "output file \"%s\" exists",
270 +                                                fbuf);
271 +                                        error(USER, errmsg);
272 +                                }
273 +                                continue;               /* don't clobber */
274 +                        }
275                          if (freopen(fbuf, "w", stdout) == NULL) {
276                                  sprintf(errmsg,
277                                          "cannot open output file \"%s\"", fbuf);
# Line 280 | Line 319 | char  *pout, *zout, *prvr;
319                          cp = NULL;
320                  render(cp, prvr);
321                  prvr = NULL;
322 +                npicts++;
323          } while (seq++);
324 +                                        /* check that we did something */
325 +        if (npicts == 0)
326 +                error(WARNING, "no output produced");
327   }
328  
329  
# Line 326 | Line 369 | char  *zfile, *oldfile;
369                          sampdens[i] = hstep;
370          } else
371                  sampdens = NULL;
372 <                                        /* open z file */
372 >                                        /* open z-file */
373          if (zfile != NULL) {
374                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
375 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
375 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
376                          error(SYSTEM, errmsg);
377                  }
378   #ifdef MSDOS
# Line 349 | Line 392 | char  *zfile, *oldfile;
392          fprtresolu(hres, vres, stdout);
393                                          /* recover file and compute first */
394          i = salvage(oldfile);
395 +        if (i >= vres)
396 +                goto alldone;
397          if (zfd != -1 && i > 0 &&
398                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
399 <                error(SYSTEM, "z file seek error in render");
399 >                error(SYSTEM, "z-file seek error in render");
400          pctdone = 100.0*i/vres;
401          if (ralrm > 0)                  /* report init stats */
402                  report();
403   #ifndef  BSD
404          else
405   #endif
406 <        signal(SIGALRM, report);
406 >        signal(SIGCONT, report);
407          ypos = vres-1 - i;
408          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
409                                                  /* compute scanlines */
# Line 381 | Line 426 | char  *zfile, *oldfile;
426                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
427                                                          /* write it out */
428   #ifndef  BSD
429 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
429 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
430   #endif
431                  for (i = ystep; i > 0; i--) {
432                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 395 | Line 440 | char  *zfile, *oldfile;
440                          goto writerr;
441                                                          /* record progress */
442                  pctdone = 100.0*(vres-1-ypos)/vres;
443 <                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
443 >                if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
444                          report();
445   #ifndef  BSD
446                  else
447 <                        signal(SIGALRM, report);
447 >                        signal(SIGCONT, report);
448   #endif
449          }
450                                                  /* clean up */
451 <        signal(SIGALRM, SIG_IGN);
452 <        if (zfd != -1) {
408 <                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
451 >        signal(SIGCONT, SIG_IGN);
452 >        if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float))
453                                  < hres*sizeof(float))
454 <                        goto writerr;
454 >                goto writerr;
455 >        fwritescan(scanbar[0], hres, stdout);
456 >        if (fflush(stdout) == EOF)
457 >                goto writerr;
458 > alldone:
459 >        if (zfd != -1) {
460                  if (close(zfd) == -1)
461                          goto writerr;
462                  for (i = 0; i <= psample; i++)
463                          free((char *)zbar[i]);
464          }
416        fwritescan(scanbar[0], hres, stdout);
417        if (fflush(stdout) == EOF)
418                goto writerr;
465          for (i = 0; i <= psample; i++)
466                  free((char *)scanbar[i]);
467          if (sampdens != NULL)
# Line 423 | Line 469 | char  *zfile, *oldfile;
469          pctdone = 100.0;
470          if (ralrm > 0)
471                  report();
472 +        signal(SIGCONT, SIG_DFL);
473          return;
474   writerr:
475          error(SYSTEM, "write error in render");
# Line 457 | Line 504 | int  xres, y, xstep;
504                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
505                  else
506                          b = fillsample(scanline+i-xstep,
507 <                                        zline ? zline+i-xstep : NULL,
507 >                                        zline ? zline+i-xstep : (float *)NULL,
508                                          i-xstep, y, xstep, 0, b/2);
509                  if (sd) *sd++ = nc & 1 ? bl : b;
510                  bl = b;
# Line 485 | Line 532 | int  xres, y, ysize;
532                          zline[ysize] = zbar[ysize][i];
533                  }
534                  
535 <                b = fillsample(vline, zbar[0] ? zline : NULL,
535 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
536                                  i, y, 0, ysize, b/2);
537                  
538                  for (j = 1; j < ysize; j++)
# Line 543 | Line 590 | int  b;
590                                                          /* recurse */
591          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
592          
593 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
593 >        ncut += fillsample(colline+(len>>1),
594 >                        zline ? zline+(len>>1) : (float *)NULL,
595                          x+(xlen>>1), y+(ylen>>1),
596                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
597  
# Line 558 | Line 606 | int  x, y;                     /* pixel position */
606   {
607          static RAY  thisray;
608  
609 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
610 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
609 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
610 >                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
611                  setcolor(col, 0.0, 0.0, 0.0);
612                  return(0.0);
613          }
# Line 585 | Line 633 | char  *oldfile;
633          int  x, y;
634  
635          if (oldfile == NULL)
636 <                return(0);
637 <        
636 >                goto gotzip;
637 >
638          if ((fp = fopen(oldfile, "r")) == NULL) {
639                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
640                  error(WARNING, errmsg);
641 <                return(0);
641 >                goto gotzip;
642          }
643   #ifdef MSDOS
644          setmode(fileno(fp), O_BINARY);
645   #endif
646                                  /* discard header */
647 <        getheader(fp, NULL);
647 >        getheader(fp, NULL, NULL);
648                                  /* get picture size */
649          if (!fscnresolu(&x, &y, fp)) {
650 <                sprintf(errmsg, "bad recover file \"%s\"", oldfile);
650 >                sprintf(errmsg, "bad recover file \"%s\" - not removed",
651 >                                oldfile);
652                  error(WARNING, errmsg);
653                  fclose(fp);
654 <                return(0);
654 >                goto gotzip;
655          }
656  
657          if (x != hres || y != vres) {
# Line 626 | Line 675 | char  *oldfile;
675          fclose(fp);
676          unlink(oldfile);
677          return(y);
678 + gotzip:
679 +        if (fflush(stdout) == EOF)
680 +                error(SYSTEM, "error writing picture header");
681 +        return(0);
682   writerr:
683          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
684          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines