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.21 by greg, Wed Jan 20 15:19:47 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   int  dimlist[MAXDIM];                   /* sampling dimensions */
33   int  ndims = 0;                         /* number of sampling dimensions */
34   int  samplendx;                         /* sample index number */
# Line 33 | Line 36 | int  samplendx;                                /* sample index number */
36   VIEW  ourview = STDVIEW;                /* view parameters */
37   int  hresolu = 512;                     /* horizontal resolution */
38   int  vresolu = 512;                     /* vertical resolution */
39 < double  pixaspect = 1.0;                /* pixel aspect ratio */
39 > double  pixaspect = 1.0;                /* pixel aspect ratio */
40  
41   int  psample = 4;                       /* pixel sample size */
42 < double  maxdiff = .05;                  /* max. difference for interpolation */
43 < double  dstrpix = 0.67;                 /* square pixel distribution */
42 > double  maxdiff = .05;                  /* max. difference for interpolation */
43 > double  dstrpix = 0.67;                 /* square pixel distribution */
44  
45 < double  dstrsrc = 0.0;                  /* square source distribution */
46 < double  shadthresh = .05;               /* shadow threshold */
47 < double  shadcert = .5;                  /* shadow certainty */
45 > double  dstrsrc = 0.0;                  /* square source distribution */
46 > double  shadthresh = .05;               /* shadow threshold */
47 > double  shadcert = .5;                  /* shadow certainty */
48   int  directrelay = 1;                   /* number of source relays */
49   int  vspretest = 512;                   /* virtual source pretest density */
50 < int  directinvis = 0;                   /* sources invisible? */
51 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
50 > int  directvis = 1;                     /* sources visible? */
51 > double  srcsizerat = .25;               /* maximum ratio source size/dist. */
52  
53 < double  specthresh = .15;               /* specular sampling threshold */
54 < double  specjitter = 1.;                /* specular sampling jitter */
53 > double  specthresh = .15;               /* specular sampling threshold */
54 > double  specjitter = 1.;                /* specular sampling jitter */
55  
56   int  maxdepth = 6;                      /* maximum recursion depth */
57 < double  minweight = 5e-3;               /* minimum ray weight */
57 > double  minweight = 5e-3;               /* minimum ray weight */
58  
59   COLOR  ambval = BLKCOLOR;               /* ambient value */
60 < double  ambacc = 0.2;                   /* ambient accuracy */
60 > double  ambacc = 0.2;                   /* ambient accuracy */
61   int  ambres = 32;                       /* ambient resolution */
62   int  ambdiv = 128;                      /* ambient divisions */
63   int  ambssamp = 0;                      /* ambient super-samples */
# Line 62 | Line 65 | int  ambounce = 0;                     /* ambient bounces */
65   char  *amblist[128];                    /* ambient include/exclude list */
66   int  ambincl = -1;                      /* include == 1, exclude == 0 */
67  
68 + #ifdef MSDOS
69 + int  ralrm = 60;                        /* seconds between reports */
70 + #else
71   int  ralrm = 0;                         /* seconds between reports */
72 + #endif
73  
74 < double  pctdone = 0.0;                  /* percentage done */
74 > double  pctdone = 0.0;                  /* percentage done */
75  
76   long  tlastrept = 0L;                   /* time at last report */
77  
# Line 73 | Line 80 | extern long  tstart;                   /* starting time */
80  
81   extern long  nrays;                     /* number of rays traced */
82  
83 < #define  MAXDIV         16              /* maximum sample size */
83 > #define  MAXDIV         16              /* maximum sample size */
84  
85 < #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
85 > #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
86  
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
87   static int  hres, vres;                 /* resolution for this frame */
88  
89   extern char  *mktemp();
90  
91 < double  pixvalue();
91 > double  pixvalue();
92  
93  
94   quit(code)                      /* quit program */
# Line 95 | Line 96 | int  code;
96   {
97          if (code)                       /* report status */
98                  report();
99 <        if (hfname != NULL) {           /* delete header file */
100 <                if (hfp != NULL)
100 <                        fclose(hfp);
101 <                unlink(hfname);
102 <        }
99 >        headclean();                    /* delete header file */
100 >        pfclean();                      /* clean up persist files */
101          exit(code);
102   }
103  
# Line 108 | Line 106 | int  code;
106   report()                /* report progress */
107   {
108          struct rusage  rubuf;
109 <        double  t;
109 >        double  t;
110  
111          getrusage(RUSAGE_SELF, &rubuf);
112          t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6;
# Line 134 | Line 132 | report()               /* report progress */
132   #endif
133  
134  
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
135   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
136   int  seq;
137   char  *pout, *zout, *prvr;
# Line 179 | Line 147 | char  *pout, *zout, *prvr;
147   * sequenced file naming.
148   */
149   {
150 <        extern char  *rindex(), *strncpy(), *strcat();
150 >        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
151          char  fbuf[128], fbuf2[128];
152          register char  *cp;
153 <        RESOLU  rs;
154 <        double  pa;
187 <                                        /* finished writing header */
188 <        closeheader();
153 >        RESOLU  rs;
154 >        double  pa;
155                                          /* check sampling */
156          if (psample < 1)
157                  psample = 1;
# Line 209 | Line 175 | char  *pout, *zout, *prvr;
175                                  error(USER, "unexpected EOF on view input");
176                  prvr = fbuf;                    /* mark for renaming */
177          }
178 <        if (pout != NULL) {
178 >        if (pout != NULL & prvr != NULL) {
179                  sprintf(fbuf, pout, seq);
180 <                if (prvr != NULL && !strcmp(prvr, fbuf)) {      /* rename */
181 <                        fbuf2[0] = '\0';
182 <                        if ((cp = rindex(fbuf, '/')) != NULL)
183 <                                strncpy(fbuf2, fbuf, cp-fbuf+1);
184 <                        strcat(fbuf2, RFTEMPLATE);
180 >                if (!strcmp(prvr, fbuf)) {      /* rename */
181 >                        strcpy(fbuf2, fbuf);
182 >                        for (cp = fbuf2; *cp; cp++)
183 >                                ;
184 >                        while (cp > fbuf2 && !ISDIRSEP(cp[-1]))
185 >                                cp--;
186 >                        strcpy(cp, RFTEMPLATE);
187                          prvr = mktemp(fbuf2);
188                          if (rename(fbuf, prvr) < 0 && errno != ENOENT) {
189                                  sprintf(errmsg,
# Line 236 | Line 204 | char  *pout, *zout, *prvr;
204                                          "cannot open output file \"%s\"", fbuf);
205                                  error(SYSTEM, errmsg);
206                          }
207 + #ifdef MSDOS
208 +                        setmode(fileno(stdout), O_BINARY);
209 + #endif
210                          dupheader();
211                  }
212                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 255 | Line 226 | char  *pout, *zout, *prvr;
226                  normaspect(viewaspect(&ourview), &pa, &hres, &vres);
227                  if (seq) {
228                          if (ralrm > 0) {
229 <                                sprintf(errmsg, "starting frame %d\n", seq);
230 <                                eputs(errmsg);
229 >                                fprintf(stderr, "FRAME %d:", seq);
230 >                                fprintview(&ourview, stderr);
231 >                                putc('\n', stderr);
232 >                                fflush(stderr);
233                          }
234                          printf("FRAME=%d\n", seq);
235                  }
# Line 325 | Line 298 | char  *zfile, *oldfile;
298                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
299                          error(SYSTEM, errmsg);
300                  }
301 + #ifdef MSDOS
302 +                setmode(zfd, O_BINARY);
303 + #endif
304                  for (i = 0; i <= psample; i++) {
305                          zbar[i] = (float *)malloc(hres*sizeof(float));
306                          if (zbar[i] == NULL)
# Line 345 | Line 321 | char  *zfile, *oldfile;
321          pctdone = 100.0*i/vres;
322          if (ralrm > 0)                  /* report init stats */
323                  report();
324 < #ifndef  BSD
324 > #ifndef  BSD
325          else
326   #endif
327          signal(SIGALRM, report);
# Line 370 | Line 346 | char  *zfile, *oldfile;
346                                                          /* fill bar */
347                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
348                                                          /* write it out */
349 < #ifndef  BSD
349 > #ifndef  BSD
350                  signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
351   #endif
352                  for (i = ystep; i > 0; i--) {
# Line 387 | Line 363 | char  *zfile, *oldfile;
363                  pctdone = 100.0*(vres-1-ypos)/vres;
364                  if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
365                          report();
366 < #ifndef  BSD
366 > #ifndef  BSD
367                  else
368                          signal(SIGALRM, report);
369   #endif
# Line 411 | Line 387 | char  *zfile, *oldfile;
387          if (sampdens != NULL)
388                  free(sampdens);
389          pctdone = 100.0;
390 +        if (ralrm > 0)
391 +                report();
392          return;
393   writerr:
394          error(SYSTEM, "write error in render");
# Line 420 | Line 398 | memerr:
398  
399  
400   fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
401 < register COLOR  *scanline;
402 < register float  *zline;
401 > register COLOR  *scanline;
402 > register float  *zline;
403   register char  *sd;
404   int  xres, y, xstep;
405   {
406          static int  nc = 0;             /* number of calls */
407          int  bl = xstep, b = xstep;
408 <        double  z;
408 >        double  z;
409          register int  i;
410          
411          z = pixvalue(scanline[0], 0, y);
# Line 455 | Line 433 | int  xres, y, xstep;
433  
434  
435   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
436 < register COLOR  *scanbar[];
437 < register float  *zbar[];
436 > register COLOR  *scanbar[];
437 > register float  *zbar[];
438   int  xres, y, ysize;
439   {
440          COLOR  vline[MAXDIV+1];
# Line 486 | Line 464 | int  xres, y, ysize;
464  
465  
466   int
467 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
468 < register COLOR  *colline;
469 < register float  *zline;
467 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
468 > register COLOR  *colline;
469 > register float  *zline;
470   int  x, y;
471   int  xlen, ylen;
472   int  b;
473   {
474 <        extern double  fabs();
475 <        double  ratio;
498 <        double  z;
474 >        double  ratio;
475 >        double  z;
476          COLOR  ctmp;
477          int  ncut;
478          register int  len;
# Line 581 | Line 558 | char  *oldfile;
558                  error(WARNING, errmsg);
559                  return(0);
560          }
561 + #ifdef MSDOS
562 +        setmode(fileno(fp), O_BINARY);
563 + #endif
564                                  /* discard header */
565 <        getheader(fp, NULL);
565 >        getheader(fp, NULL, NULL);
566                                  /* get picture size */
567          if (!fscnresolu(&x, &y, fp)) {
568                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines