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.10 by greg, Sat Aug 8 18:45:02 1992 UTC vs.
Revision 2.22 by greg, Thu Jan 21 10:08:59 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 26 | Line 25 | static char SCCSid[] = "$SunId$ LBL";
25  
26   #include  "random.h"
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 33 | 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 62 | 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  
# Line 73 | Line 84 | extern long  tstart;                   /* starting time */
84  
85   extern 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  
80 #define  RFTEMPLATE     "rfXXXXXX"
81 #define  HFTEMPLATE     "/tmp/hfXXXXXX"
82
83 static char  *hfname = NULL;            /* header file name */
84 static FILE  *hfp = NULL;               /* header file pointer */
85
91   static int  hres, vres;                 /* resolution for this frame */
92  
93   extern char  *mktemp();
94  
95 < double  pixvalue();
95 > double  pixvalue();
96  
97  
98   quit(code)                      /* quit program */
# Line 95 | Line 100 | int  code;
100   {
101          if (code)                       /* report status */
102                  report();
103 <        if (hfname != NULL) {           /* delete header file */
104 <                if (hfp != NULL)
100 <                        fclose(hfp);
101 <                unlink(hfname);
102 <        }
103 >        headclean();                    /* delete header file */
104 >        pfclean();                      /* clean up persist files */
105          exit(code);
106   }
107  
# Line 108 | Line 110 | int  code;
110   report()                /* report progress */
111   {
112          struct rusage  rubuf;
113 <        double  t;
113 >        double  t;
114  
115          getrusage(RUSAGE_SELF, &rubuf);
116          t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
# Line 129 | Line 131 | report()               /* report progress */
131          sprintf(errmsg, "%ld 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  
137 openheader()                    /* save standard output to header file */
138 {
139        hfname = mktemp(HFTEMPLATE);
140        if (freopen(hfname, "w", stdout) == NULL) {
141                sprintf(errmsg, "cannot open header file \"%s\"", hfname);
142                error(SYSTEM, errmsg);
143        }
144 }
145
146
147 closeheader()                   /* done with header output */
148 {
149        if (hfname == NULL)
150                return;
151        if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL)
152                error(SYSTEM, "error reopening header file");
153 }
154
155
156 dupheader()                     /* repeat header on standard output */
157 {
158        register int  c;
159
160        if (fseek(hfp, 0L, 0) < 0)
161                error(SYSTEM, "seek error on header file");
162        while ((c = getc(hfp)) != EOF)
163                putchar(c);
164 }
165
166
139   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
140   int  seq;
141   char  *pout, *zout, *prvr;
# Line 179 | 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          register char  *cp;
157 <        RESOLU  rs;
158 <        double  pa;
187 <                                        /* finished writing header */
188 <        closeheader();
157 >        RESOLU  rs;
158 >        double  pa;
159                                          /* check sampling */
160          if (psample < 1)
161                  psample = 1;
# Line 209 | Line 179 | char  *pout, *zout, *prvr;
179                                  error(USER, "unexpected EOF on view input");
180                  prvr = fbuf;                    /* mark for renaming */
181          }
182 <        if (pout != NULL) {
182 >        if (pout != NULL & prvr != NULL) {
183                  sprintf(fbuf, pout, seq);
184 <                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
185 <                        fbuf2[0] = '\0';
186 <                        if ((cp = rindex(fbuf, '/')) != NULL)
187 <                                strncpy(fbuf2, fbuf, cp-fbuf+1);
188 <                        strcat(fbuf2, RFTEMPLATE);
184 >                if (!strcmp(prvr, fbuf)) {      /* rename */
185 >                        strcpy(fbuf2, fbuf);
186 >                        for (cp = fbuf2; *cp; cp++)
187 >                                ;
188 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
189 >                                cp--;
190 >                        strcpy(cp, RFTEMPLATE);
191                          prvr = mktemp(fbuf2);
192                          if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
193                                  sprintf(errmsg,
# Line 236 | Line 208 | char  *pout, *zout, *prvr;
208                                          "cannot open output file \"%s\"", fbuf);
209                                  error(SYSTEM, errmsg);
210                          }
211 + #ifdef MSDOS
212 +                        setmode(fileno(stdout), O_BINARY);
213 + #endif
214                          dupheader();
215                  }
216                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 255 | Line 230 | char  *pout, *zout, *prvr;
230                  normaspect(viewaspect(&ourview), &pa, &hres, &vres);
231                  if (seq) {
232                          if (ralrm > 0) {
233 <                                sprintf(errmsg, "starting frame %d\n", seq);
234 <                                eputs(errmsg);
233 >                                fprintf(stderr, "FRAME %d:", seq);
234 >                                fprintview(&ourview, stderr);
235 >                                putc('\n', stderr);
236 >                                fflush(stderr);
237                          }
238                          printf("FRAME=%d\n", seq);
239                  }
# Line 325 | Line 302 | char  *zfile, *oldfile;
302                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
303                          error(SYSTEM, errmsg);
304                  }
305 + #ifdef MSDOS
306 +                setmode(zfd, O_BINARY);
307 + #endif
308                  for (i = 0; i <= psample; i++) {
309                          zbar[i] = (float *)malloc(hres*sizeof(float));
310                          if (zbar[i] == NULL)
# Line 345 | Line 325 | char  *zfile, *oldfile;
325          pctdone = 100.0*i/vres;
326          if (ralrm > 0)                  /* report init stats */
327                  report();
328 < #ifndef  BSD
328 > #ifndef  BSD
329          else
330   #endif
331 <        signal(SIGALRM, report);
331 >        signal(SIGCONT, report);
332          ypos = vres-1 - i;
333          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
334                                                  /* compute scanlines */
# Line 370 | Line 350 | char  *zfile, *oldfile;
350                                                          /* fill bar */
351                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
352                                                          /* write it out */
353 < #ifndef  BSD
354 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
353 > #ifndef  BSD
354 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
355   #endif
356                  for (i = ystep; i > 0; i--) {
357                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 387 | Line 367 | char  *zfile, *oldfile;
367                  pctdone = 100.0*(vres-1-ypos)/vres;
368                  if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
369                          report();
370 < #ifndef  BSD
370 > #ifndef  BSD
371                  else
372 <                        signal(SIGALRM, report);
372 >                        signal(SIGCONT, report);
373   #endif
374          }
375                                                  /* clean up */
376 <        signal(SIGALRM, SIG_IGN);
376 >        signal(SIGCONT, SIG_IGN);
377          if (zfd != -1) {
378                  if (write(zfd, (char *)zbar[0], hres*sizeof(float))
379                                  < hres*sizeof(float))
# Line 411 | Line 391 | char  *zfile, *oldfile;
391          if (sampdens != NULL)
392                  free(sampdens);
393          pctdone = 100.0;
394 +        if (ralrm > 0)
395 +                report();
396          return;
397   writerr:
398          error(SYSTEM, "write error in render");
# Line 420 | Line 402 | memerr:
402  
403  
404   fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
405 < register COLOR  *scanline;
406 < register float  *zline;
405 > register COLOR  *scanline;
406 > register float  *zline;
407   register char  *sd;
408   int  xres, y, xstep;
409   {
410          static int  nc = 0;             /* number of calls */
411          int  bl = xstep, b = xstep;
412 <        double  z;
412 >        double  z;
413          register int  i;
414          
415          z = pixvalue(scanline[0], 0, y);
# Line 455 | Line 437 | int  xres, y, xstep;
437  
438  
439   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
440 < register COLOR  *scanbar[];
441 < register float  *zbar[];
440 > register COLOR  *scanbar[];
441 > register float  *zbar[];
442   int  xres, y, ysize;
443   {
444          COLOR  vline[MAXDIV+1];
# Line 486 | Line 468 | int  xres, y, ysize;
468  
469  
470   int
471 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
472 < register COLOR  *colline;
473 < register float  *zline;
471 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
472 > register COLOR  *colline;
473 > register float  *zline;
474   int  x, y;
475   int  xlen, ylen;
476   int  b;
477   {
478 <        extern double  fabs();
479 <        double  ratio;
498 <        double  z;
478 >        double  ratio;
479 >        double  z;
480          COLOR  ctmp;
481          int  ncut;
482          register int  len;
# Line 581 | Line 562 | char  *oldfile;
562                  error(WARNING, errmsg);
563                  return(0);
564          }
565 + #ifdef MSDOS
566 +        setmode(fileno(fp), O_BINARY);
567 + #endif
568                                  /* discard header */
569 <        getheader(fp, NULL);
569 >        getheader(fp, NULL, NULL);
570                                  /* get picture size */
571          if (!fscnresolu(&x, &y, fp)) {
572                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines