| 1 | 
– | 
/* Copyright (c) 1995 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 | 
  | 
 *  rview.c - routines and variables for interactive view generation. | 
| 6 | 
  | 
 * | 
| 7 | 
< | 
 *     3/24/87 | 
| 7 | 
> | 
 *  External symbols declared in rpaint.h | 
| 8 | 
  | 
 */ | 
| 9 | 
  | 
 | 
| 10 | 
< | 
#include  "ray.h" | 
| 10 | 
> | 
#include "copyright.h" | 
| 11 | 
  | 
 | 
| 15 | 
– | 
#include  "rpaint.h" | 
| 16 | 
– | 
 | 
| 12 | 
  | 
#include  <signal.h> | 
| 18 | 
– | 
 | 
| 13 | 
  | 
#include  <ctype.h> | 
| 14 | 
  | 
 | 
| 15 | 
< | 
VIEW  ourview = STDVIEW;                /* viewing parameters */ | 
| 16 | 
< | 
int  hresolu, vresolu;                  /* image resolution */ | 
| 15 | 
> | 
#include  "ray.h" | 
| 16 | 
> | 
#include  "rpaint.h" | 
| 17 | 
  | 
 | 
| 18 | 
+ | 
 | 
| 19 | 
+ | 
CUBE  thescene;                         /* our scene */ | 
| 20 | 
+ | 
OBJECT  nsceneobjs;                     /* number of objects in our scene */ | 
| 21 | 
+ | 
 | 
| 22 | 
  | 
int  dimlist[MAXDIM];                   /* sampling dimensions */ | 
| 23 | 
  | 
int  ndims = 0;                         /* number of sampling dimensions */ | 
| 24 | 
  | 
int  samplendx = 0;                     /* index for this sample */ | 
| 25 | 
  | 
 | 
| 26 | 
+ | 
extern void  ambnotify(); | 
| 27 | 
+ | 
void  (*addobjnotify[])() = {ambnotify, NULL}; | 
| 28 | 
+ | 
 | 
| 29 | 
+ | 
VIEW  ourview = STDVIEW;                /* viewing parameters */ | 
| 30 | 
+ | 
int  hresolu, vresolu;                  /* image resolution */ | 
| 31 | 
+ | 
 | 
| 32 | 
+ | 
void  (*trace)() = NULL;                /* trace call */ | 
| 33 | 
+ | 
 | 
| 34 | 
+ | 
int  do_irrad = 0;                      /* compute irradiance? */ | 
| 35 | 
+ | 
 | 
| 36 | 
  | 
int  psample = 8;                       /* pixel sample size */ | 
| 37 | 
  | 
double  maxdiff = .15;                  /* max. sample difference */ | 
| 38 | 
  | 
 | 
| 47 | 
  | 
double  srcsizerat = 0.;                /* maximum ratio source size/dist. */ | 
| 48 | 
  | 
 | 
| 49 | 
  | 
COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */ | 
| 50 | 
< | 
double  salbedo = 0.;                   /* global scattering albedo */ | 
| 50 | 
> | 
COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */ | 
| 51 | 
  | 
double  seccg = 0.;                     /* global scattering eccentricity */ | 
| 52 | 
  | 
double  ssampdist = 0.;                 /* scatter sampling distance */ | 
| 53 | 
  | 
 | 
| 56 | 
  | 
 | 
| 57 | 
  | 
int  backvis = 1;                       /* back face visibility */ | 
| 58 | 
  | 
 | 
| 59 | 
< | 
int  maxdepth = 4;                      /* maximum recursion depth */ | 
| 59 | 
> | 
int  maxdepth = 6;                      /* maximum recursion depth */ | 
| 60 | 
  | 
double  minweight = 1e-2;               /* minimum ray weight */ | 
| 61 | 
  | 
 | 
| 62 | 
+ | 
char  *ambfile = NULL;                  /* ambient file name */ | 
| 63 | 
  | 
