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.21 by greg, Wed Jan 20 15:19:47 1993 UTC vs.
Revision 2.41 by greg, Fri Dec 8 18:49:20 1995 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  <sys/utsname.h>
24 + #include  <unistd.h>
25   #endif
26 + #endif
27  
28 + extern time_t   time();
29 +
30   #include  <signal.h>
31  
32   #include  "view.h"
# Line 29 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
39  
40   #define  RFTEMPLATE     "rfXXXXXX"
41  
42 + #ifndef SIGCONT
43 + #define SIGCONT         SIGIO
44 + #endif
45 +
46   int  dimlist[MAXDIM];                   /* sampling dimensions */
47   int  ndims = 0;                         /* number of sampling dimensions */
48   int  samplendx;                         /* sample index number */
# Line 50 | Line 64 | int  vspretest = 512;                  /* virtual source pretest dens
64   int  directvis = 1;                     /* sources visible? */
65   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
66  
67 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
68 + double  salbedo = 0.;                   /* global scattering albedo */
69 + double  seccg = 0.;                     /* global scattering eccentricity */
70 + double  ssampdist = 0.;                 /* scatter sampling distance */
71 +
72   double  specthresh = .15;               /* specular sampling threshold */
73   double  specjitter = 1.;                /* specular sampling jitter */
74  
75 + int  backvis = 1;                       /* back face visibility */
76 +
77   int  maxdepth = 6;                      /* maximum recursion depth */
78   double  minweight = 5e-3;               /* minimum ray weight */
79  
# Line 73 | Line 94 | int  ralrm = 0;                                /* seconds between reports */
94  
95   double  pctdone = 0.0;                  /* percentage done */
96  
97 < long  tlastrept = 0L;                   /* time at last report */
97 > time_t  tlastrept = 0L;                 /* time at last report */
98  
99 < extern long  time();
79 < extern long  tstart;                    /* starting time */
99 > extern time_t  tstart;                  /* starting time */
100  
101 < extern long  nrays;                     /* number of rays traced */
101 > extern unsigned long  nrays;            /* number of rays traced */
102  
103   #define  MAXDIV         16              /* maximum sample size */
104  
# Line 90 | Line 110 | extern char  *mktemp();
110  
111   double  pixvalue();
112  
113 + #ifdef NIX
114 + #define  file_exists(f) (access(f,F_OK)==0)
115 + #else
116 + #include  <sys/types.h>
117 + #include  <sys/stat.h>
118 + int
119 + file_exists(fname)                              /* ordinary file exists? */
120 + char  *fname;
121 + {
122 +        struct stat  sbuf;
123 +        if (stat(fname, &sbuf) < 0) return(0);
124 +        return((sbuf.st_mode & S_IFREG) != 0);
125 + }
126 + #endif
127  
128 +
129   quit(code)                      /* quit program */
130   int  code;
131   {
# Line 102 | Line 137 | int  code;
137   }
138  
139  
140 < #ifdef BSD
140 > #ifndef NIX
141   report()                /* report progress */
142   {
143 +        double  u, s;
144 + #ifdef BSD
145 +        char  hostname[257];
146          struct rusage  rubuf;
147 <        double  t;
147 > #else
148 >        struct tms  tbuf;
149 >        struct utsname  nambuf;
150 >        double  period;
151 > #define hostname  nambuf.nodename
152 > #endif
153  
154 +        tlastrept = time((time_t *)NULL);
155 + #ifdef BSD
156          getrusage(RUSAGE_SELF, &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          getrusage(RUSAGE_CHILDREN, &rubuf);
160 <        t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
161 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
160 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
161 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
162 >        gethostname(hostname, sizeof(hostname));
163 > #else
164 >        times(&tbuf);
165 > #ifdef _SC_CLK_TCK
166 >        period = 1.0 / sysconf(_SC_CLK_TCK);
167 > #else
168 >        period = 1.0 / 60.0;
169 > #endif
170 >        u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
171 >        s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
172 >        uname(&nambuf);
173 > #endif
174  
175 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
176 <                        nrays, pctdone, t/3600.0);
175 >        sprintf(errmsg,
176 >                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
177 >                        nrays, pctdone, u/3600., s/3600.,
178 >                        (tlastrept-tstart)/3600., hostname);
179          eputs(errmsg);
180 <        tlastrept = time((long *)0);
180 > #ifndef BSD
181 >        signal(SIGCONT, report);
182 > #undef hostname
183 > #endif
184   }
185   #else
186   report()                /* report progress */
187   {
188 <        tlastrept = time((long *)0);
189 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
188 >        tlastrept = time((time_t *)NULL);
189 >        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
190                          nrays, pctdone, (tlastrept-tstart)/3600.0);
191          eputs(errmsg);
130        signal(SIGALRM, report);
192   }
193   #endif
194  
# Line 149 | Line 210 | char  *pout, *zout, *prvr;
210   {
211          extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
212          char  fbuf[128], fbuf2[128];
213 +        int  npicts;
214          register char  *cp;
215          RESOLU  rs;
216          double  pa;
# Line 185 | Line 247 | char  *pout, *zout, *prvr;
247                                  cp--;
248                          strcpy(cp, RFTEMPLATE);
249                          prvr = mktemp(fbuf2);
250 <                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
251 <                                sprintf(errmsg,
250 >                        if (rename(fbuf, prvr) < 0)
251 >                                if (errno == ENOENT) {  /* ghost file */
252 >                                        sprintf(errmsg,
253 >                                                "new output file \"%s\"",
254 >                                                fbuf);
255 >                                        error(WARNING, errmsg);
256 >                                        prvr = NULL;
257 >                                } else {                /* serious error */
258 >                                        sprintf(errmsg,
259                                          "cannot rename \"%s\" to \"%s\"",
260                                                  fbuf, prvr);
261 <                                error(SYSTEM, errmsg);
262 <                        }
261 >                                        error(SYSTEM, errmsg);
262 >                                }
263                  }
264          }
265 <                                        /* render sequence */
265 >        npicts = 0;                     /* render sequence */
266          do {
267                  if (seq && nextview(stdin) == EOF)
268                          break;
269 +                pctdone = 0.0;
270                  if (pout != NULL) {
271                          sprintf(fbuf, pout, seq);
272 +                        if (file_exists(fbuf)) {
273 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
274 +                                        sprintf(errmsg,
275 +                                                "output file \"%s\" exists",
276 +                                                fbuf);
277 +                                        error(USER, errmsg);
278 +                                }
279 +                                continue;               /* don't clobber */
280 +                        }
281                          if (freopen(fbuf, "w", stdout) == NULL) {
282                                  sprintf(errmsg,
283                                          "cannot open output file \"%s\"", fbuf);
# Line 246 | Line 325 | char  *pout, *zout, *prvr;
325                          cp = NULL;
326                  render(cp, prvr);
327                  prvr = NULL;
328 +                npicts++;
329          } while (seq++);
330 +                                        /* check that we did something */
331 +        if (npicts == 0)
332 +                error(WARNING, "no output produced");
333   }
334  
335  
# Line 292 | Line 375 | char  *zfile, *oldfile;
375                          sampdens[i] = hstep;
376          } else
377                  sampdens = NULL;
378 <                                        /* open z file */
378 >                                        /* open z-file */
379          if (zfile != NULL) {
380                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
381 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
381 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
382                          error(SYSTEM, errmsg);
383                  }
384   #ifdef MSDOS
# Line 317 | Line 400 | char  *zfile, *oldfile;
400          i = salvage(oldfile);
401          if (zfd != -1 && i > 0 &&
402                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
403 <                error(SYSTEM, "z file seek error in render");
403 >                error(SYSTEM, "z-file seek error in render");
404          pctdone = 100.0*i/vres;
405          if (ralrm > 0)                  /* report init stats */
406                  report();
407   #ifndef  BSD
408          else
409   #endif
410 <        signal(SIGALRM, report);
410 >        signal(SIGCONT, report);
411          ypos = vres-1 - i;
412          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
413                                                  /* compute scanlines */
# Line 347 | Line 430 | char  *zfile, *oldfile;
430                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
431                                                          /* write it out */
432   #ifndef  BSD
433 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
433 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
434   #endif
435                  for (i = ystep; i > 0; i--) {
436                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 361 | Line 444 | char  *zfile, *oldfile;
444                          goto writerr;
445                                                          /* record progress */
446                  pctdone = 100.0*(vres-1-ypos)/vres;
447 <                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
447 >                if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
448                          report();
449   #ifndef  BSD
450                  else
451 <                        signal(SIGALRM, report);
451 >                        signal(SIGCONT, report);
452   #endif
453          }
454                                                  /* clean up */
455 <        signal(SIGALRM, SIG_IGN);
455 >        signal(SIGCONT, SIG_IGN);
456          if (zfd != -1) {
457                  if (write(zfd, (char *)zbar[0], hres*sizeof(float))
458                                  < hres*sizeof(float))
# Line 389 | Line 472 | char  *zfile, *oldfile;
472          pctdone = 100.0;
473          if (ralrm > 0)
474                  report();
475 +        signal(SIGCONT, SIG_DFL);
476          return;
477   writerr:
478          error(SYSTEM, "write error in render");
# Line 423 | Line 507 | int  xres, y, xstep;
507                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
508                  else
509                          b = fillsample(scanline+i-xstep,
510 <                                        zline ? zline+i-xstep : NULL,
510 >                                        zline ? zline+i-xstep : (float *)NULL,
511                                          i-xstep, y, xstep, 0, b/2);
512                  if (sd) *sd++ = nc & 1 ? bl : b;
513                  bl = b;
# Line 451 | Line 535 | int  xres, y, ysize;
535                          zline[ysize] = zbar[ysize][i];
536                  }
537                  
538 <                b = fillsample(vline, zbar[0] ? zline : NULL,
538 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
539                                  i, y, 0, ysize, b/2);
540                  
541                  for (j = 1; j < ysize; j++)
# Line 509 | Line 593 | int  b;
593                                                          /* recurse */
594          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
595          
596 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
596 >        ncut += fillsample(colline+(len>>1),
597 >                        zline ? zline+(len>>1) : (float *)NULL,
598                          x+(xlen>>1), y+(ylen>>1),
599                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
600  
# Line 524 | Line 609 | int  x, y;                     /* pixel position */
609   {
610          static RAY  thisray;
611  
612 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
613 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
612 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
613 >                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
614                  setcolor(col, 0.0, 0.0, 0.0);
615                  return(0.0);
616          }
# Line 551 | Line 636 | char  *oldfile;
636          int  x, y;
637  
638          if (oldfile == NULL)
639 <                return(0);
640 <        
639 >                goto gotzip;
640 >
641          if ((fp = fopen(oldfile, "r")) == NULL) {
642                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
643                  error(WARNING, errmsg);
644 <                return(0);
644 >                goto gotzip;
645          }
646   #ifdef MSDOS
647          setmode(fileno(fp), O_BINARY);
# Line 565 | Line 650 | char  *oldfile;
650          getheader(fp, NULL, NULL);
651                                  /* get picture size */
652          if (!fscnresolu(&x, &y, fp)) {
653 <                sprintf(errmsg, "bad recover file \"%s\"", oldfile);
653 >                sprintf(errmsg, "bad recover file \"%s\" - not removed",
654 >                                oldfile);
655                  error(WARNING, errmsg);
656                  fclose(fp);
657 <                return(0);
657 >                goto gotzip;
658          }
659  
660          if (x != hres || y != vres) {
# Line 592 | Line 678 | char  *oldfile;
678          fclose(fp);
679          unlink(oldfile);
680          return(y);
681 + gotzip:
682 +        if (fflush(stdout) == EOF)
683 +                error(SYSTEM, "error writing picture header");
684 +        return(0);
685   writerr:
686          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
687          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines