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.12 by greg, Tue Sep 8 15:35:16 1992 UTC vs.
Revision 2.25 by greg, Fri May 28 18:59:50 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  
98   quit(code)                      /* quit program */
# Line 97 | Line 100 | int  code;
100   {
101          if (code)                       /* report status */
102                  report();
103 <        if (hfname != NULL) {           /* delete header file */
104 <                if (hfp != NULL)
102 <                        fclose(hfp);
103 <                unlink(hfname);
104 <        }
103 >        headclean();                    /* delete header file */
104 >        pfclean();                      /* clean up persist files */
105          exit(code);
106   }
107  
# Line 110 | 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 119 | 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 128 | 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  
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
139   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
140   int  seq;
141   char  *pout, *zout, *prvr;
# Line 181 | 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;
189 <                                        /* finished writing header */
190 <        closeheader();
157 >        RESOLU  rs;
158 >        double  pa;
159                                          /* check sampling */
160          if (psample < 1)
161                  psample = 1;
# Line 211 | 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 231 | Line 201 | char  *pout, *zout, *prvr;
201          do {
202                  if (seq && nextview(stdin) == EOF)
203                          break;
204 +                pctdone = 0.0;
205                  if (pout != NULL) {
206                          sprintf(fbuf, pout, seq);
207                          if (freopen(fbuf, "w", stdout) == NULL) {
# Line 238 | Line 209 | char  *pout, *zout, *prvr;
209                                          "cannot open output file \"%s\"", fbuf);
210                                  error(SYSTEM, errmsg);
211                          }
212 + #ifdef MSDOS
213 +                        setmode(fileno(stdout), O_BINARY);
214 + #endif
215                          dupheader();
216                  }
217                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 329 | Line 303 | char  *zfile, *oldfile;
303                          sprintf(errmsg, "cannot open z file \"%s\"", zfile);
304                          error(SYSTEM, errmsg);
305                  }
306 + #ifdef MSDOS
307 +                setmode(zfd, O_BINARY);
308 + #endif
309                  for (i = 0; i <= psample; i++) {
310                          zbar[i] = (float *)malloc(hres*sizeof(float));
311                          if (zbar[i] == NULL)
# Line 349 | Line 326 | char  *zfile, *oldfile;
326          pctdone = 100.0*i/vres;
327          if (ralrm > 0)                  /* report init stats */
328                  report();
329 < #ifndef  BSD
329 > #ifndef  BSD
330          else
331   #endif
332 <        signal(SIGALRM, report);
332 >        signal(SIGCONT, report);
333          ypos = vres-1 - i;
334          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
335                                                  /* compute scanlines */
# Line 374 | Line 351 | char  *zfile, *oldfile;
351                                                          /* fill bar */
352                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
353                                                          /* write it out */
354 < #ifndef  BSD
355 <                signal(SIGALRM, SIG_IGN);       /* don't interrupt writes */
354 > #ifndef  BSD
355 >                signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
356   #endif
357                  for (i = ystep; i > 0; i--) {
358                          if (zfd != -1 && write(zfd, (char *)zbar[i],
# Line 391 | Line 368 | char  *zfile, *oldfile;
368                  pctdone = 100.0*(vres-1-ypos)/vres;
369                  if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm)
370                          report();
371 < #ifndef  BSD
371 > #ifndef  BSD
372                  else
373 <                        signal(SIGALRM, report);
373 >                        signal(SIGCONT, report);
374   #endif
375          }
376                                                  /* clean up */
377 <        signal(SIGALRM, SIG_IGN);
377 >        signal(SIGCONT, SIG_IGN);
378          if (zfd != -1) {
379                  if (write(zfd, (char *)zbar[0], hres*sizeof(float))
380                                  < hres*sizeof(float))
# Line 415 | Line 392 | char  *zfile, *oldfile;
392          if (sampdens != NULL)
393                  free(sampdens);
394          pctdone = 100.0;
395 +        if (ralrm > 0)
396 +                report();
397 +        signal(SIGCONT, SIG_DFL);
398          return;
399   writerr:
400          error(SYSTEM, "write error in render");
# Line 424 | Line 404 | memerr:
404  
405  
406   fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
407 < register COLOR  *scanline;
408 < register float  *zline;
407 > register COLOR  *scanline;
408 > register float  *zline;
409   register char  *sd;
410   int  xres, y, xstep;
411   {
412          static int  nc = 0;             /* number of calls */
413          int  bl = xstep, b = xstep;
414 <        double  z;
414 >        double  z;
415          register int  i;
416          
417          z = pixvalue(scanline[0], 0, y);
# Line 459 | Line 439 | int  xres, y, xstep;
439  
440  
441   fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
442 < register COLOR  *scanbar[];
443 < register float  *zbar[];
442 > register COLOR  *scanbar[];
443 > register float  *zbar[];
444   int  xres, y, ysize;
445   {
446          COLOR  vline[MAXDIV+1];
# Line 490 | Line 470 | int  xres, y, ysize;
470  
471  
472   int
473 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
474 < register COLOR  *colline;
475 < register float  *zline;
473 > fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
474 > register COLOR  *colline;
475 > register float  *zline;
476   int  x, y;
477   int  xlen, ylen;
478   int  b;
479   {
480 <        extern double  fabs();
481 <        double  ratio;
502 <        double  z;
480 >        double  ratio;
481 >        double  z;
482          COLOR  ctmp;
483          int  ncut;
484          register int  len;
# Line 585 | Line 564 | char  *oldfile;
564                  error(WARNING, errmsg);
565                  return(0);
566          }
567 + #ifdef MSDOS
568 +        setmode(fileno(fp), O_BINARY);
569 + #endif
570                                  /* discard header */
571 <        getheader(fp, NULL);
571 >        getheader(fp, NULL, NULL);
572                                  /* get picture size */
573          if (!fscnresolu(&x, &y, fp)) {
574                  sprintf(errmsg, "bad recover file \"%s\"", oldfile);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines