--- ray/src/rt/rpict.c 1996/06/08 21:16:06 2.47
+++ ray/src/rt/rpict.c 2003/02/22 02:07:29 2.52
@@ -1,13 +1,67 @@
-/* Copyright (c) 1996 Regents of the University of California */
-
#ifndef lint
-static char SCCSid[] = "$SunId$ LBL";
+static const char RCSid[] = "$Id: rpict.c,v 2.52 2003/02/22 02:07:29 greg Exp $";
#endif
-
/*
* rpict.c - routines and variables for picture generation.
*/
+/* ====================================================================
+ * The Radiance Software License, Version 1.0
+ *
+ * Copyright (c) 1990 - 2002 The Regents of the University of California,
+ * through Lawrence Berkeley National Laboratory. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes Radiance software
+ * (http://radsite.lbl.gov/)
+ * developed by the Lawrence Berkeley National Laboratory
+ * (http://www.lbl.gov/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
+ * and "The Regents of the University of California" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact radiance@radsite.lbl.gov.
+ *
+ * 5. Products derived from this software may not be called "Radiance",
+ * nor may "Radiance" appear in their name, without prior written
+ * permission of Lawrence Berkeley National Laboratory.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of Lawrence Berkeley National Laboratory. For more
+ * information on Lawrence Berkeley National Laboratory, please see
+ * .
+ */
+
#include "ray.h"
#include
@@ -28,8 +82,6 @@ extern time_t time();
#include "view.h"
-#include "resolu.h"
-
#include "random.h"
#include "paths.h"
@@ -40,10 +92,16 @@ extern time_t time();
#define SIGCONT SIGIO
#endif
+CUBE thescene; /* our scene */
+OBJECT nsceneobjs; /* number of objects in our scene */
+
int dimlist[MAXDIM]; /* sampling dimensions */
int ndims = 0; /* number of sampling dimensions */
int samplendx; /* sample index number */
+extern void ambnotify();
+void (*addobjnotify[])() = {ambnotify, NULL};
+
VIEW ourview = STDVIEW; /* view parameters */
int hresolu = 512; /* horizontal resolution */
int vresolu = 512; /* vertical resolution */
@@ -53,6 +111,12 @@ int psample = 4; /* pixel sample size */
double maxdiff = .05; /* max. difference for interpolation */
double dstrpix = 0.67; /* square pixel distribution */
+double mblur = 0.; /* motion blur parameter */
+
+void (*trace)() = NULL; /* trace call */
+
+int do_irrad = 0; /* compute irradiance? */
+
double dstrsrc = 0.0; /* square source distribution */
double shadthresh = .05; /* shadow threshold */
double shadcert = .5; /* shadow certainty */
@@ -74,6 +138,7 @@ int backvis = 1; /* back face visibility */
int maxdepth = 6; /* maximum recursion depth */
double minweight = 5e-3; /* minimum ray weight */
+char *ambfile = NULL; /* ambient file name */
COLOR ambval = BLKCOLOR; /* ambient value */
int ambvwt = 0; /* initial weight for ambient value */
double ambacc = 0.2; /* ambient accuracy */
@@ -84,28 +149,24 @@ int ambounce = 0; /* ambient bounces */
char *amblist[128]; /* ambient include/exclude list */
int ambincl = -1; /* include == 1, exclude == 0 */
-#ifdef MSDOS
-int ralrm = 60; /* seconds between reports */
-#else
int ralrm = 0; /* seconds between reports */
-#endif
double pctdone = 0.0; /* percentage done */
-
time_t tlastrept = 0L; /* time at last report */
+time_t tstart; /* starting time */
-extern time_t tstart; /* starting time */
-
-extern unsigned long nrays; /* number of rays traced */
-
#define MAXDIV 16 /* maximum sample size */
#define pixjitter() (.5+dstrpix*(.5-frandom()))
int hres, vres; /* resolution for this frame */
+static VIEW lastview; /* the previous view input */
+
extern char *mktemp();
+void report();
+
double pixvalue();
#ifdef NIX
@@ -124,18 +185,22 @@ char *fname;
#endif
+void
quit(code) /* quit program */
int code;
{
if (code) /* report status */
report();
+#ifndef NIX
headclean(); /* delete header file */
pfclean(); /* clean up persist files */
+#endif
exit(code);
}
#ifndef NIX
+void
report() /* report progress */
{
extern char *myhostname();
@@ -176,6 +241,7 @@ report() /* report progress */
#endif
}
#else
+void
report() /* report progress */
{
tlastrept = time((time_t *)NULL);
@@ -186,6 +252,7 @@ report() /* report progress */
#endif
+void
rpict(seq, pout, zout, prvr) /* generate image(s) */
int seq;
char *pout, *zout, *prvr;
@@ -228,6 +295,7 @@ char *pout, *zout, *prvr;
for ( ; seq < rn; seq++)
if (nextview(stdin) == EOF)
error(USER, "unexpected EOF on view input");
+ setview(&ourview);
prvr = fbuf; /* mark for renaming */
}
if (pout != NULL & prvr != NULL) {
@@ -269,6 +337,7 @@ char *pout, *zout, *prvr;
fbuf);
error(USER, errmsg);
}
+ setview(&ourview);
continue; /* don't clobber */
}
if (freopen(fbuf, "w", stdout) == NULL) {
@@ -284,7 +353,7 @@ char *pout, *zout, *prvr;
hres = hresolu; vres = vresolu; pa = pixaspect;
if (prvr != NULL)
if (viewfile(prvr, &ourview, &rs) <= 0
- || rs.or != PIXSTANDARD) {
+ || rs.rt != PIXSTANDARD) {
sprintf(errmsg,
"cannot recover view parameters from \"%s\"", prvr);
error(WARNING, errmsg);
@@ -331,6 +400,7 @@ FILE *fp;
{
char linebuf[256];
+ copystruct(&lastview, &ourview);
while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
return(0);
@@ -341,7 +411,6 @@ FILE *fp;
render(zfile, oldfile) /* render the scene */
char *zfile, *oldfile;
{
- extern long lseek();
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */
float *zbar[MAXDIV+1]; /* z values */
char *sampdens; /* previous sample density */
@@ -352,6 +421,12 @@ char *zfile, *oldfile;
COLOR *colptr;
float *zptr;
register int i;
+ /* check for empty image */
+ if (hres <= 0 || vres <= 0) {
+ error(WARNING, "empty output picture");
+ fprtresolu(0, 0, stdout);
+ return;
+ }
/* allocate scanlines */
for (i = 0; i <= psample; i++) {
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
@@ -362,7 +437,7 @@ char *zfile, *oldfile;
ystep = (psample*99+70)/140;
if (hstep > 2) {
i = hres/hstep + 2;
- if ((sampdens = malloc(i)) == NULL)
+ if ((sampdens = (char *)malloc(i)) == NULL)
goto memerr;
while (i--)
sampdens[i] = hstep;
@@ -394,7 +469,7 @@ char *zfile, *oldfile;
if (i >= vres)
goto alldone;
if (zfd != -1 && i > 0 &&
- lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
+ lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0)
error(SYSTEM, "z-file seek error in render");
pctdone = 100.0*i/vres;
if (ralrm > 0) /* report init stats */
@@ -404,7 +479,8 @@ char *zfile, *oldfile;
#endif
signal(SIGCONT, report);
ypos = vres-1 - i; /* initialize sampling */
- init_drawsources(psample);
+ if (directvis)
+ init_drawsources(psample);
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
/* compute scanlines */
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
@@ -424,8 +500,8 @@ char *zfile, *oldfile;
hres, ypos, hstep);
/* fill bar */
fillscanbar(scanbar, zbar, hres, ypos, ystep);
- /* add bitty sources */
- drawsources(scanbar, zbar, 0, hres, ypos, ystep);
+ if (directvis) /* add bitty sources */
+ drawsources(scanbar, zbar, 0, hres, ypos, ystep);
/* write it out */
#ifndef BSD
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */
@@ -462,10 +538,10 @@ alldone:
if (close(zfd) == -1)
goto writerr;
for (i = 0; i <= psample; i++)
- free((char *)zbar[i]);
+ free((void *)zbar[i]);
}
for (i = 0; i <= psample; i++)
- free((char *)scanbar[i]);
+ free((void *)scanbar[i]);
if (sampdens != NULL)
free(sampdens);
pctdone = 100.0;
@@ -602,18 +678,37 @@ pixvalue(col, x, y) /* compute pixel value */
COLOR col; /* returned color */
int x, y; /* pixel position */
{
- static RAY thisray;
-
- if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
- (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
+ RAY thisray;
+ FVECT lorg, ldir;
+ double hpos, vpos, lmax, d;
+ /* compute view ray */
+ hpos = (x+pixjitter())/hres;
+ vpos = (y+pixjitter())/vres;
+ if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
+ &ourview, hpos, vpos)) < -FTINY) {
setcolor(col, 0.0, 0.0, 0.0);
return(0.0);
}
- rayorigin(&thisray, NULL, PRIMARY, 1.0);
-
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */
+ /* optional motion blur */
+ if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
+ &lastview, hpos, vpos)) >= -FTINY) {
+ register int i;
+ register double d = mblur*(.5-urand(281+samplendx));
+
+ thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
+ for (i = 3; i--; ) {
+ thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i];
+ thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i];
+ }
+ if (normalize(thisray.rdir) == 0.0)
+ return(0.0);
+ }
+
+ rayorigin(&thisray, NULL, PRIMARY, 1.0);
+
rayvalue(&thisray); /* trace ray */
copycolor(col, thisray.rcol); /* return color */
@@ -669,7 +764,7 @@ char *oldfile;
}
if (fflush(stdout) == EOF)
goto writerr;
- free((char *)scanline);
+ free((void *)scanline);
fclose(fp);
unlink(oldfile);
return(y);