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.48 by gregl, Mon Oct 20 16:46:37 1997 UTC vs.
Revision 2.52 by greg, Sat Feb 22 02:07:29 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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 + * 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"
66  
67   #include  <sys/types.h>
# Line 28 | Line 82 | extern time_t  time();
82  
83   #include  "view.h"
84  
31 #include  "resolu.h"
32
85   #include  "random.h"
86  
87   #include  "paths.h"
# Line 40 | 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 53 | 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 74 | 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 */
# Line 84 | Line 149 | int  ambounce = 0;                     /* ambient bounces */
149   char  *amblist[128];                    /* ambient include/exclude list */
150   int  ambincl = -1;                      /* include == 1, exclude == 0 */
151  
87 #ifdef MSDOS
88 int  ralrm = 60;                        /* seconds between reports */
89 #else
152   int  ralrm = 0;                         /* seconds between reports */
91 #endif
153  
154   double  pctdone = 0.0;                  /* percentage done */
94
155   time_t  tlastrept = 0L;                 /* time at last report */
156 + time_t  tstart;                         /* starting time */
157  
97 extern time_t  tstart;                  /* starting time */
98
99 extern unsigned long  nrays;            /* number of rays traced */
100
158   #define  MAXDIV         16              /* maximum sample size */
159  
160   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
161  
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 124 | 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();
# Line 176 | Line 241 | report()               /* report progress */
241   #endif
242   }
243   #else
244 + void
245   report()                /* report progress */
246   {
247          tlastrept = time((time_t *)NULL);
# Line 186 | 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 228 | 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 269 | 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 284 | 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 331 | 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 341 | Line 411 | FILE  *fp;
411   render(zfile, oldfile)                          /* render the scene */
412   char  *zfile, *oldfile;
413   {
344        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 352 | 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 362 | 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 394 | 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 463 | 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 603 | 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  
614        rayorigin(&thisray, NULL, PRIMARY, 1.0);
615
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 */
# Line 670 | 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