COLOR  ambval = BLKCOLOR;               /* ambient value */ | 
| 64 | 
< | 
double  ambacc = 0.2;                   /* ambient accuracy */ | 
| 65 | 
< | 
int  ambres = 8;                        /* ambient resolution */ | 
| 66 | 
< | 
int  ambdiv = 32;                       /* ambient divisions */ | 
| 67 | 
< | 
int  ambssamp = 0;                      /* ambient super-samples */ | 
| 64 | 
> | 
int  ambvwt = 0;                        /* initial weight for ambient value */ | 
| 65 | 
> | 
double  ambacc = 0.3;                   /* ambient accuracy */ | 
| 66 | 
> | 
int  ambres = 32;                       /* ambient resolution */ | 
| 67 | 
> | 
int  ambdiv = 256;                      /* ambient divisions */ | 
| 68 | 
> | 
int  ambssamp = 64;                     /* ambient super-samples */ | 
| 69 | 
  | 
int  ambounce = 0;                      /* ambient bounces */ | 
| 70 | 
  | 
char  *amblist[128];                    /* ambient include/exclude list */ | 
| 71 | 
  | 
int  ambincl = -1;                      /* include == 1, exclude == 0 */ | 
| 72 | 
  | 
 | 
| 73 | 
  | 
int  greyscale = 0;                     /* map colors to brightness? */ | 
| 74 | 
< | 
char  *devname = dev_default;           /* output device name */ | 
| 74 | 
> | 
char  *dvcname = dev_default;           /* output device name */ | 
| 75 | 
  | 
 | 
| 76 | 
  | 
struct driver  *dev = NULL;             /* driver functions */ | 
| 77 | 
  | 
 | 
| 90 | 
  | 
#define  CTRL(c)        ((c)-'@') | 
| 91 | 
  | 
 | 
| 92 | 
  | 
 | 
| 93 | 
+ | 
void | 
| 94 | 
  | 
quit(code)                      /* quit program */ | 
| 95 | 
  | 
int  code; | 
| 96 | 
  | 
{ | 
| 103 | 
  | 
} | 
| 104 | 
  | 
 | 
| 105 | 
  | 
 | 
| 106 | 
+ | 
void | 
| 107 | 
  | 
devopen(dname)                          /* open device driver */ | 
| 108 | 
  | 
char  *dname; | 
| 109 | 
  | 
{ | 
| 114 | 
  | 
        id = octname!=NULL ? octname : progname; | 
| 115 | 
  | 
                                                /* check device table */ | 
| 116 | 
  | 
        for (i = 0; devtable[i].name; i++) | 
| 117 | 
< | 
                if (!strcmp(dname, devtable[i].name)) | 
| 117 | 
> | 
                if (!strcmp(dname, devtable[i].name)) { | 
| 118 | 
  | 
                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) { | 
| 119 | 
  | 
                                sprintf(errmsg, "cannot initialize %s", dname); | 
| 120 | 
  | 
                                error(USER, errmsg); | 
| 121 | 
  | 
                        } else | 
| 122 | 
  | 
                                return; | 
| 123 | 
< | 
#ifndef NIX                                                 | 
| 123 | 
> | 
                } | 
| 124 | 
  | 
                                                /* not there, try exec */ | 
| 125 | 
  | 
        if ((dev = comm_init(dname, id)) == NULL) { | 
| 126 | 
  | 
                sprintf(errmsg, "cannot start device \"%s\"", dname); | 
| 127 | 
  | 
                error(USER, errmsg); | 
| 128 | 
  | 
        } | 
| 117 | 
– | 
#endif | 
| 129 | 
  | 
} | 
| 130 | 
  | 
 | 
| 131 | 
  | 
 | 
| 132 | 
+ | 
void | 
| 133 | 
  | 
devclose()                              /* close our device */ | 
| 134 | 
  | 
{ | 
| 135 | 
  | 
        if (dev != NULL) | 
| 138 | 
  | 
} | 
| 139 | 
  | 
 | 
