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.23 by greg, Fri Jan 29 12:15:40 1993 UTC vs.
Revision 2.40 by greg, Wed Dec 21 09:51:56 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1994 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 57 | Line 67 | double srcsizerat = .25;               /* maximum ratio source size
67   double  specthresh = .15;               /* specular sampling threshold */
68   double  specjitter = 1.;                /* specular sampling jitter */
69  
70 + int  backvis = 1;                       /* back face visibility */
71 +
72   int  maxdepth = 6;                      /* maximum recursion depth */
73   double  minweight = 5e-3;               /* minimum ray weight */
74  
# Line 77 | Line 89 | int  ralrm = 0;                                /* seconds between reports */
89  
90   double  pctdone = 0.0;                  /* percentage done */
91  
92 < long  tlastrept = 0L;                   /* time at last report */
92 > time_t  tlastrept = 0L;                 /* time at last report */
93  
94 < extern long  time();
83 < extern long  tstart;                    /* starting time */
94 > extern time_t  tstart;                  /* starting time */
95  
96 < extern long  nrays;                     /* number of rays traced */
96 > extern unsigned long  nrays;            /* number of rays traced */
97  
98   #define  MAXDIV         16              /* maximum sample size */
99  
# Line 94 | Line 105 | extern char  *mktemp();
105  
106   double  pixvalue();
107  
108 + #ifdef NIX
109 + #define  file_exists(f) (access(f,F_OK)==0)
110 + #else
111 + #include  <sys/types.h>
112 + #include  <sys/stat.h>
113 + int
114 + file_exists(fname)                              /* ordinary file exists? */
115 + char  *fname;
116 + {
117 +        struct stat  sbuf;
118 +        if (stat(fname, &sbuf) < 0) return(0);
119 +        return((sbuf.st_mode & S_IFREG) != 0);
120 + }
121 + #endif
122  
123 +
124   quit(code)                      /* quit program */
125   int  code;
126   {
# Line 106 | Line 132 | int  code;
132   }
133  
134  
135 < #ifdef BSD
135 > #ifndef NIX
136   report()                /* report progress */
137   {
138 +        double  u, s;
139 + #ifdef BSD
140 +        char  hostname[257];
141          struct rusage  rubuf;
142 <        double  t;
142 > #else
143 >        struct tms  tbuf;
144 >        struct utsname  nambuf;
145 >        double  period;
146 > #define hostname  nambuf.nodename
147 > #endif
148  
149 +        tlastrept = time((time_t *)NULL);
150 + #ifdef BSD
151          getrusage(RUSAGE_SELF, &rubuf);
152 <        t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
153 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
152 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
153 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
154          getrusage(RUSAGE_CHILDREN, &rubuf);
155 <        t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
156 <        t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
155 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
156 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
157 >        gethostname(hostname, sizeof(hostname));
158 > #else
159 >        times(&tbuf);
160 > #ifdef _SC_CLK_TCK
161 >        period = 1.0 / sysconf(_SC_CLK_TCK);
162 > #else
163 >        period = 1.0 / 60.0;
164 > #endif
165 >        u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
166 >        s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
167 >        uname(&nambuf);
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., hostname);
174          eputs(errmsg);
175 <        tlastrept = time((long *)0);
175 > #ifndef BSD
176 >        signal(SIGCONT, report);
177 > #undef hostname
178 > #endif
179   }
180   #else
181   report()                /* report progress */
182   {
183 <        tlastrept = time((long *)0);
184 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
183 >        tlastrept = time((time_t *)NULL);
184 >        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
185                          nrays, pctdone, (tlastrept-tstart)/3600.0);
186          eputs(errmsg);
134        signal(SIGCONT, report);
187   }
188   #endif
189  
# Line 153 | Line 205 | char  *pout, *zout, *prvr;
205   {
206          extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
207          char  fbuf[128], fbuf2[128];
208 +        int  npicts;
209          register char  *cp;
210          RESOLU  rs;
211          double  pa;
# Line 189 | Line 242 | char  *pout, *zout, *prvr;
242                                  cp--;
243                          strcpy(cp, RFTEMPLATE);
244                          prvr = mktemp(fbuf2);
245 <                        if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
246 <                                sprintf(errmsg,
245 >                        if (rename(fbuf, prvr) < 0)
246 >                                if (errno == ENOENT) {  /* ghost file */
247 >                                        sprintf(errmsg,
248 >                                                "new output file \"%s\"",
249 >                                                fbuf);
250 >                                        error(WARNING, errmsg);
251 >                                        prvr = NULL;
252 >                                } else {                /* serious error */
253 >                                        sprintf(errmsg,
254                                          "cannot rename \"%s\" to \"%s\"",
255                                                  fbuf, prvr);
256 <                                error(SYSTEM, errmsg);
257 <                        }
256 >                                        error(SYSTEM, errmsg);
257 >                                }
258                  }
259          }
260 <                                        /* render sequence */
260 >        npicts = 0;                     /* render sequence */
261          do {
262                  if (seq && nextview(stdin) == EOF)
263                          break;
264 +                pctdone = 0.0;
265                  if (pout != NULL) {
266                          sprintf(fbuf, pout, seq);
267 +                        if (file_exists(fbuf)) {
268 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
269 +                                        sprintf(errmsg,
270 +                                                "output file \"%s\" exists",
271 +                                                fbuf);
272 +                                        error(USER, errmsg);
273 +                                }
274 +                                continue;               /* don't clobber */
275 +                        }
276                          if (freopen(fbuf, "w", stdout) == NULL) {
277                                  sprintf(errmsg,
278                                          "cannot open output file \"%s\"", fbuf);
# Line 250 | Line 320 | char  *pout, *zout, *prvr;
320                          cp = NULL;
321                  render(cp, prvr);
322                  prvr = NULL;
323 +                npicts++;
324          } while (seq++);
325 +                                        /* check that we did something */
326 +        if (npicts == 0)
327 +                error(WARNING, "no output produced");
328   }
329  
330  
# Line 296 | Line 370 | char  *zfile, *oldfile;
370                          sampdens[i] = hstep;
371          } else
372                  sampdens = NULL;
373 <                                        /* open z file */
373 >                                        /* open z-file */
374          if (zfile != NULL) {
375                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
376 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
376 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
377                          error(SYSTEM, errmsg);
378                  }
379   #ifdef MSDOS
# Line 321 | Line 395 | char  *zfile, *oldfile;
395          i = salvage(oldfile);
396          if (zfd != -1 && i > 0 &&
397                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
398 <                error(SYSTEM, "z file seek error in render");
398 >                error(SYSTEM, "z-file seek error in render");
399          pctdone = 100.0*i/vres;
400          if (ralrm > 0)                  /* report init stats */
401                  report();
# Line 365 | Line 439 | char  *zfile, *oldfile;
439                          goto writerr;
440                                                          /* record progress */
441                  pctdone = 100.0*(vres-1-ypos)/vres;
442 <                if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
442 >                if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
443                          report();
444   #ifndef  BSD
445                  else
# Line 428 | Line 502 | int  xres, y, xstep;
502                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
503                  else
504                          b = fillsample(scanline+i-xstep,
505 <                                        zline ? zline+i-xstep : NULL,
505 >                                        zline ? zline+i-xstep : (float *)NULL,
506                                          i-xstep, y, xstep, 0, b/2);
507                  if (sd) *sd++ = nc & 1 ? bl : b;
508                  bl = b;
# Line 456 | Line 530 | int  xres, y, ysize;
530                          zline[ysize] = zbar[ysize][i];
531                  }
532                  
533 <                b = fillsample(vline, zbar[0] ? zline : NULL,
533 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
534                                  i, y, 0, ysize, b/2);
535                  
536                  for (j = 1; j < ysize; j++)
# Line 514 | Line 588 | int  b;
588                                                          /* recurse */
589          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
590          
591 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
591 >        ncut += fillsample(colline+(len>>1),
592 >                        zline ? zline+(len>>1) : (float *)NULL,
593                          x+(xlen>>1), y+(ylen>>1),
594                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
595  
# Line 529 | Line 604 | int  x, y;                     /* pixel position */
604   {
605          static RAY  thisray;
606  
607 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
608 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
607 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
608 >                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
609                  setcolor(col, 0.0, 0.0, 0.0);
610                  return(0.0);
611          }
# Line 556 | Line 631 | char  *oldfile;
631          int  x, y;
632  
633          if (oldfile == NULL)
634 <                return(0);
635 <        
634 >                goto gotzip;
635 >
636          if ((fp = fopen(oldfile, "r")) == NULL) {
637                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
638                  error(WARNING, errmsg);
639 <                return(0);
639 >                goto gotzip;
640          }
641   #ifdef MSDOS
642          setmode(fileno(fp), O_BINARY);
# Line 570 | Line 645 | char  *oldfile;
645          getheader(fp, NULL, NULL);
646                                  /* get picture size */
647          if (!fscnresolu(&x, &y, fp)) {
648 <                sprintf(errmsg, "bad recover file \"%s\"", oldfile);
648 >                sprintf(errmsg, "bad recover file \"%s\" - not removed",
649 >                                oldfile);
650                  error(WARNING, errmsg);
651                  fclose(fp);
652 <                return(0);
652 >                goto gotzip;
653          }
654  
655          if (x != hres || y != vres) {
# Line 597 | Line 673 | char  *oldfile;
673          fclose(fp);
674          unlink(oldfile);
675          return(y);
676 + gotzip:
677 +        if (fflush(stdout) == EOF)
678 +                error(SYSTEM, "error writing picture header");
679 +        return(0);
680   writerr:
681          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
682          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines