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.13 by greg, Tue Sep 8 20:56:20 1992 UTC vs.
Revision 2.27 by greg, Mon Aug 2 21:48:37 1993 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   #endif
19  
20   #include  <signal.h>
21 #include  <fcntl.h>
21  
22   #include  "view.h"
23  
# Line 28 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27  
28   #include  "paths.h"
29  
30 + #define  RFTEMPLATE     "rfXXXXXX"
31 +
32 + #ifndef SIGCONT
33 + #define SIGCONT         SIGIO
34 + #endif
35 +
36   int  dimlist[MAXDIM];                   /* sampling dimensions */
37   int  ndims = 0;                         /* number of sampling dimensions */
38   int  samplendx;                         /* sample index number */
# Line 35 | Line 40 | int  samplendx;                                /* sample index number */
40   VIEW  ourview = STDVIEW;                /* view parameters */
41   int  hresolu = 512;                     /* horizontal resolution */
42   int  vresolu = 512;                     /* vertical resolution */
43 < double  pixaspect = 1.0;                /* pixel aspect ratio */
43 > double  pixaspect = 1.0;                /* pixel aspect ratio */
44  
45   int  psample = 4;                       /* pixel sample size */
46 < double  maxdiff = .05;                  /* max. difference for interpolation */
47 < double  dstrpix = 0.67;                 /* square pixel distribution */
46 > double  maxdiff = .05;                  /* max. difference for interpolation */
47 > double  dstrpix = 0.67;                 /* square pixel distribution */
48  
49 < double  dstrsrc = 0.0;                  /* square source distribution */
50 < double  shadthresh = .05;               /* shadow threshold */
51 < double  shadcert = .5;                  /* shadow certainty */
49 > double  dstrsrc = 0.0;                  /* square source distribution */
50 > double  shadthresh = .05;               /* shadow threshold */
51 > double  shadcert = .5;                  /* shadow certainty */
52   int  directrelay = 1;                   /* number of source relays */
53   int  vspretest = 512;                   /* virtual source pretest density */
54 < int  directinvis = 0;                   /* sources invisible? */
55 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
54 > int  directvis = 1;                     /* sources visible? */
55 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
56  
57 < double  specthresh = .15;               /* specular sampling threshold */
58 < double  specjitter = 1.;                /* specular sampling jitter */
57 > double  specthresh = .15;               /* specular sampling threshold */
58 > double  specjitter = 1.;                /* specular sampling jitter */
59  
60   int  maxdepth = 6;                      /* maximum recursion depth */
61 < double  minweight = 5e-3;               /* minimum ray weight */
61 > double  minweight = 5e-3;               /* minimum ray weight */
62  
63   COLOR  ambval = BLKCOLOR;               /* ambient value */
64 < double  ambacc = 0.2;                   /* ambient accuracy */
64 > double  ambacc = 0.2;                   /* ambient accuracy */
65   int  ambres = 32;                       /* ambient resolution */
66   int  ambdiv = 128;                      /* ambient divisions */
67   int  ambssamp = 0;                      /* ambient super-samples */
# Line 64 | Line 69 | int  ambounce = 0;                     /* ambient bounces */
69   char  *amblist[128];                    /* ambient include/exclude list */
70   int  ambincl = -1;                      /* include == 1, exclude == 0 */
71  
72 + #ifdef MSDOS
73 + int  ralrm = 60;                        /* seconds between reports */
74 + #else
75   int  ralrm = 0;                         /* seconds between reports */
76 + #endif
77  
78 < double  pctdone = 0.0;                  /* percentage done */
78 > double  pctdone = 0.0;                  /* percentage done */
79  
80   long  tlastrept = 0L;                   /* time at last report */
81  
82   extern long  time();
83   extern long  tstart;                    /* starting time */
84  
85 < extern long  nrays;                     /* number of rays traced */
85 > extern unsigned long  nrays;            /* number of rays traced */
86  
87 < #define  MAXDIV         16              /* maximum sample size */
87 > #define  MAXDIV         16              /* maximum sample size */
88  
89 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
89 > #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
90  
82 #define  RFTEMPLATE     "rfXXXXXX"
83 #define  HFTEMPLATE     TEMPLATE
84
85 static char  *hfname = NULL;            /* header file name */
86 static FILE  *hfp = NULL;               /* header file pointer */
87
91   static int  hres, vres;                 /* resolution for this frame */
92  
93   extern char  *mktemp();
94  
95 < double  pixvalue();
95 > double  pixvalue();
96  
97 + #ifdef NIX
98 + #define  file_exists(f) (access(f,F_OK)==0)
99 + #else
100 + #include  <sys/types.h>
101 + #include  <sys/stat.h>
102 + int
103 + file_exists(fname)                              /* ordinary file exists? */
104 + char  *fname;
105 + {
106 +        struct stat  sbuf;
107 +        if (stat(fname, &sbuf) < 0) return(0);
108 +        return((sbuf.st_mode & S_IFREG) != 0);
109 + }
110 + #endif
111  
112 +
113   quit(code)                      /* quit program */
114   int  code;
115   {
116          if (code)                       /* report status */
117                  report();
118 <        if (hfname != NULL) {           /* delete header file */
119 <                if (hfp != NULL)
102 <                        fclose(hfp);
103 <                unlink(hfname);
104 <        }
118 >        headclean();                    /* delete header file */
119 >        pfclean();                      /* clean up persist files */
120          exit(code);
121   }
122  
# Line 110 | Line 125 | int  code;
125   report()                /* report progress */
126   {
127          struct rusage  rubuf;
128 <        double  t;
128 >        double  t;
129  
130          getrusage(RUSAGE_SELF, &rubuf);
131          t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
# Line 119 | Line 134 | report()               /* report progress */
134          t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
135          t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
136  
137 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
137 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n",
138                          nrays, pctdone, t/3600.0);
139          eputs(errmsg);
140          tlastrept = time((long *)0);
# Line 128 | Line 143 | report()               /* report progress */
143   report()                /* report progress */
144   {
145          tlastrept = time((long *)0);
146 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
146 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n",
147                          nrays, pctdone, (tlastrept-tstart)/3600.0);
148          eputs(errmsg);
149 <        signal(SIGALRM, report);
149 >        signal(SIGCONT, report);
150   }
151   #endif
152  
153  
139 openheader()                    /* save standard output to header file */
140 {
141        hfname = mktemp(HFTEMPLATE);
142        if (freopen(hfname, "w", stdout) == NULL) {
143                sprintf(errmsg, "cannot open header file \"%s\"", hfname);
144                error(SYSTEM, errmsg);
145        }
146 }
147
148
149 closeheader()                   /* done with header output */
150 {
151        if (hfname == NULL)
152                return;
153        if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL)
154                error(SYSTEM, "error reopening header file");
155 }
156
157
158 dupheader()                     /* repeat header on standard output */
159 {
160        register int  c;
161
162        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
154   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
155   int  seq;
156   char  *pout, *zout, *prvr;
# Line 181 | Line 166 | char  *pout, *zout, *prvr;
166   * sequenced file naming.
167   */
168   {
169 <        extern char  *rindex(), *strncpy(), *strcat();
169 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
170          char  fbuf[128], fbuf2[128];
171 +        int  npicts;
172          register char  *cp;
173 <        RESOLU  rs;
174 <        double  pa;
189 <                                        /* finished writing header */
190 <        closeheader();
173 >        RESOLU  rs;
174 >        double  pa;
175                                          /* check sampling */
176          if (psample < 1)
177                  psample = 1;
# Line 211 | Line 195 | char  *pout, *zout, *prvr;
195                                  error(USER, "unexpected EOF on view input");
196                  prvr = fbuf;                    /* mark for renaming */
197          }
198 <        if (pout != NULL) {
198 >        if (pout != NULL & prvr != NULL) {
199                  sprintf(fbuf, pout, seq);
200 <                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
201 <                        fbuf2[0] = '\0';
202 <                        if ((cp = rindex(fbuf, '/')) != NULL)
203 <                                strncpy(fbuf2, fbuf, cp-fbuf+1);
204 <                        strcat(fbuf2, RFTEMPLATE);
200 >                if (!strcmp(prvr, fbuf)) {      /* rename */
201 >                        strcpy(fbuf2, fbuf);
202 >                        for (cp = fbuf2; *cp; cp++)
203 >                                ;
204 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
205 >                                cp--;
206 >                        strcpy(cp, RFTEMPLATE);
207                          prvr = mktemp(fbuf2);
208                          if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
209                                  sprintf(errmsg,
# Line 227 | Line 213 | char  *pout, *zout, *prvr;
213                          }
214                  }
215          }
216 <                                        /* render sequence */
216 >        npicts = 0;                     /* render sequence */
217          do {
218                  if (seq && nextview(stdin) == EOF)
219                          break;
220 +                pctdone = 0.0;
221                  if (pout != NULL) {
222                          sprintf(fbuf, pout, seq);
223 +                        if (file_exists(fbuf)) {
224 +                                if (prvr != NULL || !strcmp(fbuf, pout)) {
225 +                                        sprintf(errmsg,
226 +                                                "output file \"%s\" exists",
227 +                                                fbuf);
228 +                                        error(USER, errmsg);
229 +                                }
230 +                                continue;               /* don't clobber */
231 +                        }
232                          if (freopen(fbuf, "w", stdout) == NULL) {
233                                  sprintf(errmsg,
234                                          "cannot open output file \"%s\"", fbuf);
235                                  error(SYSTEM, errmsg);
236                          }
237 + #ifdef MSDOS
238 +                        setmode(fileno(stdout), O_BINARY);
239 + #endif
240                          dupheader();
241                  }
242                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 277 | Line 276 | char  *pout, *zout, *prvr;
276                          cp = NULL;
277                  render(cp, prvr);
278                  prvr = NULL;
279 +                npicts++;
280          } while (seq++);
281 +                                        /* check that we did something */
282 +        if (npicts == 0)
283 +                error(WARNING, "no output produced");
284   }
285  
286  
# Line 323 | Line 326 | char  *zfile, *oldfile;
326                          sampdens[i] = hstep;
327          } else
328                  sampdens = NULL;
329 <                                        /* open z file */
329 >                                        /* open z-file */
330          if (zfile != NULL) {
331                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
332 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
332 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
333                          error(SYSTEM, errmsg);
334                  }
335 + #ifdef MSDOS
336 +                setmode(zfd, O_BINARY);
337 + #endif
338                  for (i = 0; i <= psample; i++) {
339                          zbar[i] = (float *)malloc(hres*sizeof(float));
340                          if (zbar[i] == NULL)
# Line 345 | Line 351 | char  *zfile, *oldfile;
351          i = salvage(oldfile);
352          if (zfd != -1 && i > 0 &&
353                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
354 <                error(SYSTEM, "z file seek error in render");
354 >                error(SYSTEM, "z-file seek error in render");
355          pctdone = 100.0*i/vres;
356          if (ralrm > 0)                  /* report init stats */
357                  report();
358 < #ifndef  BSD
358 > #ifndef  BSD
359          else
360   #endif
361 <        signal(SIGALRM, report);
361 >        signal(SIGCONT, report);
362          ypos = vres-1 - i;
363          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
364                                                  /* compute scanlines */
# Line 374 | Line 380 | char  *zfile, *oldfile;
380                                                          /* fill bar */
381                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
382                                                          /* write it out */
383 < #ifndef  BSD
384 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
383 > #ifndef  BSD
384 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
385   #endif
386                  for (i = ystep; i > 0; i--) {
387                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 391 | Line 397 | char  *zfile, *oldfile;
397                  pctdone = 100.0*(vres-1-ypos)/vres;
398                  if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
399                          report();
400 < #ifndef  BSD
400 > #ifndef  BSD
401                  else
402 <                        signal(SIGALRM, report);
402 >                        signal(SIGCONT, report);
403   #endif
404          }
405                                                  /* clean up */
406 <        signal(SIGALRM, SIG_IGN);
406 >        signal(SIGCONT, SIG_IGN);
407          if (zfd != -1) {
408                  if (write(zfd, (char *)zbar[0], hres*sizeof(float))
409                                  < hres*sizeof(float))
# Line 417 | Line 423 | char  *zfile, *oldfile;
423          pctdone = 100.0;
424          if (ralrm > 0)
425                  report();
426 +        signal(SIGCONT, SIG_DFL);
427          return;
428   writerr:
429          error(SYSTEM, "write error in render");
# Line 426 | Line 433 | memerr:
433  
434  
435   fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
436 < register COLOR  *scanline;
437 < register float  *zline;
436 > register COLOR  *scanline;
437 > register float  *zline;
438   register char  *sd;
439   int  xres, y, xstep;
440   {
441          static int  nc = 0;             /* number of calls */
442          int  bl = xstep, b = xstep;
443 <        double  z;
443 >        double  z;
444          register int  i;
445          
446          z = pixvalue(scanline[0], 0, y);
# Line 461 | Line 468 | int  xres, y, xstep;
468  
469  
470   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
471 < register COLOR  *scanbar[];
472 < register float  *zbar[];
471 > register COLOR  *scanbar[];
472 > register float  *zbar[];
473   int  xres, y, ysize;
474   {
475          COLOR  vline[MAXDIV+1];
# Line 492 | Line 499 | int  xres, y, ysize;
499  
500  
501   int
502 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
503 < register COLOR  *colline;
504 < register float  *zline;
502 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
503 > register COLOR  *colline;
504 > register float  *zline;
505   int  x, y;
506   int  xlen, ylen;
507   int  b;
508   {
509 <        extern double  fabs();
510 <        double  ratio;
504 <        double  z;
509 >        double  ratio;
510 >        double  z;
511          COLOR  ctmp;
512          int  ncut;
513          register int  len;
# Line 587 | Line 593 | char  *oldfile;
593                  error(WARNING, errmsg);
594                  return(0);
595          }
596 + #ifdef MSDOS
597 +        setmode(fileno(fp), O_BINARY);
598 + #endif
599                                  /* discard header */
600 <        getheader(fp, NULL);
600 >        getheader(fp, NULL, NULL);
601                                  /* get picture size */
602          if (!fscnresolu(&x, &y, fp)) {
603                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines