--- ray/src/rt/rvmain.c 2003/02/22 02:07:29 2.1
+++ ray/src/rt/rvmain.c 2025/04/23 02:35:26 2.24
@@ -1,130 +1,99 @@
#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.24 2025/04/23 02:35:26 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 "pmapray.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);
+static void
+set_defaults(void)
+{
+ shadthresh = .1;
+ shadcert = .25;
+ directrelay = 0;
+ vspretest = 128;
+ srcsizerat = 0.;
+ specthresh = .3;
+ specjitter = 1.;
+ maxdepth = 6;
+ minweight = 1e-3;
+ ambacc = 0.3;
+ ambres = 32;
+ ambdiv = 256;
+ ambssamp = 64;
+}
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)) \
goto badopt
-#define bool(olen,var) switch (argv[i][olen]) { \
+#define check_bool(olen,var) switch (argv[i][olen]) { \
case '\0': var = !var; break; \
case 'y': case 'Y': case 't': case 'T': \
case '+': case '1': var = 1; break; \
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 */
+ set_defaults();
/* option city */
for (i = 1; i < argc; i++) {
/* expand arguments */
@@ -160,6 +129,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;
@@ -178,7 +153,7 @@ char *argv[];
}
break;
case 'b': /* grayscale */
- bool(2,greyscale);
+ check_bool(2,greyscale);
break;
case 'p': /* pixel */
switch (argv[i][2]) {
@@ -202,7 +177,7 @@ char *argv[];
break;
case 'w': /* warnings */
rval = erract[WARNING].pf != NULL;
- bool(2,rval);
+ check_bool(2,rval);
if (rval) erract[WARNING].pf = wputs;
else erract[WARNING].pf = NULL;
break;
@@ -222,22 +197,20 @@ char *argv[];
goto badopt;
}
}
+ /* set/check spectral sampling */
+ if (setspectrsamp(CNDX, WLPART) <= 0)
+ error(USER, "unsupported spectral sampling");
+
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");
+#if !defined(_WIN32) && !defined(_WIN64)
+ sigdie(SIGHUP, "Hangup");
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) {
@@ -254,52 +227,61 @@ 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;
-
- marksources(); /* find and mark sources */
-
- setambient(); /* initialize ambient calculation */
-
+ /* set up output & start process(es) */
+ SET_FILE_BINARY(stdout);
+
+ ray_init(octnm); /* also calls ray_init_pmap() */
+
+/* temporary shortcut, until winrview is refactored into a "device" */
+#ifndef WIN_RVIEW
rview(); /* run interactive viewer */
- ambsync(); /* flush ambient file */
+ devclose(); /* close output device */
+#endif
+
+ /* PMAP: free photon maps */
+ ray_done_pmap();
+
+#ifdef WIN_RVIEW
+ return 1;
+#endif
quit(0);
badopt:
sprintf(errmsg, "command line error at '%s'", argv[i]);
error(USER, errmsg);
+ return 1; /* pro forma return */
#undef check
-#undef bool
+#undef check_bool
}
void
-wputs(s) /* warning output function */
-char *s;
+wputs( /* warning output function */
+ const char *s
+)
{
int lasterrno = errno;
+ if (erract[WARNING].pf == NULL)
+ return; /* called by calcomp or someone */
eputs(s);
errno = lasterrno;
}
void
-eputs(s) /* put string to stderr */
-register char *s;
+eputs( /* put string to stderr */
+ const char *s
+)
{
static int midline = 0;
@@ -317,28 +299,33 @@ register char *s;
}
-void
-onsig(signo) /* fatal signal */
-int signo;
+static void
+onsig( /* fatal signal */
+ int signo
+)
{
static int gotsig = 0;
if (gotsig++) /* two signals and we're gone! */
_exit(signo);
+#if !defined(_WIN32) && !defined(_WIN64)
alarm(15); /* allow 15 seconds to clean up */
signal(SIGALRM, SIG_DFL); /* make certain we do die */
+#endif
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 +333,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 +345,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]);