ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.4 by greg, Fri Mar 12 13:37:03 1993 UTC vs.
Revision 2.66 by greg, Thu Jul 3 15:00:19 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 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   * Executive program for oconv, rpict and pfilt
6   */
7  
8   #include "standard.h"
9 < #include "paths.h"
9 >
10   #include <ctype.h>
11  
12 + #include "platform.h"
13 + #include "view.h"
14 + #include "paths.h"
15 + #include "vars.h"
16  
17 < typedef struct {
18 <        char    *name;          /* variable name */
19 <        short   nick;           /* # characters required for nickname */
20 <        short   nass;           /* # assignments made */
21 <        char    *value;         /* assigned value(s) */
22 <        int     (*fixval)();    /* assignment checking function */
23 < } VARIABLE;
24 <
25 < int     onevalue(), catvalues();
26 <
27 <                                /* variables */
28 < #define OBJECT          0               /* object files */
29 < #define SCENE           1               /* scene files */
30 < #define MATERIAL        2               /* material files */
31 < #define RENDER          3               /* rendering options */
32 < #define OCONV           4               /* oconv options */
33 < #define PFILT           5               /* pfilt options */
34 < #define VIEW            6               /* view(s) for picture(s) */
35 < #define ZONE            7               /* simulation zone */
36 < #define QUALITY         8               /* desired rendering quality */
37 < #define OCTREE          9               /* octree file name */
38 < #define PICTURE         10              /* picture file name */
39 < #define AMBFILE         11              /* ambient file name */
40 < #define OPTFILE         12              /* rendering options file */
41 < #define EXPOSURE        13              /* picture exposure setting */
42 < #define RESOLUTION      14              /* maximum picture resolution */
43 < #define UP              15              /* view up (X, Y or Z) */
43 < #define INDIRECT        16              /* indirection in lighting */
44 < #define DETAIL          17              /* level of scene detail */
45 < #define PENUMBRAS       18              /* shadow penumbras are desired */
46 < #define VARIABILITY     19              /* level of light variability */
47 < #define REPORT          20              /* report frequency and errfile */
17 >                                /* variables (alphabetical by name) */
18 > #define AMBFILE         0               /* ambient file name */
19 > #define DETAIL          1               /* level of scene detail */
20 > #define EXPOSURE        2               /* picture exposure setting */
21 > #define EYESEP          3               /* interocular distance */
22 > #define ILLUM           4               /* mkillum input files */
23 > #define INDIRECT        5               /* indirection in lighting */
24 > #define MATERIAL        6               /* material files */
25 > #define MKILLUM         7               /* mkillum options */
26 > #define OBJECT          8               /* object files */
27 > #define OCONV           9               /* oconv options */
28 > #define OCTREE          10              /* octree file name */
29 > #define OPTFILE         11              /* rendering options file */
30 > #define PENUMBRAS       12              /* shadow penumbras are desired */
31 > #define PFILT           13              /* pfilt options */
32 > #define PICTURE         14              /* picture file root name */
33 > #define QUALITY         15              /* desired rendering quality */
34 > #define RAWFILE         16              /* raw picture file root name */
35 > #define RENDER          17              /* rendering options */
36 > #define REPORT          18              /* report frequency and errfile */
37 > #define RESOLUTION      19              /* maximum picture resolution */
38 > #define SCENE           20              /* scene files */
39 > #define UP              21              /* view up (X, Y or Z) */
40 > #define VARIABILITY     22              /* level of light variability */
41 > #define VIEWS           23              /* view(s) for picture(s) */
42 > #define ZFILE           24              /* distance file root name */
43 > #define ZONE            25              /* simulation zone */
44                                  /* total number of variables */
45 < #define NVARS           21
45 > int NVARS = 26;
46  
47 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
48 <        {"objects",     3,      0,      NULL,   catvalues},
49 <        {"scene",       3,      0,      NULL,   catvalues},
47 > VARIABLE        vv[] = {                /* variable-value pairs */
48 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
49 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
50 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
51 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
52 >        {"illum",       3,      0,      NULL,   catvalues},
53 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
54          {"materials",   3,      0,      NULL,   catvalues},
55 <        {"render",      3,      0,      NULL,   catvalues},
55 >        {"mkillum",     3,      0,      NULL,   catvalues},
56 >        {"objects",     3,      0,      NULL,   catvalues},
57          {"oconv",       3,      0,      NULL,   catvalues},
57        {"pfilt",       2,      0,      NULL,   catvalues},
58        {"view",        2,      0,      NULL,   NULL},
59        {"ZONE",        2,      0,      NULL,   onevalue},
60        {"QUALITY",     3,      0,      NULL,   onevalue},
58          {"OCTREE",      3,      0,      NULL,   onevalue},
62        {"PICTURE",     3,      0,      NULL,   onevalue},
63        {"AMBFILE",     3,      0,      NULL,   onevalue},
59          {"OPTFILE",     3,      0,      NULL,   onevalue},
60 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
60 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
61 >        {"pfilt",       2,      0,      NULL,   catvalues},
62 >        {"PICTURE",     3,      0,      NULL,   onevalue},
63 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
64 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
65 >        {"render",      3,      0,      NULL,   catvalues},
66 >        {"REPORT",      3,      0,      NULL,   onevalue},
67          {"RESOLUTION",  3,      0,      NULL,   onevalue},
68 +        {"scene",       3,      0,      NULL,   catvalues},
69          {"UP",          2,      0,      NULL,   onevalue},
70 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
71 <        {"DETAIL",      3,      0,      NULL,   onevalue},
72 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
73 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
72 <        {"REPORT",      3,      0,      NULL,   onevalue},
70 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
71 >        {"view",        2,      0,      NULL,   NULL},
72 >        {"ZFILE",       2,      0,      NULL,   onevalue},
73 >        {"ZONE",        2,      0,      NULL,   onevalue},
74   };
75  
76 < VARIABLE        *matchvar();
77 < char    *nvalue();
78 < int     vscale();
76 >                                /* overture calculation file */
77 > #ifdef NULL_DEVICE
78 > char    overfile[] = NULL_DEVICE;
79 > #else
80 > char    overfile[] = "overture.unf";
81 > #endif
82  
83 < #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
83 > extern time_t   time();
84  
85 < #define vnam(vc)        (vv[vc].name)
86 < #define vdef(vc)        (vv[vc].nass)
87 < #define vval(vc)        (vv[vc].value)
88 < #define vint(vc)        atoi(vval(vc))
85 < #define vlet(vc)        UPPER(vval(vc)[0])
86 < #define vbool(vc)       (vlet(vc)=='T')
85 > time_t  scenedate;              /* date of latest scene or object file */
86 > time_t  octreedate;             /* date of octree */
87 > time_t  matdate;                /* date of latest material file */
88 > time_t  illumdate;              /* date of last illum file */
89  
90 < #define HIGH            2
91 < #define MEDIUM          1
92 < #define LOW             0
90 > char    *oct0name;              /* name of pre-mkillum octree */
91 > time_t  oct0date;               /* date of pre-mkillum octree */
92 > char    *oct1name;              /* name of post-mkillum octree */
93 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
94  
95 < int     lowqopts(), medqopts(), hiqopts();
93 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94 <
95 < #define renderopts      (*setqopts[vscale(QUALITY)])
96 <
97 < extern long     fdate(), time();
98 <
99 < long    scenedate;              /* date of latest scene or object file */
100 < long    octreedate;             /* date of octree */
101 <
95 > int     nowarn = 0;             /* no warnings */
96   int     explicate = 0;          /* explicate variables */
97   int     silent = 0;             /* do work silently */
98 < int     noaction = 0;           /* don't do anything */
98 > int     touchonly = 0;          /* touch files only */
99 > int     nprocs = 1;             /* maximum executing processes */
100 > int     sayview = 0;            /* print view out */
101   char    *rvdevice = NULL;       /* rview output device */
102   char    *viewselect = NULL;     /* specific view only */
103  
104   int     overture = 0;           /* overture calculation needed */
105  
106 + int     children_running = 0;   /* set negative in children */
107 +
108   char    *progname;              /* global argv[0] */
109 + char    *rifname;               /* global rad input file name */
110  
111 < char    radname[MAXPATH];       /* root Radiance file name */
111 > char    radname[PATH_MAX];      /* root Radiance file name */
112  
113  
114   main(argc, argv)
# Line 117 | Line 116 | int    argc;
116   char    *argv[];
117   {
118          char    ropts[512];
119 +        char    popts[64];
120          int     i;
121  
122          progname = argv[0];
# Line 127 | Line 127 | char   *argv[];
127                          silent++;
128                          break;
129                  case 'n':
130 <                        noaction++;
130 >                        nprocs = 0;
131                          break;
132 +                case 'N':
133 +                        nprocs = atoi(argv[++i]);
134 +                        if (nprocs < 0)
135 +                                nprocs = 0;
136 +                        break;
137 +                case 't':
138 +                        touchonly++;
139 +                        break;
140                  case 'e':
141                          explicate++;
142                          break;
143                  case 'o':
144                          rvdevice = argv[++i];
145                          break;
146 +                case 'V':
147 +                        sayview++;
148 +                        break;
149                  case 'v':
150                          viewselect = argv[++i];
151                          break;
152 +                case 'w':
153 +                        nowarn++;
154 +                        break;
155                  default:
156                          goto userr;
157                  }
158          if (i >= argc)
159                  goto userr;
160 +        rifname = argv[i];
161                                  /* assign Radiance root file name */
162 <        rootname(radname, argv[i]);
162 >        rootname(radname, rifname);
163                                  /* load variable values */
164 <        load(argv[i]);
164 >        loadvars(rifname);
165                                  /* get any additional assignments */
166          for (i++; i < argc; i++)
167 <                setvariable(argv[i]);
167 >                if (setvariable(argv[i], matchvar) < 0) {
168 >                        fprintf(stderr, "%s: unknown variable: %s\n",
169 >                                        progname, argv[i]);
170 >                        quit(1);
171 >                }
172                                  /* check assignments */
173          checkvalues();
174                                  /* check files and dates */
# Line 158 | Line 177 | char   *argv[];
177          setdefaults();
178                                  /* print all values if requested */
179          if (explicate)
180 <                printvals();
181 <                                /* run simulation */
180 >                printvars(stdout);
181 >                                /* build octree (and run mkillum) */
182          oconv();
183 <        renderopts(ropts);
183 >                                /* check date on ambient file */
184 >        checkambfile();
185 >                                /* run simulation */
186 >        renderopts(ropts, popts);
187          xferopts(ropts);
188          if (rvdevice != NULL)
189 <                rview(ropts);
189 >                rview(ropts, popts);
190          else
191 <                rpict(ropts);
192 <        exit(0);
191 >                rpict(ropts, popts);
192 >        quit(0);
193   userr:
194          fprintf(stderr,
195 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
195 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
196                          progname);
197 <        exit(1);
197 >        quit(1);
198   }
199  
200  
# Line 191 | Line 213 | register char  *rn, *fn;
213   }
214  
215  
216 < load(rfname)                    /* load Radiance simulation file */
217 < char    *rfname;
216 > time_t
217 > checklast(fnames)                       /* check files and find most recent */
218 > register char   *fnames;
219   {
220 <        FILE    *fp;
221 <        char    buf[512];
199 <        register char   *cp;
220 >        char    thisfile[PATH_MAX];
221 >        time_t  thisdate, lastdate = 0;
222  
223 <        if (rfname == NULL)
224 <                fp = stdin;
225 <        else if ((fp = fopen(rfname, "r")) == NULL)
226 <                syserr(rfname);
227 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
228 <                for (cp = buf; *cp; cp++) {
229 <                        switch (*cp) {
230 <                        case '\\':
231 <                        case '\n':
232 <                                *cp = ' ';
211 <                                continue;
212 <                        case '#':
213 <                                *cp = '\0';
214 <                                break;
215 <                        default:
216 <                                continue;
217 <                        }
218 <                        break;
219 <                }
220 <                setvariable(buf);
223 >        if (fnames == NULL)
224 >                return(0);
225 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
226 >                if (thisfile[0] == '!' ||
227 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
228 >                        continue;
229 >                if (!(thisdate = fdate(thisfile)))
230 >                        syserr(thisfile);
231 >                if (thisdate > lastdate)
232 >                        lastdate = thisdate;
233          }
234 <        fclose(fp);
234 >        return(lastdate);
235   }
236  
237  
238 < setvariable(ass)                /* assign variable according to string */
239 < register char   *ass;
238 > char *
239 > newfname(orig, pred)            /* create modified file name */
240 > char    *orig;
241 > int     pred;
242   {
229        char    varname[32];
243          register char   *cp;
244 <        register VARIABLE       *vp;
245 <        register int    i;
233 <        int     n;
244 >        register int    n;
245 >        int     suffix;
246  
247 <        while (isspace(*ass))           /* skip leading space */
248 <                ass++;
249 <        cp = varname;                   /* extract name */
250 <        while (cp < varname+sizeof(varname)-1
251 <                        && *ass && !isspace(*ass) && *ass != '=')
240 <                *cp++ = *ass++;
241 <        *cp = '\0';
242 <        if (!varname[0])
243 <                return;         /* no variable name! */
244 <                                        /* trim value */
245 <        while (isspace(*ass) || *ass == '=')
246 <                ass++;
247 <        cp = ass + strlen(ass);
248 <        do
249 <                *cp-- = '\0';
250 <        while (cp >= ass && isspace(*cp));
251 <        n = cp - ass + 1;
252 <        if (!n) {
253 <                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
254 <                                progname, varname);
255 <                return;
247 >        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
248 >        while (*cp) {
249 >                if (*cp == '.') suffix = n;
250 >                else if (ISDIRSEP(*cp)) suffix = -1;
251 >                cp++; n++;
252          }
253 <                                        /* match variable from list */
254 <        vp = matchvar(varname);
259 <        if (vp == NULL) {
260 <                fprintf(stderr, "%s: unknown variable '%s'\n",
261 <                                progname, varname);
262 <                exit(1);
263 <        }
264 <                                        /* assign new value */
265 <        if (i = vp->nass) {
266 <                cp = vp->value;
267 <                while (i--)
268 <                        while (*cp++)
269 <                                ;
270 <                i = cp - vp->value;
271 <                vp->value = realloc(vp->value, i+n+1);
272 <        } else
273 <                vp->value = malloc(n+1);
274 <        if (vp->value == NULL)
253 >        if (suffix == -1) suffix = n;
254 >        if ((cp = bmalloc(n+2)) == NULL)
255                  syserr(progname);
256 <        strcpy(vp->value+i, ass);
257 <        vp->nass++;
258 < }
279 <
280 <
281 < VARIABLE *
282 < matchvar(nam)                   /* match a variable by its name */
283 < char    *nam;
284 < {
285 <        int     n = strlen(nam);
286 <        register int    i;
287 <
288 <        for (i = 0; i < NVARS; i++)
289 <                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
290 <                        return(vv+i);
291 <        return(NULL);
292 < }
293 <
294 <
295 < char *
296 < nvalue(vp, n)                   /* return nth variable value */
297 < VARIABLE        *vp;
298 < register int    n;
299 < {
300 <        register char   *cp;
301 <
302 <        if (vp == NULL || n < 0 || n >= vp->nass)
303 <                return(NULL);
304 <        cp = vp->value;
305 <        while (n--)
306 <                while (*cp++)
307 <                        ;
256 >        strncpy(cp, orig, suffix);
257 >        cp[suffix] = pred;                      /* root name + pred + suffix */
258 >        strcpy(cp+suffix+1, orig+suffix);
259          return(cp);
260   }
261  
262  
312 int
313 vscale(vc)                      /* return scale for variable vc */
314 int     vc;
315 {
316        switch(vlet(vc)) {
317        case 'H':
318                return(HIGH);
319        case 'M':
320                return(MEDIUM);
321        case 'L':
322                return(LOW);
323        }
324        badvalue(vc);
325 }
326
327
328 checkvalues()                   /* check assignments */
329 {
330        register int    i;
331
332        for (i = 0; i < NVARS; i++)
333                if (vv[i].fixval != NULL)
334                        (*vv[i].fixval)(vv+i);
335 }
336
337
338 onevalue(vp)                    /* only one assignment for this variable */
339 register VARIABLE       *vp;
340 {
341        if (vp->nass < 2)
342                return;
343        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
344                        progname, vp->name);
345        do
346                vp->value += strlen(vp->value)+1;
347        while (--vp->nass > 1);
348 }
349
350
351 catvalues(vp)                   /* concatenate variable values */
352 register VARIABLE       *vp;
353 {
354        register char   *cp;
355
356        if (vp->nass < 2)
357                return;
358        for (cp = vp->value; vp->nass > 1; vp->nass--) {
359                while (*cp)
360                        cp++;
361                *cp++ = ' ';
362        }
363 }
364
365
366 long
367 checklast(fnames)                       /* check files and find most recent */
368 register char   *fnames;
369 {
370        char    thisfile[MAXPATH];
371        long    thisdate, lastdate = -1;
372        register char   *cp;
373
374        while (*fnames) {
375                while (isspace(*fnames)) fnames++;
376                cp = thisfile;
377                while (*fnames && !isspace(*fnames))
378                        *cp++ = *fnames++;
379                *cp = '\0';
380                if ((thisdate = fdate(thisfile)) < 0)
381                        syserr(thisfile);
382                if (thisdate > lastdate)
383                        lastdate = thisdate;
384        }
385        return(lastdate);
386 }
387
388
263   checkfiles()                    /* check for existence and modified times */
264   {
265 <        char    *cp;
392 <        long    objdate;
265 >        time_t  objdate;
266  
267          if (!vdef(OCTREE)) {
268 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
268 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
269                          syserr(progname);
270 <                sprintf(cp, "%s.oct", radname);
398 <                vval(OCTREE) = cp;
270 >                sprintf(vval(OCTREE), "%s.oct", radname);
271                  vdef(OCTREE)++;
272 +        } else if (vval(OCTREE)[0] == '!') {
273 +                fprintf(stderr, "%s: illegal '%s' specification\n",
274 +                                progname, vnam(OCTREE));
275 +                quit(1);
276          }
277          octreedate = fdate(vval(OCTREE));
278 <        scenedate = -1;
279 <        if (vdef(SCENE)) {
280 <                scenedate = checklast(vval(SCENE));
281 <                if (vdef(OBJECT)) {
282 <                        objdate = checklast(vval(OBJECT));
283 <                        if (objdate > scenedate)
284 <                                scenedate = objdate;
285 <                }
278 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
279 >                oct0name = newfname(vval(OCTREE), '0');
280 >                oct1name = newfname(vval(OCTREE), '1');
281 >                oct0date = fdate(oct0name);
282 >                oct1date = fdate(oct1name);
283 >        } else
284 >                oct0name = oct1name = vval(OCTREE);
285 >        if ((scenedate = checklast(vval(SCENE))) &&
286 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
287 >                scenedate = objdate;
288 >        illumdate = checklast(vval(ILLUM));
289 >        if (!octreedate & !scenedate & !illumdate) {
290 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
291 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
292 >                quit(1);
293          }
294 <        if (octreedate < 0 & scenedate < 0) {
412 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
413 <                                vnam(OCTREE), vnam(SCENE));
414 <                exit(1);
415 <        }
294 >        matdate = checklast(vval(MATERIAL));
295   }      
296  
297  
# Line 421 | Line 300 | double org[3], *sizp;
300   {
301          extern FILE     *popen();
302          static double   oorg[3], osiz = 0.;
303 <        char    buf[MAXPATH+16];
303 >        double  min[3], max[3];
304 >        char    buf[1024];
305          FILE    *fp;
306 +        register int    i;
307  
308 <        if (osiz <= FTINY) {
309 <                oconv();                /* does nothing if done already */
310 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
311 <                if ((fp = popen(buf, "r")) == NULL)
312 <                        syserr("getinfo");
313 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
314 <                                &oorg[2], &osiz) != 4) {
315 <                        fprintf(stderr,
308 >        if (osiz <= FTINY)
309 >                if (!nprocs && fdate(oct1name) <
310 >                                (scenedate>illumdate?scenedate:illumdate)) {
311 >                                                        /* run getbbox */
312 >                        sprintf(buf, "getbbox -w -h %s",
313 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
314 >                        if ((fp = popen(buf, "r")) == NULL)
315 >                                syserr("getbbox");
316 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
317 >                                        &min[0], &max[0], &min[1], &max[1],
318 >                                        &min[2], &max[2]) != 6) {
319 >                                fprintf(stderr,
320 >                        "%s: error reading bounding box from getbbox\n",
321 >                                                progname);
322 >                                quit(1);
323 >                        }
324 >                        for (i = 0; i < 3; i++)
325 >                                if (max[i] - min[i] > osiz)
326 >                                        osiz = max[i] - min[i];
327 >                        for (i = 0; i < 3; i++)
328 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
329 >                        pclose(fp);
330 >                } else {                                /* from octree */
331 >                        oconv();        /* does nothing if done already */
332 >                        sprintf(buf, "getinfo -d < %s", oct1name);
333 >                        if ((fp = popen(buf, "r")) == NULL)
334 >                                syserr("getinfo");
335 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
336 >                                        &oorg[2], &osiz) != 4) {
337 >                                fprintf(stderr,
338                          "%s: error reading bounding cube from getinfo\n",
339 <                                        progname);
340 <                        exit(1);
339 >                                                progname);
340 >                                quit(1);
341 >                        }
342 >                        pclose(fp);
343                  }
439                pclose(fp);
440        }
344          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
345   }
346  
347  
348   setdefaults()                   /* set default values for unassigned var's */
349   {
350 <        double  org[3], size;
350 >        double  org[3], lim[3], size;
351          char    buf[128];
352  
353          if (!vdef(ZONE)) {
# Line 454 | Line 357 | setdefaults()                  /* set default values for unassigned v
357                  vval(ZONE) = savqstr(buf);
358                  vdef(ZONE)++;
359          }
360 +        if (!vdef(EYESEP)) {
361 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
362 +                                &org[0], &lim[0], &org[1], &lim[1],
363 +                                &org[2], &lim[2]) != 6)
364 +                        badvalue(ZONE);
365 +                sprintf(buf, "%f",
366 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
367 +                vval(EYESEP) = savqstr(buf);
368 +                vdef(EYESEP)++;
369 +        }
370          if (!vdef(INDIRECT)) {
371                  vval(INDIRECT) = "0";
372                  vdef(INDIRECT)++;
# Line 470 | Line 383 | setdefaults()                  /* set default values for unassigned v
383                  vval(PICTURE) = radname;
384                  vdef(PICTURE)++;
385          }
386 <        if (!vdef(VIEW)) {
387 <                vval(VIEW) = "X";
388 <                vdef(VIEW)++;
386 >        if (!vdef(VIEWS)) {
387 >                vval(VIEWS) = "X";
388 >                vdef(VIEWS)++;
389          }
390          if (!vdef(DETAIL)) {
391                  vval(DETAIL) = "M";
# Line 489 | Line 402 | setdefaults()                  /* set default values for unassigned v
402   }
403  
404  
405 < printvals()                     /* print variable values */
405 > oconv()                         /* run oconv and mkillum if necessary */
406   {
407 <        register int    i, j;
407 >        static char     illumtmp[] = "ilXXXXXX";
408 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
409  
410 <        for (i = 0; i < NVARS; i++)
411 <                for (j = 0; j < vdef(i); j++)
412 <                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
413 <        fflush(stdout);
414 < }
415 <
416 <
417 < oconv()                         /* run oconv if necessary */
418 < {
419 <        char    combuf[512], ocopts[64];
420 <
421 <        if (octreedate >= scenedate)    /* check dates */
410 >        oconvopts(ocopts);              /* get options */
411 >        if (octreedate < scenedate) {   /* check date on original octree */
412 >                if (touchonly && octreedate)
413 >                        touch(vval(OCTREE));
414 >                else {                          /* build command */
415 >                        if (vdef(MATERIAL))
416 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
417 >                                                vval(MATERIAL), vval(SCENE),
418 >                                                vval(OCTREE));
419 >                        else
420 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
421 >                                                vval(SCENE), vval(OCTREE));
422 >                        
423 >                        if (runcom(combuf)) {           /* run it */
424 >                                fprintf(stderr,
425 >                                "%s: error generating octree\n\t%s removed\n",
426 >                                                progname, vval(OCTREE));
427 >                                unlink(vval(OCTREE));
428 >                                quit(1);
429 >                        }
430 >                }
431 >                octreedate = time((time_t *)NULL);
432 >                if (octreedate < scenedate)     /* in case clock is off */
433 >                        octreedate = scenedate;
434 >        }
435 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
436 >                oct1date = octreedate > matdate ? octreedate : matdate;
437 >        if (oct1date >= octreedate & oct1date >= matdate
438 >                        & oct1date >= illumdate)        /* all done */
439                  return;
440 <                                        /* build command */
441 <        oconvopts(ocopts);
442 <        if (vdef(MATERIAL))
443 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
444 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
445 <        else
446 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
447 <                                vval(SCENE), vval(OCTREE));
448 <        
449 <        if (runcom(combuf)) {           /* run it */
450 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
451 <                                progname, vval(OCTREE));
452 <                unlink(vval(OCTREE));
453 <                exit(1);
440 >                                                /* make octree0 */
441 >        if (oct0date < scenedate | oct0date < illumdate) {
442 >                if (touchonly && oct0date)
443 >                        touch(oct0name);
444 >                else {                          /* build command */
445 >                        if (octreedate)
446 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
447 >                                        vval(OCTREE), vval(ILLUM), oct0name);
448 >                        else if (vdef(MATERIAL))
449 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
450 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
451 >                        else
452 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
453 >                                        vval(ILLUM), oct0name);
454 >                        if (runcom(combuf)) {           /* run it */
455 >                                fprintf(stderr,
456 >                                "%s: error generating octree\n\t%s removed\n",
457 >                                                progname, oct0name);
458 >                                unlink(oct0name);
459 >                                quit(1);
460 >                        }
461 >                }
462 >                oct0date = time((time_t *)NULL);
463 >                if (oct0date < octreedate)      /* in case clock is off */
464 >                        oct0date = octreedate;
465 >                if (oct0date < illumdate)       /* ditto */
466 >                        oct0date = illumdate;
467 >                }
468 >        if (touchonly && oct1date)
469 >                touch(oct1name);
470 >        else {
471 >                mkillumopts(mkopts);            /* build mkillum command */
472 >                mktemp(illumtmp);
473 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
474 >                                oct0name, vval(ILLUM), illumtmp);
475 >                if (runcom(combuf)) {                   /* run it */
476 >                        fprintf(stderr, "%s: error running mkillum\n",
477 >                                        progname);
478 >                        unlink(illumtmp);
479 >                        quit(1);
480 >                }
481 >                                                /* make octree1 (frozen) */
482 >                if (octreedate)
483 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
484 >                                vval(OCTREE), illumtmp, oct1name);
485 >                else if (vdef(MATERIAL))
486 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
487 >                                vval(MATERIAL), illumtmp, oct1name);
488 >                else
489 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
490 >                                illumtmp, oct1name);
491 >                if (runcom(combuf)) {           /* run it */
492 >                        fprintf(stderr,
493 >                                "%s: error generating octree\n\t%s removed\n",
494 >                                        progname, oct1name);
495 >                        unlink(oct1name);
496 >                        unlink(illumtmp);
497 >                        quit(1);
498 >                }
499 >                rmfile(illumtmp);
500          }
501 <        octreedate = time(0);
501 >        oct1date = time((time_t *)NULL);
502 >        if (oct1date < oct0date)        /* in case clock is off */
503 >                oct1date = oct0date;
504   }
505  
506  
# Line 547 | Line 526 | register char  *oo;
526   }
527  
528  
529 + mkillumopts(mo)                         /* get mkillum options */
530 + register char   *mo;
531 + {
532 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
533 +
534 +        *mo = '\0';
535 +        if (vdef(MKILLUM))
536 +                addarg(mo, vval(MKILLUM));
537 + }
538 +
539 +
540 + checkambfile()                  /* check date on ambient file */
541 + {
542 +        time_t  afdate;
543 +
544 +        if (!vdef(AMBFILE))
545 +                return;
546 +        if (!(afdate = fdate(vval(AMBFILE))))
547 +                return;
548 +        if (oct1date > afdate)
549 +                if (touchonly)
550 +                        touch(vval(AMBFILE));
551 +                else
552 +                        rmfile(vval(AMBFILE));
553 + }
554 +
555 +
556   double
557   ambval()                                /* compute ambient value */
558   {
559          if (vdef(EXPOSURE)) {
560                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
561 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
562 <                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
557 <                        return(.5/atof(vval(EXPOSURE)));
558 <                badvalue(EXPOSURE);
561 >                        return(.5/pow(2.,vflt(EXPOSURE)));
562 >                return(.5/vflt(EXPOSURE));
563          }
564          if (vlet(ZONE) == 'E')
565                  return(10.);
# Line 565 | Line 569 | ambval()                               /* compute ambient value */
569   }
570  
571  
572 < lowqopts(op)                            /* low quality rendering options */
572 > renderopts(op, po)                      /* set rendering options */
573 > char    *op, *po;
574 > {
575 >        switch(vscale(QUALITY)) {
576 >        case LOW:
577 >                lowqopts(op, po);
578 >                break;
579 >        case MEDIUM:
580 >                medqopts(op, po);
581 >                break;
582 >        case HIGH:
583 >                hiqopts(op, po);
584 >                break;
585 >        }
586 > }
587 >
588 >
589 > lowqopts(op, po)                        /* low quality rendering options */
590   register char   *op;
591 + char    *po;
592   {
593          double  d, org[3], siz[3];
594  
595          *op = '\0';
596 +        *po = '\0';
597          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
598                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
599                  badvalue(ZONE);
600          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
601 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
602 +                badvalue(ZONE);
603          getoctcube(org, &d);
604          d *= 3./(siz[0]+siz[1]+siz[2]);
605          switch (vscale(DETAIL)) {
606          case LOW:
607 <                op = addarg(op, "-ps 16 -dp 16");
607 >                po = addarg(po, "-ps 16");
608 >                op = addarg(op, "-dp 64");
609                  sprintf(op, " -ar %d", (int)(4*d));
610                  op += strlen(op);
611                  break;
612          case MEDIUM:
613 <                op = addarg(op, "-ps 8 -dp 32");
613 >                po = addarg(po, "-ps 8");
614 >                op = addarg(op, "-dp 128");
615                  sprintf(op, " -ar %d", (int)(8*d));
616                  op += strlen(op);
617                  break;
618          case HIGH:
619 <                op = addarg(op, "-ps 4 -dp 64");
619 >                po = addarg(po, "-ps 4");
620 >                op = addarg(op, "-dp 256");
621                  sprintf(op, " -ar %d", (int)(16*d));
622                  op += strlen(op);
623                  break;
624          }
625 <        op = addarg(op, "-pt .16");
625 >        po = addarg(po, "-pt .16");
626          if (vbool(PENUMBRAS))
627                  op = addarg(op, "-ds .4");
628          else
629                  op = addarg(op, "-ds 0");
630 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
630 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
631          if (vdef(AMBFILE)) {
632                  sprintf(op, " -af %s", vval(AMBFILE));
633                  op += strlen(op);
# Line 607 | Line 635 | register char  *op;
635                  overture = 0;
636          switch (vscale(VARIABILITY)) {
637          case LOW:
638 <                op = addarg(op, "-aa .4 -ad 32");
638 >                op = addarg(op, "-aa .4 -ad 64");
639                  break;
640          case MEDIUM:
641 <                op = addarg(op, "-aa .3 -ad 64");
641 >                op = addarg(op, "-aa .3 -ad 128");
642                  break;
643          case HIGH:
644 <                op = addarg(op, "-aa .25 -ad 128");
644 >                op = addarg(op, "-aa .25 -ad 256");
645                  break;
646          }
647          op = addarg(op, "-as 0");
# Line 626 | Line 654 | register char  *op;
654   }
655  
656  
657 < medqopts(op)                            /* medium quality rendering options */
657 > medqopts(op, po)                        /* medium quality rendering options */
658   register char   *op;
659 + char    *po;
660   {
661 <        double  d, org[3], siz[3];
661 >        double  d, org[3], siz[3], asz;
662  
663          *op = '\0';
664 +        *po = '\0';
665          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
666                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
667                  badvalue(ZONE);
668          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
669 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
670 +                badvalue(ZONE);
671          getoctcube(org, &d);
672 <        d *= 3./(siz[0]+siz[1]+siz[2]);
672 >        asz = (siz[0]+siz[1]+siz[2])/3.;
673 >        d /= asz;
674          switch (vscale(DETAIL)) {
675          case LOW:
676 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
677 <                op = addarg(op, "-dp 64");
676 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
677 >                op = addarg(op, "-dp 256");
678                  sprintf(op, " -ar %d", (int)(8*d));
679                  op += strlen(op);
680 +                sprintf(op, " -ms %.2g", asz/20.);
681 +                op += strlen(op);
682                  break;
683          case MEDIUM:
684 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
685 <                op = addarg(op, "-dp 128");
684 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
685 >                op = addarg(op, "-dp 512");
686                  sprintf(op, " -ar %d", (int)(16*d));
687                  op += strlen(op);
688 +                sprintf(op, " -ms %.2g", asz/40.);
689 +                op += strlen(op);
690                  break;
691          case HIGH:
692 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
693 <                op = addarg(op, "-dp 256");
692 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
693 >                op = addarg(op, "-dp 1024");
694                  sprintf(op, " -ar %d", (int)(32*d));
695                  op += strlen(op);
696 +                sprintf(op, " -ms %.2g", asz/80.);
697 +                op += strlen(op);
698                  break;
699          }
700 <        op = addarg(op, "-pt .08");
700 >        po = addarg(po, "-pt .08");
701          if (vbool(PENUMBRAS))
702 <                op = addarg(op, "-ds .2 -dj .35");
702 >                op = addarg(op, "-ds .2 -dj .5");
703          else
704                  op = addarg(op, "-ds .3");
705 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
706 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
707 <        op += strlen(op);
705 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
706 >        if (overture = vint(INDIRECT)) {
707 >                sprintf(op, " -ab %d", overture);
708 >                op += strlen(op);
709 >        }
710          if (vdef(AMBFILE)) {
711                  sprintf(op, " -af %s", vval(AMBFILE));
712                  op += strlen(op);
# Line 673 | Line 714 | register char  *op;
714                  overture = 0;
715          switch (vscale(VARIABILITY)) {
716          case LOW:
717 <                op = addarg(op, "-aa .25 -ad 128 -as 0");
717 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
718                  break;
719          case MEDIUM:
720 <                op = addarg(op, "-aa .2 -ad 300 -as 64");
720 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
721                  break;
722          case HIGH:
723 <                op = addarg(op, "-aa .15 -ad 500 -as 128");
723 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
724                  break;
725          }
726          d = ambval();
# Line 691 | Line 732 | register char  *op;
732   }
733  
734  
735 < hiqopts(op)                             /* high quality rendering options */
735 > hiqopts(op, po)                         /* high quality rendering options */
736   register char   *op;
737 + char    *po;
738   {
739 <        double  d, org[3], siz[3];
739 >        double  d, org[3], siz[3], asz;
740  
741          *op = '\0';
742 +        *po = '\0';
743          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
744                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
745                  badvalue(ZONE);
746          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
747 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
748 +                badvalue(ZONE);
749          getoctcube(org, &d);
750 <        d *= 3./(siz[0]+siz[1]+siz[2]);
750 >        asz = (siz[0]+siz[1]+siz[2])/3.;
751 >        d /= asz;
752          switch (vscale(DETAIL)) {
753          case LOW:
754 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
755 <                op = addarg(op, "-dp 256");
754 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
755 >                op = addarg(op, "-dp 1024");
756                  sprintf(op, " -ar %d", (int)(16*d));
757                  op += strlen(op);
758 +                sprintf(op, " -ms %.2g", asz/40.);
759 +                op += strlen(op);
760                  break;
761          case MEDIUM:
762 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
763 <                op = addarg(op, "-dp 512");
762 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
763 >                op = addarg(op, "-dp 2048");
764                  sprintf(op, " -ar %d", (int)(32*d));
765                  op += strlen(op);
766 +                sprintf(op, " -ms %.2g", asz/80.);
767 +                op += strlen(op);
768                  break;
769          case HIGH:
770 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
771 <                op = addarg(op, "-dp 1024");
770 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
771 >                op = addarg(op, "-dp 4096");
772                  sprintf(op, " -ar %d", (int)(64*d));
773                  op += strlen(op);
774 +                sprintf(op, " -ms %.2g", asz/160.);
775 +                op += strlen(op);
776                  break;
777          }
778 <        op = addarg(op, "-pt .04");
778 >        po = addarg(po, "-pt .04");
779          if (vbool(PENUMBRAS))
780 <                op = addarg(op, "-ds .1 -dj .7");
780 >                op = addarg(op, "-ds .1 -dj .65");
781          else
782                  op = addarg(op, "-ds .2");
783 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
783 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
784          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
785          op += strlen(op);
786          if (vdef(AMBFILE)) {
# Line 738 | Line 790 | register char  *op;
790                  overture = 0;
791          switch (vscale(VARIABILITY)) {
792          case LOW:
793 <                op = addarg(op, "-aa .15 -ad 200 -as 0");
793 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
794                  break;
795          case MEDIUM:
796 <                op = addarg(op, "-aa .125 -ad 512 -as 128");
796 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
797                  break;
798          case HIGH:
799 <                op = addarg(op, "-aa .08 -ad 850 -as 256");
799 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
800                  break;
801          }
802          d = ambval();
# Line 760 | Line 812 | xferopts(ro)                           /* transfer options if indicated */
812   char    *ro;
813   {
814          int     fd, n;
815 +        register char   *cp;
816          
817          n = strlen(ro);
818          if (n < 2)
819                  return;
820          if (vdef(OPTFILE)) {
821 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
821 >                for (cp = ro; cp[1]; cp++)
822 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
823 >                                        (cp[2] == '-' && isalpha(cp[3]))))
824 >                                *cp = '\n';
825 >                        else
826 >                                *cp = cp[1];
827 >                *cp = '\n';
828 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
829 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
830                          syserr(vval(OPTFILE));
831 <                if (write(fd, ro+1, n-1) != n-1)
771 <                        syserr(vval(OPTFILE));
772 <                write(fd, "\n", 1);
773 <                close(fd);
774 <                sprintf(ro, " \"^%s\"", vval(OPTFILE));
831 >                sprintf(ro, " @%s", vval(OPTFILE));
832          }
833 < #ifdef MSDOS
833 > #ifdef _WIN32
834          else if (n > 50) {
835 <                register char   *evp = bmalloc(n+6);
779 <                if (evp == NULL)
780 <                        syserr(progname);
781 <                strcpy(evp, "ROPT=");
782 <                strcat(evp, ro);
783 <                if (putenv(evp) != 0) {
784 <                        fprintf(stderr, "%s: out of environment space\n",
785 <                                        progname);
786 <                        exit(1);
787 <                }
835 >                setenv("ROPT", ro+1);
836                  strcpy(ro, " $ROPT");
837          }
838   #endif
# Line 799 | Line 847 | register char  *po;
847                  po = addarg(po, "-1 -e");
848                  po = addarg(po, vval(EXPOSURE));
849          }
850 <        if (vscale(QUALITY) == HIGH)
851 <                po = addarg(po, "-r .65");
850 >        switch (vscale(QUALITY)) {
851 >        case MEDIUM:
852 >                po = addarg(po, "-r .6");
853 >                break;
854 >        case HIGH:
855 >                po = addarg(po, "-m .25");
856 >                break;
857 >        }
858          if (vdef(PFILT))
859                  po = addarg(po, vval(PFILT));
860   }
# Line 861 | Line 915 | register char  *vs;
915                  zpos = -1; vs++;
916          }
917          viewtype = 'v';
918 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
918 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
919                  viewtype = *vs++;
920          cp = viewopts;
921          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 872 | Line 926 | register char  *vs;
926                          badvalue(ZONE);
927                  for (i = 0; i < 3; i++) {
928                          dim[i] -= cent[i];
929 +                        if (dim[i] <= FTINY)
930 +                                badvalue(ZONE);
931                          cent[i] += .5*dim[i];
932                  }
933                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
# Line 914 | Line 970 | register char  *vs;
970                  case 'h':
971                          cp = addarg(cp, "-vh 180 -vv 180");
972                          break;
973 +                case 'c':
974 +                        cp = addarg(cp, "-vh 180 -vv 90");
975 +                        break;
976                  }
977          } else {
978                  while (!isspace(*vs))           /* else skip id */
# Line 924 | Line 983 | register char  *vs;
983                          cp += strlen(cp);
984                  }
985          }
986 <                                        /* append any additional options */
986 >        if (cp == viewopts)             /* append any additional options */
987 >                vs++;           /* skip prefixed space if unneeded */
988          strcpy(cp, vs);
989 + #ifdef _WIN32
990 +        if (strlen(viewopts) > 40) {
991 +                setenv("VIEW", viewopts);
992 +                return("$VIEW");
993 +        }
994 + #endif
995          return(viewopts);
996   }
997  
# Line 933 | Line 999 | register char  *vs;
999   char *
1000   getview(n, vn)                          /* get view n, or NULL if none */
1001   int     n;
1002 < char    *vn;
1002 > char    *vn;            /* returned view name */
1003   {
1004          register char   *mv;
1005  
1006 <        if (viewselect != NULL) {
1006 >        if (viewselect != NULL) {               /* command-line selected */
1007                  if (n)                          /* only do one */
1008                          return(NULL);
1009                  if (viewselect[0] == '-') {     /* already specified */
# Line 950 | Line 1016 | char   *vn;
1016                                  ;
1017                          *vn = '\0';
1018                  }
1019 +                                                /* view number? */
1020 +                if (isint(viewselect))
1021 +                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1022                                                  /* check list */
1023 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1023 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1024                          if (matchword(viewselect, mv))
1025                                  return(specview(mv));
1026                  return(specview(viewselect));   /* standard view? */
1027          }
1028 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1029 <                if (*mv != '-')
1030 <                        while (*mv && !isspace(*mv))
1031 <                                *vn++ = *mv++;
1028 >        mv = nvalue(VIEWS, n);          /* use view n */
1029 >        if (vn != NULL & mv != NULL) {
1030 >                register char   *mv2 = mv;
1031 >                if (*mv2 != '-')
1032 >                        while (*mv2 && !isspace(*mv2))
1033 >                                *vn++ = *mv2++;
1034                  *vn = '\0';
1035          }
1036 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1036 >        return(specview(mv));
1037   }
1038  
1039  
1040 < rview(opts)                             /* run rview with first view */
1041 < char    *opts;
1040 > printview(vopts)                        /* print out selected view */
1041 > register char   *vopts;
1042   {
1043 <        char    combuf[512];
1043 >        VIEW    vwr;
1044 >        char    buf[128];
1045 >        register char   *cp;
1046 > again:
1047 >        if (vopts == NULL)
1048 >                return(-1);
1049 > #ifdef _WIN32
1050 >        if (vopts[0] == '$') {
1051 >                vopts = getenv(vopts+1);
1052 >                goto again;
1053 >        }
1054 > #endif
1055 >        copystruct(&vwr, &stdview);
1056 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1057 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1058 >                        *atos(buf, sizeof(buf), cp += 4)) {
1059 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1060 >                sscanview(&vwr, cp);            /* reset tail */
1061 >        }
1062 >        fputs(VIEWSTR, stdout);
1063 >        fprintview(&vwr, stdout);               /* print full spec. */
1064 >        fputc('\n', stdout);
1065 >        return(0);
1066 > }
1067 >
1068 >
1069 > rview(opts, po)                         /* run rview with first view */
1070 > char    *opts, *po;
1071 > {
1072 >        char    *vw;
1073 >        char    combuf[PATH_MAX];
1074                                          /* build command */
1075 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1075 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1076 >                return;
1077 >        if (sayview)
1078 >                printview(vw);
1079 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1080          if (rvdevice != NULL)
1081                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1082 <        strcat(combuf, vval(OCTREE));
1082 >        if (vdef(EXPOSURE))
1083 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1084 >        strcat(combuf, oct1name);
1085          if (runcom(combuf)) {           /* run it */
1086                  fprintf(stderr, "%s: error running rview\n", progname);
1087 <                exit(1);
1087 >                quit(1);
1088          }
1089   }
1090  
1091  
1092 < rpict(opts)                             /* run rpict and pfilt for each view */
1093 < char    *opts;
1092 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1093 > char    *opts, *po;
1094   {
1095 <        char    combuf[1024];
1096 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1095 >        char    combuf[PATH_MAX];
1096 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1097 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1098          char    pfopts[128];
1099          char    vs[32], *vw;
1100          int     vn, mult;
1101 +        time_t  rfdt, pfdt;
1102                                          /* get pfilt options */
1103          pfiltopts(pfopts);
1104                                          /* get resolution, reporting */
1105 <        mult = vscale(QUALITY)+1;
1105 >        switch (vscale(QUALITY)) {
1106 >        case LOW:
1107 >                mult = 1;
1108 >                break;
1109 >        case MEDIUM:
1110 >                mult = 2;
1111 >                break;
1112 >        case HIGH:
1113 >                mult = 3;
1114 >                break;
1115 >        }
1116          {
1117                  int     xres, yres;
1118                  double  aspect;
# Line 1020 | Line 1139 | char   *opts;
1139                  else
1140                          badvalue(REPORT);
1141          }
1142 <                                        /* check date on ambient file */
1024 <        if (vdef(AMBFILE)) {
1025 <                long    afdate = fdate(vval(AMBFILE));
1026 <                if (afdate >= 0 & octreedate > afdate)
1027 <                        rmfile(vval(AMBFILE));
1028 <        }
1029 <                                        /* do each view */
1030 <        vn = 0;
1142 >        vn = 0;                                 /* do each view */
1143          while ((vw = getview(vn++, vs)) != NULL) {
1144 +                if (sayview)
1145 +                        printview(vw);
1146                  if (!vs[0])
1147                          sprintf(vs, "%d", vn);
1148                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1149 +                if (vdef(ZFILE))
1150 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1151 +                else
1152 +                        zopt[0] = '\0';
1153                                                  /* check date on picture */
1154 <                if (fdate(picfile) > octreedate)
1154 >                pfdt = fdate(picfile);
1155 >                if (pfdt >= oct1date)
1156                          continue;
1157 +                                                /* get raw file name */
1158 +                sprintf(rawfile, "%s_%s.unf",
1159 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1160 +                rfdt = fdate(rawfile);
1161 +                if (touchonly) {                /* update times only */
1162 +                        if (rfdt) {
1163 +                                if (rfdt < oct1date)
1164 +                                        touch(rawfile);
1165 +                        } else if (pfdt && pfdt < oct1date)
1166 +                                touch(picfile);
1167 +                        continue;
1168 +                }
1169 +                if (next_process())             /* parallel running? */
1170 +                        continue;
1171 +                /* XXX Remember to call finish_process() */
1172                                                  /* build rpict command */
1173 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1174 <                if (fdate(rawfile) > octreedate)        /* recover */
1175 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1042 <                                        rep, opts, rawfile, vval(OCTREE));
1173 >                if (rfdt >= oct1date)           /* recover */
1174 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1175 >                                rep, po, opts, zopt, rawfile, oct1name);
1176                  else {
1177                          if (overture) {         /* run overture calculation */
1178                                  sprintf(combuf,
1179                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1180                                                  rep, vw, opts,
1181 <                                                vval(OCTREE), rawfile);
1181 >                                                oct1name, overfile);
1182                                  if (runcom(combuf)) {
1183                                          fprintf(stderr,
1184 <                        "%s: error in overture for view %s\n\t%s removed\n",
1185 <                                                progname, vs, rawfile);
1186 <                                        unlink(rawfile);
1054 <                                        exit(1);
1184 >                                        "%s: error in overture for view %s\n",
1185 >                                                progname, vs);
1186 >                                        quit(1);
1187                                  }
1188 + #ifndef NULL_DEVICE
1189 +                                rmfile(overfile);
1190 + #endif
1191                          }
1192 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1193 <                                        rep, vw, res, opts,
1194 <                                        vval(OCTREE), rawfile);
1192 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1193 >                                        rep, vw, res, po, opts, zopt,
1194 >                                        oct1name, rawfile);
1195                  }
1196                  if (runcom(combuf)) {           /* run rpict */
1197                          fprintf(stderr, "%s: error rendering view %s\n",
1198                                          progname, vs);
1199 <                        exit(1);
1199 >                        quit(1);
1200                  }
1201 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1202                                                  /* build pfilt command */
1203 <                if (mult > 1)
1204 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1203 >                        if (mult > 1)
1204 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1205                                          pfopts, mult, mult, rawfile, picfile);
1206 <                else
1207 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 <                                        rawfile, picfile);
1209 <                if (runcom(combuf)) {           /* run pfilt */
1210 <                        fprintf(stderr,
1211 <                        "%s: error filtering view %s\n\t%s removed\n",
1212 <                                        progname, vs, picfile);
1213 <                        unlink(picfile);
1214 <                        exit(1);
1206 >                        else
1207 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 >                                                rawfile, picfile);
1209 >                        if (runcom(combuf)) {           /* run pfilt */
1210 >                                fprintf(stderr,
1211 >                                "%s: error filtering view %s\n\t%s removed\n",
1212 >                                                progname, vs, picfile);
1213 >                                unlink(picfile);
1214 >                                quit(1);
1215 >                        }
1216                  }
1217 <                                                /* remove raw file */
1218 <                rmfile(rawfile);
1217 >                                                /* remove/rename raw file */
1218 >                if (vdef(RAWFILE)) {
1219 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1220 >                        mvfile(rawfile, combuf);
1221 >                } else
1222 >                        rmfile(rawfile);
1223 >                finish_process();               /* leave if child */
1224          }
1225 +        wait_process(1);                /* wait for children to finish */
1226   }
1227  
1228  
1229 + touch(fn)                       /* update a file */
1230 + char    *fn;
1231 + {
1232 +        if (!silent)
1233 +                printf("\ttouch %s\n", fn);
1234 +        if (!nprocs)
1235 +                return(0);
1236 + #ifdef notused
1237 +        if (access(fn, F_OK) == -1)             /* create it */
1238 +                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1239 +                        return(-1);
1240 + #endif
1241 +        return(setfdate(fn, time((time_t *)NULL)));
1242 + }
1243 +
1244 +
1245   runcom(cs)                      /* run command */
1246   char    *cs;
1247   {
1248          if (!silent)            /* echo it */
1249                  printf("\t%s\n", cs);
1250 <        if (noaction)
1250 >        if (!nprocs)
1251                  return(0);
1252          fflush(stdout);         /* flush output and pass to shell */
1253          return(system(cs));
# Line 1099 | Line 1258 | rmfile(fn)                     /* remove a file */
1258   char    *fn;
1259   {
1260          if (!silent)
1261 < #ifdef MSDOS
1261 > #ifdef _WIN32
1262                  printf("\tdel %s\n", fn);
1263   #else
1264                  printf("\trm -f %s\n", fn);
1265   #endif
1266 <        if (noaction)
1266 >        if (!nprocs)
1267                  return(0);
1268          return(unlink(fn));
1269   }
1270  
1271  
1272 + mvfile(fold, fnew)              /* move a file */
1273 + char    *fold, *fnew;
1274 + {
1275 +        if (!silent)
1276 + #ifdef _WIN32
1277 +                printf("\trename %s %s\n", fold, fnew);
1278 + #else
1279 +                printf("\tmv %s %s\n", fold, fnew);
1280 + #endif
1281 +        if (!nprocs)
1282 +                return(0);
1283 +        return(rename(fold, fnew));
1284 + }
1285 +
1286 +
1287 + #ifdef RHAS_FORK_EXEC
1288 + int
1289 + next_process()                  /* fork the next process (max. nprocs) */
1290 + {
1291 +        int     child_pid;
1292 +
1293 +        if (nprocs <= 1)
1294 +                return(0);              /* it's us or no one */
1295 +        if (children_running < 0) {
1296 +                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1297 +                                progname);
1298 +                quit(1);
1299 +        }
1300 +        if (children_running >= nprocs)
1301 +                wait_process(0);        /* wait for someone to finish */
1302 +        fflush(stdout);
1303 +        child_pid = fork();             /* split process */
1304 +        if (child_pid == 0) {           /* we're the child */
1305 +                children_running = -1;
1306 +                return(0);
1307 +        }
1308 +        if (child_pid > 0) {            /* we're the parent */
1309 +                ++children_running;
1310 +                return(1);
1311 +        }
1312 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1313 +        return(0);
1314 + }
1315 +
1316 + wait_process(all)                       /* wait for process(es) to finish */
1317 + int     all;
1318 + {
1319 +        int     ourstatus = 0;
1320 +        int     pid, status;
1321 +
1322 +        if (all)
1323 +                all = children_running;
1324 +        else if (children_running > 0)
1325 +                all = 1;
1326 +        while (all-- > 0) {
1327 +                pid = wait(&status);
1328 +                if (pid < 0)
1329 +                        syserr(progname);
1330 +                status = status>>8 & 0xff;
1331 +                --children_running;
1332 +                if (status != 0) {      /* child's problem is our problem */
1333 +                        if (ourstatus == 0 & children_running > 0)
1334 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1335 +                                                progname);
1336 +                        ourstatus = status;
1337 +                        all = children_running;
1338 +                }
1339 +        }
1340 +        if (ourstatus != 0)
1341 +                quit(ourstatus);        /* bad status from child */
1342 + }
1343 + #else   /* ! RHAS_FORK_EXEC */
1344 + int
1345 + next_process()
1346 + {
1347 +        return(0);                      /* cannot start new process */
1348 + }
1349 + wait_process(all)
1350 + int     all;
1351 + {
1352 +        (void)all;                      /* no one to wait for */
1353 + }
1354 + #endif  /* ! RHAS_FORK_EXEC */
1355 +
1356 + finish_process()                        /* exit a child process */
1357 + {
1358 +        if (children_running >= 0)
1359 +                return;                 /* in parent -- noop */
1360 +        exit(0);
1361 + }
1362 +
1363 + #ifdef _WIN32
1364 + setenv(vname, value)            /* set an environment variable */
1365 + char    *vname, *value;
1366 + {
1367 +        register char   *evp;
1368 +
1369 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1370 +        if (evp == NULL)
1371 +                syserr(progname);
1372 +        sprintf(evp, "%s=%s", vname, value);
1373 +        if (putenv(evp) != 0) {
1374 +                fprintf(stderr, "%s: out of environment space\n", progname);
1375 +                quit(1);
1376 +        }
1377 +        if (!silent)
1378 +                printf("set %s\n", evp);
1379 + }
1380 + #endif
1381 +
1382 +
1383   badvalue(vc)                    /* report bad variable value and exit */
1384   int     vc;
1385   {
1386          fprintf(stderr, "%s: bad value for variable '%s'\n",
1387                          progname, vnam(vc));
1388 <        exit(1);
1388 >        quit(1);
1389   }
1390  
1391  
# Line 1123 | Line 1393 | syserr(s)                      /* report a system error and exit */
1393   char    *s;
1394   {
1395          perror(s);
1396 <        exit(1);
1396 >        quit(1);
1397 > }
1398 >
1399 >
1400 > void
1401 > quit(ec)                        /* exit program */
1402 > int     ec;
1403 > {
1404 >        exit(ec);
1405   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines