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.45 by greg, Fri Mar 15 21:02:09 1996 UTC vs.
Revision 2.54 by greg, Mon Mar 10 17:26:26 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id";
3   #endif
6
4   /*
5   *  rpict.c - routines and variables for picture generation.
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11  
12   #include  <sys/types.h>
# Line 28 | Line 27 | extern time_t  time();
27  
28   #include  "view.h"
29  
31 #include  "resolu.h"
32
30   #include  "random.h"
31  
32   #include  "paths.h"
# Line 40 | Line 37 | extern time_t  time();
37   #define SIGCONT         SIGIO
38   #endif
39  
40 + CUBE  thescene;                         /* our scene */
41 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
42 +
43   int  dimlist[MAXDIM];                   /* sampling dimensions */
44   int  ndims = 0;                         /* number of sampling dimensions */
45   int  samplendx;                         /* sample index number */
46  
47 + extern void  ambnotify();
48 + void  (*addobjnotify[])() = {ambnotify, NULL};
49 +
50   VIEW  ourview = STDVIEW;                /* view parameters */
51   int  hresolu = 512;                     /* horizontal resolution */
52   int  vresolu = 512;                     /* vertical resolution */
# Line 53 | Line 56 | int  psample = 4;                      /* pixel sample size */
56   double  maxdiff = .05;                  /* max. difference for interpolation */
57   double  dstrpix = 0.67;                 /* square pixel distribution */
58  
59 + double  mblur = 0.;                     /* motion blur parameter */
60 +
61 + void  (*trace)() = NULL;                /* trace call */
62 +
63 + int  do_irrad = 0;                      /* compute irradiance? */
64 +
65   double  dstrsrc = 0.0;                  /* square source distribution */
66   double  shadthresh = .05;               /* shadow threshold */
67   double  shadcert = .5;                  /* shadow certainty */
# Line 62 | Line 71 | int  directvis = 1;                    /* sources visible? */
71   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
72  
73   COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
74 < double  salbedo = 0.;                   /* global scattering albedo */
74 > COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
75   double  seccg = 0.;                     /* global scattering eccentricity */
76   double  ssampdist = 0.;                 /* scatter sampling distance */
77  
# Line 74 | Line 83 | int  backvis = 1;                      /* back face visibility */
83   int  maxdepth = 6;                      /* maximum recursion depth */
84   double  minweight = 5e-3;               /* minimum ray weight */
85  
86 + char  *ambfile = NULL;                  /* ambient file name */
87   COLOR  ambval = BLKCOLOR;               /* ambient value */
88   int  ambvwt = 0;                        /* initial weight for ambient value */
89   double  ambacc = 0.2;                   /* ambient accuracy */
# Line 84 | Line 94 | int  ambounce = 0;                     /* ambient bounces */
94   char  *amblist[128];                    /* ambient include/exclude list */
95   int  ambincl = -1;                      /* include == 1, exclude == 0 */
96  
87 #ifdef MSDOS
88 int  ralrm = 60;                        /* seconds between reports */
89 #else
97   int  ralrm = 0;                         /* seconds between reports */
91 #endif
98  
99   double  pctdone = 0.0;                  /* percentage done */
94
100   time_t  tlastrept = 0L;                 /* time at last report */
101 + time_t  tstart;                         /* starting time */
102  
97 extern time_t  tstart;                  /* starting time */
98
99 extern unsigned long  nrays;            /* number of rays traced */
100
103   #define  MAXDIV         16              /* maximum sample size */
104  
105   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
106  
107 < static int  hres, vres;                 /* resolution for this frame */
107 > int  hres, vres;                        /* resolution for this frame */
108  
109 + static VIEW     lastview;               /* the previous view input */
110 +
111   extern char  *mktemp();
112  
113 + void  report();
114 +
115   double  pixvalue();
116  
117   #ifdef NIX
# Line 124 | Line 130 | char  *fname;
130   #endif
131  
132  
133 + void
134   quit(code)                      /* quit program */
135   int  code;
136   {
137          if (code)                       /* report status */
138                  report();
139 + #ifndef NIX
140          headclean();                    /* delete header file */
141          pfclean();                      /* clean up persist files */
142 + #endif
143          exit(code);
144   }
145  
146  
147   #ifndef NIX
148 + void
149   report()                /* report progress */
150   {
151          extern char  *myhostname();
# Line 176 | Line 186 | report()               /* report progress */
186   #endif
187   }
188   #else
189 + void
190   report()                /* report progress */
191   {
192          tlastrept = time((time_t *)NULL);
# Line 186 | Line 197 | report()               /* report progress */
197   #endif
198  
199  
200 + void
201   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
202   int  seq;
203   char  *pout, *zout, *prvr;
# Line 201 | Line 213 | char  *pout, *zout, *prvr;
213   * sequenced file naming.
214   */
215   {
204        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
216          char  fbuf[128], fbuf2[128];
217          int  npicts;
218          register char  *cp;
# Line 228 | Line 239 | char  *pout, *zout, *prvr;
239                  for ( ; seq < rn; seq++)
240                          if (nextview(stdin) == EOF)
241                                  error(USER, "unexpected EOF on view input");
242 +                setview(&ourview);
243                  prvr = fbuf;                    /* mark for renaming */
244          }
245          if (pout != NULL & prvr != NULL) {
# Line 269 | Line 281 | char  *pout, *zout, *prvr;
281                                                  fbuf);
282                                          error(USER, errmsg);
283                                  }
284 +                                setview(&ourview);
285                                  continue;               /* don't clobber */
286                          }
287                          if (freopen(fbuf, "w", stdout) == NULL) {
# Line 284 | Line 297 | char  *pout, *zout, *prvr;
297                  hres = hresolu; vres = vresolu; pa = pixaspect;
298                  if (prvr != NULL)
299                          if (viewfile(prvr, &ourview, &rs) <= 0
300 <                                        || rs.or != PIXSTANDARD) {
300 >                                        || rs.rt != PIXSTANDARD) {
301                                  sprintf(errmsg,
302                          "cannot recover view parameters from \"%s\"", prvr);
303                                  error(WARNING, errmsg);
# Line 331 | Line 344 | FILE  *fp;
344   {
345          char  linebuf[256];
346  
347 +        copystruct(&lastview, &ourview);
348          while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
349                  if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
350                          return(0);
# Line 341 | Line 355 | FILE  *fp;
355   render(zfile, oldfile)                          /* render the scene */
356   char  *zfile, *oldfile;
357   {
344        extern long  lseek();
358          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
359          float  *zbar[MAXDIV+1];         /* z values */
360          char  *sampdens;                /* previous sample density */
# Line 352 | Line 365 | char  *zfile, *oldfile;
365          COLOR  *colptr;
366          float  *zptr;
367          register int  i;
368 +                                        /* check for empty image */
369 +        if (hres <= 0 || vres <= 0) {
370 +                error(WARNING, "empty output picture");
371 +                fprtresolu(0, 0, stdout);
372 +                return;
373 +        }
374                                          /* allocate scanlines */
375          for (i = 0; i <= psample; i++) {
376                  scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
# Line 362 | Line 381 | char  *zfile, *oldfile;
381          ystep = (psample*99+70)/140;
382          if (hstep > 2) {
383                  i = hres/hstep + 2;
384 <                if ((sampdens = malloc(i)) == NULL)
384 >                if ((sampdens = (char *)malloc(i)) == NULL)
385                          goto memerr;
386                  while (i--)
387                          sampdens[i] = hstep;
# Line 394 | Line 413 | char  *zfile, *oldfile;
413          if (i >= vres)
414                  goto alldone;
415          if (zfd != -1 && i > 0 &&
416 <                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
416 >                        lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0)
417                  error(SYSTEM, "z-file seek error in render");
418          pctdone = 100.0*i/vres;
419          if (ralrm > 0)                  /* report init stats */
# Line 403 | Line 422 | char  *zfile, *oldfile;
422          else
423   #endif
424          signal(SIGCONT, report);
425 <        ypos = vres-1 - i;
425 >        ypos = vres-1 - i;                      /* initialize sampling */
426 >        if (directvis)
427 >                init_drawsources(psample);
428          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
429                                                  /* compute scanlines */
430          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
# Line 423 | Line 444 | char  *zfile, *oldfile;
444                                  hres, ypos, hstep);
445                                                          /* fill bar */
446                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
447 <                                                        /* add bitty sources */
448 <                drawsources(&ourview, hres, vres, scanbar, zbar,
428 <                                0, hres, ypos, ystep, psample);
447 >                if (directvis)                          /* add bitty sources */
448 >                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
449                                                          /* write it out */
450   #ifndef  BSD
451                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 462 | Line 482 | alldone:
482                  if (close(zfd) == -1)
483                          goto writerr;
484                  for (i = 0; i <= psample; i++)
485 <                        free((char *)zbar[i]);
485 >                        free((void *)zbar[i]);
486          }
487          for (i = 0; i <= psample; i++)
488 <                free((char *)scanbar[i]);
488 >                free((void *)scanbar[i]);
489          if (sampdens != NULL)
490                  free(sampdens);
491          pctdone = 100.0;
# Line 602 | Line 622 | pixvalue(col, x, y)            /* compute pixel value */
622   COLOR  col;                     /* returned color */
623   int  x, y;                      /* pixel position */
624   {
625 <        static RAY  thisray;
626 <
627 <        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
628 <                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
625 >        RAY  thisray;
626 >        FVECT   lorg, ldir;
627 >        double  hpos, vpos, lmax, d;
628 >                                                /* compute view ray */
629 >        hpos = (x+pixjitter())/hres;
630 >        vpos = (y+pixjitter())/vres;
631 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
632 >                                        &ourview, hpos, vpos)) < -FTINY) {
633                  setcolor(col, 0.0, 0.0, 0.0);
634                  return(0.0);
635          }
636  
613        rayorigin(&thisray, NULL, PRIMARY, 1.0);
614
637          samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
638  
639 +                                                /* optional motion blur */
640 +        if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
641 +                                        &lastview, hpos, vpos)) >= -FTINY) {
642 +                register int    i;
643 +                register double  d = mblur*(.5-urand(281+samplendx));
644 +
645 +                thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
646 +                for (i = 3; i--; ) {
647 +                        thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i];
648 +                        thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i];
649 +                }
650 +                if (normalize(thisray.rdir) == 0.0)
651 +                        return(0.0);
652 +        }
653 +
654 +        rayorigin(&thisray, NULL, PRIMARY, 1.0);
655 +
656          rayvalue(&thisray);                     /* trace ray */
657  
658          copycolor(col, thisray.rcol);           /* return color */
# Line 669 | Line 708 | char  *oldfile;
708          }
709          if (fflush(stdout) == EOF)
710                  goto writerr;
711 <        free((char *)scanline);
711 >        free((void *)scanline);
712          fclose(fp);
713          unlink(oldfile);
714          return(y);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines