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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines