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.57 by schorsch, Mon Jun 30 14:59:12 2003 UTC vs.
Revision 2.71 by schorsch, Sat Oct 23 18:55:53 2004 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char RCSid[] = "$Id";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  rpict.c - routines and variables for picture generation.
# Line 7 | Line 7 | static const char RCSid[] = "$Id";
7  
8   #include "copyright.h"
9  
10 #include  "ray.h"
11
10   #include  <sys/types.h>
11  
12   #ifndef NON_POSIX
# Line 25 | Line 23 | static const char RCSid[] = "$Id";
23   #include  <signal.h>
24  
25   #include  "platform.h"
26 + #include  "ray.h"
27 + #include  "paths.h"
28 + #include  "ambient.h"
29   #include  "view.h"
30   #include  "random.h"
31   #include  "paths.h"
32 + #include  "rtmisc.h" /* myhostname() */
33  
34  
35   #define  RFTEMPLATE     "rfXXXXXX"
# Line 45 | Line 47 | int  dimlist[MAXDIM];                  /* sampling dimensions */
47   int  ndims = 0;                         /* number of sampling dimensions */
48   int  samplendx;                         /* sample index number */
49  
50 < extern void  ambnotify();
50 > //extern void  ambnotify();
51   void  (*addobjnotify[])() = {ambnotify, NULL};
52  
53   VIEW  ourview = STDVIEW;                /* view parameters */
# Line 81 | Line 83 | double specjitter = 1.;                /* specular sampling jitter *
83  
84   int  backvis = 1;                       /* back face visibility */
85  
86 < int  maxdepth = 6;                      /* maximum recursion depth */
87 < double  minweight = 5e-3;               /* minimum ray weight */
86 > int  maxdepth = 7;                      /* maximum recursion depth */
87 > double  minweight = 4e-3;               /* minimum ray weight */
88  
89   char  *ambfile = NULL;                  /* ambient file name */
90   COLOR  ambval = BLKCOLOR;               /* ambient value */
91   int  ambvwt = 0;                        /* initial weight for ambient value */
92   double  ambacc = 0.2;                   /* ambient accuracy */
93 < int  ambres = 32;                       /* ambient resolution */
94 < int  ambdiv = 128;                      /* ambient divisions */
95 < int  ambssamp = 0;                      /* ambient super-samples */
93 > int  ambres = 64;                       /* ambient resolution */
94 > int  ambdiv = 512;                      /* ambient divisions */
95 > int  ambssamp = 128;                    /* ambient super-samples */
96   int  ambounce = 0;                      /* ambient bounces */
97   char  *amblist[128];                    /* ambient include/exclude list */
98   int  ambincl = -1;                      /* include == 1, exclude == 0 */
# Line 109 | Line 111 | int  hres, vres;                       /* resolution for this frame */
111  
112   static VIEW     lastview;               /* the previous view input */
113  
114 < extern char  *mktemp();  /* XXX should be in stdlib.h or unistd.h */
114 > //extern char  *mktemp();  /* XXX should be in stdlib.h or unistd.h */
115  
116 < void  report();
116 > //double        pixvalue();
117  
118 < double  pixvalue();
118 > static void report(int);
119 > static int nextview(FILE *fp);
120 > static void render(char *zfile, char *oldfile);
121 > static void fillscanline(COLOR *scanline, float *zline, char *sd, int xres,
122 >                int y, int xstep);
123 > static void fillscanbar(COLOR *scanbar[], float *zbar[], int xres,
124 >                int y, int ysize);
125 > static int fillsample(COLOR *colline, float *zline, int x, int y,
126 >                int xlen, int ylen, int b);
127 > static double pixvalue(COLOR  col, int  x, int  y);
128 > static int salvage(char  *oldfile);
129 > static int pixnumber(int  x, int  y, int  xres, int  yres);
130  
131 < #ifdef RHAS_ACCESS
132 < #define  file_exists(f) (access(f,F_OK)==0)
133 < #else
131 >
132 >
133 > #ifdef RHAS_STAT
134   #include  <sys/types.h>
135   #include  <sys/stat.h>
136   int
# Line 128 | Line 141 | char  *fname;
141          if (stat(fname, &sbuf) < 0) return(0);
142          return((sbuf.st_mode & S_IFREG) != 0);
143   }
144 + #else
145 + #define  file_exists(f) (access(f,F_OK)==0)
146   #endif
147  
148  
# Line 136 | Line 151 | quit(code)                     /* quit program */
151   int  code;
152   {
153          if (code)                       /* report status */
154 <                report();
154 >                report(0);
155   #ifndef NON_POSIX
156          headclean();                    /* delete header file */
157          pfclean();                      /* clean up persist files */
# Line 146 | Line 161 | int  code;
161  
162  
163   #ifndef NON_POSIX
164 < void
165 < report()                /* report progress */
164 > static void
165 > report(int dummy)               /* report progress */
166   {
152        extern char  *myhostname();
167          double  u, s;
168   #ifdef BSD
169          struct rusage  rubuf;
# Line 187 | Line 201 | report()               /* report progress */
201   #endif
202   }
203   #else
204 < void
205 < report()                /* report progress */
204 > static void
205 > report(int dummy)               /* report progress */
206   {
207          tlastrept = time((time_t *)NULL);
208          sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
# Line 198 | Line 212 | report()               /* report progress */
212   #endif
213  
214  
215 < void
216 < rpict(seq, pout, zout, prvr)                    /* generate image(s) */
217 < int  seq;
218 < char  *pout, *zout, *prvr;
215 > extern void
216 > rpict(                  /* generate image(s) */
217 >        int  seq,
218 >        char  *pout,
219 >        char  *zout,
220 >        char  *prvr
221 > )
222   /*
223   * If seq is greater than zero, then we will render a sequence of
224   * images based on view parameter strings read from the standard input.
# Line 243 | Line 260 | char  *pout, *zout, *prvr;
260                  setview(&ourview);
261                  prvr = fbuf;                    /* mark for renaming */
262          }
263 <        if (pout != NULL & prvr != NULL) {
263 >        if ((pout != NULL) & (prvr != NULL)) {
264                  sprintf(fbuf, pout, seq);
265                  if (!strcmp(prvr, fbuf)) {      /* rename */
266                          strcpy(fbuf2, fbuf);
# Line 253 | Line 270 | char  *pout, *zout, *prvr;
270                                  cp--;
271                          strcpy(cp, RFTEMPLATE);
272                          prvr = mktemp(fbuf2);
273 <                        if (rename(fbuf, prvr) < 0)
273 >                        if (rename(fbuf, prvr) < 0) {
274                                  if (errno == ENOENT) {  /* ghost file */
275                                          sprintf(errmsg,
276                                                  "new output file \"%s\"",
# Line 266 | Line 283 | char  *pout, *zout, *prvr;
283                                                  fbuf, prvr);
284                                          error(SYSTEM, errmsg);
285                                  }
286 +                        }
287                  }
288          }
289          npicts = 0;                     /* render sequence */
# Line 294 | Line 312 | char  *pout, *zout, *prvr;
312                          dupheader();
313                  }
314                  hres = hresolu; vres = vresolu; pa = pixaspect;
315 <                if (prvr != NULL)
316 <                        if (viewfile(prvr, &ourview, &rs) <= 0
299 <                                        || rs.rt != PIXSTANDARD) {
315 >                if (prvr != NULL) {
316 >                        if (viewfile(prvr, &ourview, &rs) <= 0) {
317                                  sprintf(errmsg,
318                          "cannot recover view parameters from \"%s\"", prvr);
319                                  error(WARNING, errmsg);
# Line 305 | Line 322 | char  *pout, *zout, *prvr;
322                                  hres = scanlen(&rs);
323                                  vres = numscans(&rs);
324                          }
325 +                }
326                  if ((cp = setview(&ourview)) != NULL)
327                          error(USER, cp);
328                  normaspect(viewaspect(&ourview), &pa, &hres, &vres);
# Line 322 | Line 340 | char  *pout, *zout, *prvr;
340                  putchar('\n');
341                  if (pa < .99 || pa > 1.01)
342                          fputaspect(pa, stdout);
343 +                fputnow(stdout);
344                  fputformat(COLRFMT, stdout);
345                  putchar('\n');
346                  if (zout != NULL)
# Line 338 | Line 357 | char  *pout, *zout, *prvr;
357   }
358  
359  
360 < nextview(fp)                            /* get next view from fp */
361 < FILE  *fp;
360 > static int
361 > nextview(                               /* get next view from fp */
362 >        FILE  *fp
363 > )
364   {
365          char  linebuf[256];
366  
367 <        copystruct(&lastview, &ourview);
367 >        lastview = ourview;
368          while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
369                  if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
370                          return(0);
# Line 351 | Line 372 | FILE  *fp;
372   }      
373  
374  
375 < render(zfile, oldfile)                          /* render the scene */
376 < char  *zfile, *oldfile;
375 > static void
376 > render(                         /* render the scene */
377 >        char  *zfile,
378 >        char  *oldfile
379 > )
380   {
381          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
382          float  *zbar[MAXDIV+1];         /* z values */
# Line 410 | Line 434 | char  *zfile, *oldfile;
434          if (i >= vres)
435                  goto alldone;
436          if (zfd != -1 && i > 0 &&
437 <                        lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0)
437 >                        lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0)
438                  error(SYSTEM, "z-file seek error in render");
439          pctdone = 100.0*i/vres;
440          if (ralrm > 0)                  /* report init stats */
441 <                report();
441 >                report(0);
442   #ifdef SIGCONT
443          else
444          signal(SIGCONT, report);
# Line 460 | Line 484 | char  *zfile, *oldfile;
484                                                          /* record progress */
485                  pctdone = 100.0*(vres-1-ypos)/vres;
486                  if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
487 <                        report();
487 >                        report(0);
488   #ifdef SIGCONT
489                  else
490                          signal(SIGCONT, report);
# Line 489 | Line 513 | alldone:
513                  free(sampdens);
514          pctdone = 100.0;
515          if (ralrm > 0)
516 <                report();
516 >                report(0);
517   #ifdef SIGCONT
518          signal(SIGCONT, SIG_DFL);
519   #endif
# Line 501 | Line 525 | memerr:
525   }
526  
527  
528 < fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
529 < register COLOR  *scanline;
530 < register float  *zline;
531 < register char  *sd;
532 < int  xres, y, xstep;
528 > static void
529 > fillscanline(   /* fill scan at y */
530 >        register COLOR  *scanline,
531 >        register float  *zline,
532 >        register char  *sd,
533 >        int  xres,
534 >        int  y,
535 >        int  xstep
536 > )
537   {
538          static int  nc = 0;             /* number of calls */
539          int  bl = xstep, b = xstep;
# Line 536 | Line 564 | int  xres, y, xstep;
564   }
565  
566  
567 < fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
568 < register COLOR  *scanbar[];
569 < register float  *zbar[];
570 < int  xres, y, ysize;
567 > static void
568 > fillscanbar(    /* fill interior */
569 >        register COLOR  *scanbar[],
570 >        register float  *zbar[],
571 >        int  xres,
572 >        int  y,
573 >        int  ysize
574 > )
575   {
576          COLOR  vline[MAXDIV+1];
577          float  zline[MAXDIV+1];
# Line 565 | Line 597 | int  xres, y, ysize;
597   }
598  
599  
600 < int
601 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
602 < register COLOR  *colline;
603 < register float  *zline;
604 < int  x, y;
605 < int  xlen, ylen;
606 < int  b;
600 > static int
601 > fillsample( /* fill interior points */
602 >        register COLOR  *colline,
603 >        register float  *zline,
604 >        int  x,
605 >        int  y,
606 >        int  xlen,
607 >        int  ylen,
608 >        int  b
609 > )
610   {
611          double  ratio;
612          double  z;
# Line 618 | Line 653 | int  b;
653   }
654  
655  
656 < double
657 < pixvalue(col, x, y)             /* compute pixel value */
658 < COLOR  col;                     /* returned color */
659 < int  x, y;                      /* pixel position */
656 > static double
657 > pixvalue(               /* compute pixel value */
658 >        COLOR  col,                     /* returned color */
659 >        int  x,                 /* pixel position */
660 >        int  y
661 > )
662   {
663          RAY  thisray;
664          FVECT   lorg, ldir;
665 <        double  hpos, vpos, lmax, d;
665 >        double  hpos, vpos, lmax;
666                                                  /* compute view ray */
667          hpos = (x+pixjitter())/hres;
668          vpos = (y+pixjitter())/vres;
# Line 662 | Line 699 | int  x, y;                     /* pixel position */
699   }
700  
701  
702 < int
703 < salvage(oldfile)                /* salvage scanlines from killed program */
704 < char  *oldfile;
702 > static int
703 > salvage(                /* salvage scanlines from killed program */
704 >        char  *oldfile
705 > )
706   {
707          COLR  *scanline;
708          FILE  *fp;
# Line 718 | Line 756 | gotzip:
756   writerr:
757          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
758          error(SYSTEM, errmsg);
759 +        return -1; /* pro forma return */
760   }
761  
762  
763 < int
764 < pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
765 < register int  x, y;
766 < int  xres, yres;
763 > static int
764 > pixnumber(              /* compute pixel index (brushed) */
765 >        register int  x,
766 >        register int  y,
767 >        int  xres,
768 >        int  yres
769 > )
770   {
771          x -= y;
772          while (x < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines