--- ray/src/rt/rvmain.c 2003/02/22 02:07:29 2.1 +++ ray/src/rt/rvmain.c 2009/12/12 19:01:00 2.10 @@ -1,114 +1,62 @@ #ifndef lint -static const char RCSid[] = "$Id: rvmain.c,v 2.1 2003/02/22 02:07:29 greg Exp $"; +static const char RCSid[] = "$Id: rvmain.c,v 2.10 2009/12/12 19:01:00 greg Exp $"; #endif /* * rvmain.c - main for rview interactive viewer */ -/* ==================================================================== - * 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 "copyright.h" -#include "ray.h" +#include +#include +#include "platform.h" +#include "ray.h" #include "source.h" - #include "ambient.h" - +#include "rpaint.h" #include "random.h" - #include "paths.h" +#include "view.h" -#include +extern char *progname; /* global argv[0] */ -#include "view.h" +VIEW ourview = STDVIEW; /* viewing parameters */ +int hresolu, vresolu; /* image resolution */ -char *progname; /* argv[0] */ +int psample = 8; /* pixel sample size */ +double maxdiff = .15; /* max. sample difference */ -char *octname; /* octree name */ +int greyscale = 0; /* map colors to brightness? */ +char *dvcname = dev_default; /* output device name */ -char *sigerr[NSIG]; /* signal error messages */ +double exposure = 1.0; /* exposure for scene */ -char *shm_boundary = NULL; /* boundary of shared memory */ +int newparam = 1; /* parameter setting changed */ + +struct driver *dev = NULL; /* driver functions */ -char *errfile = NULL; /* error output file */ +char rifname[128]; /* rad input file name */ -extern int greyscale; /* map colors to brightness? */ -extern char *dvcname; /* output device name */ -extern double exposure; /* exposure compensation */ +VIEW oldview; /* previous view parameters */ -extern VIEW ourview; /* viewing parameters */ +PNODE ptrunk; /* the base of our image */ +RECT pframe; /* current frame boundaries */ +int pdepth; /* image depth in current frame */ -extern char rifname[]; /* rad input file name */ +char *errfile = NULL; /* error output file */ -extern int hresolu; /* horizontal resolution */ -extern int vresolu; /* vertical resolution */ +int nproc = 1; /* number of processes */ -extern int psample; /* pixel sample size */ -extern double maxdiff; /* max. sample difference */ +char *sigerr[NSIG]; /* signal error messages */ -void onsig(); -void sigdie(); -void printdefaults(); +static void onsig(int signo); +static void sigdie(int signo, char *msg); +static void printdefaults(void); int -main(argc, argv) -int argc; -char *argv[]; +main(int argc, char *argv[]) { #define check(ol,al) if (argv[i][ol] || \ badarg(argc-i-1,argv+i+1,al)) \ @@ -120,11 +68,26 @@ char *argv[]; case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; } + char *octnm = NULL; char *err; int rval; int i; /* global program name */ progname = argv[0] = fixargv0(argv[0]); + /* set our defaults */ + shadthresh = .1; + shadcert = .25; + directrelay = 0; + vspretest = 128; + srcsizerat = 0.; + specthresh = .3; + specjitter = 1.; + maxdepth = 6; + minweight = 1e-2; + ambacc = 0.3; + ambres = 32; + ambdiv = 256; + ambssamp = 64; /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -160,6 +123,12 @@ char *argv[]; continue; } switch (argv[i][1]) { + case 'n': /* # processes */ + check(2,"i"); + nproc = atoi(argv[++i]); + if (nproc <= 0) + error(USER, "bad number of processes"); + break; case 'v': /* view file */ if (argv[i][2] != 'f') goto badopt; @@ -225,20 +194,12 @@ char *argv[]; err = setview(&ourview); /* set viewing parameters */ if (err != NULL) error(USER, err); - /* initialize object types */ - initotypes(); - /* initialize urand */ - initurand(2048); - /* set up signal handling */ + /* set up signal handling */ sigdie(SIGINT, "Interrupt"); sigdie(SIGHUP, "Hangup"); sigdie(SIGTERM, "Terminate"); sigdie(SIGPIPE, "Broken pipe"); sigdie(SIGALRM, "Alarm clock"); -#ifdef SIGXCPU - sigdie(SIGXCPU, "CPU limit exceeded"); - sigdie(SIGXFSZ, "File size exceeded"); -#endif /* open error file */ if (errfile != NULL) { if (freopen(errfile, "a", stderr) == NULL) @@ -254,33 +215,28 @@ char *argv[]; #endif /* get octree */ if (i == argc) - octname = NULL; + octnm = NULL; else if (i == argc-1) - octname = argv[i]; + octnm = argv[i]; else goto badopt; - if (octname == NULL) + if (octnm == NULL) error(USER, "missing octree argument"); - /* set up output */ -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); -#endif - readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); - nsceneobjs = nobjects; + /* set up output & start process(es) */ + SET_FILE_BINARY(stdout); + + ray_init(octnm); - marksources(); /* find and mark sources */ - - setambient(); /* initialize ambient calculation */ - rview(); /* run interactive viewer */ - ambsync(); /* flush ambient file */ + devclose(); /* close output device */ quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); + return 1; /* pro forma return */ #undef check #undef bool @@ -288,8 +244,9 @@ badopt: void -wputs(s) /* warning output function */ -char *s; +wputs( /* warning output function */ + char *s +) { int lasterrno = errno; eputs(s); @@ -298,8 +255,9 @@ char *s; void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + char *s +) { static int midline = 0; @@ -317,9 +275,10 @@ register char *s; } -void -onsig(signo) /* fatal signal */ -int signo; +static void +onsig( /* fatal signal */ + int signo +) { static int gotsig = 0; @@ -331,14 +290,16 @@ int signo; eputs("signal - "); eputs(sigerr[signo]); eputs("\n"); + devclose(); quit(3); } -void -sigdie(signo, msg) /* set fatal signal */ -int signo; -char *msg; +static void +sigdie( /* set fatal signal */ + int signo, + char *msg +) { if (signal(signo, onsig) == SIG_IGN) signal(signo, SIG_IGN); @@ -346,11 +307,10 @@ char *msg; } -void -printdefaults() /* print default values to stdout */ +static void +printdefaults(void) /* print default values to stdout */ { - register char *cp; - + printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : "-b-\t\t\t\t# greyscale off\n"); printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, @@ -359,6 +319,7 @@ printdefaults() /* print default values to stdout */ ourview.type==VT_HEM ? "hemispherical" : ourview.type==VT_ANG ? "angular" : ourview.type==VT_CYL ? "cylindrical" : + ourview.type==VT_PLS ? "planisphere" : "unknown"); printf("-vp %f %f %f\t# view point\n", ourview.vp[0], ourview.vp[1], ourview.vp[2]);