| 140 | 
  | 
 | 
| 141 | 
+ | 
void | 
| 142 | 
  | 
printdevices()                          /* print list of output devices */ | 
| 143 | 
  | 
{ | 
| 144 | 
  | 
        register int  i; | 
| 148 | 
  | 
} | 
| 149 | 
  | 
 | 
| 150 | 
  | 
 | 
| 151 | 
+ | 
void | 
| 152 | 
  | 
rview()                         /* do a view */ | 
| 153 | 
  | 
{ | 
| 154 | 
  | 
        char  buf[32]; | 
| 155 | 
  | 
 | 
| 156 | 
< | 
        devopen(devname);               /* open device */ | 
| 156 | 
> | 
        devopen(dvcname);               /* open device */ | 
| 157 | 
  | 
        newimage();                     /* start image (calls fillreserves) */ | 
| 158 | 
  | 
 | 
| 159 | 
  | 
        for ( ; ; ) {                   /* quit in command() */ | 
| 181 | 
  | 
} | 
| 182 | 
  | 
 | 
| 183 | 
  | 
 | 
| 184 | 
+ | 
void | 
| 185 | 
  | 
fillreserves()                  /* fill memory reserves */ | 
| 186 | 
  | 
{ | 
| 187 | 
  | 
        if (reserve_mem != NULL) | 
| 188 | 
  | 
                return; | 
| 189 | 
< | 
        reserve_mem = malloc(RESERVE_AMT); | 
| 189 | 
> | 
        reserve_mem = (char *)malloc(RESERVE_AMT); | 
| 190 | 
  | 
} | 
| 191 | 
  | 
 | 
| 192 | 
  | 
 | 
| 193 | 
+ | 
void | 
| 194 | 
  | 
freereserves()                  /* free memory reserves */ | 
| 195 | 
  | 
{ | 
| 196 | 
  | 
        if (reserve_mem == NULL) | 
| 200 | 
  | 
} | 
| 201 | 
  | 
 | 
| 202 | 
  | 
 | 
| 203 | 
+ | 
void | 
| 204 | 
  | 
command(prompt)                 /* get/execute command */ | 
| 205 | 
  | 
char  *prompt; | 
| 206 | 
  | 
{ | 
| 329 | 
  | 
                devclose(); | 
| 330 | 
  | 
                kill(0, SIGTSTP); | 
| 331 | 
  | 
                /* pc stops here */ | 
| 332 | 
< | 
                devopen(devname); | 
| 332 | 
> | 
                devopen(dvcname); | 
| 333 | 
  | 
                redraw(); | 
| 334 | 
  | 
                break; | 
| 335 | 
  | 
#endif | 
| 349 | 
  | 
} | 
| 350 | 
  | 
 | 
| 351 | 
  | 
 | 
| 352 | 
+ | 
void | 
| 353 | 
  | 
rsample()                       /* sample the image */ | 
| 354 | 
  | 
{ | 
| 355 | 
  | 
        int  xsiz, ysiz, y; | 
| 372 | 
  | 
                return; | 
| 373 | 
  | 
        pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); | 
| 374 | 
  | 
        if (pl == NULL) { | 
| 375 | 
< | 
                free((char *)rl); | 
| 375 | 
> | 
                free((void *)rl); | 
| 376 | 
  | 
                return; | 
| 377 | 
  | 
        } | 
| 378 | 
  | 
        /* | 
| 433 | 
  | 
                } | 
| 434 | 
  | 
        } | 
| 435 | 
  | 
escape: | 
| 436 | 
< | 
        free((char *)rl); | 
| 437 | 
< | 
        free((char *)pl); | 
| 436 | 
> | 
        free((void *)rl); | 
| 437 | 
> | 
        free((void *)pl); | 
| 438 | 
  | 
} | 
| 439 | 
  | 
 | 
| 440 | 
  | 
 |