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.14 by greg, Mon Sep 21 12:07:52 1992 UTC vs.
Revision 2.26 by greg, Fri Jul 30 10:31:09 1993 UTC

# Line 27 | 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 45 | Line 51 | 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? */
54 > int  directvis = 1;                     /* sources visible? */
55   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
56  
57   double  specthresh = .15;               /* specular sampling threshold */
# Line 63 | 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 */
79  
# Line 72 | Line 82 | long  tlastrept = 0L;                  /* time at last report */
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 */
88  
89   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
90  
81 #define  RFTEMPLATE     "rfXXXXXX"
82 #define  HFTEMPLATE     TEMPLATE
83
84 static char  *hfname = NULL;            /* header file name */
85 static FILE  *hfp = NULL;               /* header file pointer */
86
91   static int  hres, vres;                 /* resolution for this frame */
92  
93   extern char  *mktemp();
# Line 96 | Line 100 | int  code;
100   {
101          if (code)                       /* report status */
102                  report();
103 <        if (hfname != NULL) {           /* delete header file */
104 <                if (hfp != NULL)
101 <                        fclose(hfp);
102 <                unlink(hfname);
103 <        }
103 >        headclean();                    /* delete header file */
104 >        pfclean();                      /* clean up persist files */
105          exit(code);
106   }
107  
# Line 118 | Line 119 | report()               /* report progress */
119          t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
120          t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
121  
122 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n",
122 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n",
123                          nrays, pctdone, t/3600.0);
124          eputs(errmsg);
125          tlastrept = time((long *)0);
# Line 127 | Line 128 | report()               /* report progress */
128   report()                /* report progress */
129   {
130          tlastrept = time((long *)0);
131 <        sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n",
131 >        sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n",
132                          nrays, pctdone, (tlastrept-tstart)/3600.0);
133          eputs(errmsg);
134 <        signal(SIGALRM, report);
134 >        signal(SIGCONT, report);
135   }
136   #endif
137  
138  
138 openheader()                    /* save standard output to header file */
139 {
140        hfname = mktemp(HFTEMPLATE);
141        if (freopen(hfname, "w", stdout) == NULL) {
142                sprintf(errmsg, "cannot open header file \"%s\"", hfname);
143                error(SYSTEM, errmsg);
144        }
145 }
146
147
148 closeheader()                   /* done with header output */
149 {
150        if (hfname == NULL)
151                return;
152        if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL)
153                error(SYSTEM, "error reopening header file");
154 }
155
156
157 dupheader()                     /* repeat header on standard output */
158 {
159        register int  c;
160
161        if (fseek(hfp, 0L, 0) < 0)
162                error(SYSTEM, "seek error on header file");
163        while ((c = getc(hfp)) != EOF)
164                putchar(c);
165 }
166
167
139   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
140   int  seq;
141   char  *pout, *zout, *prvr;
# Line 180 | Line 151 | char  *pout, *zout, *prvr;
151   * sequenced file naming.
152   */
153   {
154 <        extern char  *rindex(), *strncpy(), *strcat();
154 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
155          char  fbuf[128], fbuf2[128];
156 +        int  npicts;
157          register char  *cp;
158          RESOLU  rs;
159          double  pa;
188                                        /* finished writing header */
189        closeheader();
160                                          /* check sampling */
161          if (psample < 1)
162                  psample = 1;
# Line 210 | Line 180 | char  *pout, *zout, *prvr;
180                                  error(USER, "unexpected EOF on view input");
181                  prvr = fbuf;                    /* mark for renaming */
182          }
183 <        if (pout != NULL) {
183 >        if (pout != NULL & prvr != NULL) {
184                  sprintf(fbuf, pout, seq);
185 <                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
186 <                        fbuf2[0] = '\0';
187 <                        if ((cp = rindex(fbuf, '/')) != NULL)
188 <                                strncpy(fbuf2, fbuf, cp-fbuf+1);
189 <                        strcat(fbuf2, RFTEMPLATE);
185 >                if (!strcmp(prvr, fbuf)) {      /* rename */
186 >                        strcpy(fbuf2, fbuf);
187 >                        for (cp = fbuf2; *cp; cp++)
188 >                                ;
189 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
190 >                                cp--;
191 >                        strcpy(cp, RFTEMPLATE);
192                          prvr = mktemp(fbuf2);
193                          if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
194                                  sprintf(errmsg,
# Line 226 | Line 198 | char  *pout, *zout, *prvr;
198                          }
199                  }
200          }
201 <                                        /* render sequence */
201 >        npicts = 0;                     /* render sequence */
202          do {
203                  if (seq && nextview(stdin) == EOF)
204                          break;
205 +                pctdone = 0.0;
206                  if (pout != NULL) {
207                          sprintf(fbuf, pout, seq);
208 +                        if (prvr == NULL && access(fbuf, F_OK) == 0)
209 +                                continue;               /* don't clobber */
210                          if (freopen(fbuf, "w", stdout) == NULL) {
211                                  sprintf(errmsg,
212                                          "cannot open output file \"%s\"", fbuf);
213                                  error(SYSTEM, errmsg);
214                          }
215 + #ifdef MSDOS
216 +                        setmode(fileno(stdout), O_BINARY);
217 + #endif
218                          dupheader();
219                  }
220                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 276 | Line 254 | char  *pout, *zout, *prvr;
254                          cp = NULL;
255                  render(cp, prvr);
256                  prvr = NULL;
257 +                npicts++;
258          } while (seq++);
259 +                                        /* check that we did something */
260 +        if (npicts == 0)
261 +                error(WARNING, "no output produced");
262   }
263  
264  
# Line 322 | Line 304 | char  *zfile, *oldfile;
304                          sampdens[i] = hstep;
305          } else
306                  sampdens = NULL;
307 <                                        /* open z file */
307 >                                        /* open z-file */
308          if (zfile != NULL) {
309                  if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) {
310 <                        sprintf(errmsg, "cannot open z file \"%s\"", zfile);
310 >                        sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
311                          error(SYSTEM, errmsg);
312                  }
313 + #ifdef MSDOS
314 +                setmode(zfd, O_BINARY);
315 + #endif
316                  for (i = 0; i <= psample; i++) {
317                          zbar[i] = (float *)malloc(hres*sizeof(float));
318                          if (zbar[i] == NULL)
# Line 344 | Line 329 | char  *zfile, *oldfile;
329          i = salvage(oldfile);
330          if (zfd != -1 && i > 0 &&
331                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
332 <                error(SYSTEM, "z file seek error in render");
332 >                error(SYSTEM, "z-file seek error in render");
333          pctdone = 100.0*i/vres;
334          if (ralrm > 0)                  /* report init stats */
335                  report();
336   #ifndef  BSD
337          else
338   #endif
339 <        signal(SIGALRM, report);
339 >        signal(SIGCONT, report);
340          ypos = vres-1 - i;
341          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
342                                                  /* compute scanlines */
# Line 374 | Line 359 | char  *zfile, *oldfile;
359                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
360                                                          /* write it out */
361   #ifndef  BSD
362 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
362 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
363   #endif
364                  for (i = ystep; i > 0; i--) {
365                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 392 | Line 377 | char  *zfile, *oldfile;
377                          report();
378   #ifndef  BSD
379                  else
380 <                        signal(SIGALRM, report);
380 >                        signal(SIGCONT, report);
381   #endif
382          }
383                                                  /* clean up */
384 <        signal(SIGALRM, SIG_IGN);
384 >        signal(SIGCONT, SIG_IGN);
385          if (zfd != -1) {
386                  if (write(zfd, (char *)zbar[0], hres*sizeof(float))
387                                  < hres*sizeof(float))
# Line 416 | Line 401 | char  *zfile, *oldfile;
401          pctdone = 100.0;
402          if (ralrm > 0)
403                  report();
404 +        signal(SIGCONT, SIG_DFL);
405          return;
406   writerr:
407          error(SYSTEM, "write error in render");
# Line 498 | Line 484 | int  x, y;
484   int  xlen, ylen;
485   int  b;
486   {
501        extern double  fabs();
487          double  ratio;
488          double  z;
489          COLOR  ctmp;
# Line 586 | Line 571 | char  *oldfile;
571                  error(WARNING, errmsg);
572                  return(0);
573          }
574 + #ifdef MSDOS
575 +        setmode(fileno(fp), O_BINARY);
576 + #endif
577                                  /* discard header */
578 <        getheader(fp, NULL);
578 >        getheader(fp, NULL, NULL);
579                                  /* get picture size */
580          if (!fscnresolu(&x, &y, fp)) {
581                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines