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.42 by greg, Tue Jan 23 16:27:31 1996 UTC vs.
Revision 2.52 by greg, Sat Feb 22 02:07:29 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 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10   *
11 < *     8/14/85
11 > * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 > * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 > *
14 > * Redistribution and use in source and binary forms, with or without
15 > * modification, are permitted provided that the following conditions
16 > * are met:
17 > *
18 > * 1. Redistributions of source code must retain the above copyright
19 > *         notice, this list of conditions and the following disclaimer.
20 > *
21 > * 2. Redistributions in binary form must reproduce the above copyright
22 > *       notice, this list of conditions and the following disclaimer in
23 > *       the documentation and/or other materials provided with the
24 > *       distribution.
25 > *
26 > * 3. The end-user documentation included with the redistribution,
27 > *           if any, must include the following acknowledgment:
28 > *             "This product includes Radiance software
29 > *                 (http://radsite.lbl.gov/)
30 > *                 developed by the Lawrence Berkeley National Laboratory
31 > *               (http://www.lbl.gov/)."
32 > *       Alternately, this acknowledgment may appear in the software itself,
33 > *       if and wherever such third-party acknowledgments normally appear.
34 > *
35 > * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 > *       and "The Regents of the University of California" must
37 > *       not be used to endorse or promote products derived from this
38 > *       software without prior written permission. For written
39 > *       permission, please contact [email protected].
40 > *
41 > * 5. Products derived from this software may not be called "Radiance",
42 > *       nor may "Radiance" appear in their name, without prior written
43 > *       permission of Lawrence Berkeley National Laboratory.
44 > *
45 > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 > * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 > * SUCH DAMAGE.
57 > * ====================================================================
58 > *
59 > * This software consists of voluntary contributions made by many
60 > * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 > * information on Lawrence Berkeley National Laboratory, please see
62 > * <http://www.lbl.gov/>.
63   */
64  
65   #include  "ray.h"
# Line 20 | Line 72 | static char SCCSid[] = "$SunId$ LBL";
72   #include  <sys/resource.h>
73   #else
74   #include  <sys/times.h>
23 #include  <sys/utsname.h>
75   #include  <unistd.h>
76   #endif
77   #endif
# Line 31 | Line 82 | extern time_t  time();
82  
83   #include  "view.h"
84  
34 #include  "resolu.h"
35
85   #include  "random.h"
86  
87   #include  "paths.h"
# Line 43 | Line 92 | extern time_t  time();
92   #define SIGCONT         SIGIO
93   #endif
94  
95 + CUBE  thescene;                         /* our scene */
96 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
97 +
98   int  dimlist[MAXDIM];                   /* sampling dimensions */
99   int  ndims = 0;                         /* number of sampling dimensions */
100   int  samplendx;                         /* sample index number */
101  
102 + extern void  ambnotify();
103 + void  (*addobjnotify[])() = {ambnotify, NULL};
104 +
105   VIEW  ourview = STDVIEW;                /* view parameters */
106   int  hresolu = 512;                     /* horizontal resolution */
107   int  vresolu = 512;                     /* vertical resolution */
# Line 56 | Line 111 | int  psample = 4;                      /* pixel sample size */
111   double  maxdiff = .05;                  /* max. difference for interpolation */
112   double  dstrpix = 0.67;                 /* square pixel distribution */
113  
114 + double  mblur = 0.;                     /* motion blur parameter */
115 +
116 + void  (*trace)() = NULL;                /* trace call */
117 +
118 + int  do_irrad = 0;                      /* compute irradiance? */
119 +
120   double  dstrsrc = 0.0;                  /* square source distribution */
121   double  shadthresh = .05;               /* shadow threshold */
122   double  shadcert = .5;                  /* shadow certainty */
# Line 65 | Line 126 | int  directvis = 1;                    /* sources visible? */
126   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
127  
128   COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
129 < double  salbedo = 0.;                   /* global scattering albedo */
129 > COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
130   double  seccg = 0.;                     /* global scattering eccentricity */
131   double  ssampdist = 0.;                 /* scatter sampling distance */
132  
# Line 77 | Line 138 | int  backvis = 1;                      /* back face visibility */
138   int  maxdepth = 6;                      /* maximum recursion depth */
139   double  minweight = 5e-3;               /* minimum ray weight */
140  
141 + char  *ambfile = NULL;                  /* ambient file name */
142   COLOR  ambval = BLKCOLOR;               /* ambient value */
143 + int  ambvwt = 0;                        /* initial weight for ambient value */
144   double  ambacc = 0.2;                   /* ambient accuracy */
145   int  ambres = 32;                       /* ambient resolution */
146   int  ambdiv = 128;                      /* ambient divisions */
# Line 86 | Line 149 | int  ambounce = 0;                     /* ambient bounces */
149   char  *amblist[128];                    /* ambient include/exclude list */
150   int  ambincl = -1;                      /* include == 1, exclude == 0 */
151  
89 #ifdef MSDOS
90 int  ralrm = 60;                        /* seconds between reports */
91 #else
152   int  ralrm = 0;                         /* seconds between reports */
93 #endif
153  
154   double  pctdone = 0.0;                  /* percentage done */
96
155   time_t  tlastrept = 0L;                 /* time at last report */
156 + time_t  tstart;                         /* starting time */
157  
99 extern time_t  tstart;                  /* starting time */
100
101 extern unsigned long  nrays;            /* number of rays traced */
102
158   #define  MAXDIV         16              /* maximum sample size */
159  
160   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
161  
162 < static int  hres, vres;                 /* resolution for this frame */
162 > int  hres, vres;                        /* resolution for this frame */
163  
164 + static VIEW     lastview;               /* the previous view input */
165 +
166   extern char  *mktemp();
167  
168 + void  report();
169 +
170   double  pixvalue();
171  
172   #ifdef NIX
# Line 126 | Line 185 | char  *fname;
185   #endif
186  
187  
188 + void
189   quit(code)                      /* quit program */
190   int  code;
191   {
192          if (code)                       /* report status */
193                  report();
194 + #ifndef NIX
195          headclean();                    /* delete header file */
196          pfclean();                      /* clean up persist files */
197 + #endif
198          exit(code);
199   }
200  
201  
202   #ifndef NIX
203 + void
204   report()                /* report progress */
205   {
206 +        extern char  *myhostname();
207          double  u, s;
208   #ifdef BSD
145        char  hostname[257];
209          struct rusage  rubuf;
210   #else
211          struct tms  tbuf;
149        struct utsname  nambuf;
212          double  period;
151 #define hostname  nambuf.nodename
213   #endif
214  
215          tlastrept = time((time_t *)NULL);
# Line 159 | Line 220 | report()               /* report progress */
220          getrusage(RUSAGE_CHILDREN, &rubuf);
221          u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
222          s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
162        gethostname(hostname, sizeof(hostname));
223   #else
224          times(&tbuf);
225   #ifdef _SC_CLK_TCK
# Line 169 | Line 229 | report()               /* report progress */
229   #endif
230          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
231          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
172        uname(&nambuf);
232   #endif
233  
234          sprintf(errmsg,
235                  "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
236                          nrays, pctdone, u/3600., s/3600.,
237 <                        (tlastrept-tstart)/3600., hostname);
237 >                        (tlastrept-tstart)/3600., myhostname());
238          eputs(errmsg);
239   #ifndef BSD
240          signal(SIGCONT, report);
182 #undef hostname
241   #endif
242   }
243   #else
244 + void
245   report()                /* report progress */
246   {
247          tlastrept = time((time_t *)NULL);
# Line 193 | Line 252 | report()               /* report progress */
252   #endif
253  
254  
255 + void
256   rpict(seq, pout, zout, prvr)                    /* generate image(s) */
257   int  seq;
258   char  *pout, *zout, *prvr;
# Line 235 | Line 295 | char  *pout, *zout, *prvr;
295                  for ( ; seq < rn; seq++)
296                          if (nextview(stdin) == EOF)
297                                  error(USER, "unexpected EOF on view input");
298 +                setview(&ourview);
299                  prvr = fbuf;                    /* mark for renaming */
300          }
301          if (pout != NULL & prvr != NULL) {
# Line 276 | Line 337 | char  *pout, *zout, *prvr;
337                                                  fbuf);
338                                          error(USER, errmsg);
339                                  }
340 +                                setview(&ourview);
341                                  continue;               /* don't clobber */
342                          }
343                          if (freopen(fbuf, "w", stdout) == NULL) {
# Line 291 | Line 353 | char  *pout, *zout, *prvr;
353                  hres = hresolu; vres = vresolu; pa = pixaspect;
354                  if (prvr != NULL)
355                          if (viewfile(prvr, &ourview, &rs) <= 0
356 <                                        || rs.or != PIXSTANDARD) {
356 >                                        || rs.rt != PIXSTANDARD) {
357                                  sprintf(errmsg,
358                          "cannot recover view parameters from \"%s\"", prvr);
359                                  error(WARNING, errmsg);
# Line 338 | Line 400 | FILE  *fp;
400   {
401          char  linebuf[256];
402  
403 +        copystruct(&lastview, &ourview);
404          while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
405                  if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
406                          return(0);
# Line 348 | Line 411 | FILE  *fp;
411   render(zfile, oldfile)                          /* render the scene */
412   char  *zfile, *oldfile;
413   {
351        extern long  lseek();
414          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
415          float  *zbar[MAXDIV+1];         /* z values */
416          char  *sampdens;                /* previous sample density */
# Line 359 | Line 421 | char  *zfile, *oldfile;
421          COLOR  *colptr;
422          float  *zptr;
423          register int  i;
424 +                                        /* check for empty image */
425 +        if (hres <= 0 || vres <= 0) {
426 +                error(WARNING, "empty output picture");
427 +                fprtresolu(0, 0, stdout);
428 +                return;
429 +        }
430                                          /* allocate scanlines */
431          for (i = 0; i <= psample; i++) {
432                  scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
# Line 369 | Line 437 | char  *zfile, *oldfile;
437          ystep = (psample*99+70)/140;
438          if (hstep > 2) {
439                  i = hres/hstep + 2;
440 <                if ((sampdens = malloc(i)) == NULL)
440 >                if ((sampdens = (char *)malloc(i)) == NULL)
441                          goto memerr;
442                  while (i--)
443                          sampdens[i] = hstep;
# Line 401 | Line 469 | char  *zfile, *oldfile;
469          if (i >= vres)
470                  goto alldone;
471          if (zfd != -1 && i > 0 &&
472 <                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
472 >                        lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0)
473                  error(SYSTEM, "z-file seek error in render");
474          pctdone = 100.0*i/vres;
475          if (ralrm > 0)                  /* report init stats */
# Line 410 | Line 478 | char  *zfile, *oldfile;
478          else
479   #endif
480          signal(SIGCONT, report);
481 <        ypos = vres-1 - i;
481 >        ypos = vres-1 - i;                      /* initialize sampling */
482 >        if (directvis)
483 >                init_drawsources(psample);
484          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
485                                                  /* compute scanlines */
486          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
# Line 430 | Line 500 | char  *zfile, *oldfile;
500                                  hres, ypos, hstep);
501                                                          /* fill bar */
502                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
503 +                if (directvis)                          /* add bitty sources */
504 +                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
505                                                          /* write it out */
506   #ifndef  BSD
507                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 466 | Line 538 | alldone:
538                  if (close(zfd) == -1)
539                          goto writerr;
540                  for (i = 0; i <= psample; i++)
541 <                        free((char *)zbar[i]);
541 >                        free((void *)zbar[i]);
542          }
543          for (i = 0; i <= psample; i++)
544 <                free((char *)scanbar[i]);
544 >                free((void *)scanbar[i]);
545          if (sampdens != NULL)
546                  free(sampdens);
547          pctdone = 100.0;
# Line 494 | Line 566 | int  xres, y, xstep;
566          int  bl = xstep, b = xstep;
567          double  z;
568          register int  i;
569 <        
569 >
570          z = pixvalue(scanline[0], 0, y);
571          if (zline) zline[0] = z;
572                                  /* zig-zag start for quincunx pattern */
# Line 528 | Line 600 | int  xres, y, ysize;
600          float  zline[MAXDIV+1];
601          int  b = ysize;
602          register int  i, j;
603 <        
603 >
604          for (i = 0; i < xres; i++) {
533                
605                  copycolor(vline[0], scanbar[0][i]);
606                  copycolor(vline[ysize], scanbar[ysize][i]);
607                  if (zbar[0]) {
608                          zline[0] = zbar[0][i];
609                          zline[ysize] = zbar[ysize][i];
610                  }
540                
611                  b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
612                                  i, y, 0, ysize, b/2);
613 <                
613 >
614                  for (j = 1; j < ysize; j++)
615                          copycolor(scanbar[j][i], vline[j]);
616                  if (zbar[0])
# Line 563 | Line 633 | int  b;
633          COLOR  ctmp;
634          int  ncut;
635          register int  len;
636 <        
636 >
637          if (xlen > 0)                   /* x or y length is zero */
638                  len = xlen;
639          else
640                  len = ylen;
641 <                
641 >
642          if (len <= 1)                   /* limit recursion */
643                  return(0);
644 <        
645 <        if (b > 0
646 <        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
644 >
645 >        if (b > 0 ||
646 >        (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
647                          || bigdiff(colline[0], colline[len], maxdiff)) {
648 <        
648 >
649                  z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
650                  if (zline) zline[len>>1] = z;
651                  ncut = 1;
582                
652          } else {                                        /* interpolate */
584        
653                  copycolor(colline[len>>1], colline[len]);
654                  ratio = (double)(len>>1) / len;
655                  scalecolor(colline[len>>1], ratio);
# Line 595 | Line 663 | int  b;
663          }
664                                                          /* recurse */
665          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
666 <        
666 >
667          ncut += fillsample(colline+(len>>1),
668                          zline ? zline+(len>>1) : (float *)NULL,
669                          x+(xlen>>1), y+(ylen>>1),
# Line 610 | Line 678 | pixvalue(col, x, y)            /* compute pixel value */
678   COLOR  col;                     /* returned color */
679   int  x, y;                      /* pixel position */
680   {
681 <        static RAY  thisray;
682 <
683 <        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
684 <                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
681 >        RAY  thisray;
682 >        FVECT   lorg, ldir;
683 >        double  hpos, vpos, lmax, d;
684 >                                                /* compute view ray */
685 >        hpos = (x+pixjitter())/hres;
686 >        vpos = (y+pixjitter())/vres;
687 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
688 >                                        &ourview, hpos, vpos)) < -FTINY) {
689                  setcolor(col, 0.0, 0.0, 0.0);
690                  return(0.0);
691          }
692  
621        rayorigin(&thisray, NULL, PRIMARY, 1.0);
622
693          samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
694  
695 +                                                /* optional motion blur */
696 +        if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
697 +                                        &lastview, hpos, vpos)) >= -FTINY) {
698 +                register int    i;
699 +                register double  d = mblur*(.5-urand(281+samplendx));
700 +
701 +                thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
702 +                for (i = 3; i--; ) {
703 +                        thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i];
704 +                        thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i];
705 +                }
706 +                if (normalize(thisray.rdir) == 0.0)
707 +                        return(0.0);
708 +        }
709 +
710 +        rayorigin(&thisray, NULL, PRIMARY, 1.0);
711 +
712          rayvalue(&thisray);                     /* trace ray */
713  
714          copycolor(col, thisray.rcol);           /* return color */
715 <        
715 >
716          return(thisray.rt);                     /* return distance */
717   }
718  
# Line 677 | Line 764 | char  *oldfile;
764          }
765          if (fflush(stdout) == EOF)
766                  goto writerr;
767 <        free((char *)scanline);
767 >        free((void *)scanline);
768          fclose(fp);
769          unlink(oldfile);
770          return(y);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines