Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rvmain.c File Reference
#include "copyright.h"
#include <signal.h>
#include <time.h>
#include "platform.h"
#include "ray.h"
#include "source.h"
#include "ambient.h"
#include "rpaint.h"
#include "random.h"
#include "paths.h"
#include "view.h"

Go to the source code of this file.

Defines

#define check(ol, al)
#define bool(olen, var)

Functions

static void onsig (int signo)
static void sigdie (int signo, char *msg)
static void printdefaults (void)
int main (int argc, char *argv[])
void wputs (char *s)
void eputs (char *s)

Variables

static const char RCSid [] = "$Id: rvmain.c,v 2.10 2009/12/12 19:01:00 greg Exp $"
char * progname
VIEW ourview = STDVIEW
int hresolu
int vresolu
int psample = 8
double maxdiff = .15
int greyscale = 0
char * dvcname = dev_default
double exposure = 1.0
int newparam = 1
struct driverdev = NULL
char rifname [128]
VIEW oldview
PNODE ptrunk
RECT pframe
int pdepth
char * errfile = NULL
int nproc = 1
char * sigerr [NSIG]

Define Documentation

#define bool (   olen,
  var 
)
Value:
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; }
#define check (   ol,
  al 
)
Value:
if (argv[i][ol] || \
                            badarg(argc-i-1,argv+i+1,al)) \
                            goto badopt

Function Documentation

void eputs ( char *  s)

Definition at line 258 of file rvmain.c.

{
       static int  midline = 0;

       if (!*s)
              return;
       if (!midline++) {
              fputs(progname, stderr);
              fputs(": ", stderr);
       }
       fputs(s, stderr);
       if (s[strlen(s)-1] == '\n') {
              fflush(stderr);
              midline = 0;
       }
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 59 of file rvmain.c.

{
#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]) { \
                            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 */
       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 */
              while ((rval = expandarg(&argc, &argv, i)) > 0)
                     ;
              if (rval < 0) {
                     sprintf(errmsg, "cannot expand '%s'", argv[i]);
                     error(SYSTEM, errmsg);
              }
              if (argv[i] == NULL || argv[i][0] != '-')
                     break;               /* break from options */
              if (!strcmp(argv[i], "-version")) {
                     puts(VersionID);
                     quit(0);
              }
              if (!strcmp(argv[i], "-defaults") ||
                            !strcmp(argv[i], "-help")) {
                     printdefaults();
                     quit(0);
              }
              if (!strcmp(argv[i], "-devices")) {
                     printdevices();
                     quit(0);
              }
              rval = getrenderopt(argc-i, argv+i);
              if (rval >= 0) {
                     i += rval;
                     continue;
              }
              rval = getviewopt(&ourview, argc-i, argv+i);
              if (rval >= 0) {
                     i += rval;
                     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;
                     check(3,"s");
                     rval = viewfile(argv[++i], &ourview, NULL);
                     if (rval < 0) {
                            sprintf(errmsg,
                            "cannot open view file \"%s\"",
                                          argv[i]);
                            error(SYSTEM, errmsg);
                     } else if (rval == 0) {
                            sprintf(errmsg,
                                   "bad view file \"%s\"",
                                          argv[i]);
                            error(USER, errmsg);
                     }
                     break;
              case 'b':                          /* grayscale */
                     bool(2,greyscale);
                     break;
              case 'p':                          /* pixel */
                     switch (argv[i][2]) {
                     case 's':                          /* sample */
                            check(3,"i");
                            psample = atoi(argv[++i]);
                            break;
                     case 't':                          /* threshold */
                            check(3,"f");
                            maxdiff = atof(argv[++i]);
                            break;
                     case 'e':                          /* exposure */
                            check(3,"f");
                            exposure = atof(argv[++i]);
                            if (argv[i][0] == '+' || argv[i][0] == '-')
                                   exposure = pow(2.0, exposure);
                            break;
                     default:
                            goto badopt;
                     }
                     break;
              case 'w':                          /* warnings */
                     rval = erract[WARNING].pf != NULL;
                     bool(2,rval);
                     if (rval) erract[WARNING].pf = wputs;
                     else erract[WARNING].pf = NULL;
                     break;
              case 'e':                          /* error file */
                     check(2,"s");
                     errfile = argv[++i];
                     break;
              case 'o':                          /* output device */
                     check(2,"s");
                     dvcname = argv[++i];
                     break;
              case 'R':                          /* render input file */
                     check(2,"s");
                     strcpy(rifname, argv[++i]);
                     break;
              default:
                     goto badopt;
              }
       }
       err = setview(&ourview);    /* set viewing parameters */
       if (err != NULL)
              error(USER, err);
                                          /* set up signal handling */
       sigdie(SIGINT, "Interrupt");
       sigdie(SIGHUP, "Hangup");
       sigdie(SIGTERM, "Terminate");
       sigdie(SIGPIPE, "Broken pipe");
       sigdie(SIGALRM, "Alarm clock");
                                   /* open error file */
       if (errfile != NULL) {
              if (freopen(errfile, "a", stderr) == NULL)
                     quit(2);
              fprintf(stderr, "**************\n*** PID %5d: ",
                            getpid());
              printargs(argc, argv, stderr);
              putc('\n', stderr);
              fflush(stderr);
       }
#ifdef NICE
       nice(NICE);                 /* lower priority */
#endif
                                   /* get octree */
       if (i == argc)
              octnm = NULL;
       else if (i == argc-1)
              octnm = argv[i];
       else
              goto badopt;
       if (octnm == NULL)
              error(USER, "missing octree argument");
                                   /* set up output & start process(es) */
       SET_FILE_BINARY(stdout);
       
       ray_init(octnm);

       rview();                    /* run interactive viewer */

       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
}

Here is the call graph for this function:

static void onsig ( int  signo) [static]
static void printdefaults ( void  ) [static]
static void sigdie ( int  signo,
char *  msg 
) [static]

Definition at line 299 of file rvmain.c.

{
       if (signal(signo, onsig) == SIG_IGN)
              signal(signo, SIG_IGN);
       sigerr[signo] = msg;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void wputs ( char *  s)

Definition at line 247 of file rvmain.c.

{
       int  lasterrno = errno;
       eputs(s);
       errno = lasterrno;
}

Here is the call graph for this function:


Variable Documentation

struct driver* dev = NULL

Definition at line 37 of file rvmain.c.

Definition at line 31 of file rvmain.c.

char* errfile = NULL

Definition at line 47 of file rvmain.c.

double exposure = 1.0

Definition at line 33 of file rvmain.c.

int greyscale = 0

Definition at line 30 of file rvmain.c.

int hresolu

Definition at line 25 of file rvmain.c.

double maxdiff = .15

Definition at line 28 of file rvmain.c.

int newparam = 1

Definition at line 35 of file rvmain.c.

int nproc = 1

Definition at line 49 of file rvmain.c.

Definition at line 41 of file rvmain.c.

Definition at line 24 of file rvmain.c.

int pdepth

Definition at line 45 of file rvmain.c.

Definition at line 44 of file rvmain.c.

char* progname

Definition at line 21 of file histo.c.

int psample = 8

Definition at line 27 of file rvmain.c.

Definition at line 43 of file rvmain.c.

const char RCSid[] = "$Id: rvmain.c,v 2.10 2009/12/12 19:01:00 greg Exp $" [static]

Definition at line 2 of file rvmain.c.

char rifname[128]

Definition at line 39 of file rvmain.c.

char* sigerr[NSIG]

Definition at line 51 of file rvmain.c.

int vresolu

Definition at line 25 of file rvmain.c.